2002/css-validator/org/w3c/css/selectors AdjacentSelector.java,NONE,1.1 AttributeSelector.java,NONE,1.1 ChildSelector.java,NONE,1.1 ClassSelector.java,NONE,1.1 DescendantSelector.java,NONE,1.1 IdSelector.java,NONE,1.1 PseudoClassSelector.java,NONE,1.1 PseudoElementSelector.java,NONE,1.1 PseudoFactory.java,NONE,1.1 PseudoFunctionSelector.java,NONE,1.1 Selector.java,NONE,1.1 SelectorsList.java,NONE,1.1 TypeSelector.java,NONE,1.1 UniversalSelector.java,NONE,1.1

Update of /sources/public/2002/css-validator/org/w3c/css/selectors
In directory hutz:/tmp/cvs-serv8236/org/w3c/css/selectors

Added Files:
	AdjacentSelector.java AttributeSelector.java 
	ChildSelector.java ClassSelector.java DescendantSelector.java 
	IdSelector.java PseudoClassSelector.java 
	PseudoElementSelector.java PseudoFactory.java 
	PseudoFunctionSelector.java Selector.java SelectorsList.java 
	TypeSelector.java UniversalSelector.java 
Log Message:
Changes from Jean-Guilhem Rouel
Bug fixed: 1174 845 160 766
See
http://www.w3.org/Bugs/Public/show_bug.cgi?id=1174
http://www.w3.org/Bugs/Public/show_bug.cgi?id=845
http://www.w3.org/Bugs/Public/show_bug.cgi?id=160
http://www.w3.org/Bugs/Public/show_bug.cgi?id=766

The handling of selectors has been redone almost entirely.

Also, changelog in files has been removed.



--- NEW FILE: UniversalSelector.java ---
// $Id: UniversalSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * Universal<br />
 * Created: Sep 1, 2005 3:45:13 PM<br />
 */
public class UniversalSelector implements Selector {        
    
    /**
     * @see Selector#toString()
     */
    public String toString() {
	return "*"; 
    }
    
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
	return "*";
    }
    
}

--- NEW FILE: SelectorsList.java ---
// $Id: SelectorsList.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

import java.util.ArrayList;

import org.w3c.css.selectors.attributes.AttributeAny;
import org.w3c.css.selectors.attributes.AttributeBegin;
import org.w3c.css.selectors.attributes.AttributeExact;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;

/**
 * SelectorsList<br />
 * A class to manage a list of selectors. The following selectors exists:
 * <ul>
 * <li>Universal: *</li>
 * <li>Type: E</li>
 * <li>Descendant: E F</li>
 * <li>Child: E > F</li>
 * <li>Adjacent: E + F</li>
 * <li>Attribute:
 *   <ul>
 *   <li>Any: E[foo]</li>
 *   <li>Begin: E[lang|=en]</li>
 *   <li>Exact: E[lang=en]</li>
 *   <li>One Of: E[lang~=en]</li>
 *   <li>Start: E[foo^=bar]</li>
 *   <li>Substring: E[foo*=bar]</li>
 *   <li>Suffix: E[foo$=bar]</li>
 *   </ul></li>
 * <li>ID: E#myid</li>
 * <li>Class: E.myclass</li>
 * <li>Pseudo-class: E:first-child, ...</li>
 * <li>Pseudo-element: E:first-line, ...</li>
 * <li>Pseudo-function:
 *   <ul>
 *   <li>contains</li>
 *   <li>lang</li>
 *   <li>not</li>
 *   <li>nth-child</li>
 *   <li>nth-last-child</li>
 *   <li>nth-of-type</li>
 *   <li>nth-last-of-type</li>
 *   <li>...</li>
 *   </ul></li>
 * </ul>
 *
 * Created: Sep 1, 2005 3:34:47 PM<br />
 */
public class SelectorsList {

    // the list of selectors
    private ArrayList selectors;
        
    private ApplContext ac;

    private int specificity;

    /**
     * Creates a new empty SelectorsList     
     */
    public SelectorsList() {
	selectors = new ArrayList();
    }
    
