All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.vutbr.web.csskit.MatchConditionImpl Maven / Gradle / Ivy

Go to download

jStyleParser is a CSS parser written in Java. It has its own application interface that is designed to allow an efficient CSS processing in Java and mapping the values to the Java data types. It parses CSS 2.1 style sheets into structures that can be efficiently assigned to DOM elements. It is intended be the primary CSS parser for the CSSBox library. While handling errors, it is user agent conforming according to the CSS specification.

The newest version!
/**
 * MatchConditionImpl.java
 *
 * Created on 1.7.2013, 11:06:40 by burgetr
 */
package cz.vutbr.web.csskit;

import org.w3c.dom.Element;

import cz.vutbr.web.css.MatchCondition;
import cz.vutbr.web.css.Selector.PseudoClass;
import cz.vutbr.web.css.Selector.PseudoClassType;
import cz.vutbr.web.css.Selector.SelectorPart;

/**
 * A default match condition that matches the LINK (or other) pseudo classes to link elements.
 * 
 * @author burgetr
 */
public class MatchConditionImpl implements MatchCondition
{
    PseudoClassType pseudo;
    
    /**
     * Creates the default condition that matches the LINK pseudo class to links.
     */
    public MatchConditionImpl()
    {
        pseudo = PseudoClassType.LINK;
    }
    
    /**
     * Creates the default condition that matches the given pseudo class to links.
     * @param pseudoClass the pseudoClass to be matched to links
     */
    public MatchConditionImpl(PseudoClassType pseudoClass)
    {
        this.pseudo = pseudoClass;
    }
    
    /**
     * Sets the pseudo class that is matched to links.
     * @param pseudoClass the pseudoClass to be matched to links
     */
    public void setPseudoClass(PseudoClassType pseudoClass)
    {
        this.pseudo = pseudoClass;
    }
    
    public boolean isSatisfied(Element e, SelectorPart selpart)
    {
        if (selpart instanceof PseudoClass)
        {
            PseudoClassType type = ((PseudoClass) selpart).getType();
            return type == pseudo && e.getTagName().equalsIgnoreCase("a");
        }
        else
            return false;
    }
    
    @Override
    public Object clone() {
    	return new MatchConditionImpl(pseudo);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy