2002/css-validator/org/w3c/css/media/css3 AtRuleMedia.java,NONE,1.1 MediaAspectRatio.java,NONE,1.1 MediaColor.java,NONE,1.1 MediaColorIndex.java,NONE,1.1 MediaDeviceAspectRatio.java,NONE,1.1 MediaDeviceHeight.java,NONE,1.1 MediaDeviceWidth.java,NONE,1.1 MediaGrid.java,NONE,1.1 MediaHeight.java,NONE,1.1 MediaMonochrome.java,NONE,1.1 MediaOrientation.java,NONE,1.1 MediaResolution.java,NONE,1.1 MediaScan.java,NONE,1.1 MediaWidth.java,NONE,1.1

Update of /sources/public/2002/css-validator/org/w3c/css/media/css3
In directory hutz:/tmp/cvs-serv28700/org/w3c/css/media/css3

Added Files:
	AtRuleMedia.java MediaAspectRatio.java MediaColor.java 
	MediaColorIndex.java MediaDeviceAspectRatio.java 
	MediaDeviceHeight.java MediaDeviceWidth.java MediaGrid.java 
	MediaHeight.java MediaMonochrome.java MediaOrientation.java 
	MediaResolution.java MediaScan.java MediaWidth.java 
Log Message:
redone the Media Features of media queries, up to date per http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/, todo, parsing of media in HTML form

--- NEW FILE: MediaDeviceAspectRatio.java ---
// $Id: MediaDeviceAspectRatio.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssOperator;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#device-aspect-ratio
 */
public class MediaDeviceAspectRatio extends MediaFeature {

    int h, w;

    /**
     * Create a new MediaHeight
     */
    public MediaDeviceAspectRatio() {
    }

    /**
     * Create a new MediaHeight.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaDeviceAspectRatio(ApplContext ac, String modifier,
                                  CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() != 2) {
                throw new InvalidParamException("unrecognize", ac);
            }
            CssValue val = expression.getValue();

            if (val.getType() == CssTypes.CSS_NUMBER) {
                CssNumber valnum = (CssNumber) val;
                if (!valnum.isInteger()) {
                    throw new InvalidParamException("integer",
                            val.toString(), ac);
                }
                w = valnum.getInt();
                // TODO FIXME this should be replaced when / is no longer
                // an operator
                if (expression.getOperator() != CssOperator.SLASH) {
                    throw new InvalidParamException("operator", expression.toString(), ac);
                }
                // now the second value
                expression.next();
                val = expression.getValue();
                if (val.getType() == CssTypes.CSS_NUMBER) {
                    valnum = (CssNumber) val;
                    if (!valnum.isInteger()) {
                        throw new InvalidParamException("integer",
                                val.toString(), ac);
                    }
                    h = valnum.getInt();
                    // perfect, now set the modifier
                    setModifier(ac, modifier);
                    return;
                }
            }
            // otherwise... fail
            throw new InvalidParamException("value", expression.getValue(),
                    getFeatureName(), ac);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaDeviceAspectRatio(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        StringBuilder sb = new StringBuilder();
        sb.append(w).append('/').append(h);
        return sb.toString();
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "device-aspect-ratio";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaDeviceAspectRatio mar = (MediaDeviceAspectRatio) other;
            if (h == 0 || mar.h == 0) {
                return (w == 0 && mar.w == 0 && h == 0 && mar.h == 0);
            }
            float thisRatio = ((float) w) / ((float) h);
            float otherRatio = ((float) mar.w) / ((float) mar.h);

            return (thisRatio == otherRatio)
                    && (((modifier == null) && (mar.modifier == null)) || ((modifier != null) && modifier.equals(mar.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }
    }

    /**
     * Returns a string representation of the object.
     */
    public String toString() {
        if (h == 0 && w == 0) {
            return getFeatureName();
        }
        StringBuilder sb = new StringBuilder();
        if (modifier != null) {
            sb.append(modifier).append('-');
        }
        sb.append(getFeatureName());
        sb.append(':').append(w).append('/').append(h);
        return sb.toString();
    }
}

--- NEW FILE: MediaWidth.java ---
// $Id: MediaWidth.java,v 1.1 2011/10/21 01:49:08 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssLength;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#width
 */
public class MediaWidth extends MediaFeature {

    /**
     * Create a new MediaWidth
     */
    public MediaWidth() {
    }