    /**
     * Creates a new SelectorsList given an context
     * @param ac the context in which the selectors appear
     */
    public SelectorsList(ApplContext ac) {
	this.ac = ac;
	selectors = new ArrayList();
    }
 
    /**
     * Returns the selectors list
     * @return Returns the selectors list.
     */
    public ArrayList getSelectors() {
        return selectors;
    }

    /**
     * Sets the selectors list
     * @param selectors The selectors list to set.
     */
    public void setSelectors(ArrayList selectors) {
        this.selectors = selectors;
    }

    /**
     * Return the nth selector in this SelectorsList 
     * @param index the index of the selector to retreive
     * @return the nth selector
     */
    public Selector getSelector(int index) {
	return (Selector) selectors.get(index);
    }
    
    /**
     * The number of selectors in this SelectorsList
     * @return the number of selectors in this SelectorsList
     */
    public int size() {
	return selectors.size();
    }
    
    /**
     * Adds a selector to this SelectorsList
     * @param selector the selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addSelector(Selector selector) throws InvalidParamException {
	if(selectors.size() > 0) {
	    Selector last = (Selector) selectors.get(selectors.size() - 1);	    
	    if(last instanceof PseudoElementSelector) {
		throw new InvalidParamException("pseudo-element", selector, ac);
	    }
	}
	selectors.add(selector);
    }
    
    /**
     * Adds an attribute selector 
     * @param attribute the attribute selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addAttribute(AttributeSelector attribute) 
    throws InvalidParamException {
	addSelector(attribute);
    }
    
    /**
     * Adds an universal selector 
     * @param universal the universal selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addUniversal(UniversalSelector universal) 
    throws InvalidParamException {
	addSelector(universal);
    }
    
    /**
     * Adds a type selector 
     * @param type the type selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addType(TypeSelector type) throws InvalidParamException {
	addSelector(type);
    }
    
    /**
     * Adds a descendant selector 
     * @param descendant the descendant selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addDescendant(DescendantSelector descendant) 
    throws InvalidParamException {
	addSelector(descendant);
    }
    
    /**
     * Adds a child selector 
     * @param child the child selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addChild(ChildSelector child) throws InvalidParamException {
	addSelector(child);
    }
    
    /**
     * Adds a pseudo-class selector 
     * @param pc the pseudo-class to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addPseudoClass(PseudoClassSelector pc) 
    throws InvalidParamException {
	addSelector(pc);
    }
    
    /**
     * Adds a pseudo-element selector
     * No other selector can be added after a pseudo-element 
     * @param pe the pseudo-element to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addPseudoElement(PseudoElementSelector pe) 
    throws InvalidParamException {
	addSelector(pe);
    }
    
    /**
     * Adds a pseudo-function selector 
     * @param pf the pseudo-function to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addPseudoFunction(PseudoFunctionSelector pf) 
    throws InvalidParamException {
	addSelector(pf);
    }
    
    /**
     * Adds an adjacent selector 
     * @param adjacent the adjacent selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addAdjacent(AdjacentSelector adjacent) 
    throws InvalidParamException {
	addSelector(adjacent);
    }
    
    /**
     * Adds a class selector 
     * @param cs the class selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addClass(ClassSelector cs) throws InvalidParamException {
	addSelector(cs);
    }
    
    /**
     * Adds an id selector 
     * @param id the id selector to add
     * @throws InvalidParamException when trying to add a selector after a pseudo-element
     */
    public void addId(IdSelector id) throws InvalidParamException {
	addSelector(id);
    }        
        
    /**
     * Returns a String representation of this SelectorsList
     * @return  the String representation of this SelectorsList
     */
    public String toString() {
	StringBuffer res = new StringBuffer();
	for(int i = 0; i < selectors.size(); i++) {
	    res.append(selectors.get(i));
	}
	return res.toString();
    }
    
    /**
     * Sets the specificity of this SelectorsList
     * @param specificity the specificity yo set
     */
    public void setSpecificity(int specificity) {
	this.specificity = specificity;
    }
    
