001: /*
002:
003: ============================================================================
004: The Apache Software License, Version 1.1
005: ============================================================================
006:
007: Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
008:
009: Redistribution and use in source and binary forms, with or without modifica-
010: tion, are permitted provided that the following conditions are met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. Redistributions in binary form must reproduce the above copyright notice,
016: this list of conditions and the following disclaimer in the documentation
017: and/or other materials provided with the distribution.
018:
019: 3. The end-user documentation included with the redistribution, if any, must
020: include the following acknowledgment: "This product includes software
021: developed by the Apache Software Foundation (http://www.apache.org/)."
022: Alternately, this acknowledgment may appear in the software itself, if
023: and wherever such third-party acknowledgments normally appear.
024:
025: 4. The names "Batik" and "Apache Software Foundation" must not be
026: used to endorse or promote products derived from this software without
027: prior written permission. For written permission, please contact
028: apache@apache.org.
029:
030: 5. Products derived from this software may not be called "Apache", nor may
031: "Apache" appear in their name, without prior written permission of the
032: Apache Software Foundation.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
035: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
036: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
037: APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
039: DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
040: OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
041: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044:
045: This software consists of voluntary contributions made by many individuals
046: on behalf of the Apache Software Foundation. For more information on the
047: Apache Software Foundation, please see <http://www.apache.org/>.
048:
049: */
050:
051: package org.apache.batik.css.engine.value;
052:
053: import java.net.URL;
054:
055: import org.apache.batik.util.ParsedURL;
056: import org.w3c.dom.DOMException; // <rave>
057: import org.apache.batik.css.engine.CSSEngine;
058:
059: // </rave>
060:
061: /**
062: * This class provides a base implementation for the value factories.
063: *
064: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
065: * @version $Id$
066: */
067: public abstract class AbstractValueFactory {
068:
069: /**
070: * Returns the name of the property handled.
071: */
072: public abstract String getPropertyName();
073:
074: /**
075: * Resolves an URI.
076: */
077: protected static String resolveURI(URL base, String value) {
078: return new ParsedURL(base, value).toString();
079: }
080:
081: // <rave>
082: // BEGIN RAVE MODIFICATIONS
083: private String getPropertyName(CSSEngine engine) {
084: String name = null;
085: if (engine != null) {
086: name = engine.getExpandingShorthandProperty();
087: }
088: if (name == null) {
089: name = getPropertyName();
090: }
091: return name;
092: }
093:
094: // In the following methods, I have added an engine parameter,
095: // since Batik didn't include one. I have also updated all references
096: // to pass in the "engine" parameter which was always available at
097: // the point of using these error message methods.
098: // I also modified all references to getPropertyName() in the below
099: // to the local private method getPropertyName(engine) which does the
100: // same but checks for a global shorthand property being processed and
101: // uses that name instead if set.
102: // END RAVE MODIFICATIONS
103: // </rave>
104: /**
105: * Creates a DOM exception, given an invalid identifier.
106: */
107: // <rave>
108: // protected DOMException createInvalidIdentifierDOMException(String ident) {
109: // Object[] p = new Object[] { getPropertyName(), ident };
110: protected DOMException createInvalidIdentifierDOMException(
111: String ident, CSSEngine engine) {
112: Object[] p = new Object[] { getPropertyName(engine), ident };
113: // </rave>
114: String s = Messages.formatMessage("invalid.identifier", p);
115: // <rave>
116: // BEGIN RAVE MODIFICATIONS
117: if (this instanceof IdentifierProvider) {
118: StringMap map = ((IdentifierProvider) this )
119: .getIdentifierMap();
120: java.util.Iterator keys = map.keys();
121: java.util.ArrayList list = new java.util.ArrayList();
122: while (keys.hasNext()) {
123: String identifier = (String) keys.next();
124: // Only add non-vendor-specific identifiers
125: if (!identifier.startsWith("-")) {
126: list.add(identifier);
127: }
128: }
129: if (list.size() > 0) {
130: String identifiers = list.toString();
131: if (identifiers.length() > 80) {
132: identifiers = identifiers.substring(0, 80) + "...]";
133: }
134: s = s + " " + identifiers;
135: }
136: }
137: // END RAVE MODIFICATIONS
138: // </rave>
139: return new DOMException(DOMException.SYNTAX_ERR, s);
140: }
141:
142: /**
143: * Creates a DOM exception, given an invalid lexical unit type.
144: */
145: // <rave>
146: // protected DOMException createInvalidLexicalUnitDOMException(short type) {
147: // Object[] p = new Object[] { getPropertyName(),
148: protected DOMException createInvalidLexicalUnitDOMException(
149: short type, CSSEngine engine) {
150: Object[] p = new Object[] { getPropertyName(engine),
151: // </rave>
152: new Integer(type) };
153: String s = Messages.formatMessage("invalid.lexical.unit", p);
154: return new DOMException(DOMException.NOT_SUPPORTED_ERR, s);
155: }
156:
157: /**
158: * Creates a DOM exception, given an invalid float type.
159: */
160: // <rave>
161: // protected DOMException createInvalidFloatTypeDOMException(short t) {
162: // Object[] p = new Object[] { getPropertyName(), new Integer(t) };
163: protected DOMException createInvalidFloatTypeDOMException(short t,
164: CSSEngine engine) {
165: Object[] p = new Object[] { getPropertyName(engine),
166: new Integer(t) };
167: // </rave>
168: String s = Messages.formatMessage("invalid.float.type", p);
169: return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
170: }
171:
172: /**
173: * Creates a DOM exception, given an invalid float value.
174: */
175: // <rave>
176: // protected DOMException createInvalidFloatValueDOMException(float f) {
177: // Object[] p = new Object[] { getPropertyName(), new Float(f) };
178: protected DOMException createInvalidFloatValueDOMException(float f,
179: CSSEngine engine) {
180: Object[] p = new Object[] { getPropertyName(engine),
181: new Float(f) };
182: // </rave>
183: String s = Messages.formatMessage("invalid.float.value", p);
184: return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
185: }
186:
187: /**
188: * Creates a DOM exception, given an invalid string type.
189: */
190: // <rave>
191: // protected DOMException createInvalidStringTypeDOMException(short t) {
192: // Object[] p = new Object[] { getPropertyName(), new Integer(t) };
193: protected DOMException createInvalidStringTypeDOMException(short t,
194: CSSEngine engine) {
195: Object[] p = new Object[] { getPropertyName(engine),
196: new Integer(t) };
197: // </rave>
198: String s = Messages.formatMessage("invalid.string.type", p);
199: return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
200: }
201:
202: // <rave>
203: // protected DOMException createMalformedLexicalUnitDOMException() {
204: // Object[] p = new Object[] { getPropertyName() };
205: protected DOMException createMalformedLexicalUnitDOMException(
206: CSSEngine engine) {
207: Object[] p = new Object[] { getPropertyName(engine) };
208: // </rave>
209: String s = Messages.formatMessage("malformed.lexical.unit", p);
210: return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
211: }
212:
213: // <rave>
214: // protected DOMException createDOMException(CSSEngine engine) {
215: // Object[] p = new Object[] { getPropertyName() };
216: protected DOMException createDOMException(CSSEngine engine) {
217: Object[] p = new Object[] { getPropertyName(engine) };
218: // </rave>
219: String s = Messages.formatMessage("invalid.access", p);
220: return new DOMException(DOMException.NOT_SUPPORTED_ERR, s);
221: }
222: }
|