elena 2003/06/10 11:09:39 Modified: java/src/org/apache/xerces/dom CoreDOMImplementationImpl.java CoreDocumentImpl.java DOMImplementationImpl.java DOMImplementationSourceImpl.java EntityImpl.java NodeImpl.java java/src/org/apache/xerces/dom3/bootstrap DOMImplementationListImpl.java DOMImplementationRegistry.java java/src/org/apache/xerces/impl/xs/opti DefaultDocument.java DefaultNode.java java/src/org/apache/xerces/parsers AbstractDOMParser.java Log: Sink up with the DOM Level 3 Core Last Call interfaces. Also add a hook to support XPath DOM API if Xalan implementation can be found in the classpath. Revision Changes Path 1.25 +26 -18 xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java Index: CoreDOMImplementationImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- CoreDOMImplementationImpl.java 25 Mar 2003 20:49:14 -0000 1.24 +++ CoreDOMImplementationImpl.java 10 Jun 2003 18:09:38 -0000 1.25 @@ -55,23 +55,20 @@ * <http://www.apache.org/>. */ package org.apache.xerces.dom; +import org.apache.xerces.impl.RevalidationHandler; +import org.apache.xerces.parsers.DOMBuilderImpl; +import org.apache.xerces.util.ObjectFactory; +import org.apache.xerces.util.XMLChar; +import org.apache.xml.serialize.DOMWriterImpl; import org.w3c.dom.DOMException; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; -import org.w3c.dom.Node; -// DOM L3 LS -import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.DOMBuilder; -import org.w3c.dom.ls.DOMWriter; +import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.DOMInputSource; -import org.apache.xerces.parsers.DOMBuilderImpl; -import org.apache.xerces.util.XMLChar; -import org.apache.xml.serialize.DOMWriterImpl; -// DOM Revalidation -import org.apache.xerces.impl.RevalidationHandler; -import org.apache.xerces.util.ObjectFactory; +import org.w3c.dom.ls.DOMWriter; /** * The DOMImplementation class is description of a particular * implementation of the Document Object Model. As such its data is @@ -136,6 +133,19 @@ public boolean hasFeature(String feature, String version) { // Currently, we support only XML Level 1 version 1.0 boolean anyVersion = version == null || version.length() == 0; + // check if Xalan implementation is around and if yes report true for supporting + // XPath API + if ((feature.equalsIgnoreCase("XPath") || feature.equalsIgnoreCase("+XPath"))&& version.equals("3.0")){ + try{ + Class xpathClass = ObjectFactory.findProviderClass( + "org.apache.xpath.domapi.XPathEvaluatorImpl", + ObjectFactory.findClassLoader(), true); + } + catch (Exception e){ + return false; + } + return true; + } return ( feature.equalsIgnoreCase("Core") && (anyVersion || version.equals("1.0") || version.equals("2.0"))) @@ -272,13 +282,11 @@ /** * DOM Level 3 WD - Experimental. */ - public Node getFeature(String feature, String version) { - String msg = - DOMMessageFormatter.formatMessage( - DOMMessageFormatter.DOM_DOMAIN, - "NOT_SUPPORTED_ERR", - null); - throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); + public Object getFeature(String feature, String version) { + if (singleton.hasFeature(feature, version)){ + return singleton; + } + return null; } // DOM L3 LS 1.41 +36 -9 xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java Index: CoreDocumentImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- CoreDocumentImpl.java 25 Mar 2003 20:49:38 -0000 1.40 +++ CoreDocumentImpl.java 10 Jun 2003 18:09:38 -0000 1.41 @@ -63,6 +63,7 @@ import org.apache.xerces.dom3.DOMConfiguration; import org.apache.xerces.dom3.UserDataHandler; +import org.apache.xerces.util.ObjectFactory; import org.apache.xerces.util.XMLChar; import org.apache.xerces.xni.NamespaceContext; import org.w3c.dom.Attr; @@ -161,7 +162,10 @@ // DOM Level 3: normalizeDocument transient DOMNormalizer domNormalizer = null; - transient DOMConfigurationImpl fConfiguration= null; + transient DOMConfigurationImpl fConfiguration= null; + + // support of XPath API + transient Object fXPathEvaluator = null; /** Table for quick check of child insertion. */ private final static int[] kidOK; @@ -264,7 +268,7 @@ * since it has to operate in terms of a particular implementation. */ public CoreDocumentImpl() { - this(false); + this(false); } /** Constructor. */ @@ -489,6 +493,29 @@ throws DOMException { // no-op } + + /** + * @since DOM Level 3 + */ + public Object getFeature(String feature, String version) { + if ((feature.equalsIgnoreCase("XPath") + || feature.equalsIgnoreCase("+XPath"))&& version.equals("3.0")){ + try{ + Class xpathClass = ObjectFactory.findProviderClass( + "org.apache.xpath.domapi.XPathEvaluatorImpl", + ObjectFactory.findClassLoader(), true); + fXPathEvaluator = xpathClass.newInstance(); + java.lang.reflect.Method setDocument = xpathClass.getMethod("setDoc", new Class[]{Document.class}); + setDocument.invoke(fXPathEvaluator, new Object[]{this}); + return fXPathEvaluator; + } + catch (Exception e){ + e.printStackTrace(); + return null; + } + } + return super.getFeature(feature, version); + } // // Document methods @@ -763,7 +790,7 @@ * An attribute specifying, as part of the XML declaration, * the encoding of this document. This is null when unspecified. */ - public void setEncoding(String value) { + public void setXmlEncoding(String value) { encoding = value; } @@ -771,7 +798,7 @@ * DOM Level 3 WD - Experimental. * The encoding of this document (part of XML Declaration) */ - public String getEncoding() { + public String getXmlEncoding() { return encoding; } @@ -780,7 +807,7 @@ * version - An attribute specifying, as part of the XML declaration, * the version number of this document. This is null when unspecified */ - public void setVersion(String value) { + public void setXmlVersion(String value) { version = value; } @@ -788,7 +815,7 @@ * DOM Level 3 WD - Experimental. * The version of this document (part of XML Declaration) */ - public String getVersion() { + public String getXmlVersion() { return version; } @@ -797,7 +824,7 @@ * standalone - An attribute specifying, as part of the XML declaration, * whether this document is standalone */ - public void setStandalone(boolean value) { + public void setXmlStandalone(boolean value) { standalone = value; } @@ -806,7 +833,7 @@ * standalone that specifies whether this document is standalone * (part of XML Declaration) */ - public boolean getStandalone() { + public boolean getXmlStandalone() { return standalone; } 1.27 +15 -1 xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationImpl.java Index: DOMImplementationImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationImpl.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- DOMImplementationImpl.java 19 Nov 2002 01:41:36 -0000 1.26 +++ DOMImplementationImpl.java 10 Jun 2003 18:09:38 -0000 1.27 @@ -57,6 +57,7 @@ package org.apache.xerces.dom; +import org.apache.xerces.util.ObjectFactory; import org.w3c.dom.DOMException; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; @@ -122,6 +123,19 @@ // Currently, we support only XML Level 1 version 1.0 boolean anyVersion = version == null || version.length() == 0; + // check if Xalan implementation is around and if yes report true for supporting + // XPath API + if ((feature.equalsIgnoreCase("XPath") || feature.equalsIgnoreCase("+XPath"))&& version.equals("3.0")){ + try{ + Class xpathClass = ObjectFactory.findProviderClass( + "org.apache.xpath.domapi.XPathEvaluatorImpl", + ObjectFactory.findClassLoader(), true); + } + catch (Exception e){ + return false; + } + return true; + } return (feature.equalsIgnoreCase("Core") && (anyVersion 1.10 +2 -1 xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java Index: DOMImplementationSourceImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- DOMImplementationSourceImpl.java 8 May 2003 19:52:40 -0000 1.9 +++ DOMImplementationSourceImpl.java 10 Jun 2003 18:09:38 -0000 1.10 @@ -61,6 +61,7 @@ import org.apache.xerces.dom3.DOMImplementationList; import org.apache.xerces.dom3.DOMImplementationSource; +import org.apache.xerces.dom3.bootstrap.DOMImplementationListImpl; import org.w3c.dom.DOMImplementation; /** 1.22 +5 -5 xml-xerces/java/src/org/apache/xerces/dom/EntityImpl.java Index: EntityImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/EntityImpl.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- EntityImpl.java 8 May 2003 19:52:40 -0000 1.21 +++ EntityImpl.java 10 Jun 2003 18:09:38 -0000 1.22 @@ -209,7 +209,7 @@ * DOM Level 3 WD - experimental * the version number of this entity, when it is an external parsed entity. */ - public String getVersion() { + public String getXmlVersion() { if (needsSyncData()) { synchronizeData(); @@ -223,7 +223,7 @@ * DOM Level 3 WD - experimental * the encoding of this entity, when it is an external parsed entity. */ - public String getEncoding() { + public String getXmlEncoding() { if (needsSyncData()) { synchronizeData(); @@ -273,7 +273,7 @@ * the encoding of this entity, when it is an external parsed entity. * This is null otherwise */ - public void setEncoding(String value) { + public void setXmlEncoding(String value) { if (needsSyncData()) { synchronizeData(); @@ -312,7 +312,7 @@ * the version number of this entity, when it is an external parsed entity. * This is null otherwise */ - public void setVersion(String value) { + public void setXmlVersion(String value) { if (needsSyncData()) { synchronizeData(); } 1.68 +2 -19 xml-xerces/java/src/org/apache/xerces/dom/NodeImpl.java Index: NodeImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/NodeImpl.java,v retrieving revision 1.67 retrieving revision 1.68 diff -u -r1.67 -r1.68 --- NodeImpl.java 8 May 2003 19:52:40 -0000 1.67 +++ NodeImpl.java 10 Jun 2003 18:09:38 -0000 1.68 @@ -1791,26 +1791,9 @@ } /** - * This method returns a specialized object which implements the - * specialized APIs of the specified feature and version. The - * specialized object may also be obtained by using binding-specific - * casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations. - * @param feature The name of the feature requested (case-insensitive). - * @param version This is the version number of the feature to test. If - * the version is <code>null</code> or the empty string, supporting - * any version of the feature will cause the method to return an - * object that supports at least one version of the feature. - * @return Returns an object which implements the specialized APIs of - * the specified feature and version, if any, or <code>null</code> if - * there is no object which implements interfaces associated with that - * feature. If the <code>DOMObject</code> returned by this method - * implements the <code>Node</code> interface, it must delegate to the - * primary core <code>Node</code> and not return results inconsistent - * with the primary core <code>Node</code> such as attributes, - * childNodes, etc. * @since DOM Level 3 */ - public Node getFeature(String feature, String version) { + public Object getFeature(String feature, String version) { // we don't have any alternate node, either this node does the job // or we don't have anything that does return isSupported(feature, version) ? this : null; 1.2 +1 -2 xml-xerces/java/src/org/apache/xerces/dom3/bootstrap/DOMImplementationListImpl.java Index: DOMImplementationListImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom3/bootstrap/DOMImplementationListImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DOMImplementationListImpl.java 20 Mar 2003 00:38:30 -0000 1.1 +++ DOMImplementationListImpl.java 10 Jun 2003 18:09:39 -0000 1.2 @@ -24,7 +24,6 @@ import org.apache.xerces.dom3.DOMImplementationList; import org.w3c.dom.DOMImplementation; - public class DOMImplementationListImpl implements DOMImplementationList { @@ -69,7 +68,7 @@ /** * Add a <code>DOMImplementation</code> in the list. */ - protected void add(DOMImplementation domImpl) { + public void add(DOMImplementation domImpl) { sources.add(domImpl); } } 1.2 +16 -8 xml-xerces/java/src/org/apache/xerces/dom3/bootstrap/DOMImplementationRegistry.java Index: DOMImplementationRegistry.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom3/bootstrap/DOMImplementationRegistry.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DOMImplementationRegistry.java 20 Mar 2003 00:38:30 -0000 1.1 +++ DOMImplementationRegistry.java 10 Jun 2003 18:09:39 -0000 1.2 @@ -20,10 +20,17 @@ * Applications may also register DOMImplementationSource * implementations by using a method on this class. They may then * query instances of the registry for implementations supporting - * specific features.</p> + * specific features. * + * <p>Example:</p> + * <pre class='example'> + * // get an instance of the DOMImplementation registry + * DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); + * // get a DOM implementation the Level 3 XML module + * DOMImplementation domImpl = registry.getDOMImplementation("XML 3.0"); + * </pre> * <p>This provides an application with an implementation-independent - * starting point. + * starting point.</p> * * @see DOMImplementation * @see DOMImplementationSource @@ -32,17 +39,18 @@ package org.apache.xerces.dom3.bootstrap; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.lang.ClassLoader; +import java.lang.String; +import java.util.StringTokenizer; import java.util.Enumeration; import java.util.Hashtable; -import java.util.StringTokenizer; -import org.apache.xerces.dom3.DOMImplementationList; import org.apache.xerces.dom3.DOMImplementationSource; +import org.apache.xerces.dom3.DOMImplementationList; import org.w3c.dom.DOMImplementation; - public class DOMImplementationRegistry { // The system property to specify the DOMImplementationSource class names. @@ -100,7 +108,7 @@ * This is a space separated list in which each feature is * specified by its name optionally followed by a space * and a version number. - * This is something like: "XML 1.0 Traversal Events 2.0" + * This is something like: "XML 1.0 Traversal +Events 2.0" * @return An implementation that has the desired features, or * <code>null</code> if this source has none. */ @@ -131,7 +139,7 @@ * This is a space separated list in which each feature is * specified by its name optionally followed by a space * and a version number. - * This is something like: "XML 1.0 Traversal Events 2.0" + * This is something like: "XML 1.0 Traversal +Events 2.0" * @return A list of DOMImplementations that support the desired features. */ public DOMImplementationList getDOMImplementations(String features) 1.4 +7 -7 xml-xerces/java/src/org/apache/xerces/impl/xs/opti/DefaultDocument.java Index: DefaultDocument.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/DefaultDocument.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DefaultDocument.java 30 Dec 2002 21:21:08 -0000 1.3 +++ DefaultDocument.java 10 Jun 2003 18:09:39 -0000 1.4 @@ -184,7 +184,7 @@ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } - public String getEncoding(){ + public String getXmlEncoding(){ return null; } @@ -194,7 +194,7 @@ * of this document. This is <code>null</code> when unspecified. * @since DOM Level 3 */ - public void setEncoding(String encoding){ + public void setXmlEncoding(String encoding){ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } @@ -204,7 +204,7 @@ * <br> This attribute represents the property [standalone] defined in . * @since DOM Level 3 */ - public boolean getStandalone(){ + public boolean getXmlStandalone(){ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } /** @@ -213,7 +213,7 @@ * <br> This attribute represents the property [standalone] defined in . * @since DOM Level 3 */ - public void setStandalone(boolean standalone){ + public void setXmlStandalone(boolean standalone){ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } @@ -226,7 +226,7 @@ * not supported by this <code>Document</code>. * @since DOM Level 3 */ - public String getVersion(){ + public String getXmlVersion(){ return null; } /** @@ -238,7 +238,7 @@ * not supported by this <code>Document</code>. * @since DOM Level 3 */ - public void setVersion(String version) throws DOMException{ + public void setXmlVersion(String version) throws DOMException{ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); } 1.6 +2 -2 xml-xerces/java/src/org/apache/xerces/impl/xs/opti/DefaultNode.java Index: DefaultNode.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/DefaultNode.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DefaultNode.java 20 Mar 2003 00:38:30 -0000 1.5 +++ DefaultNode.java 10 Jun 2003 18:09:39 -0000 1.6 @@ -240,7 +240,7 @@ } - public Node getFeature(String feature, String version){ + public Object getFeature(String feature, String version){ return null; } public Object setUserData(String key, Object data, UserDataHandler handler){ 1.88 +9 -9 xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java Index: AbstractDOMParser.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v retrieving revision 1.87 retrieving revision 1.88 diff -u -r1.87 -r1.88 --- AbstractDOMParser.java 26 May 2003 17:50:45 -0000 1.87 +++ AbstractDOMParser.java 10 Jun 2003 18:09:39 -0000 1.88 @@ -584,8 +584,8 @@ } if (!fDeferNodeExpansion) { if (fCurrentEntityDecl != null && !fFilterReject) { - fCurrentEntityDecl.setEncoding(encoding); - fCurrentEntityDecl.setVersion(version); + fCurrentEntityDecl.setXmlEncoding(encoding); + fCurrentEntityDecl.setXmlVersion(version); } } else { @@ -854,15 +854,15 @@ // REVISIT: when DOM Level 3 is REC rely on Document.support // instead of specific class if (fDocumentImpl != null) { - fDocumentImpl.setVersion(version); - fDocumentImpl.setEncoding(encoding); - fDocumentImpl.setStandalone("yes".equals(standalone)); + fDocumentImpl.setXmlVersion(version); + fDocumentImpl.setXmlEncoding(encoding); + fDocumentImpl.setXmlStandalone("yes".equals(standalone)); } } else { - fDeferredDocumentImpl.setVersion(version); - fDeferredDocumentImpl.setEncoding(encoding); - fDeferredDocumentImpl.setStandalone("yes".equals(standalone)); + fDeferredDocumentImpl.setXmlVersion(version); + fDeferredDocumentImpl.setXmlEncoding(encoding); + fDeferredDocumentImpl.setXmlStandalone("yes".equals(standalone)); } } // xmlDecl(String,String,String)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]