    /**
     * Gets (and computes) the specificity of this selector.
     */
    public int getSpecificity() {	
	int a = 0;
	int b = 0;
	int c = 0;
	
	for(int i = 0; i < size(); i++) {
	    Selector s = getSelector(i);
	    if(s instanceof IdSelector) {
		a++;
	    }
	    else if(s instanceof ClassSelector ||
		    s instanceof PseudoClassSelector) {
		b++;
	    }
	    else if(s instanceof TypeSelector ||
		    s instanceof AttributeSelector) {
		c++;
	    }
	    // some pseudo-functions might influence the specificity
	    else if(s instanceof PseudoFunctionSelector) {
		specificity += ((PseudoFunctionSelector)s).getSpecificity();
	    }
	}
	specificity += a * 100 + b * 10 + c;
	
	return specificity;	
    }
    
    /**
     * Testing method
     * @param args unused
     */
    public static void main(String[] args) {
	SelectorsList s = new SelectorsList();
	try {
	    s.addType(new TypeSelector("E"));
	    s.addAttribute(new AttributeExact("foo", "warning"));
	    s.addChild(new ChildSelector());
	    s.addType(new TypeSelector("F"));
	    s.addAttribute(new AttributeBegin("lang", "en"));
	    s.addAttribute(new AttributeAny("bar"));
	    s.addAdjacent(new AdjacentSelector());	    
	    s.addType(new TypeSelector("G"));
	    s.addId(new IdSelector("id"));
	    s.addAttribute(new AttributeAny("blop"));
	    s.addDescendant(new DescendantSelector());
	    s.addType(new TypeSelector("H"));
	    
	    System.out.println(s);
	}
	catch(InvalidParamException e) {
	    System.err.println(e.getMessage());
	}
    }
    
}

--- NEW FILE: AttributeSelector.java ---
// $Id: AttributeSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

import org.w3c.css.util.ApplContext;

/**
 * Attribute<br />
 * Created: Sep 1, 2005 3:39:15 PM<br />
 */
public abstract class AttributeSelector implements Selector {

    private String name;

    /**
     * Creates a new empty attribute selector     
     */
    public AttributeSelector() {
    }
    
    /**
     * Creates a new attribute selector given its name
     * @param name the name of this attribute
     */
    public AttributeSelector(String name) {
	this.name = name;
    }
    
    /**
     * Sets the name of this attribute selector
     * @param name the name of this attribute
     */
    public void setName(String name) {
	this.name = name;	
    }

    /**
     * @see Selector#getName()
     */
    public String getName() {
	return name;
    }
    
    public abstract void applyAttribute(ApplContext ac, AttributeSelector attr);
    
    /**
     * @see Selector#toString()
     */
    public String toString() {
	return "[" + name + "]";
    }
    
}

--- NEW FILE: ClassSelector.java ---
// $Id: ClassSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * ClassSelector<br />
 * Created: Sep 1, 2005 3:59:42 PM<br />
 */
public class ClassSelector implements Selector {
    
    String name;
    
    /**
     * Creates a new class selector given its name
     * @param name the name of this class selector
     */
    public ClassSelector(String name) {
	this.name = name;
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of this class selector
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @see Selector#toString()
     */
    public String toString() {
	return "." + name;
    }
    
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
}

--- NEW FILE: TypeSelector.java ---
// $Id: TypeSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * Type<br />
 * Created: Sep 1, 2005 3:57:05 PM<br />
 */
public class TypeSelector implements Selector {

    String name;
    
    /**
     * Creates a new TypeSelector which name name is type
     * @param type the name of this type selector
     */
    public TypeSelector(String type) {
	this.name = type;
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of this selector
     * @param type The name to set.
     */
    public void setName(String type) {
        this.name = type;
    }

    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
    /**
     * @see Selector#toString()
     */
    public String toString() {
	return name;
    }
    
}

--- NEW FILE: AdjacentSelector.java ---
// $Id: AdjacentSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * Adjacent<br />
 * Created: Sep 1, 2005 3:59:08 PM<br />
 */
public class AdjacentSelector implements Selector {

    /**
     * @see Selector#toString()
     */
    public String toString() {
	return " + ";
    }

    /**
     * @see Selector#getName()
     */
    public String getName() {
	return "+";
    }
   
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
}

--- NEW FILE: PseudoClassSelector.java ---
// $Id: PseudoClassSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * PseudoClass<br />
 * Created: Sep 1, 2005 3:58:43 PM<br />
 */
public class PseudoClassSelector implements Selector {

