You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ca...@apache.org on 2008/12/22 03:12:35 UTC
svn commit: r728570 - in /xmlgraphics/batik/trunk: ./
resources/org/apache/batik/dom/resources/
resources/org/apache/batik/dom/svg/resources/ sources/org/apache/batik/dom/
sources/org/apache/batik/dom/svg/ sources/org/apache/batik/xml/
Author: cam
Date: Sun Dec 21 18:12:35 2008
New Revision: 728570
URL: http://svn.apache.org/viewvc?rev=728570&view=rev
Log:
1. DocumentType.getName() now returns the correct value.
2. Appropriate exceptions are now thrown from
DOMImplementation.createDocumentType().
3. Fixed some message resource references.
Fixes bugs 46430 and 46431.
Modified:
xmlgraphics/batik/trunk/CHANGES
xmlgraphics/batik/trunk/resources/org/apache/batik/dom/resources/Messages.properties
xmlgraphics/batik/trunk/resources/org/apache/batik/dom/svg/resources/Messages.properties
xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDOMImplementation.java
xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtensibleDOMImplementation.java
xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDOMImplementation.java
xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDocumentType.java
xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGDOMImplementation.java
xmlgraphics/batik/trunk/sources/org/apache/batik/xml/XMLUtilities.java
Modified: xmlgraphics/batik/trunk/CHANGES
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/CHANGES?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/CHANGES (original)
+++ xmlgraphics/batik/trunk/CHANGES Sun Dec 21 18:12:35 2008
@@ -10,7 +10,7 @@
1. Bugzilla problem reports fixed:
44590, 44919, 44936, 44966, 45112, 45114, 45117, 45520, 45883,
- 44553, 45958, 46072, 46124
+ 44553, 45958, 46072, 46124, 46430, 46431
2. New features
@@ -43,6 +43,9 @@
compared to other animations on the same attribute.
* Avoid canvas repaint problems that occur in some circumstances when
it is being resized.
+ * Exceptions are now thrown if an invalid QName is passed to
+ DOMImplementation.createDocumentType().
+ * DocumentType.getName() now returns the correct value.
1.7beta1 -> 1.7
---------------
Modified: xmlgraphics/batik/trunk/resources/org/apache/batik/dom/resources/Messages.properties
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/resources/org/apache/batik/dom/resources/Messages.properties?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/resources/org/apache/batik/dom/resources/Messages.properties (original)
+++ xmlgraphics/batik/trunk/resources/org/apache/batik/dom/resources/Messages.properties Sun Dec 21 18:12:35 2008
@@ -32,7 +32,7 @@
A DocumentType node cannot be imported.
add.self = \
-Cannot add a node as a child of it's self (name: {1})
+Cannot add a node as a child of itself (name: {1}).
attribute.missing = \
The "{0}" attribute was not found.
@@ -51,7 +51,7 @@
child.type = \
The current node (type: {0}, name: {1}) do not allow children of the given \
-type (type: {2}, name: {3})
+type (type: {2}, name: {3}).
children.not.allowed = \
The current node (type: {0}, name: {1}) cannot have children.
@@ -60,6 +60,15 @@
An error occured while cloning a node (type: {0}, name: {1}). \
The original error message was: "{2}".
+css.parser.class = \
+The CSS parser class {0} cannot be found.
+
+css.parser.creation = \
+The CSS parser class '{0}' cannot be instantiated.
+
+css.parser.access = \
+The CSS parser class '{0}' cannot be accessed.
+
document.child.already.exists = \
The node (type: {0}, name: {1}) cannot be inserted, since the document \
node already has a node of type {0}.
@@ -89,6 +98,9 @@
The current document is unable to create an element of the requested type \
(namespace: {0}, name: {1}).
+invalid.qname = \
+The given name ("{0}") is an invalid QName.
+
inuse.attribute = \
The given attribute "{0}" is already in use.
Modified: xmlgraphics/batik/trunk/resources/org/apache/batik/dom/svg/resources/Messages.properties
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/resources/org/apache/batik/dom/svg/resources/Messages.properties?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/resources/org/apache/batik/dom/svg/resources/Messages.properties (original)
+++ xmlgraphics/batik/trunk/resources/org/apache/batik/dom/svg/resources/Messages.properties Sun Dec 21 18:12:35 2008
@@ -44,15 +44,6 @@
doctype.not.supported = \
Cannot create a SVG DocumentType object.
-css.parser.class = \
-The CSS parser class {0} cannot be found.
-
-css.parser.creation = \
-The CSS parser class '{0}' cannot be instantiated.
-
-css.parser.access = \
-The CSS parser class '{0}' cannot be accessed.
-
noninvertiblematrix = \
The matrix is not invertible.
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDOMImplementation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDOMImplementation.java?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDOMImplementation.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDOMImplementation.java Sun Dec 21 18:12:35 2008
@@ -19,9 +19,13 @@
package org.apache.batik.dom;
import java.io.Serializable;
+import java.util.Locale;
+import java.util.MissingResourceException;
import org.apache.batik.dom.events.DocumentEventSupport;
import org.apache.batik.dom.events.EventSupport;
+import org.apache.batik.i18n.Localizable;
+import org.apache.batik.i18n.LocalizableSupport;
import org.apache.batik.dom.util.HashTable;
import org.w3c.dom.DOMImplementation;
@@ -36,9 +40,22 @@
public abstract class AbstractDOMImplementation
implements DOMImplementation,
+ Localizable,
Serializable {
/**
+ * The error messages bundle class name.
+ */
+ protected static final String RESOURCES =
+ "org.apache.batik.dom.resources.Messages";
+
+ /**
+ * The localizable support for the error messages.
+ */
+ protected LocalizableSupport localizableSupport =
+ new LocalizableSupport(RESOURCES, getClass().getClassLoader());
+
+ /**
* The supported features.
*/
protected final HashTable features = new HashTable();
@@ -129,4 +146,31 @@
public EventSupport createEventSupport(AbstractNode n) {
return new EventSupport(n);
}
+
+ // Localizable //////////////////////////////////////////////////////
+
+ /**
+ * Implements {@link Localizable#setLocale(Locale)}.
+ */
+ public void setLocale(Locale l) {
+ localizableSupport.setLocale(l);
+ }
+
+ /**
+ * Implements {@link Localizable#getLocale()}.
+ */
+ public Locale getLocale() {
+ return localizableSupport.getLocale();
+ }
+
+ protected void initLocalizable() {
+ }
+
+ /**
+ * Implements {@link Localizable#formatMessage(String,Object[])}.
+ */
+ public String formatMessage(String key, Object[] args)
+ throws MissingResourceException {
+ return localizableSupport.formatMessage(key, args);
+ }
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtensibleDOMImplementation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtensibleDOMImplementation.java?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtensibleDOMImplementation.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/ExtensibleDOMImplementation.java Sun Dec 21 18:12:35 2008
@@ -22,8 +22,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
-import java.util.Locale;
-import java.util.MissingResourceException;
import org.apache.batik.css.engine.CSSContext;
import org.apache.batik.css.engine.CSSEngine;
@@ -32,15 +30,15 @@
import org.apache.batik.css.parser.ExtendedParser;
import org.apache.batik.css.parser.ExtendedParserWrapper;
import org.apache.batik.dom.util.DOMUtilities;
-import org.apache.batik.i18n.Localizable;
-import org.apache.batik.i18n.LocalizableSupport;
import org.apache.batik.util.DoublyIndexedTable;
import org.apache.batik.util.Service;
import org.apache.batik.util.XMLResourceDescriptor;
+import org.apache.batik.xml.XMLUtilities;
import org.w3c.css.sac.Parser;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.css.DOMImplementationCSS;
import org.w3c.dom.css.ViewCSS;
@@ -57,8 +55,7 @@
public abstract class ExtensibleDOMImplementation
extends AbstractDOMImplementation
implements DOMImplementationCSS,
- StyleSheetFactory,
- Localizable {
+ StyleSheetFactory {
/**
* The custom elements factories.
@@ -76,22 +73,9 @@
protected List customShorthandManagers;
/**
- * The error messages bundle class name.
- */
- protected static final String RESOURCES =
- "org.apache.batik.dom.resources.Messages";
-
- /**
- * The localizable support for the error messages.
- */
- protected LocalizableSupport localizableSupport;
-
- /**
* Creates a new DOMImplementation.
*/
public ExtensibleDOMImplementation() {
- initLocalizable();
-
Iterator iter = getDomExtensions().iterator();
while(iter.hasNext()) {
@@ -100,35 +84,6 @@
}
}
- // Localizable //////////////////////////////////////////////////////
-
- /**
- * Implements {@link Localizable#setLocale(Locale)}.
- */
- public void setLocale(Locale l) {
- localizableSupport.setLocale(l);
- }
-
- /**
- * Implements {@link Localizable#getLocale()}.
- */
- public Locale getLocale() {
- return localizableSupport.getLocale();
- }
-
- protected void initLocalizable() {
- localizableSupport =
- new LocalizableSupport(RESOURCES, getClass().getClassLoader());
- }
-
- /**
- * Implements {@link Localizable#formatMessage(String,Object[])}.
- */
- public String formatMessage(String key, Object[] args)
- throws MissingResourceException {
- return localizableSupport.formatMessage(key, args);
- }
-
/**
* Allows the user to register a new element factory.
*/
@@ -252,6 +207,33 @@
document);
}
+ /**
+ * <b>DOM</b>: Implements {@link
+ * DOMImplementation#createDocumentType(String,String,String)}.
+ */
+ public DocumentType createDocumentType(String qualifiedName,
+ String publicId,
+ String systemId) {
+
+ if (qualifiedName == null) {
+ qualifiedName = "";
+ }
+ int test = XMLUtilities.testXMLQName(qualifiedName);
+ if ((test & XMLUtilities.IS_XML_10_NAME) == 0) {
+ throw new DOMException
+ (DOMException.INVALID_CHARACTER_ERR,
+ formatMessage("xml.name",
+ new Object[] { qualifiedName }));
+ }
+ if ((test & XMLUtilities.IS_XML_10_QNAME) == 0) {
+ throw new DOMException
+ (DOMException.INVALID_CHARACTER_ERR,
+ formatMessage("invalid.qname",
+ new Object[] { qualifiedName }));
+ }
+ return new GenericDocumentType(qualifiedName, publicId, systemId);
+ }
+
// The element factories /////////////////////////////////////////////////
/**
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDOMImplementation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDOMImplementation.java?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDOMImplementation.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDOMImplementation.java Sun Dec 21 18:12:35 2008
@@ -18,6 +18,8 @@
*/
package org.apache.batik.dom;
+import org.apache.batik.xml.XMLUtilities;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
@@ -25,7 +27,7 @@
/**
* This class implements the {@link org.w3c.dom.DOMImplementation}.
- *
+
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
* @version $Id$
*/
@@ -54,17 +56,6 @@
/**
* <b>DOM</b>: Implements {@link
- * DOMImplementation#createDocumentType(String,String,String)}.
- */
- public DocumentType createDocumentType(String qualifiedName,
- String publicId,
- String systemId) {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
- "Doctype not supported");
- }
-
- /**
- * <b>DOM</b>: Implements {@link
* DOMImplementation#createDocument(String,String,DocumentType)}.
*/
public Document createDocument(String namespaceURI,
@@ -75,4 +66,31 @@
qualifiedName));
return result;
}
+
+ /**
+ * <b>DOM</b>: Implements {@link
+ * DOMImplementation#createDocumentType(String,String,String)}.
+ */
+ public DocumentType createDocumentType(String qualifiedName,
+ String publicId,
+ String systemId) {
+
+ if (qualifiedName == null) {
+ qualifiedName = "";
+ }
+ int test = XMLUtilities.testXMLQName(qualifiedName);
+ if ((test & XMLUtilities.IS_XML_10_NAME) == 0) {
+ throw new DOMException
+ (DOMException.INVALID_CHARACTER_ERR,
+ formatMessage("xml.name",
+ new Object[] { qualifiedName }));
+ }
+ if ((test & XMLUtilities.IS_XML_10_QNAME) == 0) {
+ throw new DOMException
+ (DOMException.INVALID_CHARACTER_ERR,
+ formatMessage("invalid.qname",
+ new Object[] { qualifiedName }));
+ }
+ return new GenericDocumentType(qualifiedName, publicId, systemId);
+ }
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDocumentType.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDocumentType.java?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDocumentType.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/GenericDocumentType.java Sun Dec 21 18:12:35 2008
@@ -33,13 +33,27 @@
extends AbstractChildNode
implements DocumentType {
+ /**
+ * The qualified name of the document element.
+ */
protected String qualifiedName;
+
+ /**
+ * The DTD public ID, if specified.
+ */
protected String publicId;
+
+ /**
+ * The DTD system ID, if specified.
+ */
protected String systemId;
+ /**
+ * Creates a new DocumentType object.
+ */
public GenericDocumentType(String qualifiedName,
- String publicId,
- String systemId) {
+ String publicId,
+ String systemId) {
this.qualifiedName = qualifiedName;
this.publicId = publicId;
this.systemId = systemId;
@@ -49,18 +63,28 @@
* <b>DOM</b>: Implements {@link org.w3c.dom.Node#getNodeName()}.
* @return The name of the DTD.
*/
- public String getNodeName() { return qualifiedName; }
+ public String getNodeName() {
+ return qualifiedName;
+ }
- public short getNodeType() { return DOCUMENT_TYPE_NODE; }
+ public short getNodeType() {
+ return DOCUMENT_TYPE_NODE;
+ }
- public boolean isReadonly() { return true; }
- public void setReadonly(boolean ro) {}
+ public boolean isReadonly() {
+ return true;
+ }
+
+ public void setReadonly(boolean ro) {
+ }
/**
* <b>DOM</b>: Implements {@link org.w3c.dom.DocumentType#getName()}.
- * @return The name of the DTD.
+ * @return The name of document element as specified in the DTD.
*/
- public String getName() { return null; }
+ public String getName() {
+ return qualifiedName;
+ }
/**
* <b>DOM</b>: Implements {@link org.w3c.dom.DocumentType#getEntities()}.
@@ -82,21 +106,27 @@
* <b>DOM</b>: Implements {@link org.w3c.dom.DocumentType#getPublicId()}.
* @return The public id.
*/
- public String getPublicId() { return publicId; }
+ public String getPublicId() {
+ return publicId;
+ }
/**
* <b>DOM</b>: Implements {@link org.w3c.dom.DocumentType#getSystemId()}.
* @return The public id.
*/
- public String getSystemId() { return systemId; }
+ public String getSystemId() {
+ return systemId;
+ }
/**
* <b>DOM</b>: Implements {@link org.w3c.dom.DocumentType#getInternalSubset()}.
* @return The public id.
*/
- public String getInternalSubset() { return null; }
-
+ public String getInternalSubset() {
+ return null;
+ }
protected Node newNode() {
- return new GenericDocumentType(qualifiedName, publicId, systemId); }
+ return new GenericDocumentType(qualifiedName, publicId, systemId);
+ }
}
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGDOMImplementation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGDOMImplementation.java?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGDOMImplementation.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGDOMImplementation.java Sun Dec 21 18:12:35 2008
@@ -30,7 +30,6 @@
import org.apache.batik.dom.AbstractDocument;
import org.apache.batik.dom.AbstractStylableDocument;
import org.apache.batik.dom.ExtensibleDOMImplementation;
-import org.apache.batik.dom.GenericDocumentType;
import org.apache.batik.dom.events.DOMTimeEvent;
import org.apache.batik.dom.events.DocumentEventSupport;
import org.apache.batik.dom.util.CSSStyleDeclarationFactory;
@@ -130,16 +129,6 @@
/**
* <b>DOM</b>: Implements {@link
- * DOMImplementation#createDocumentType(String,String,String)}.
- */
- public DocumentType createDocumentType(String qualifiedName,
- String publicId,
- String systemId) {
- return new GenericDocumentType(qualifiedName, publicId, systemId);
- }
-
- /**
- * <b>DOM</b>: Implements {@link
* DOMImplementation#createDocument(String,String,DocumentType)}.
*/
public Document createDocument(String namespaceURI,
Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/xml/XMLUtilities.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/xml/XMLUtilities.java?rev=728570&r1=728569&r2=728570&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/xml/XMLUtilities.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/xml/XMLUtilities.java Sun Dec 21 18:12:35 2008
@@ -36,6 +36,10 @@
*/
public class XMLUtilities extends XMLCharacters {
+ // Bitfield constants used in the return value of testXMLQName.
+ public static final int IS_XML_10_NAME = 1;
+ public static final int IS_XML_10_QNAME = 2;
+
/**
* This class does not need to be instantiated.
*/
@@ -87,7 +91,7 @@
* Tests whether the given 32 bits character is valid in XML documents.
* Because the majority of code-points is covered by the table-lookup-test,
* we do it first.
- * This method gives meaningful results only for c >= 0 .
+ * This method gives meaningful results only for c >= 0.
*/
public static boolean isXMLCharacter(int c) {
@@ -129,6 +133,41 @@
}
/**
+ * Test whether the given string is an XML 1.0 Name and/or QName.
+ * @return A bitfield of {@link #IS_XML_10_NAME} and
+ * {@link #IS_XML_10_QNAME}.
+ */
+ public static int testXMLQName(String s) {
+ int isQName = IS_XML_10_QNAME;
+ boolean foundColon = false;
+ int len = s.length();
+ if (len == 0) {
+ return 0;
+ }
+ char c = s.charAt(0);
+ if (!isXMLNameFirstCharacter(c)) {
+ return 0;
+ }
+ if (c == ':') {
+ isQName = 0;
+ }
+ for (int i = 1; i < len; i++) {
+ c = s.charAt(i);
+ if (!isXMLNameCharacter(c)) {
+ return 0;
+ }
+ if (isQName != 0 && c == ':') {
+ if (foundColon || i == len - 1) {
+ isQName = 0;
+ } else {
+ foundColon = true;
+ }
+ }
+ }
+ return IS_XML_10_NAME | isQName;
+ }
+
+ /**
* Creates a Reader initialized to scan the characters in the given
* XML document's InputStream.
* @param is The input stream positionned at the beginning of an