001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.css.engine.value;
020:
021: import java.net.URL;
022:
023: import org.apache.batik.util.ParsedURL;
024: import org.w3c.dom.DOMException;
025:
026: /**
027: * This class provides a base implementation for the value factories.
028: *
029: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
030: * @version $Id: AbstractValueFactory.java 475477 2006-11-15 22:44:28Z cam $
031: */
032: public abstract class AbstractValueFactory {
033:
034: /**
035: * Returns the name of the property handled.
036: */
037: public abstract String getPropertyName();
038:
039: /**
040: * Resolves an URI.
041: */
042: protected static String resolveURI(URL base, String value) {
043: return new ParsedURL(base, value).toString();
044: }
045:
046: /**
047: * Creates a DOM exception, given an invalid identifier.
048: */
049: protected DOMException createInvalidIdentifierDOMException(
050: String ident) {
051: Object[] p = new Object[] { getPropertyName(), ident };
052: String s = Messages.formatMessage("invalid.identifier", p);
053: return new DOMException(DOMException.SYNTAX_ERR, s);
054: }
055:
056: /**
057: * Creates a DOM exception, given an invalid lexical unit type.
058: */
059: protected DOMException createInvalidLexicalUnitDOMException(
060: short type) {
061: Object[] p = new Object[] { getPropertyName(),
062: new Integer(type) };
063: String s = Messages.formatMessage("invalid.lexical.unit", p);
064: return new DOMException(DOMException.NOT_SUPPORTED_ERR, s);
065: }
066:
067: /**
068: * Creates a DOM exception, given an invalid float type.
069: */
070: protected DOMException createInvalidFloatTypeDOMException(short t) {
071: Object[] p = new Object[] { getPropertyName(), new Integer(t) };
072: String s = Messages.formatMessage("invalid.float.type", p);
073: return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
074: }
075:
076: /**
077: * Creates a DOM exception, given an invalid float value.
078: */
079: protected DOMException createInvalidFloatValueDOMException(float f) {
080: Object[] p = new Object[] { getPropertyName(), new Float(f) };
081: String s = Messages.formatMessage("invalid.float.value", p);
082: return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
083: }
084:
085: /**
086: * Creates a DOM exception, given an invalid string type.
087: */
088: protected DOMException createInvalidStringTypeDOMException(short t) {
089: Object[] p = new Object[] { getPropertyName(), new Integer(t) };
090: String s = Messages.formatMessage("invalid.string.type", p);
091: return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
092: }
093:
094: protected DOMException createMalformedLexicalUnitDOMException() {
095: Object[] p = new Object[] { getPropertyName() };
096: String s = Messages.formatMessage("malformed.lexical.unit", p);
097: return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
098: }
099:
100: protected DOMException createDOMException() {
101: Object[] p = new Object[] { getPropertyName() };
102: String s = Messages.formatMessage("invalid.access", p);
103: return new DOMException(DOMException.NOT_SUPPORTED_ERR, s);
104: }
105: }
|