    String name;
    
    /**
     * Creates a new pseudo-class given its name
     * @param name the name of this pseudo-class
     */
    public PseudoClassSelector(String name) {
	this.name = name;
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of this pseudo-class
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @see Selector#toString()
     */
    public String toString() {
	return ":" + name;
    }
    
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
}

--- NEW FILE: ChildSelector.java ---
// $Id: ChildSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * Child<br />
 * Created: Sep 1, 2005 3:58:00 PM<br />
 */
public class ChildSelector implements Selector {

    /**
     * @see Selector#toString()
     */
    public String toString() {
	return " > ";
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
	return ">";
    }
    
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
}

--- NEW FILE: PseudoElementSelector.java ---
// $Id: PseudoElementSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * PseudoElement<br />
 * Created: Sep 1, 2005 3:54:07 PM<br />
 */
public class PseudoElementSelector implements Selector {

    String name;
    
    /**
     * Creates a new pseudo-element given it's name
     * @param name the name of this pseudo-element
     */
    public PseudoElementSelector(String name) {
	this.name = name;
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of this pseudo-element
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @see Selector#toString()
     */
    public String toString() {
	return ":" + name;
    }
    
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
}

--- NEW FILE: PseudoFunctionSelector.java ---
// $Id: PseudoFunctionSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * PseudoFunction<br />
 * Created: Sep 2, 2005 4:04:45 PM<br />
 */
public class PseudoFunctionSelector implements Selector {

    private String name;
    private Object param;

    /**
     * Creates a new empty function selector     
     */
    public PseudoFunctionSelector() {
	
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of this pseudo-function
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Returns the parameter of this pseudo-function.
     * @return the parameter of this pseudo-function.
     */
    public Object getParam() {
        return param;
    }

    /**
     * Sets the parameter of this pseudo-function
     * @param param The param to set.
     */
    public void setParam(Object param) {
        this.param = param;
    }

    /**
     * Returns the specifictiy of this pseudo-function
     * @return
     */
    public int getSpecificity() {
	return 0;
    }
    
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
    /**
     * @see Selector#toString()
     */
    public String toString() {
	return ":" + name + "(" + param + ")";
    }    
}

--- NEW FILE: PseudoFactory.java ---
// $Id: PseudoFactory.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * PseudoFactory<br />
 * Created: Sep 2, 2005 2:41:09 PM<br />
 */
public class PseudoFactory {

    private static final String[] PSEUDOCLASS_CONSTANTSCSS3 =
    { "link", "visited", "active", "focus", "target",
	"hover", "first-child", "enabled", "disabled",
	"checked", "indeterminate", "root", "last-child",
	"first-of-type", "last-of-type", "only-of-type",
	"only-child", "empty", "valid", "invalid", "required",
	"optional", "read-only", "read-write",
	"default", "in-range", "out-of-range"
    };
    
    private static final String[] PSEUDOCLASS_CONSTANTSCSS2 =
    {
	"link", "visited", "active", "target", "focus",
	"hover", "first-child"
    };
    
    private static final String[] PSEUDOCLASS_CONSTANTSTV =
    {
	"link", "visited", "active", "focus", "first-child"
    };
    
    private static final String[] PSEUDOCLASS_CONSTANTSCSS1 =
    {
	"link", "visited", "active", "target"
    };
    
    private static final String[] PSEUDOCLASS_CONSTANTS_MOBILE =
    {
	"link", "visited", "active", "focus"
    };
    
    private static final String[] PSEUDOELEMENT_CONSTANTSCSS3 =
    { 
	"first-line", "first-letter", "before", "after",
	"selection", "marker", "value", "choices", "repeat-item", 
	"repeat-index"
    };

    private static final String[] PSEUDOELEMENT_CONSTANTSCSS2 =
    { 
	"first-line", "first-letter", "before", "after"
    };
    
    private static final String[] PSEUDOELEMENT_CONSTANTSCSS1 =
    {
	"first-line", "first-letter"
    };
    