    /**
     * Create a new MediaWidth.
     *
     * @param expression The expression for this media feature
     * @throws InvalidParamException Values are incorrect
     */
    public MediaWidth(ApplContext ac, String modifier,
                      CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (check && expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }

            CssValue val = expression.getValue();

            switch (val.getType()) {
                case CssTypes.CSS_NUMBER:
                    // a bit stupid as the only value would be 0...
                    val = ((CssNumber) val).getLength();
                case CssTypes.CSS_LENGTH:
                    CssLength l = (CssLength) val;
                    if (l.floatValue() < 0.f) {
                        throw new InvalidParamException("negative-value",
                                val.toString(), ac);
                    }
                    value = val;
                    expression.next();
                    break;
                default:
                    throw new InvalidParamException("value", expression.getValue(),
                            getFeatureName(), ac);
            }
            setModifier(ac, modifier);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaWidth(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "width";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaWidth mw = (MediaWidth) other;
            return (((value == null) && (mw.value == null)) || ((value != null) && value.equals(mw.value)))
                    && (((modifier == null) && (mw.modifier == null)) || ((modifier != null) && modifier.equals(mw.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: AtRuleMedia.java ---
// $Id: AtRuleMedia.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ERCIM and Keio University
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.Media;
import org.w3c.css.media.MediaFeature;
import org.w3c.css.parser.AtRule;
import org.w3c.css.parser.CssError;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;

import java.util.ArrayList;

/**
 * @spec TODO
 */

public class AtRuleMedia extends org.w3c.css.media.AtRuleMedia {
    static final String[] mediaCSS21 = {
            "all", "braille", "embossed", "handheld", "print", "projection",
            "screen", "speech", "tty", "tv"
    };

    static final String[] deprecatedMedia = {
            "aural"
    };

    /**
     * Adds a medium.
     *
     * @throws InvalidParamException the medium doesn't exist
     */
    public org.w3c.css.media.AtRuleMedia addMedia(String restrictor, String medium,
                                                  ApplContext ac) throws InvalidParamException {
        Media media = new Media();
        if (restrictor != null) {
            if ("not".equalsIgnoreCase(restrictor)) {
                media.setNot(true);
            } else if ("only".equalsIgnoreCase(restrictor)) {
                media.setOnly(true);
            }
        }
        if (medium == null) {
            allMedia.add(media);
            return this;
        }
        medium = medium.toLowerCase();
        for (String s : mediaCSS21) {
            if (medium.equals(s)) {
                media.setMedia(s);
                allMedia.add(media);
                return this;
            }
        }
        for (String s : deprecatedMedia) {
            if (medium.equals(s)) {
                InvalidParamException ipe = new InvalidParamException("deprecatedmedia", medium, ac);
                ac.getFrame().addError(new CssError(ipe));
                media.setMedia(s);
                allMedia.add(media);
                return this;
            }
        }
        // FIXME we can check if media exists in other CSS versions
        throw new InvalidParamException("media", medium, ac);
    }

    /**
     *
     * @param feature
     * @param ac
     * @throws InvalidParamException
     */
    public void addMediaFeature(MediaFeature feature, ApplContext ac)
            throws InvalidParamException {
        Media latest = allMedia.get(allMedia.size()-1);
        latest.addFeature(feature);
    }

    /**
     * The second must be exactly the same as this one
     * so we check that each one match each other
     */
    public boolean canApply(AtRule atRule) {
        try {
            org.w3c.css.media.AtRuleMedia second = (org.w3c.css.media.AtRuleMedia) atRule;
            return (canMatch(second) && second.canMatch(this));
        } catch (ClassCastException cce) {
            return false;
        }
    }

    /**
     * The second must only match this one
     */
    public boolean canMatch(AtRule atRule) {
        try {
            org.w3c.css.media.AtRuleMedia second = (org.w3c.css.media.AtRuleMedia) atRule;
            ArrayList<Media> otherMediaList = second.getMediaList();

            for (Media m : otherMediaList) {
                if (!allMedia.contains(m)) {
                    return false;
                }
            }
            return true;
        } catch (ClassCastException cce) {
            return false;
        }
    }

    public String getValueString() {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (Media m : allMedia) {
            if (first) {
                first = false;
            } else {
                sb.append(", ");
            }
            sb.append(m.toString());
        }
        return sb.toString();
    }

    /**
     * Returns a string representation of the object.
     */
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append('@').append(keyword()).append(' ');
        sb.append(getValueString());
        return sb.toString();
    }
}


--- NEW FILE: MediaResolution.java ---
// $Id: MediaResolution.java,v 1.1 2011/10/21 01:49:08 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssResolution;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#resolution
 */
public class MediaResolution extends MediaFeature {

    /**
     * Create a new MediaResolution
     */
    public MediaResolution() {
    }

    /**
     * Create a new MediaResolution
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaResolution(ApplContext ac, String modifier,
                           CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }
            CssValue val = expression.getValue();
            // it must be a >=0 integer only
            if (val.getType() == CssTypes.CSS_RESOLUTION) {
                CssResolution valnum = (CssResolution) val;

                if (valnum.getFloatValue() < 0.f) {
                    throw new InvalidParamException("negative-value",
                                val.toString(), ac);
                }
                value = valnum;
            } else {
                throw new InvalidParamException("unrecognize", ac);
            }
            setModifier(ac, modifier);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaResolution(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "resolution";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaResolution mr = (MediaResolution) other;
            return (((value == null) && (mr.value == null)) || ((value != null) && value.equals(mr.value)))
                    && (((modifier == null) && (mr.modifier == null)) || ((modifier != null) && modifier.equals(mr.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaDeviceHeight.java ---
// $Id: MediaDeviceHeight.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssLength;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#device-height
 */
public class MediaDeviceHeight extends MediaFeature {

    /**
     * Create a new MediaHeight
     */
    public MediaDeviceHeight() {
    }

    /**
     * Create a new MediaHeight.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaDeviceHeight(ApplContext ac, String modifier,
                             CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }

            CssValue val = expression.getValue();

            switch (val.getType()) {
                case CssTypes.CSS_NUMBER:
                    // a bit stupid as the only value would be 0...
                    val = ((CssNumber) val).getLength();
                case CssTypes.CSS_LENGTH:
                    CssLength l = (CssLength) val;
                    if (l.floatValue() < 0.f) {
                        throw new InvalidParamException("negative-value",
                                val.toString(), ac);
                    }
                    value = val;
                    expression.next();
                    break;
                default:
                    throw new InvalidParamException("value", expression.getValue(),
                            getFeatureName(), ac);
            }
            setModifier(ac, modifier);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaDeviceHeight(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }


    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "device-height";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaDeviceHeight mdh = (MediaDeviceHeight) other;
            return (((value == null) && (mdh.value == null)) || ((value != null) && value.equals(mdh.value)))
                    && (((modifier == null) && (mdh.modifier == null)) || ((modifier != null) && modifier.equals(mdh.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaHeight.java ---
// $Id: MediaHeight.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssLength;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#height
 */
public class MediaHeight extends MediaFeature {

    /**
     * Create a new MediaHeight
     */
    public MediaHeight() {
    }

    /**
     * Create a new MediaHeight.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaHeight(ApplContext ac, String modifier,
                       CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }
            CssValue val = expression.getValue();

            switch (val.getType()) {
                case CssTypes.CSS_NUMBER:
                    // a bit stupid as the only value would be 0...
                    val = ((CssNumber) val).getLength();
                case CssTypes.CSS_LENGTH:
                    CssLength l = (CssLength) val;
                    if (l.floatValue() < 0.f) {
                        throw new InvalidParamException("negative-value",
                                val.toString(), ac);
                    }
                    value = val;
                    expression.next();
                    break;
                default:
                    throw new InvalidParamException("value", expression.getValue(),
                            getFeatureName(), ac);
            }
            setModifier(ac, modifier);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaHeight(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "height";
    }

   /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaHeight mh = (MediaHeight) other;
            return (((value == null) && (mh.value == null)) || ((value != null) && value.equals(mh.value)))
                    && (((modifier == null) && (mh.modifier == null)) || ((modifier != null) && modifier.equals(mh.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaColor.java ---
// $Id: MediaColor.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#color
 */
public class MediaColor extends MediaFeature {

    /**
     * Create a new MediaColor
     */
    public MediaColor() {
    }

    /**
     * Create a new MediaColor.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaColor(ApplContext ac, String modifier,
                      CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }
            CssValue val = expression.getValue();
            // it must be a >=0 integer only
            if (val.getType() == CssTypes.CSS_NUMBER) {
                CssNumber valnum = (CssNumber) val;
                if (!valnum.isInteger()) {
                    throw new InvalidParamException("integer",
                            val.toString(), ac);
                }
                if (valnum.getInt() < 0) {
                    throw new InvalidParamException("negative-value",
                                val.toString(), ac);
                }
                value = valnum;
            } else {
                throw new InvalidParamException("unrecognize", ac);
            }
            setModifier(ac, modifier);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaColor(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "color";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaColor mh = (MediaColor) other;
            return (((value == null) && (mh.value == null)) || ((value != null) && value.equals(mh.value)))
                    && (((modifier == null) && (mh.modifier == null)) || ((modifier != null) && modifier.equals(mh.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaMonochrome.java ---
// $Id: MediaMonochrome.java,v 1.1 2011/10/21 01:49:08 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#monochrome
 */
public class MediaMonochrome extends MediaFeature {

    /**
     * Create a new MediaMonochrome
     */
    public MediaMonochrome() {
    }

    /**
     * Create a new MediaMonochrome.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaMonochrome(ApplContext ac, String modifier,
                           CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }
            CssValue val = expression.getValue();
            // it must be a >=0 integer only
            if (val.getType() == CssTypes.CSS_NUMBER) {
                CssNumber valnum = (CssNumber) val;
                if (!valnum.isInteger()) {
                    throw new InvalidParamException("integer",
                            val.toString(), ac);
                }
                if (valnum.getInt() < 0) {
                    throw new InvalidParamException("negative-value",
                                val.toString(), ac);
                }
                value = valnum;
            } else {
                throw new InvalidParamException("unrecognize", ac);
            }
            setModifier(ac, modifier);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaMonochrome(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "monochrome";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaMonochrome mm = (MediaMonochrome) other;
            return (((value == null) && (mm.value == null)) || ((value != null) && value.equals(mm.value)))
                    && (((modifier == null) && (mm.modifier == null)) || ((modifier != null) && modifier.equals(mm.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaGrid.java ---
// $Id: MediaGrid.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#grid
 */
public class MediaGrid extends MediaFeature {

    /**
     * Create a new MediaGrid
     */
    public MediaGrid() {
    }

    /**
     * Create a new MediaGrid.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaGrid(ApplContext ac, String modifier,
                     CssExpression expression, boolean check)
            throws InvalidParamException {

        if (modifier != null) {
            throw new InvalidParamException("nomodifiermedia",
                    getFeatureName(), ac);
        }

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }

            CssValue val = expression.getValue();
            // it must be a >=0 integer only
            if (val.getType() == CssTypes.CSS_NUMBER) {
                CssNumber valnum = (CssNumber) val;
                if (!valnum.isInteger()) {
                    throw new InvalidParamException("integer",
                            val.toString(), ac);
                }
                int gridval = valnum.getInt();
                if (gridval != 0 && gridval != 1) {
                    throw new InvalidParamException("grid",
                            val.toString(), ac);
                }
                value = valnum;
            } else {
                throw new InvalidParamException("unrecognize", ac);
            }
        }
    }

    // just in case someone wants to call it externally...
    public void setModifier(ApplContext ac, String modifier)
            throws InvalidParamException {
        throw new InvalidParamException("nomodifiermedia",
                getFeatureName(), ac);
    }

    public MediaGrid(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "grid";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaGrid mg = (MediaGrid) other;
            return (((value == null) && (mg.value == null)) || ((value != null) && value.equals(mg.value)))
                    && (((modifier == null) && (mg.modifier == null)) || ((modifier != null) && modifier.equals(mg.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaScan.java ---
// $Id: MediaScan.java,v 1.1 2011/10/21 01:49:08 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#scan
 */
public class MediaScan extends MediaFeature {

    static CssIdent progressive, interlace;

    static {
        progressive = CssIdent.getIdent("progressive");
        interlace = CssIdent.getIdent("interlace");
    }

    /**
     * Create a new MediaScan
     */
    public MediaScan() {
    }

    /**
     * Create a new MediaScan.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaScan(ApplContext ac, String modifier,
                     CssExpression expression, boolean check)
            throws InvalidParamException {

        if (modifier != null) {
            throw new InvalidParamException("nomodifiermedia",
                    getFeatureName(), ac);
        }

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }

            CssValue val = expression.getValue();

            switch (val.getType()) {
                case CssTypes.CSS_IDENT:
                    CssIdent id = (CssIdent) val;
                    if (progressive.equals(id)) {
                        value = progressive;
                        break;
                    }
                    if (interlace.equals(id)) {
                        value = interlace;
                        break;
                    }
                    // let it flow through the exception
                default:
                    throw new InvalidParamException("value", expression.getValue(),
                            getFeatureName(), ac);
            }
        } else {
            // TODO add a warning for value less mediafeature that makes no sense
        }
    }

    public MediaScan(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    // just in case someone wants to call it externally...
    public void setModifier(ApplContext ac, String modifier)
            throws InvalidParamException {
        throw new InvalidParamException("nomodifiermedia",
                getFeatureName(), ac);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "scan";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaScan ms = (MediaScan) other;
            return (((value == null) && (ms.value == null)) || ((value != null) && value.equals(ms.value)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaOrientation.java ---
// $Id: MediaOrientation.java,v 1.1 2011/10/21 01:49:08 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#orientation
 */
public class MediaOrientation extends MediaFeature {

    static CssIdent portrait, landscape;

    static {
        portrait = CssIdent.getIdent("progressive");
        landscape = CssIdent.getIdent("interlace");
    }

    /**
     * Create a new MediaOientation
     */
    public MediaOrientation() {
    }

    /**
     * Create a new MediaOrientation.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaOrientation(ApplContext ac, String modifier,
                            CssExpression expression, boolean check)
            throws InvalidParamException {

        if (modifier != null) {
            throw new InvalidParamException("nomodifiermedia",
                    getFeatureName(), ac);
        }

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }

            CssValue val = expression.getValue();

            switch (val.getType()) {
                case CssTypes.CSS_IDENT:
                    CssIdent id = (CssIdent) val;
                    if (portrait.equals(id)) {
                        value = portrait;
                        break;
                    }
                    if (landscape.equals(id)) {
                        value = landscape;
                        break;
                    }
                    // let it flow through the exception
                default:
                    throw new InvalidParamException("value", expression.getValue(),
                            getFeatureName(), ac);
            }
        } else {
            // TODO add a warning for value less mediafeature that makes no sense
        }
    }

    public MediaOrientation(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    // just in case someone wants to call it externally...
    public void setModifier(ApplContext ac, String modifier)
            throws InvalidParamException {
        throw new InvalidParamException("nomodifiermedia",
                getFeatureName(), ac);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "orientation";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaOrientation mo = (MediaOrientation) other;
            return (((value == null) && (mo.value == null)) || ((value != null) && value.equals(mo.value)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaDeviceWidth.java ---
// $Id: MediaDeviceWidth.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssLength;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#device-width
 */
public class MediaDeviceWidth extends MediaFeature {

    /**
     * Create a new MediaWidth
     */
    public MediaDeviceWidth() {
    }

    /**
     * Create a new MediaWidth.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaDeviceWidth(ApplContext ac, String modifier,
                            CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }

            CssValue val = expression.getValue();

            switch (val.getType()) {
                case CssTypes.CSS_NUMBER:
                    // a bit stupid as the only value would be 0...
                    val = ((CssNumber) val).getLength();
                case CssTypes.CSS_LENGTH:
                    CssLength l = (CssLength) val;
                    if (l.floatValue() < 0.f) {
                        throw new InvalidParamException("negative-value",
                                val.toString(), ac);
                    }
                    value = val;
                    expression.next();
                    break;
                default:
                    throw new InvalidParamException("value", expression.getValue(),
                            getFeatureName(), ac);
            }
            setModifier(ac, modifier);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaDeviceWidth(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "device-width";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaDeviceWidth mdw = (MediaDeviceWidth) other;
            return (((value == null) && (mdw.value == null)) || ((value != null) && value.equals(mdw.value)))
                    && (((modifier == null) && (mdw.modifier == null)) || ((modifier != null) && modifier.equals(mdw.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaColorIndex.java ---
// $Id: MediaColorIndex.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#color-index
 */
public class MediaColorIndex extends MediaFeature {

    /**
     * Create a new MediaColorIndex
     */
    public MediaColorIndex() {
    }

    /**
     * Create a new MediaColorIndex.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaColorIndex(ApplContext ac, String modifier,
                           CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() > 1) {
                throw new InvalidParamException("unrecognize", ac);
            }
            CssValue val = expression.getValue();
            // it must be a >=0 integer only
            if (val.getType() == CssTypes.CSS_NUMBER) {
                CssNumber valnum = (CssNumber) val;
                if (!valnum.isInteger()) {
                    throw new InvalidParamException("integer",
                            val.toString(), ac);
                }
                if (valnum.getInt() < 0) {
                    throw new InvalidParamException("negative-value",
                                val.toString(), ac);
                }
                value = valnum;
            } else {
                throw new InvalidParamException("unrecognize", ac);
            }
            setModifier(ac, modifier);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaColorIndex(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        return value;
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "color-index";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaColorIndex mci = (MediaColorIndex) other;
            return (((value == null) && (mci.value == null)) || ((value != null) && value.equals(mci.value)))
                    && (((modifier == null) && (mci.modifier == null)) || ((modifier != null) && modifier.equals(mci.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }

    }
}

--- NEW FILE: MediaAspectRatio.java ---
// $Id: MediaAspectRatio.java,v 1.1 2011/10/21 01:49:07 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECRIM and Keio University, 2011
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media.css3;

import org.w3c.css.media.MediaFeature;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssNumber;
import org.w3c.css.values.CssOperator;
import org.w3c.css.values.CssTypes;
import org.w3c.css.values.CssValue;

/**
 * @spec http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/#aspect-ratio
 */
public class MediaAspectRatio extends MediaFeature {

    int h, w;

    /**
     * Create a new MediaHeight
     */
    public MediaAspectRatio() {
    }

    /**
     * Create a new MediaHeight.
     *
     * @param expression The expression for this media feature
     * @throws org.w3c.css.util.InvalidParamException
     *          Values are incorrect
     */
    public MediaAspectRatio(ApplContext ac, String modifier,
                            CssExpression expression, boolean check)
            throws InvalidParamException {

        if (expression != null) {
            if (expression.getCount() != 2) {
                throw new InvalidParamException("unrecognize", ac);
            }
            CssValue val = expression.getValue();

            if (val.getType() == CssTypes.CSS_NUMBER) {
                CssNumber valnum = (CssNumber) val;
                if (!valnum.isInteger()) {
                    throw new InvalidParamException("integer",
                            val.toString(), ac);
                }
                w = valnum.getInt();
                // TODO FIXME this should be replaced when / is no longer
                // an operator
                if (expression.getOperator() != CssOperator.SLASH) {
                    throw new InvalidParamException("operator", expression.toString(), ac);
                }
                // now the second value
                expression.next();
                val = expression.getValue();
                if (val.getType() == CssTypes.CSS_NUMBER) {
                    valnum = (CssNumber) val;
                    if (!valnum.isInteger()) {
                        throw new InvalidParamException("integer",
                                val.toString(), ac);
                    }
                    h = valnum.getInt();
                    // perfect, now set the modifier
                    setModifier(ac, modifier);
                    return;
                }
            }
            // otherwise... fail
            throw new InvalidParamException("value", expression.getValue(),
                    getFeatureName(), ac);
        } else {
            if (modifier != null) {
                throw new InvalidParamException("nomodifiershortmedia",
                        getFeatureName(), ac);
            }
        }
    }

    public MediaAspectRatio(ApplContext ac, String modifier, CssExpression expression)
            throws InvalidParamException {
        this(ac, modifier, expression, false);
    }

    /**
     * Returns the value of this media feature.
     */

    public Object get() {
        StringBuilder sb = new StringBuilder();
        sb.append(w).append('/').append(h);
        return sb.toString();
    }

    /**
     * Returns the name of this media feature.
     */
    public final String getFeatureName() {
        return "aspect-ratio";
    }

    /**
     * Compares two media features for equality.
     *
     * @param other The other media features.
     */
    public boolean equals(MediaFeature other) {
        try {
            MediaAspectRatio mar = (MediaAspectRatio) other;
            if (h == 0 || mar.h == 0) {
                return (w == 0 && mar.w == 0 && h == 0 && mar.h == 0);
            }
            float thisRatio = ((float) w) / ((float) h);
            float otherRatio = ((float) mar.w) / ((float) mar.h);

            return (thisRatio == otherRatio)
                    && (((modifier == null) && (mar.modifier == null)) || ((modifier != null) && modifier.equals(mar.modifier)));
        } catch (ClassCastException cce) {
            return false;
        }
    }

    /**
     * Returns a string representation of the object.
     */
    public String toString() {
        if (h == 0 && w == 0) {
            return getFeatureName();
        }
        StringBuilder sb = new StringBuilder();
        if (modifier != null) {
            sb.append(modifier).append('-');
        }
        sb.append(getFeatureName());
        sb.append(':').append(w).append('/').append(h);
        return sb.toString();
    }
}

Received on Friday, 21 October 2011 01:49:19 UTC