You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by hi...@apache.org on 2001/02/12 07:18:26 UTC

cvs commit: xml-batik/sources/org/apache/batik/css/value AbstractValueFactory.java

hillion     01/02/11 22:18:26

  Modified:    sources/org/apache/batik/bridge CSSUtilities.java
               sources/org/apache/batik/css/svg PaintFactory.java
                        SVGColorFactory.java SimpleColorFactory.java
               sources/org/apache/batik/css/value AbstractValueFactory.java
  Added:       sources/org/apache/batik/css/svg ImmutableSVGColorValue.java
                        ImmutableSVGPaintValue.java SVGCSSNumber.java
                        SVGCSSNumberList.java SVGCSSReadOnlyNumber.java
                        SVGCSSReadOnlyNumberList.java
                        SVGCSSReadOnlyValue.java SVGCSSValue.java
                        SVGImmutableValue.java
  Log:
  Commited CSS support for ICC colors.
  
  Revision  Changes    Path
  1.13      +106 -46   xml-batik/sources/org/apache/batik/bridge/CSSUtilities.java
  
  Index: CSSUtilities.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/CSSUtilities.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CSSUtilities.java	2001/02/08 23:24:05	1.12
  +++ CSSUtilities.java	2001/02/12 06:18:25	1.13
  @@ -56,14 +56,16 @@
   import org.w3c.dom.css.CSSValueList;
   import org.w3c.dom.css.RGBColor;
   import org.w3c.dom.css.ViewCSS;
  +import org.w3c.dom.svg.SVGColor;
   import org.w3c.dom.svg.SVGDocument;
   import org.w3c.dom.svg.SVGElement;
  +import org.w3c.dom.svg.SVGPaint;
   
   /**
    * A collection of utility methods involving CSS.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: CSSUtilities.java,v 1.12 2001/02/08 23:24:05 vhardy Exp $
  + * @version $Id: CSSUtilities.java,v 1.13 2001/02/12 06:18:25 hillion Exp $
    */
   public class CSSUtilities implements SVGConstants {
   
  @@ -470,23 +472,43 @@
                                                BridgeContext ctx,
                                                CSSStyleDeclaration decl,
                                                UnitProcessor.Context uctx) {
  -        CSSPrimitiveValue v =
  -            (CSSPrimitiveValue)decl.getPropertyCSSValue(CSS_STROKE_PROPERTY);
  +        CSSValue val = decl.getPropertyCSSValue(CSS_STROKE_PROPERTY);
   
  -        switch(v.getPrimitiveType()) {
  -        case CSSPrimitiveValue.CSS_IDENT:
  -            return null; // 'stroke:none'
  +        if (val.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
  +            CSSPrimitiveValue v = (CSSPrimitiveValue)val;
   
  -        case CSSPrimitiveValue.CSS_RGBCOLOR:
  -            CSSPrimitiveValue vv = (CSSPrimitiveValue)decl.getPropertyCSSValue
  -                (CSS_STROKE_OPACITY_PROPERTY);
  -            float opacity = convertOpacity(vv);
  -            return convertColor(v.getRGBColorValue(), opacity);
  -        case CSSPrimitiveValue.CSS_URI:
  -            return convertURIToPaint(element, node, ctx, decl,
  -                                     uctx, v.getStringValue());
  -         default:
  -             throw new Error(); // can't be reached
  +            switch(v.getPrimitiveType()) {
  +            case CSSPrimitiveValue.CSS_IDENT:
  +                return null; // 'stroke:none'
  +
  +            case CSSPrimitiveValue.CSS_RGBCOLOR:
  +                CSSPrimitiveValue vv = (CSSPrimitiveValue)decl.getPropertyCSSValue
  +                    (CSS_STROKE_OPACITY_PROPERTY);
  +                float opacity = convertOpacity(vv);
  +                return convertColor(v.getRGBColorValue(), opacity);
  +            case CSSPrimitiveValue.CSS_URI:
  +                return convertURIToPaint(element, node, ctx, decl,
  +                                         uctx, v.getStringValue());
  +            default:
  +                throw new Error(); // can't be reached
  +            }
  +        } else { // SVGPaint
  +            SVGPaint p = (SVGPaint)val;
  +
  +            switch (p.getPaintType()) {
  +            case SVGPaint.SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR");
  +            case SVGPaint.SVG_PAINTTYPE_URI_NONE:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_URI_NONE");
  +            case SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_URI_CURRENTCOLOR");
  +            case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_URI_RGBCOLOR");
  +            case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR");
  +            default:
  +                throw new Error(); // can't be reached
  +            }
           }
       }
   
  @@ -680,22 +702,42 @@
                                              CSSStyleDeclaration decl,
                                              UnitProcessor.Context uctx) {
   
  -        CSSPrimitiveValue v =
  -            (CSSPrimitiveValue) decl.getPropertyCSSValue(CSS_FILL_PROPERTY);
  -        switch(v.getPrimitiveType()) {
  -        case CSSPrimitiveValue.CSS_IDENT:
  -            return null; // fill:'none'
  -        case CSSPrimitiveValue.CSS_RGBCOLOR:
  -            CSSPrimitiveValue vv =
  -                (CSSPrimitiveValue)decl.getPropertyCSSValue(CSS_FILL_OPACITY_PROPERTY);
  -            float opacity = convertOpacity(vv);
  -            return convertColor(v.getRGBColorValue(), opacity);
  -        case CSSPrimitiveValue.CSS_URI:
  -            return convertURIToPaint(element, node, ctx,
  -                                     decl, uctx, v.getStringValue());
  +        CSSValue val = decl.getPropertyCSSValue(CSS_FILL_PROPERTY);
   
  -        default:
  -            throw new Error(); // can't be reached
  +        if (val.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
  +            CSSPrimitiveValue v = (CSSPrimitiveValue)val;
  +            switch(v.getPrimitiveType()) {
  +            case CSSPrimitiveValue.CSS_IDENT:
  +                return null; // fill:'none'
  +            case CSSPrimitiveValue.CSS_RGBCOLOR:
  +                CSSPrimitiveValue vv =
  +                    (CSSPrimitiveValue)decl.getPropertyCSSValue
  +                    (CSS_FILL_OPACITY_PROPERTY);
  +                float opacity = convertOpacity(vv);
  +                return convertColor(v.getRGBColorValue(), opacity);
  +            case CSSPrimitiveValue.CSS_URI:
  +                return convertURIToPaint(element, node, ctx,
  +                                         decl, uctx, v.getStringValue());
  +            default:
  +                throw new Error(); // can't be reached
  +            }
  +        } else { // SVGPaint
  +            SVGPaint p = (SVGPaint)val;
  +
  +            switch (p.getPaintType()) {
  +            case SVGPaint.SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR");
  +            case SVGPaint.SVG_PAINTTYPE_URI_NONE:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_URI_NONE");
  +            case SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_URI_CURRENTCOLOR");
  +            case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_URI_RGBCOLOR");
  +            case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
  +                throw new InternalError("!!! TODO SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR");
  +            default:
  +                throw new Error(); // can't be reached
  +            }
           }
       }
   
  @@ -769,12 +811,18 @@
        * @param decl the css style declaration
        */
       public static Color convertFloodColorToPaint(CSSStyleDeclaration decl) {
  -        CSSPrimitiveValue v =
  -            (CSSPrimitiveValue) decl.getPropertyCSSValue(CSS_FLOOD_COLOR_PROPERTY);
  -        CSSPrimitiveValue vv =
  -            (CSSPrimitiveValue)decl.getPropertyCSSValue(CSS_FLOOD_OPACITY_PROPERTY);
  -        float opacity = convertOpacity(vv);
  -        return convertColor(v.getRGBColorValue(), opacity);
  +        CSSValue val = decl.getPropertyCSSValue(CSS_FLOOD_COLOR_PROPERTY);
  +
  +        if (val.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
  +            CSSPrimitiveValue v = (CSSPrimitiveValue)val;
  +            CSSPrimitiveValue vv =
  +                (CSSPrimitiveValue)decl.getPropertyCSSValue(CSS_FLOOD_OPACITY_PROPERTY);
  +            float opacity = convertOpacity(vv);
  +            return convertColor(v.getRGBColorValue(), opacity);
  +        } else { // SVGColor
  +            SVGColor c = (SVGColor)val;
  +            throw new InternalError("!!! TODO: SVG_COLORTYPE_RGBCOLOR_ICCCOLOR");
  +        }
       }
   
       /**
  @@ -783,9 +831,15 @@
        * @param decl the css style declaration
        */
       public static Color convertLightingColor(CSSStyleDeclaration decl) {
  -        CSSPrimitiveValue v =
  -            (CSSPrimitiveValue) decl.getPropertyCSSValue(CSS_LIGHTING_COLOR_PROPERTY);
  -        return convertColor(v.getRGBColorValue(), 1);
  +        CSSValue val = decl.getPropertyCSSValue(CSS_LIGHTING_COLOR_PROPERTY);
  +
  +        if (val.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
  +            CSSPrimitiveValue v = (CSSPrimitiveValue)val;
  +            return convertColor(v.getRGBColorValue(), 1);
  +        } else { // SVGPaint
  +            SVGColor c = (SVGColor)val;
  +            throw new InternalError("!!! TODO: SVG_COLORTYPE_RGBCOLOR_ICCCOLOR");
  +        }
       }
   
       /**
  @@ -794,12 +848,18 @@
        * @param decl the css style declaration
        */
       public static Color convertStopColorToPaint(CSSStyleDeclaration decl) {
  -        CSSPrimitiveValue v =
  -            (CSSPrimitiveValue) decl.getPropertyCSSValue(CSS_STOP_COLOR_PROPERTY);
  -        CSSPrimitiveValue vv =
  -            (CSSPrimitiveValue)decl.getPropertyCSSValue(CSS_STOP_OPACITY_PROPERTY);
  -        float opacity = convertOpacity(vv);
  -        return convertColor(v.getRGBColorValue(), opacity);
  +        CSSValue val = decl.getPropertyCSSValue(CSS_STOP_COLOR_PROPERTY);
  +
  +        if (val.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
  +            CSSPrimitiveValue v = (CSSPrimitiveValue)val;
  +            CSSPrimitiveValue vv =
  +                (CSSPrimitiveValue)decl.getPropertyCSSValue(CSS_STOP_OPACITY_PROPERTY);
  +            float opacity = convertOpacity(vv);
  +            return convertColor(v.getRGBColorValue(), opacity);
  +        } else { // SVGColor
  +            SVGColor c = (SVGColor)val;
  +            throw new InternalError("!!! TODO: SVG_COLORTYPE_RGBCOLOR_ICCCOLOR");
  +        }
       }
   
       /**
  
  
  
  1.3       +183 -4    xml-batik/sources/org/apache/batik/css/svg/PaintFactory.java
  
  Index: PaintFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/svg/PaintFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PaintFactory.java	2000/11/27 05:49:03	1.2
  +++ PaintFactory.java	2001/02/12 06:18:25	1.3
  @@ -8,18 +8,29 @@
   
   package org.apache.batik.css.svg;
   
  +import org.apache.batik.css.CSSDOMExceptionFactory;
  +import org.apache.batik.css.CSSOMValue;
  +
  +import org.apache.batik.css.value.ImmutableFloat;
  +import org.apache.batik.css.value.ImmutableRGBColor;
   import org.apache.batik.css.value.ImmutableString;
   import org.apache.batik.css.value.ImmutableValue;
  +import org.apache.batik.css.value.ValueFactory;
  +
   import org.w3c.css.sac.LexicalUnit;
   import org.w3c.css.sac.Parser;
  +
   import org.w3c.dom.DOMException;
  +
   import org.w3c.dom.css.CSSPrimitiveValue;
   
  +import org.w3c.dom.svg.SVGPaint;
  +
   /**
    * This class provides a factory for values of type paint.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: PaintFactory.java,v 1.2 2000/11/27 05:49:03 hillion Exp $
  + * @version $Id: PaintFactory.java,v 1.3 2001/02/12 06:18:25 hillion Exp $
    */
   public class PaintFactory
       extends    SVGColorFactory
  @@ -41,9 +52,135 @@
        * Creates a value from a lexical unit.
        */
       public ImmutableValue createValue(LexicalUnit lu) throws DOMException {
  -	if (lu.getLexicalUnitType() == LexicalUnit.SAC_URI) {
  -	    return new ImmutableString(CSSPrimitiveValue.CSS_URI,
  -				       lu.getStringValue());
  +	switch (lu.getLexicalUnitType()) {
  +	case LexicalUnit.SAC_INHERIT:
  +	    return INHERIT;
  +	case LexicalUnit.SAC_IDENT:
  +            return super.createValue(lu);
  +        case LexicalUnit.SAC_RGBCOLOR:
  +            LexicalUnit l = lu.getParameters();
  +            ValueFactory ph = new ColorComponentFactory(getParser());
  +            CSSPrimitiveValue r = new CSSOMValue(ph, createColorValue(l));
  +            l = l.getNextLexicalUnit().getNextLexicalUnit();
  +            CSSPrimitiveValue g = new CSSOMValue(ph, createColorValue(l));
  +            l = l.getNextLexicalUnit().getNextLexicalUnit();
  +            CSSPrimitiveValue b = new CSSOMValue(ph, createColorValue(l));
  +            lu = lu.getNextLexicalUnit();
  +            if (lu == null) {
  +                return new ImmutableRGBColor(r, g, b);
  +            }
  +            if (lu.getLexicalUnitType() != LexicalUnit.SAC_FUNCTION) {
  +                throw CSSDOMExceptionFactory.createDOMException
  +                    (DOMException.INVALID_ACCESS_ERR,
  +                     "invalid.lexical.unit",
  +                     new Object[] { new Integer(lu.getLexicalUnitType()) });
  +            }
  +            if (!lu.getFunctionName().toLowerCase().equals("icc-color")) {
  +                throw CSSDOMExceptionFactory.createDOMException
  +                    (DOMException.INVALID_ACCESS_ERR,
  +                     "invalid.lexical.unit",
  +                     new Object[] { new Integer(lu.getLexicalUnitType()) });
  +            }
  +            lu = lu.getParameters();
  +            if (lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
  +                throw CSSDOMExceptionFactory.createDOMException
  +                    (DOMException.INVALID_ACCESS_ERR,
  +                     "invalid.lexical.unit",
  +                     new Object[] { new Integer(lu.getLexicalUnitType()) });
  +            }
  +            String cp = lu.getStringValue();
  +            lu = lu.getNextLexicalUnit();
  +            SVGCSSNumberList nl = new SVGCSSNumberList();
  +            while (lu != null) {
  +                lu = lu.getNextLexicalUnit();
  +                if (lu == null) {
  +                    throw CSSDOMExceptionFactory.createDOMException
  +                        (DOMException.INVALID_ACCESS_ERR,
  +                         "invalid.lexical.unit",
  +                         new Object[] { null });
  +                }
  +                nl.appendItem(new SVGCSSNumber(getColorValue(lu)));
  +                lu = lu.getNextLexicalUnit();
  +            }
  +            return new ImmutableSVGPaintValue
  +                (SVGPaint.SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR,
  +                 r, g, b, cp, nl, null);
  +
  +        case LexicalUnit.SAC_URI:
  +            String uri = lu.getStringValue();
  +            lu = lu.getNextLexicalUnit();
  +            if (lu == null) {
  +                return new ImmutableString(CSSPrimitiveValue.CSS_URI, uri);
  +            }
  +
  +            switch (lu.getLexicalUnitType()) {
  +            case LexicalUnit.SAC_RGBCOLOR:
  +                l = lu.getParameters();
  +                ph = new ColorComponentFactory(getParser());
  +                r = new CSSOMValue(ph, createColorValue(l));
  +                l = l.getNextLexicalUnit().getNextLexicalUnit();
  +                g = new CSSOMValue(ph, createColorValue(l));
  +                l = l.getNextLexicalUnit().getNextLexicalUnit();
  +                b = new CSSOMValue(ph, createColorValue(l));
  +                lu = lu.getNextLexicalUnit();
  +                if (lu == null) {
  +                    return new ImmutableSVGPaintValue
  +                        (SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR,
  +                         r, g, b, null, null, uri);
  +                }
  +                if (lu.getLexicalUnitType() != LexicalUnit.SAC_FUNCTION) {
  +                    throw CSSDOMExceptionFactory.createDOMException
  +                        (DOMException.INVALID_ACCESS_ERR,
  +                         "invalid.lexical.unit",
  +                         new Object[] { new Integer(lu.getLexicalUnitType()) });
  +                }
  +                if (!lu.getFunctionName().toLowerCase().equals("icc-color")) {
  +                    throw CSSDOMExceptionFactory.createDOMException
  +                        (DOMException.INVALID_ACCESS_ERR,
  +                         "invalid.lexical.unit",
  +                         new Object[] { new Integer(lu.getLexicalUnitType()) });
  +                }
  +                lu = lu.getParameters();
  +                if (lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
  +                    throw CSSDOMExceptionFactory.createDOMException
  +                        (DOMException.INVALID_ACCESS_ERR,
  +                         "invalid.lexical.unit",
  +                         new Object[] { new Integer(lu.getLexicalUnitType()) });
  +                }
  +                cp = lu.getStringValue();
  +                lu = lu.getNextLexicalUnit();
  +                nl = new SVGCSSNumberList();
  +                while (lu != null) {
  +                    lu = lu.getNextLexicalUnit();
  +                    if (lu == null) {
  +                        throw CSSDOMExceptionFactory.createDOMException
  +                            (DOMException.INVALID_ACCESS_ERR,
  +                             "invalid.lexical.unit",
  +                             new Object[] { null });
  +                    }
  +                    nl.appendItem(new SVGCSSNumber(getColorValue(lu)));
  +                    lu = lu.getNextLexicalUnit();
  +                }
  +                return new ImmutableSVGPaintValue
  +                    (SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR,
  +                     r, g, b, cp, nl, uri);
  +            case LexicalUnit.SAC_IDENT:
  +                String id = lu.getStringValue().toLowerCase();
  +                if (id.equals(CSS_NONE_VALUE)) {
  +                    return new ImmutableSVGPaintValue
  +                        (SVGPaint.SVG_PAINTTYPE_URI_NONE,
  +                         null, null, null, null, null, uri);
  +                } else if (id.equals(CSS_CURRENTCOLOR_VALUE)) {
  +                    return new ImmutableSVGPaintValue
  +                        (SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR,
  +                         null, null, null, null, null, uri);
  +                } else {
  +                    throw CSSDOMExceptionFactory.createDOMException
  +                        (DOMException.INVALID_ACCESS_ERR,
  +                         "invalid.lexical.unit",
  +                         new Object[] { new Integer(lu.getLexicalUnitType()) });
  +                }
  +            }
   	}
   	return super.createValue(lu);
       }
  @@ -61,4 +198,46 @@
   	}
   	return super.createStringValue(type, value);
       }
  +
  +    /**
  +     * Creates a float value usable by an RGBColor.
  +     * @param lu The SAC lexical unit used to create the value.
  +     */
  +    protected ImmutableValue createColorValue(LexicalUnit lu) {
  +	switch (lu.getLexicalUnitType()) {
  +	case LexicalUnit.SAC_INTEGER:
  +	    return new ImmutableFloat(CSSPrimitiveValue.CSS_NUMBER,
  +				      lu.getIntegerValue());
  +	case LexicalUnit.SAC_REAL:
  +	    return new ImmutableFloat(CSSPrimitiveValue.CSS_NUMBER,
  +				      lu.getFloatValue());
  +	case LexicalUnit.SAC_PERCENTAGE:
  +	    return new ImmutableFloat(CSSPrimitiveValue.CSS_PERCENTAGE,
  +				      lu.getFloatValue());
  +	default:
  +	    throw CSSDOMExceptionFactory.createDOMException
  +		(DOMException.INVALID_ACCESS_ERR,
  +		 "invalid.lexical.unit",
  +		 new Object[] { new Integer(lu.getLexicalUnitType()) });
  +	}
  +    }
  +
  +    /**
  +     * Creates a float value usable by an RGBColor.
  +     * @param lu The SAC lexical unit used to create the value.
  +     */
  +    protected float getColorValue(LexicalUnit lu) {
  +	switch (lu.getLexicalUnitType()) {
  +	case LexicalUnit.SAC_INTEGER:
  +	    return lu.getIntegerValue();
  +	case LexicalUnit.SAC_REAL:
  +	    return lu.getFloatValue();
  +	default:
  +	    throw CSSDOMExceptionFactory.createDOMException
  +		(DOMException.INVALID_ACCESS_ERR,
  +		 "invalid.lexical.unit",
  +		 new Object[] { new Integer(lu.getLexicalUnitType()) });
  +	}
  +    }
  +
   }
  
  
  
  1.2       +13 -1     xml-batik/sources/org/apache/batik/css/svg/SVGColorFactory.java
  
  Index: SVGColorFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/svg/SVGColorFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SVGColorFactory.java	2000/10/10 18:38:04	1.1
  +++ SVGColorFactory.java	2001/02/12 06:18:25	1.2
  @@ -8,14 +8,18 @@
   
   package org.apache.batik.css.svg;
   
  +import org.apache.batik.css.CSSOMValue;
  +
  +import org.apache.batik.css.value.ImmutableValue;
   import org.apache.batik.css.value.ColorFactory;
  +
   import org.w3c.css.sac.Parser;
   
   /**
    * This class provides a factory for values of color type.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: SVGColorFactory.java,v 1.1 2000/10/10 18:38:04 hillion Exp $
  + * @version $Id: SVGColorFactory.java,v 1.2 2001/02/12 06:18:25 hillion Exp $
    */
   public class SVGColorFactory extends ColorFactory {
       {
  @@ -160,4 +164,12 @@
       public SVGColorFactory(Parser p, String prop) {
   	super(p, prop);
       }
  +
  +    /**
  +     * Creates a new CSSValue.
  +     */
  +    protected CSSOMValue createCSSValue(ImmutableValue v) {
  +        return new SVGCSSValue(this, v);
  +    }
  +
   }
  
  
  
  1.4       +116 -1    xml-batik/sources/org/apache/batik/css/svg/SimpleColorFactory.java
  
  Index: SimpleColorFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/svg/SimpleColorFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleColorFactory.java	2000/11/27 05:49:04	1.3
  +++ SimpleColorFactory.java	2001/02/12 06:18:25	1.4
  @@ -8,16 +8,29 @@
   
   package org.apache.batik.css.svg;
   
  +import org.apache.batik.css.CSSDOMExceptionFactory;
  +import org.apache.batik.css.CSSOMValue;
  +
  +import org.apache.batik.css.value.ImmutableFloat;
  +import org.apache.batik.css.value.ImmutableRGBColor;
   import org.apache.batik.css.value.ImmutableString;
   import org.apache.batik.css.value.ImmutableValue;
  +import org.apache.batik.css.value.ValueFactory;
  +
  +import org.w3c.css.sac.LexicalUnit;
   import org.w3c.css.sac.Parser;
  +
  +import org.w3c.dom.DOMException;
  +
   import org.w3c.dom.css.CSSPrimitiveValue;
   
  +import org.w3c.dom.svg.SVGColor;
  +
   /**
    * This class provides a factory for values of type color.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: SimpleColorFactory.java,v 1.3 2000/11/27 05:49:04 hillion Exp $
  + * @version $Id: SimpleColorFactory.java,v 1.4 2001/02/12 06:18:25 hillion Exp $
    */
   public class SimpleColorFactory
       extends    SVGColorFactory
  @@ -32,5 +45,107 @@
        */
       public SimpleColorFactory(Parser p, String prop) {
   	super(p, prop);
  +    }
  +
  +    /**
  +     * Creates a value from a lexical unit.
  +     */
  +    public ImmutableValue createValue(LexicalUnit lu) throws DOMException {
  +	switch (lu.getLexicalUnitType()) {
  +	case LexicalUnit.SAC_INHERIT:
  +	    return INHERIT;
  +	case LexicalUnit.SAC_IDENT:
  +            return super.createValue(lu);
  +        case LexicalUnit.SAC_RGBCOLOR:
  +            LexicalUnit l = lu.getParameters();
  +            ValueFactory ph = new ColorComponentFactory(getParser());
  +            CSSPrimitiveValue r = new CSSOMValue(ph, createColorValue(l));
  +            l = l.getNextLexicalUnit().getNextLexicalUnit();
  +            CSSPrimitiveValue g = new CSSOMValue(ph, createColorValue(l));
  +            l = l.getNextLexicalUnit().getNextLexicalUnit();
  +            CSSPrimitiveValue b = new CSSOMValue(ph, createColorValue(l));
  +            lu = lu.getNextLexicalUnit();
  +            if (lu == null) {
  +                return new ImmutableRGBColor(r, g, b);
  +            }
  +            if (lu.getLexicalUnitType() != LexicalUnit.SAC_FUNCTION) {
  +                throw CSSDOMExceptionFactory.createDOMException
  +                    (DOMException.INVALID_ACCESS_ERR,
  +                     "invalid.lexical.unit",
  +                     new Object[] { new Integer(lu.getLexicalUnitType()) });
  +            }
  +            if (!lu.getFunctionName().toLowerCase().equals("icc-color")) {
  +                throw CSSDOMExceptionFactory.createDOMException
  +                    (DOMException.INVALID_ACCESS_ERR,
  +                     "invalid.lexical.unit",
  +                     new Object[] { new Integer(lu.getLexicalUnitType()) });
  +            }
  +            lu = lu.getParameters();
  +            if (lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
  +                throw CSSDOMExceptionFactory.createDOMException
  +                    (DOMException.INVALID_ACCESS_ERR,
  +                     "invalid.lexical.unit",
  +                     new Object[] { new Integer(lu.getLexicalUnitType()) });
  +            }
  +            String cp = lu.getStringValue();
  +            lu = lu.getNextLexicalUnit();
  +            SVGCSSNumberList nl = new SVGCSSNumberList();
  +            while (lu != null) {
  +                lu = lu.getNextLexicalUnit();
  +                if (lu == null) {
  +                    throw CSSDOMExceptionFactory.createDOMException
  +                        (DOMException.INVALID_ACCESS_ERR,
  +                         "invalid.lexical.unit",
  +                         new Object[] { null });
  +                }
  +                nl.appendItem(new SVGCSSNumber(getColorValue(lu)));
  +                lu = lu.getNextLexicalUnit();
  +            }
  +            return new ImmutableSVGColorValue
  +                (SVGColor.SVG_COLORTYPE_RGBCOLOR_ICCCOLOR,
  +                 r, g, b, cp, nl);
  +	}
  +	return super.createValue(lu);
  +    }
  +
  +    /**
  +     * Creates a float value usable by an RGBColor.
  +     * @param lu The SAC lexical unit used to create the value.
  +     */
  +    protected ImmutableValue createColorValue(LexicalUnit lu) {
  +	switch (lu.getLexicalUnitType()) {
  +	case LexicalUnit.SAC_INTEGER:
  +	    return new ImmutableFloat(CSSPrimitiveValue.CSS_NUMBER,
  +				      lu.getIntegerValue());
  +	case LexicalUnit.SAC_REAL:
  +	    return new ImmutableFloat(CSSPrimitiveValue.CSS_NUMBER,
  +				      lu.getFloatValue());
  +	case LexicalUnit.SAC_PERCENTAGE:
  +	    return new ImmutableFloat(CSSPrimitiveValue.CSS_PERCENTAGE,
  +				      lu.getFloatValue());
  +	default:
  +	    throw CSSDOMExceptionFactory.createDOMException
  +		(DOMException.INVALID_ACCESS_ERR,
  +		 "invalid.lexical.unit",
  +		 new Object[] { new Integer(lu.getLexicalUnitType()) });
  +	}
  +    }
  +
  +    /**
  +     * Creates a float value usable by an RGBColor.
  +     * @param lu The SAC lexical unit used to create the value.
  +     */
  +    protected float getColorValue(LexicalUnit lu) {
  +	switch (lu.getLexicalUnitType()) {
  +	case LexicalUnit.SAC_INTEGER:
  +	    return lu.getIntegerValue();
  +	case LexicalUnit.SAC_REAL:
  +	    return lu.getFloatValue();
  +	default:
  +	    throw CSSDOMExceptionFactory.createDOMException
  +		(DOMException.INVALID_ACCESS_ERR,
  +		 "invalid.lexical.unit",
  +		 new Object[] { new Integer(lu.getLexicalUnitType()) });
  +	}
       }
   }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/ImmutableSVGColorValue.java
  
  Index: ImmutableSVGColorValue.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import org.apache.batik.css.CSSDOMExceptionFactory;
  import org.apache.batik.css.CSSOMValue;
  
  import org.apache.batik.css.value.AbstractImmutableValue;
  import org.apache.batik.css.value.ImmutableValue;
  
  import org.w3c.dom.css.CSSPrimitiveValue;
  import org.w3c.dom.css.RGBColor;
  
  import org.w3c.dom.DOMException;
  
  import org.w3c.dom.svg.SVGColor;
  import org.w3c.dom.svg.SVGICCColor;
  import org.w3c.dom.svg.SVGNumberList;
  
  /**
   * This class represents the immutable value used to implement a SVGColor.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: ImmutableSVGColorValue.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public class ImmutableSVGColorValue
      extends AbstractImmutableValue
      implements SVGImmutableValue,
                 RGBColor,
                 SVGICCColor {
  
      /**
       * The SVG color type.
       */
      protected short colorType;
  
      /**
       * The red value
       */
      protected CSSPrimitiveValue red;
  
      /**
       * The green value
       */
      protected CSSPrimitiveValue green;
  
      /**
       * The blue value
       */
      protected CSSPrimitiveValue blue;
  
      /**
       * The color profile.
       */
      protected String colorProfile;
  
      /**
       * The colors.
       */
      protected SVGCSSNumberList colors;
  
      /**
       * Creates a new ImmutableSVGColorValue.
       */
      public ImmutableSVGColorValue(short ctype,
                                    CSSPrimitiveValue r,
                                    CSSPrimitiveValue g,
                                    CSSPrimitiveValue b,
                                    String cprofile,
                                    SVGCSSNumberList l) {
          colorType = ctype;
          red = r;
          green = g;
          blue = b;
          colorProfile = cprofile;
          colors = l;
      }
      
      /**
       * Indicates whether some other object is "equal to" this one.
       * @param obj the reference object with which to compare.
       */
      public boolean equals(Object obj) {
  	if (obj == null || !(obj instanceof ImmutableSVGColorValue)) {
  	    return false;
  	}
  	ImmutableSVGColorValue v = (ImmutableSVGColorValue)obj;
  	if (colorType != v.colorType) {
              return false;
          }
          if (red != null) {
              if (!red.equals(v.red) ||
                  !green.equals(v.green) ||
                  !blue.equals(v.blue)) {
                  return false;
              }
          } else if (v.red != null) {
              return false;
          }
          if (colorProfile != null) {
              if (colorProfile.equals(v.colorProfile)) {
                  return false;
              }
          } else if (v.colorProfile != null) {
              return false;
          }
          if (colors != null) {
              return colors.equals(v.colors);
          } else if (v.colors != null) {
              return false;
          }
          return true;
      }
  
      /**
       * Returns a deep read-only copy of this object.
       */
      public ImmutableValue createReadOnlyCopy() {
  	return new ImmutableSVGColorValue
              (colorType,
               (red == null) ? null : ((CSSOMValue)red).createReadOnlyCopy(),
               (green == null) ? null : ((CSSOMValue)green).createReadOnlyCopy(),
               (blue == null) ? null : ((CSSOMValue)blue).createReadOnlyCopy(),
               colorProfile,
               (colors == null) ? null : colors.createReadOnlyCopy());
      }
  
      /**
       *  A string representation of the current value. 
       */
      public String getCssText() {
          switch (colorType) {
          case SVGColor.SVG_COLORTYPE_RGBCOLOR:
              return "rgb("
                  + red.getCssText() + ", "
                  + green.getCssText() + ", "
                  + blue.getCssText() + ")";
          case SVGColor.SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
              StringBuffer res = new StringBuffer();
              res .append("rgb(")
                  .append(red.getCssText()).append(", ")
                  .append(green.getCssText()).append(", ")
                  .append(blue.getCssText()).append(") icc-color(")
                  .append(colorProfile);
              if (colors.getNumberOfItems() != 0) {
                  res.append(", ").append(colors.toString());
              }
              res.append(")");
              return res.toString();
          }
          throw CSSDOMExceptionFactory.createDOMException
              (DOMException.INVALID_ACCESS_ERR,
               "invalid.primitive.unit",
               new Object[] { new Integer(colorType) });
      }
  
      // SVGPaint /////////////////////////////////////////////////////////////
  
      /**
       * Returns the paint type, if this object represents a SVGPaint.
       */
      public short getPaintType() {
  	throw CSSDOMExceptionFactory.createDOMException
  	    (DOMException.INVALID_ACCESS_ERR, "invalid.value", null);
      }
  
      /**
       * Returns the URI of the paint, if this object represents a SVGPaint.
       */
      public String getUri() {
  	throw CSSDOMExceptionFactory.createDOMException
  	    (DOMException.INVALID_ACCESS_ERR, "invalid.value", null);
      }
  
      /**
       * Returns the color type, if this object represents a SVGColor.
       */
      public short getColorType() {
          return colorType;
      }
  
      /**
       * Returns the RGBColor, if this object represents a SVGColor.
       */
      public RGBColor getRGBColor() {
          return this;
      }
  
      /**
       * Returns the RGBColor, if this object represents a SVGColor.
       */
      public SVGICCColor getICCColor() {
          return this;
      }
  
      // RGBColor //////////////////////////////////////////////////////////////
  
      /**
       * This attribute is used for the red value of the RGB color. 
       */
      public CSSPrimitiveValue getRed() {
  	return red;
      }
  
      /**
       * This attribute is used for the green value of the RGB color. 
       */
      public CSSPrimitiveValue getGreen() {
  	return green;
      }
      
      /**
       * This attribute is used for the blue value of the RGB color. 
       */
      public CSSPrimitiveValue getBlue() {
  	return blue;
      }
  
      // SVGICCColor //////////////////////////////////////////////////////////
  
      /**
       * Returns the color profile of this ICC color.
       */
      public String getColorProfile() {
          return colorProfile;
      }
  
      /**
       * Sets the color profile of this ICC color.
       */
      public void setColorProfile(String colorProfile) throws DOMException {
      }
  
      /**
       * Returns the colors in this ICC color.
       */
      public SVGNumberList getColors() {
          return colors;
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/ImmutableSVGPaintValue.java
  
  Index: ImmutableSVGPaintValue.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import org.apache.batik.css.CSSOMValue;
  
  import org.apache.batik.css.value.ImmutableValue;
  
  import org.w3c.dom.css.CSSPrimitiveValue;
  
  import org.w3c.dom.svg.SVGPaint;
  
  /**
   * This class represents the immutable value used to implement a SVGPaint.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: ImmutableSVGPaintValue.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public class ImmutableSVGPaintValue extends ImmutableSVGColorValue {
  
      /**
       * The URI of this paint.
       */
      protected String uri;
  
      /**
       * Creates a new ImmutableSVGPaintValue.
       */
      public ImmutableSVGPaintValue(short ctype,
                                    CSSPrimitiveValue r,
                                    CSSPrimitiveValue g,
                                    CSSPrimitiveValue b,
                                    String cprofile,
                                    SVGCSSNumberList l,
                                    String url) {
          super(ctype, r, g, b, cprofile, l);
          uri = url;
      }
      
      /**
       * Returns the paint type, if this object represents a SVGPaint.
       */
      public short getPaintType() {
          return getColorType();
      }
  
      /**
       * Returns the URI of the paint, if this object represents a SVGPaint.
       */
      public String getUri() {
          return uri;
      }
  
      /**
       * Indicates whether some other object is "equal to" this one.
       * @param obj the reference object with which to compare.
       */
      public boolean equals(Object obj) {
  	if (obj == null || !(obj instanceof ImmutableSVGPaintValue)) {
  	    return false;
  	}
  	ImmutableSVGPaintValue v = (ImmutableSVGPaintValue)obj;
          if (!super.equals(obj)) {
              return false;
          }
          if (uri != null) {
              if (!uri.equals(v.uri)) {
                  return false;
              }
          } else if (v.uri != null) {
              return false;
          }
          return true;
      }
  
      /**
       * Returns a deep read-only copy of this object.
       */
      public ImmutableValue createReadOnlyCopy() {
  	return new ImmutableSVGPaintValue
              (colorType,
               (red == null) ? null : ((CSSOMValue)red).createReadOnlyCopy(),
               (green == null) ? null : ((CSSOMValue)green).createReadOnlyCopy(),
               (blue == null) ? null : ((CSSOMValue)blue).createReadOnlyCopy(),
               colorProfile,
               (colors == null) ? null : colors.createReadOnlyCopy(),
               uri);
      }
  
      /**
       *  A string representation of the current value. 
       */
      public String getCssText() {
          switch (colorType) {
          case SVGPaint.SVG_PAINTTYPE_URI_NONE:
              return "url('" + uri + "') none";
          case SVGPaint.SVG_PAINTTYPE_URI_CURRENTCOLOR:
              return "url('" + uri + "') currentColor";
          case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR:
              StringBuffer res = new StringBuffer();
              res .append("url('").append(uri)
                  .append("') rgb(")
                  .append(red.getCssText()).append(", ")
                  .append(green.getCssText()).append(", ")
                  .append(blue.getCssText()).append(")");
              return res.toString();
          case SVGPaint.SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
              res = new StringBuffer();
              res .append("url('").append(uri)
                  .append("') rgb(")
                  .append(red.getCssText()).append(", ")
                  .append(green.getCssText()).append(", ")
                  .append(blue.getCssText()).append(") icc-color(")
                  .append(colorProfile);
              if (colors.getNumberOfItems() != 0) {
                  res.append(", ").append(colors.toString());
              }
              res.append(")");
              return res.toString();
          default:
              return super.getCssText();
          }
      }
  
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/SVGCSSNumber.java
  
  Index: SVGCSSNumber.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import org.w3c.dom.DOMException;
  
  import org.w3c.dom.svg.SVGNumber;
  
  /**
   * This class provides an implementation of SVGNumber.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: SVGCSSNumber.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public class SVGCSSNumber implements SVGNumber {
      
      /**
       * The value of this number.
       */
      protected float value;
  
      /**
       * Creates a new SVGCSSNumber.
       */
      public SVGCSSNumber(float f) {
          value = f;
      }
  
      /**
       * Returns the value of this float.
       */
      public float getValue() {
          return value;
      }
  
      /**
       * Sets the value of this number.
       */
      public void setValue(float f) {
          value = f;
      }
  
      /**
       * Indicates whether some other object is "equal to" this one.
       * @param obj the reference object with which to compare.
       */
      public boolean equals(Object obj) {
          if (obj == null || !(obj instanceof SVGCSSNumber)) {
              return false;
          }
          SVGCSSNumber n = (SVGCSSNumber)obj;
          return value == n.value;
      }
      
      /**
       * Returns a printable representation of this object.
       */
      public String toString() {
          return "" + value;
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/SVGCSSNumberList.java
  
  Index: SVGCSSNumberList.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.List;
  
  import org.w3c.dom.DOMException;
  
  import org.w3c.dom.svg.SVGException;
  import org.w3c.dom.svg.SVGNumber;
  import org.w3c.dom.svg.SVGNumberList;
  
  /**
   * This class provides an implementation of SVGNumberList.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: SVGCSSNumberList.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public class SVGCSSNumberList implements SVGNumberList {
  
      /**
       * The underlying list.
       */
      protected List list = new LinkedList();
  
      /**
       * Creates a readonly copy of this list.
       */
      SVGCSSNumberList createReadOnlyCopy() {
          SVGCSSReadOnlyNumberList res = new SVGCSSReadOnlyNumberList();
          List l = res.getList();
          Iterator it = list.iterator();
          while (it.hasNext()) {
              l.add(new SVGCSSReadOnlyNumber(((SVGNumber)it.next()).getValue()));
          }
          return res;
      }
  
      /**
       * Returns the underlying list.
       */
      public List getList() {
          return list;
      }
  
      /**
       * returns the number of items in this list.
       */
      public int getNumberOfItems() {
          return list.size();
      }
   
      /**
       * Clears this list.
       */
      public void clear() throws DOMException {
          list.clear();
      }
  
      /**
       * Initializes this list with the given item.
       */
      public SVGNumber initialize(SVGNumber item)
          throws DOMException, SVGException {
          list.clear();
          list.add(item);
          return item;
      }
  
      /**
       * Returns the item at the given index.
       */
      public SVGNumber getItem(int index) throws DOMException {
          if (index < 0 || index >= list.size()) {
              throw new DOMException(DOMException.INDEX_SIZE_ERR, "");
          }
          return (SVGNumber)list.get(index);
      }
  
      /**
       * Inserts the given item at the given index.
       */
      public SVGNumber insertItemBefore(SVGNumber item, int index)
          throws DOMException, SVGException {
          index = (index < 1) ? 0 : (index > list.size()) ? list.size() : index;
          list.add(index, item);
          return item;
      }
  
      /**
       * Inserts the item at the given index.
       */
      public SVGNumber replaceItem(SVGNumber item, int index)
          throws DOMException, SVGException {
          Object result = removeItem(index);
          list.add(index, item);
          return (SVGNumber)result;
      }
  
      /**
       * Removes the item at the given index.
       */
      public SVGNumber removeItem(int index) throws DOMException {
          if (index < 0 || index >= list.size()) {
              throw new DOMException(DOMException.INDEX_SIZE_ERR, "");
          }
          return (SVGNumber)list.remove(index);
      }
      
      /**
       * Appends the item at the given index.
       */
      public SVGNumber appendItem(SVGNumber item)
          throws DOMException, SVGException {
          list.add(item);
          return item;
      }
  
      /**
       * Indicates whether some other object is "equal to" this one.
       * @param obj the reference object with which to compare.
       */
      public boolean equals(Object obj) {
          if (obj == null || !(obj instanceof SVGCSSNumberList)) {
              return false;
          }
          SVGCSSNumberList nl = (SVGCSSNumberList)obj;
          List l = nl.getList();
  
          if (list.size() != l.size()) {
              return false;
          }
  
          Iterator it1 = list.iterator();
          Iterator it2 = l.iterator();
          while (it1.hasNext()) {
              if (!it1.next().equals(it2.next())) {
                  return false;
              }
          }
          return true;
      }
  
      /**
       * Returns a printable representation of this object.
       */
      public String toString() {
          StringBuffer res = new StringBuffer();
          Iterator it = list.iterator();
          if (it.hasNext()) {
              res.append(it.next().toString());
          }
          while (it.hasNext()) {
              res.append(", ");
              res.append(it.next().toString());
          }
          return res.toString();
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/SVGCSSReadOnlyNumber.java
  
  Index: SVGCSSReadOnlyNumber.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import org.w3c.dom.DOMException;
  
  /**
   * This class provides a read-only implementation of SVGNumber.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: SVGCSSReadOnlyNumber.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public class SVGCSSReadOnlyNumber extends SVGCSSNumber {
      
      /**
       * Creates a new SVGCSSReadOnlyNumber.
       */
      public SVGCSSReadOnlyNumber(float f) {
          super(f);
      }
  
      /**
       * Sets the value of this number.
       */
      public void setValue(float f) throws DOMException {
          throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/SVGCSSReadOnlyNumberList.java
  
  Index: SVGCSSReadOnlyNumberList.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import org.w3c.dom.DOMException;
  
  import org.w3c.dom.svg.SVGException;
  import org.w3c.dom.svg.SVGNumber;
  
  import org.w3c.dom.DOMException;
  
  /**
   * This class provides a read-only SVG number list.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: SVGCSSReadOnlyNumberList.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public class SVGCSSReadOnlyNumberList extends SVGCSSNumberList {
      /**
       * Clears this list.
       */
      public void clear() throws DOMException {
          throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
      }
  
      /**
       * Initializes this list with the given item.
       */
      public SVGNumber initialize(SVGNumber item)
          throws DOMException, SVGException {
          throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
      }
  
      /**
       * Inserts the given item at the given index.
       */
      public SVGNumber insertItemBefore(SVGNumber item, int index)
          throws DOMException, SVGException {
          throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
      }
  
      /**
       * Inserts the item at the given index.
       */
      public SVGNumber replaceItem(SVGNumber item, int index)
          throws DOMException, SVGException {
          throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
      }
  
      /**
       * Removes the item at the given index.
       */
      public SVGNumber removeItem(int index) throws DOMException {
          throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
      }
      
      /**
       * Appends the item at the given index.
       */
      public SVGNumber appendItem(SVGNumber item)
          throws DOMException, SVGException {
          throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/SVGCSSReadOnlyValue.java
  
  Index: SVGCSSReadOnlyValue.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import org.apache.batik.css.CSSDOMExceptionFactory;
  import org.apache.batik.css.CSSOMReadOnlyValue;
  
  import org.apache.batik.css.value.ImmutableValue;
  
  import org.w3c.dom.DOMException;
  
  import org.w3c.dom.css.CSSValue;
  import org.w3c.dom.css.RGBColor;
  
  import org.w3c.dom.svg.SVGException;
  import org.w3c.dom.svg.SVGICCColor;
  import org.w3c.dom.svg.SVGPaint;
  
  /**
   * This class represents a read-only SVG CSS value.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: SVGCSSReadOnlyValue.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public class SVGCSSReadOnlyValue
      extends CSSOMReadOnlyValue
      implements SVGPaint {
      
      /**
       * Creates a new SVG CSS value.
       */
      public SVGCSSReadOnlyValue(ImmutableValue v) {
          super(v);
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGPaint#getPaintType()}.
       */
      public short getPaintType() {
          return ((SVGImmutableValue)value).getPaintType();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGPaint#getUri()}.
       */
      public String getUri() {
          return ((SVGImmutableValue)value).getUri();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGPaint#setUri(String)}.
       */
      public void setUri(String uri) {
  	throw CSSDOMExceptionFactory.createDOMException
  	    (DOMException.INVALID_ACCESS_ERR,
  	     "readonly.value",
  	     new Object[] {});
      }
  
      /**
       * <b>DOM</b>: Implements {@link
       * org.w3c.dom.svg.SVGPaint#setPaint(short,String,String,String)}.
       */
      public void setPaint (short paintType, String uri, String rgbColor,
                            String iccColor) throws SVGException {
  	throw CSSDOMExceptionFactory.createDOMException
  	    (DOMException.INVALID_ACCESS_ERR,
  	     "readonly.value",
  	     new Object[] {});
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGColor#getColorType()}.
       */
      public short getColorType() {
          return ((SVGImmutableValue)value).getColorType();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGColor#getRGBColor()}.
       */
      public RGBColor getRGBColor() {
          return ((SVGImmutableValue)value).getRGBColor();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGColor#getICCColor()}.
       */
      public SVGICCColor getICCColor() {
          return ((SVGImmutableValue)value).getICCColor();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGColor#setRGBColor(String)}.
       */
      public void setRGBColor(String rgbColor) throws SVGException {
  	throw CSSDOMExceptionFactory.createDOMException
  	    (DOMException.INVALID_ACCESS_ERR,
  	     "readonly.value",
  	     new Object[] {});
      }
  
      /**
       * <b>DOM</b>: Implements {@link
       * org.w3c.dom.svg.SVGColor#setRGBColorICCColor(String,String)}.
       */
      public void setRGBColorICCColor(String rgbColor, String iccColor)
          throws SVGException {
  	throw CSSDOMExceptionFactory.createDOMException
  	    (DOMException.INVALID_ACCESS_ERR,
  	     "readonly.value",
  	     new Object[] {});
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/SVGCSSValue.java
  
  Index: SVGCSSValue.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import org.apache.batik.css.CSSOMReadOnlyValue;
  import org.apache.batik.css.CSSOMValue;
  
  import org.apache.batik.css.value.ImmutableValue;
  import org.apache.batik.css.value.ValueFactory;
  
  import org.w3c.dom.DOMException;
  
  import org.w3c.dom.css.CSSValue;
  import org.w3c.dom.css.RGBColor;
  
  import org.w3c.dom.svg.SVGException;
  import org.w3c.dom.svg.SVGICCColor;
  import org.w3c.dom.svg.SVGPaint;
  
  /**
   * This class represents a SVG CSS value.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: SVGCSSValue.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public class SVGCSSValue
      extends    CSSOMValue
      implements SVGPaint {
      
      /**
       * Creates a new CSS value.
       */
      public SVGCSSValue(ValueFactory vf, ImmutableValue v) {
          super(vf, v);
      }
  
      /**
       * Returns a read-only copy of this value.
       */
      public CSSOMReadOnlyValue createReadOnlyCopy() {
  	return new SVGCSSReadOnlyValue(value.createReadOnlyCopy());
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGPaint#getPaintType()}.
       */
      public short getPaintType() {
          return ((SVGImmutableValue)value).getPaintType();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGPaint#getUri()}.
       */
      public String getUri() {
          return ((SVGImmutableValue)value).getUri();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGPaint#setUri(String)}.
       */
      public void setUri(String uri) {
          throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
      }
  
      /**
       * <b>DOM</b>: Implements {@link
       * org.w3c.dom.svg.SVGPaint#setPaint(short,String,String,String)}.
       */
      public void setPaint (short paintType, String uri, String rgbColor,
                            String iccColor) throws SVGException {
          throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGColor#getColorType()}.
       */
      public short getColorType() {
          return ((SVGImmutableValue)value).getColorType();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGColor#getRGBColor()}.
       */
      public RGBColor getRGBColor() {
          return ((SVGImmutableValue)value).getRGBColor();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGColor#getICCColor()}.
       */
      public SVGICCColor getICCColor() {
          return ((SVGImmutableValue)value).getICCColor();
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGColor#setRGBColor(String)}.
       */
      public void setRGBColor(String rgbColor) throws SVGException {
          throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
      }
  
      /**
       * <b>DOM</b>: Implements {@link
       * org.w3c.dom.svg.SVGColor#setRGBColorICCColor(String,String)}.
       */
      public void setRGBColorICCColor(String rgbColor, String iccColor)
          throws SVGException {
          throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
      }
  }
  
  
  
  1.1                  xml-batik/sources/org/apache/batik/css/svg/SVGImmutableValue.java
  
  Index: SVGImmutableValue.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.css.svg;
  
  import org.apache.batik.css.value.ImmutableValue;
  
  import org.w3c.dom.css.RGBColor;
  
  import org.w3c.dom.svg.SVGICCColor;
  
  /**
   * This interface represents the immutable values used internally to
   * represents SVG CSS values.
   *
   * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
   * @version $Id: SVGImmutableValue.java,v 1.1 2001/02/12 06:18:25 hillion Exp $
   */
  public interface SVGImmutableValue extends ImmutableValue {
  
      /**
       * Returns the paint type, if this object represents a SVGPaint.
       */
      short getPaintType();
  
      /**
       * Returns the URI of the paint, if this object represents a SVGPaint.
       */
      String getUri();
  
      /**
       * Returns the color type, if this object represents a SVGColor.
       */
      short getColorType();
  
      /**
       * Returns the RGBColor, if this object represents a SVGColor.
       */
      RGBColor getRGBColor();
  
      /**
       * Returns the RGBColor, if this object represents a SVGColor.
       */
      SVGICCColor getICCColor();
  
  }
  
  
  
  1.3       +9 -2      xml-batik/sources/org/apache/batik/css/value/AbstractValueFactory.java
  
  Index: AbstractValueFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/value/AbstractValueFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractValueFactory.java	2000/10/25 17:57:20	1.2
  +++ AbstractValueFactory.java	2001/02/12 06:18:26	1.3
  @@ -22,7 +22,7 @@
    * This class provides a base implementation for every value factories.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: AbstractValueFactory.java,v 1.2 2000/10/25 17:57:20 hillion Exp $
  + * @version $Id: AbstractValueFactory.java,v 1.3 2001/02/12 06:18:26 hillion Exp $
    */
   public abstract class AbstractValueFactory
       implements ValueFactory,
  @@ -91,7 +91,7 @@
   			       CSSOMStyleDeclaration d,
   			       String imp) throws DOMException {
   	d.setPropertyCSSValue(getPropertyName(),
  -			      new CSSOMValue(this, createValue(lu)),
  +			      createCSSValue(createValue(lu)),
   			      imp);
       }
       
  @@ -121,6 +121,13 @@
   	    (DOMException.NOT_SUPPORTED_ERR,
   	     "bad.unit.type",
   	     new Object[] { new Integer(type) });
  +    }
  +
  +    /**
  +     * Creates a new CSSValue.
  +     */
  +    protected CSSOMValue createCSSValue(ImmutableValue v) {
  +        return new CSSOMValue(this, v);
       }
   
       /**