    private static final String[] PSEUDOFUNCTION_CONSTANTSCSS3 = 
    {
	"nth-child", "nth-last-child", "nth-of-type", "nth-last-of-type",
	"lang", "contains", "not"
    };
    
    private static final String[] PSEUDOFUNCTION_CONSTANTSCSS2 = 
    {
	"lang"
    };
    
    /**
     * Returns the possible pseudo-classes for a profile
     * @param profile the profile to get associated pseudo-classes
     * @return the possible pseudo-classes for the profile
     */
    public static String[] getPseudoClass(String profile) {
	if(profile == null || profile.equals("css2")) {
	    return PSEUDOCLASS_CONSTANTSCSS2;
	}
	if(profile.equals("css1")) {
	    return PSEUDOCLASS_CONSTANTSCSS1;
	}
	if(profile.equals("css3")) {
	    return PSEUDOCLASS_CONSTANTSCSS3;
	}
	if(profile.equals("tv")) {
	    return PSEUDOCLASS_CONSTANTSTV;
	}
	if(profile.equals("mobile")) {
	    return PSEUDOCLASS_CONSTANTS_MOBILE;
	}
	return null;
    }
    
    /**
     * Returns the possible pseudo-elements for a profile
     * @param profile the profile to get associated pseudo-elements
     * @return the possible pseudo-elements for the profile
     */
    public static String[] getPseudoElement(String profile) {
	if(profile == null || profile.equals("css2") || profile.equals("tv")) {
	    return PSEUDOELEMENT_CONSTANTSCSS2;
	}
	if(profile.equals("css1")) {
	    return PSEUDOELEMENT_CONSTANTSCSS1;
	}
	if(profile.equals("css3")) {
	    return PSEUDOELEMENT_CONSTANTSCSS3;
	}
	return null;
    }
    
    /**
     * Returns the possible pseudo-functions for a profile
     * @param profile the profile to get associated pseudo-functions
     * @return the possible pseudo-functions for the profile
     */
    public static String[] getPseudoFunction(String profile) {
	if(profile == null || profile.equals("css2") ||
		profile.equals("mobile") || profile.equals("tv")) {
	    return PSEUDOFUNCTION_CONSTANTSCSS2;
	}
	if(profile.equals("css3")) {
	    return PSEUDOFUNCTION_CONSTANTSCSS3;
	}
	return null;
    }
    
}

--- NEW FILE: IdSelector.java ---
// $Id: IdSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * IdSelector<br />
 * Created: Sep 1, 2005 4:45:00 PM<br />
 */
public class IdSelector implements Selector {

    String name;
    
    /**
     * Creates a new id selector given its name
     * @param name
     */
    public IdSelector(String name) {
	this.name = name;
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of this id selector
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @see Selector#toString()
     */
    public String toString() {
	return "#" + name;
    }
    
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
}

--- NEW FILE: Selector.java ---
// $Id: Selector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * Selector<br />
 * Basic class for all the selectors
 * Created: Sep 1, 2005 3:31:35 PM<br />
 */
public interface Selector {  
    
    /**
     * Returns a String representation of this Selector
     * @return  the String representation of this Selector
     */
    public String toString();
    
    /**
     * Returns the name of this selector
     * @return
     */
    public String getName();
    
    /**
     * Returns <code>true</code> if a selector can be applied to this selector
     * @param other
     * @return
     */
    public boolean canApply(Selector other);
}

--- NEW FILE: DescendantSelector.java ---
// $Id: DescendantSelector.java,v 1.1 2005/09/08 12:24:01 ylafon Exp $
// Author: Jean-Guilhem Rouel
// (c) COPYRIGHT MIT, ERCIM and Keio, 2005.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.selectors;

/**
 * Descendant<br />
 * Created: Sep 1, 2005 3:57:40 PM<br />
 */
public class DescendantSelector implements Selector {

    /**
     * @see Selector#toString()
     */
    public String toString() {
	return " ";
    }
    
    /**
     * @see Selector#getName()
     */
    public String getName() {
	return " ";
    }
    
    /**
     * @see Selector#canApply(Selector)
     */
    public boolean canApply(Selector other) {
	return false;
    }
    
}

Received on Thursday, 8 September 2005 12:24:11 UTC