Merge
This commit is contained in:
commit
eaf60b4da7
jaxp/src
java.xml/share/classes/com/sun/org/apache
jdk.xml.dom/share/classes/org/w3c/dom
css
CSS2Properties.javaCSSCharsetRule.javaCSSFontFaceRule.javaCSSImportRule.javaCSSMediaRule.javaCSSPageRule.javaCSSPrimitiveValue.javaCSSRule.javaCSSRuleList.javaCSSStyleDeclaration.javaCSSStyleRule.javaCSSStyleSheet.javaCSSUnknownRule.javaCSSValue.javaCSSValueList.javaCounter.javaDOMImplementationCSS.javaDocumentCSS.javaElementCSSInlineStyle.javaRGBColor.javaRect.javaViewCSS.java
html
HTMLAnchorElement.javaHTMLAppletElement.javaHTMLAreaElement.javaHTMLBRElement.javaHTMLBaseElement.javaHTMLBaseFontElement.javaHTMLBodyElement.javaHTMLButtonElement.javaHTMLCollection.javaHTMLDListElement.javaHTMLDOMImplementation.javaHTMLDirectoryElement.javaHTMLDivElement.javaHTMLDocument.javaHTMLElement.javaHTMLFieldSetElement.javaHTMLFontElement.javaHTMLFormElement.javaHTMLFrameElement.javaHTMLFrameSetElement.javaHTMLHRElement.javaHTMLHeadElement.javaHTMLHeadingElement.javaHTMLHtmlElement.javaHTMLIFrameElement.javaHTMLImageElement.javaHTMLInputElement.javaHTMLIsIndexElement.javaHTMLLIElement.javaHTMLLabelElement.javaHTMLLegendElement.javaHTMLLinkElement.javaHTMLMapElement.javaHTMLMenuElement.javaHTMLMetaElement.javaHTMLModElement.javaHTMLOListElement.javaHTMLObjectElement.javaHTMLOptGroupElement.javaHTMLOptionElement.javaHTMLParagraphElement.javaHTMLParamElement.javaHTMLPreElement.javaHTMLQuoteElement.javaHTMLScriptElement.javaHTMLSelectElement.javaHTMLStyleElement.javaHTMLTableCaptionElement.javaHTMLTableCellElement.javaHTMLTableColElement.javaHTMLTableElement.javaHTMLTableRowElement.javaHTMLTableSectionElement.javaHTMLTextAreaElement.javaHTMLTitleElement.javaHTMLUListElement.java
stylesheets
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -150,6 +150,16 @@ public final class XalanConstants {
|
||||
*/
|
||||
public static final String SP_MAX_ELEMENT_DEPTH = "jdk.xml.maxElementDepth";
|
||||
|
||||
/**
|
||||
* JDK TransformerFactory and Transformer attribute that specifies a class
|
||||
* loader that will be used for extension functions class loading
|
||||
* Value: a "null", the default value, means that the default EF class loading
|
||||
* path will be used.
|
||||
* Instance of ClassLoader: the specified instance of ClassLoader will be used
|
||||
* for extension functions loading during translation process
|
||||
*/
|
||||
public static final String JDK_EXTENSION_CLASSLOADER = "jdk.xml.transform.extensionClassLoader";
|
||||
|
||||
//legacy System Properties
|
||||
public final static String ENTITY_EXPANSION_LIMIT = "entityExpansionLimit";
|
||||
public static final String ELEMENT_ATTRIBUTE_LIMIT = "elementAttributeLimit" ;
|
||||
|
21
jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java
21
jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java
@ -104,6 +104,9 @@ class FunctionCall extends Expression {
|
||||
protected final static String EXSLT_STRINGS =
|
||||
"http://exslt.org/strings";
|
||||
|
||||
protected final static String XALAN_CLASSPACKAGE_NAMESPACE =
|
||||
"xalan://";
|
||||
|
||||
// Namespace format constants
|
||||
protected final static int NAMESPACE_FORMAT_JAVA = 0;
|
||||
protected final static int NAMESPACE_FORMAT_CLASS = 1;
|
||||
@ -900,8 +903,22 @@ class FunctionCall extends Expression {
|
||||
if (_className != null && _className.length() > 0) {
|
||||
final int nArgs = _arguments.size();
|
||||
try {
|
||||
if (_clazz == null) {
|
||||
_clazz = ObjectFactory.findProviderClass(_className, true);
|
||||
if (_clazz == null) {
|
||||
final boolean isSecureProcessing = getXSLTC().isSecureProcessing();
|
||||
final boolean isExtensionFunctionEnabled = getXSLTC()
|
||||
.getFeature(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION);
|
||||
|
||||
//Check if FSP and SM - only then process with loading
|
||||
if (namespace != null && isSecureProcessing
|
||||
&& isExtensionFunctionEnabled
|
||||
&& (namespace.equals(JAVA_EXT_XALAN)
|
||||
|| namespace.equals(JAVA_EXT_XSLTC)
|
||||
|| namespace.equals(JAVA_EXT_XALAN_OLD)
|
||||
|| namespace.startsWith(XALAN_CLASSPACKAGE_NAMESPACE))) {
|
||||
_clazz = getXSLTC().loadExternalFunction(_className);
|
||||
} else {
|
||||
_clazz = ObjectFactory.findProviderClass(_className, true);
|
||||
}
|
||||
|
||||
if (_clazz == null) {
|
||||
final ErrorMsg msg =
|
||||
|
@ -23,24 +23,6 @@
|
||||
|
||||
package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Manifest;
|
||||
import javax.xml.XMLConstants;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.classfile.JavaClass;
|
||||
import com.sun.org.apache.xalan.internal.XalanConstants;
|
||||
import com.sun.org.apache.xalan.internal.utils.FeatureManager;
|
||||
@ -50,7 +32,27 @@ import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
|
||||
import com.sun.org.apache.xml.internal.dtm.DTM;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Manifest;
|
||||
import javax.xml.XMLConstants;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
@ -152,12 +154,26 @@ public final class XSLTC {
|
||||
|
||||
private final FeatureManager _featureManager;
|
||||
|
||||
/**
|
||||
* Extension function class loader variables
|
||||
*/
|
||||
|
||||
/* Class loader reference that will be used to external extension functions loading */
|
||||
private ClassLoader _extensionClassLoader;
|
||||
|
||||
/**
|
||||
* HashSet with the loaded classes
|
||||
*/
|
||||
private final Map<String, Class> _externalExtensionFunctions;
|
||||
|
||||
/**
|
||||
* XSLTC compiler constructor
|
||||
*/
|
||||
public XSLTC(boolean useServicesMechanism, FeatureManager featureManager) {
|
||||
_parser = new Parser(this, useServicesMechanism);
|
||||
_featureManager = featureManager;
|
||||
_extensionClassLoader = null;
|
||||
_externalExtensionFunctions = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,6 +223,8 @@ public final class XSLTC {
|
||||
return _accessExternalDTD;
|
||||
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
|
||||
return _xmlSecurityManager;
|
||||
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
|
||||
return _extensionClassLoader;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -222,6 +240,11 @@ public final class XSLTC {
|
||||
_accessExternalDTD = (String)value;
|
||||
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
|
||||
_xmlSecurityManager = (XMLSecurityManager)value;
|
||||
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
|
||||
_extensionClassLoader = (ClassLoader) value;
|
||||
/* Clear the external extension functions HashMap if extension class
|
||||
loader was changed */
|
||||
_externalExtensionFunctions.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,6 +279,41 @@ public final class XSLTC {
|
||||
_bcelClasses = new Vector();
|
||||
}
|
||||
|
||||
private void setExternalExtensionFunctions(String name, Class clazz) {
|
||||
if (_isSecureProcessing && clazz != null && !_externalExtensionFunctions.containsKey(name)) {
|
||||
_externalExtensionFunctions.put(name, clazz);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function loads an external external extension functions.
|
||||
* The filtering of function types (external,internal) takes place in FunctionCall class
|
||||
*
|
||||
*/
|
||||
Class loadExternalFunction(String name) throws ClassNotFoundException {
|
||||
Class loaded = null;
|
||||
//Check if the function is not loaded already
|
||||
if (_externalExtensionFunctions.containsKey(name)) {
|
||||
loaded = _externalExtensionFunctions.get(name);
|
||||
} else if (_extensionClassLoader != null) {
|
||||
loaded = Class.forName(name, true, _extensionClassLoader);
|
||||
setExternalExtensionFunctions(name, loaded);
|
||||
}
|
||||
if (loaded == null) {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
//Return loaded class
|
||||
return (Class) loaded;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns unmodifiable view of HashMap with loaded external extension
|
||||
* functions - will be needed for the TransformerImpl
|
||||
*/
|
||||
public Map<String, Class> getExternalExtensionFunctions() {
|
||||
return Collections.unmodifiableMap(_externalExtensionFunctions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the compiler to produce a new translet
|
||||
*/
|
||||
@ -283,6 +341,7 @@ public final class XSLTC {
|
||||
-1, // LEVEL_MULTIPLE
|
||||
-1 // LEVEL_ANY
|
||||
};
|
||||
_externalExtensionFunctions.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -602,6 +602,9 @@ public class ErrorMessages extends ListResourceBundle {
|
||||
{ErrorMsg.JAXP_INVALID_ATTR_ERR,
|
||||
"TransformerFactory does not recognise attribute ''{0}''."},
|
||||
|
||||
{ErrorMsg.JAXP_INVALID_ATTR_VALUE_ERR,
|
||||
"Incorrect value specified for ''{0}'' attribute."},
|
||||
|
||||
/*
|
||||
* Note to translators: "setResult()" and "startDocument()" are Java
|
||||
* method names that should not be translated.
|
||||
|
1
jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java
1
jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java
@ -117,6 +117,7 @@ public final class ErrorMsg {
|
||||
public static final String JAXP_NO_SOURCE_ERR = "JAXP_NO_SOURCE_ERR";
|
||||
public static final String JAXP_COMPILE_ERR = "JAXP_COMPILE_ERR";
|
||||
public static final String JAXP_INVALID_ATTR_ERR = "JAXP_INVALID_ATTR_ERR";
|
||||
public static final String JAXP_INVALID_ATTR_VALUE_ERR = "JAXP_INVALID_ATTR_VALUE_ERR";
|
||||
public static final String JAXP_SET_RESULT_ERR = "JAXP_SET_RESULT_ERR";
|
||||
public static final String JAXP_NO_TRANSLET_ERR = "JAXP_NO_TRANSLET_ERR";
|
||||
public static final String JAXP_NO_HANDLER_ERR = "JAXP_NO_HANDLER_ERR";
|
||||
|
@ -24,27 +24,26 @@
|
||||
package com.sun.org.apache.xalan.internal.xsltc.trax;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.XalanConstants;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Properties;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.transform.Templates;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.URIResolver;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
||||
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.DOM;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.Translet;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
|
||||
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
||||
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.transform.Templates;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.URIResolver;
|
||||
|
||||
/**
|
||||
* @author Morten Jorgensen
|
||||
@ -131,8 +130,30 @@ public final class TemplatesImpl implements Templates, Serializable {
|
||||
private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
|
||||
|
||||
static final class TransletClassLoader extends ClassLoader {
|
||||
|
||||
private final Map<String,Class> _loadedExternalExtensionFunctions;
|
||||
|
||||
TransletClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
_loadedExternalExtensionFunctions = null;
|
||||
}
|
||||
|
||||
TransletClassLoader(ClassLoader parent,Map<String, Class> mapEF) {
|
||||
super(parent);
|
||||
_loadedExternalExtensionFunctions = mapEF;
|
||||
}
|
||||
|
||||
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
||||
Class<?> ret = null;
|
||||
// The _loadedExternalExtensionFunctions will be empty when the
|
||||
// SecurityManager is not set and the FSP is turned off
|
||||
if (_loadedExternalExtensionFunctions != null) {
|
||||
ret = _loadedExternalExtensionFunctions.get(name);
|
||||
}
|
||||
if (ret == null) {
|
||||
ret = super.loadClass(name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -330,7 +351,7 @@ public final class TemplatesImpl implements Templates, Serializable {
|
||||
TransletClassLoader loader = (TransletClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return new TransletClassLoader(ObjectFactory.findClassLoader());
|
||||
return new TransletClassLoader(ObjectFactory.findClassLoader(),_tfactory.getExternalExtensionsMap());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -27,12 +27,12 @@ import com.sun.org.apache.xalan.internal.XalanConstants;
|
||||
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
|
||||
import com.sun.org.apache.xalan.internal.utils.FeatureManager;
|
||||
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase;
|
||||
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase.State;
|
||||
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
||||
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
||||
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
|
||||
import com.sun.org.apache.xalan.internal.utils.XMLSecurityPropertyManager;
|
||||
import com.sun.org.apache.xalan.internal.utils.XMLSecurityPropertyManager.Property;
|
||||
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase.State;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
|
||||
@ -50,6 +50,7 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import java.util.zip.ZipEntry;
|
||||
@ -57,7 +58,6 @@ import java.util.zip.ZipFile;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import javax.xml.transform.ErrorListener;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Templates;
|
||||
@ -231,6 +231,13 @@ public class TransformerFactoryImpl
|
||||
|
||||
private final FeatureManager _featureManager;
|
||||
|
||||
private ClassLoader _extensionClassLoader = null;
|
||||
|
||||
// Unmodifiable view of external extension function from xslt compiler
|
||||
// It will be populated by user-specified extension functions during the
|
||||
// type checking
|
||||
private Map<String, Class> _xsltcExtensionFunctions;
|
||||
|
||||
/**
|
||||
* javax.xml.transform.sax.TransformerFactory implementation.
|
||||
*/
|
||||
@ -261,6 +268,12 @@ public class TransformerFactoryImpl
|
||||
|
||||
//Parser's security manager
|
||||
_xmlSecurityManager = new XMLSecurityManager(true);
|
||||
//Unmodifiable hash map with loaded external extension functions
|
||||
_xsltcExtensionFunctions = null;
|
||||
}
|
||||
|
||||
public Map<String,Class> getExternalExtensionsMap() {
|
||||
return _xsltcExtensionFunctions;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,6 +337,8 @@ public class TransformerFactoryImpl
|
||||
return Boolean.FALSE;
|
||||
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) {
|
||||
return _xmlSecurityManager;
|
||||
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
|
||||
return _extensionClassLoader;
|
||||
}
|
||||
|
||||
/** Check to see if the property is managed by the security manager **/
|
||||
@ -439,6 +454,16 @@ public class TransformerFactoryImpl
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ( name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) {
|
||||
if (value instanceof ClassLoader) {
|
||||
_extensionClassLoader = (ClassLoader) value;
|
||||
return;
|
||||
} else {
|
||||
final ErrorMsg err
|
||||
= new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_VALUE_ERR, "Extension Functions ClassLoader");
|
||||
throw new IllegalArgumentException(err.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (_xmlSecurityManager != null &&
|
||||
_xmlSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, value)) {
|
||||
@ -881,7 +906,6 @@ public class TransformerFactoryImpl
|
||||
// Reset the per-session attributes to their default values
|
||||
// after each newTemplates() call.
|
||||
resetTransientAttributes();
|
||||
|
||||
return new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this);
|
||||
}
|
||||
}
|
||||
@ -898,8 +922,10 @@ public class TransformerFactoryImpl
|
||||
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, _accessExternalStylesheet);
|
||||
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
|
||||
xsltc.setProperty(XalanConstants.SECURITY_MANAGER, _xmlSecurityManager);
|
||||
xsltc.setProperty(XalanConstants.JDK_EXTENSION_CLASSLOADER, _extensionClassLoader);
|
||||
xsltc.init();
|
||||
|
||||
if (!_isNotSecureProcessing)
|
||||
_xsltcExtensionFunctions = xsltc.getExternalExtensionFunctions();
|
||||
// Set a document loader (for xsl:include/import) if defined
|
||||
if (_uriResolver != null) {
|
||||
xsltc.setSourceLoader(this);
|
||||
|
@ -108,32 +108,6 @@ public class CoreDOMImplementationImpl
|
||||
|
||||
boolean anyVersion = version == null || version.length() == 0;
|
||||
|
||||
// check if Xalan implementation is around and if yes report true for supporting
|
||||
// XPath API
|
||||
// if a plus sign "+" is prepended to any feature name, implementations
|
||||
// are considered in which the specified feature may not be directly
|
||||
// castable DOMImplementation.getFeature(feature, version). Without a
|
||||
// plus, only features whose interfaces are directly castable are considered.
|
||||
if ((feature.equalsIgnoreCase("+XPath"))
|
||||
&& (anyVersion || version.equals("3.0"))) {
|
||||
try {
|
||||
Class xpathClass = ObjectFactory.findProviderClass(
|
||||
"com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
|
||||
|
||||
// Check if the DOM XPath implementation implements
|
||||
// the interface org.w3c.dom.XPathEvaluator
|
||||
Class interfaces[] = xpathClass.getInterfaces();
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
if (interfaces[i].getName().equals(
|
||||
"org.w3c.dom.xpath.XPathEvaluator")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (feature.startsWith("+")) {
|
||||
feature = feature.substring(1);
|
||||
}
|
||||
@ -281,25 +255,7 @@ public class CoreDOMImplementationImpl
|
||||
*/
|
||||
public Object getFeature(String feature, String version) {
|
||||
if (singleton.hasFeature(feature, version)) {
|
||||
if ((feature.equalsIgnoreCase("+XPath"))) {
|
||||
try {
|
||||
Class xpathClass = ObjectFactory.findProviderClass(
|
||||
"com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
|
||||
// Check if the DOM XPath implementation implements
|
||||
// the interface org.w3c.dom.XPathEvaluator
|
||||
Class interfaces[] = xpathClass.getInterfaces();
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
if (interfaces[i].getName().equals(
|
||||
"org.w3c.dom.xpath.XPathEvaluator")) {
|
||||
return xpathClass.newInstance();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return singleton;
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -498,44 +498,6 @@ extends ParentNode implements Document {
|
||||
* @since DOM Level 3
|
||||
*/
|
||||
public Object getFeature(String feature, String version) {
|
||||
|
||||
boolean anyVersion = version == null || version.length() == 0;
|
||||
|
||||
// if a plus sign "+" is prepended to any feature name, implementations
|
||||
// are considered in which the specified feature may not be directly
|
||||
// castable DOMImplementation.getFeature(feature, version). Without a
|
||||
// plus, only features whose interfaces are directly castable are
|
||||
// considered.
|
||||
if ((feature.equalsIgnoreCase("+XPath"))
|
||||
&& (anyVersion || version.equals("3.0"))) {
|
||||
|
||||
// If an XPathEvaluator was created previously
|
||||
// return it otherwise create a new one.
|
||||
if (fXPathEvaluator != null) {
|
||||
return fXPathEvaluator;
|
||||
}
|
||||
|
||||
try {
|
||||
Class xpathClass = ObjectFactory.findProviderClass (
|
||||
"com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
|
||||
Constructor xpathClassConstr =
|
||||
xpathClass.getConstructor(new Class[] { Document.class });
|
||||
|
||||
// Check if the DOM XPath implementation implements
|
||||
// the interface org.w3c.dom.XPathEvaluator
|
||||
Class interfaces[] = xpathClass.getInterfaces();
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
if (interfaces[i].getName().equals(
|
||||
"org.w3c.dom.xpath.XPathEvaluator")) {
|
||||
fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
|
||||
return fXPathEvaluator;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return super.getFeature(feature, version);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@ import java.io.UnsupportedEncodingException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DocumentType;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.html.HTMLDocument;
|
||||
|
||||
|
||||
/**
|
||||
@ -273,45 +272,6 @@ public class OutputFormat
|
||||
setIndenting( indenting );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new output format with the proper method,
|
||||
* document type identifiers and media type for the specified
|
||||
* document.
|
||||
*
|
||||
* @param doc The document to output
|
||||
* @see #whichMethod
|
||||
*/
|
||||
public OutputFormat( Document doc )
|
||||
{
|
||||
setMethod( whichMethod( doc ) );
|
||||
setDoctype( whichDoctypePublic( doc ), whichDoctypeSystem( doc ) );
|
||||
setMediaType( whichMediaType( getMethod() ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new output format with the proper method,
|
||||
* document type identifiers and media type for the specified
|
||||
* document, and with the specified encoding. If <tt>indent</tt>
|
||||
* is true, the document will be pretty printed with the default
|
||||
* indentation level and default line wrapping.
|
||||
*
|
||||
* @param doc The document to output
|
||||
* @param encoding The specified encoding
|
||||
* @param indenting True for pretty printing
|
||||
* @see #setEncoding
|
||||
* @see #setIndenting
|
||||
* @see #whichMethod
|
||||
*/
|
||||
public OutputFormat( Document doc, String encoding, boolean indenting )
|
||||
{
|
||||
this( doc );
|
||||
setEncoding( encoding );
|
||||
setIndenting( indenting );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the method specified for this output format.
|
||||
* Typically the method will be <tt>xml</tt>, <tt>html</tt>
|
||||
@ -840,110 +800,6 @@ public class OutputFormat
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the output method for the specified document.
|
||||
* If the document is an instance of {@link org.w3c.dom.html.HTMLDocument}
|
||||
* then the method is said to be <tt>html</tt>. If the root
|
||||
* element is 'html' and all text nodes preceding the root
|
||||
* element are all whitespace, then the method is said to be
|
||||
* <tt>html</tt>. Otherwise the method is <tt>xml</tt>.
|
||||
*
|
||||
* @param doc The document to check
|
||||
* @return The suitable method
|
||||
*/
|
||||
public static String whichMethod( Document doc )
|
||||
{
|
||||
Node node;
|
||||
String value;
|
||||
int i;
|
||||
|
||||
// If document is derived from HTMLDocument then the default
|
||||
// method is html.
|
||||
if ( doc instanceof HTMLDocument )
|
||||
return Method.HTML;
|
||||
|
||||
// Lookup the root element and the text nodes preceding it.
|
||||
// If root element is html and all text nodes contain whitespace
|
||||
// only, the method is html.
|
||||
|
||||
// FIXME (SM) should we care about namespaces here?
|
||||
|
||||
node = doc.getFirstChild();
|
||||
while (node != null) {
|
||||
// If the root element is html, the method is html.
|
||||
if ( node.getNodeType() == Node.ELEMENT_NODE ) {
|
||||
if ( node.getNodeName().equalsIgnoreCase( "html" ) ) {
|
||||
return Method.HTML;
|
||||
} else if ( node.getNodeName().equalsIgnoreCase( "root" ) ) {
|
||||
return Method.FOP;
|
||||
} else {
|
||||
return Method.XML;
|
||||
}
|
||||
} else if ( node.getNodeType() == Node.TEXT_NODE ) {
|
||||
// If a text node preceding the root element contains
|
||||
// only whitespace, this might be html, otherwise it's
|
||||
// definitely xml.
|
||||
value = node.getNodeValue();
|
||||
for ( i = 0 ; i < value.length() ; ++i )
|
||||
if ( value.charAt( i ) != 0x20 && value.charAt( i ) != 0x0A &&
|
||||
value.charAt( i ) != 0x09 && value.charAt( i ) != 0x0D )
|
||||
return Method.XML;
|
||||
}
|
||||
node = node.getNextSibling();
|
||||
}
|
||||
// Anything else, the method is xml.
|
||||
return Method.XML;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the document type public identifier
|
||||
* specified for this document, or null.
|
||||
*/
|
||||
public static String whichDoctypePublic( Document doc )
|
||||
{
|
||||
DocumentType doctype;
|
||||
|
||||
/* DOM Level 2 was introduced into the code base*/
|
||||
doctype = doc.getDoctype();
|
||||
if ( doctype != null ) {
|
||||
// Note on catch: DOM Level 1 does not specify this method
|
||||
// and the code will throw a NoSuchMethodError
|
||||
try {
|
||||
return doctype.getPublicId();
|
||||
} catch ( Error except ) { }
|
||||
}
|
||||
|
||||
if ( doc instanceof HTMLDocument )
|
||||
return DTD.XHTMLPublicId;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the document type system identifier
|
||||
* specified for this document, or null.
|
||||
*/
|
||||
public static String whichDoctypeSystem( Document doc )
|
||||
{
|
||||
DocumentType doctype;
|
||||
|
||||
/* DOM Level 2 was introduced into the code base*/
|
||||
doctype = doc.getDoctype();
|
||||
if ( doctype != null ) {
|
||||
// Note on catch: DOM Level 1 does not specify this method
|
||||
// and the code will throw a NoSuchMethodError
|
||||
try {
|
||||
return doctype.getSystemId();
|
||||
} catch ( Error except ) { }
|
||||
}
|
||||
|
||||
if ( doc instanceof HTMLDocument )
|
||||
return DTD.XHTMLSystemId;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the suitable media format for a document
|
||||
* output with the specified method.
|
||||
|
94
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/SafeThread.java
Normal file
94
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/SafeThread.java
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.org.apache.xml.internal.utils;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
/**
|
||||
* This is a combination of ThreadControllerWrapper's inner class SafeThread
|
||||
* that was introduced as a fix for CR 6607339
|
||||
* and sun.misc.ManagedLocalsThread, a thread that has it's thread locals, and
|
||||
* inheritable thread locals erased on construction. Except the run method,
|
||||
* it is identical to sun.misc.ManagedLocalsThread.
|
||||
*/
|
||||
public class SafeThread extends Thread {
|
||||
|
||||
private static final Unsafe UNSAFE;
|
||||
private static final long THREAD_LOCALS;
|
||||
private static final long INHERITABLE_THREAD_LOCALS;
|
||||
|
||||
private volatile boolean ran = false;
|
||||
|
||||
public SafeThread(Runnable target) {
|
||||
super(target);
|
||||
eraseThreadLocals();
|
||||
}
|
||||
|
||||
public SafeThread(Runnable target, String name) {
|
||||
super(target, name);
|
||||
eraseThreadLocals();
|
||||
}
|
||||
|
||||
public SafeThread(ThreadGroup group, Runnable target, String name) {
|
||||
super(group, target, name);
|
||||
eraseThreadLocals();
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
if (Thread.currentThread() != this) {
|
||||
throw new IllegalStateException("The run() method in a"
|
||||
+ " SafeThread cannot be called from another thread.");
|
||||
}
|
||||
synchronized (this) {
|
||||
if (!ran) {
|
||||
ran = true;
|
||||
} else {
|
||||
throw new IllegalStateException("The run() method in a"
|
||||
+ " SafeThread cannot be called more than once.");
|
||||
}
|
||||
}
|
||||
super.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops all thread locals (and inherited thread locals).
|
||||
*/
|
||||
public final void eraseThreadLocals() {
|
||||
UNSAFE.putObject(this, THREAD_LOCALS, null);
|
||||
UNSAFE.putObject(this, INHERITABLE_THREAD_LOCALS, null);
|
||||
}
|
||||
|
||||
static {
|
||||
UNSAFE = Unsafe.getUnsafe();
|
||||
Class<?> t = Thread.class;
|
||||
try {
|
||||
THREAD_LOCALS = UNSAFE.objectFieldOffset(t.getDeclaredField("threadLocals"));
|
||||
INHERITABLE_THREAD_LOCALS = UNSAFE.objectFieldOffset(t.getDeclaredField("inheritableThreadLocals"));
|
||||
} catch (Exception e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
150
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/ThreadControllerWrapper.java
150
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/ThreadControllerWrapper.java
@ -3,11 +3,12 @@
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
@ -17,110 +18,73 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* $Id: ThreadControllerWrapper.java,v 1.2.4.1 2005/09/15 08:15:59 suresh_emailid Exp $
|
||||
*/
|
||||
package com.sun.org.apache.xml.internal.utils;
|
||||
|
||||
/**
|
||||
* A utility class that wraps the ThreadController, which is used
|
||||
* by IncrementalSAXSource for the incremental building of DTM.
|
||||
* A utility class that wraps the ThreadController, which is used by
|
||||
* IncrementalSAXSource for the incremental building of DTM.
|
||||
*/
|
||||
public class ThreadControllerWrapper
|
||||
{
|
||||
|
||||
/** The ThreadController pool */
|
||||
private static ThreadController m_tpool = new ThreadController();
|
||||
|
||||
public static Thread runThread(Runnable runnable, int priority)
|
||||
{
|
||||
return m_tpool.run(runnable, priority);
|
||||
}
|
||||
|
||||
public static void waitThread(Thread worker, Runnable task)
|
||||
throws InterruptedException
|
||||
{
|
||||
m_tpool.waitThread(worker, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread controller utility class for incremental SAX source. Must
|
||||
* be overriden with a derived class to support thread pooling.
|
||||
*
|
||||
* All thread-related stuff is in this class.
|
||||
*/
|
||||
public static class ThreadController
|
||||
{
|
||||
public class ThreadControllerWrapper {
|
||||
|
||||
/**
|
||||
* This class was introduced as a fix for CR 6607339.
|
||||
* The ThreadController pool
|
||||
*/
|
||||
final class SafeThread extends Thread {
|
||||
private volatile boolean ran = false;
|
||||
private static ThreadController m_tpool = new ThreadController();
|
||||
|
||||
public SafeThread(Runnable target) {
|
||||
super(target);
|
||||
}
|
||||
public static Thread runThread(Runnable runnable, int priority) {
|
||||
return m_tpool.run(runnable, priority);
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
if (Thread.currentThread() != this) {
|
||||
throw new IllegalStateException("The run() method in a"
|
||||
+ " SafeThread cannot be called from another thread.");
|
||||
}
|
||||
synchronized (this) {
|
||||
if (!ran) {
|
||||
ran = true;
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("The run() method in a"
|
||||
+ " SafeThread cannot be called more than once.");
|
||||
}
|
||||
}
|
||||
super.run();
|
||||
}
|
||||
public static void waitThread(Thread worker, Runnable task)
|
||||
throws InterruptedException {
|
||||
m_tpool.waitThread(worker, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will get a thread from the pool, execute the task
|
||||
* and return the thread to the pool.
|
||||
* Thread controller utility class for incremental SAX source. Must be
|
||||
* overridden with a derived class to support thread pooling.
|
||||
*
|
||||
* The return value is used only to wait for completion
|
||||
*
|
||||
*
|
||||
* NEEDSDOC @param task
|
||||
* @param priority if >0 the task will run with the given priority
|
||||
* ( doesn't seem to be used in xalan, since it's allways the default )
|
||||
* @return The thread that is running the task, can be used
|
||||
* to wait for completion
|
||||
* All thread-related stuff is in this class.
|
||||
*/
|
||||
public Thread run(Runnable task, int priority)
|
||||
{
|
||||
public static class ThreadController {
|
||||
|
||||
Thread t = new SafeThread(task);
|
||||
/**
|
||||
* Will get a thread from the pool, execute the task and return the
|
||||
* thread to the pool.
|
||||
*
|
||||
* The return value is used only to wait for completion
|
||||
*
|
||||
*
|
||||
* @param task the Runnable
|
||||
*
|
||||
* @param priority if >0 the task will run with the given priority (
|
||||
* doesn't seem to be used in xalan, since it's always the default )
|
||||
* @return The thread that is running the task, can be used to wait for
|
||||
* completion
|
||||
*/
|
||||
public Thread run(Runnable task, int priority) {
|
||||
|
||||
t.start();
|
||||
Thread t = new SafeThread(task);
|
||||
t.start();
|
||||
|
||||
// if( priority > 0 )
|
||||
// t.setPriority( priority );
|
||||
return t;
|
||||
//if( priority > 0 )
|
||||
// t.setPriority( priority );
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the task is completed on the worker thread.
|
||||
*
|
||||
* @param worker worker thread
|
||||
* @param task the Runnable
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void waitThread(Thread worker, Runnable task)
|
||||
throws InterruptedException {
|
||||
|
||||
// This should wait until the transformThread is considered not alive.
|
||||
worker.join();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the task is completed on the worker
|
||||
* thread.
|
||||
*
|
||||
* NEEDSDOC @param worker
|
||||
* NEEDSDOC @param task
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void waitThread(Thread worker, Runnable task)
|
||||
throws InterruptedException
|
||||
{
|
||||
|
||||
// This should wait until the transformThread is considered not alive.
|
||||
worker.join();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -637,26 +637,8 @@ class Lexer
|
||||
}
|
||||
else
|
||||
{
|
||||
// To older XPath code it doesn't matter if
|
||||
// error() is called or errorForDOM3().
|
||||
m_processor.errorForDOM3(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
|
||||
new String[] {prefix}); //"Prefix must resolve to a namespace: {0}";
|
||||
|
||||
/** old code commented out 17-Sep-2004
|
||||
// error("Could not locate namespace for prefix: "+prefix);
|
||||
// m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
|
||||
// new String[] {prefix}); //"Prefix must resolve to a namespace: {0}";
|
||||
*/
|
||||
|
||||
/*** Old code commented out 10-Jan-2001
|
||||
addToTokenQueue(prefix);
|
||||
addToTokenQueue(":");
|
||||
|
||||
String s = pat.substring(posOfNSSep + 1, posOfScan);
|
||||
|
||||
if (s.length() > 0)
|
||||
addToTokenQueue(s);
|
||||
***/
|
||||
m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
|
||||
new String[] {prefix}); //"Prefix must resolve to a namespace: {0}";
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -28,7 +28,6 @@ import javax.xml.transform.TransformerException;
|
||||
import com.sun.org.apache.xalan.internal.res.XSLMessages;
|
||||
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
|
||||
import com.sun.org.apache.xpath.internal.XPathProcessorException;
|
||||
import com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception;
|
||||
import com.sun.org.apache.xpath.internal.objects.XNumber;
|
||||
import com.sun.org.apache.xpath.internal.objects.XString;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
|
||||
@ -622,50 +621,6 @@ public class XPathParser
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is added to support DOM 3 XPath API.
|
||||
* <p>
|
||||
* This method is exactly like error(String, Object[]); except that
|
||||
* the underlying TransformerException is
|
||||
* XpathStylesheetDOM3Exception (which extends TransformerException).
|
||||
* <p>
|
||||
* So older XPath code in Xalan is not affected by this. To older XPath code
|
||||
* the behavior of whether error() or errorForDOM3() is called because it is
|
||||
* always catching TransformerException objects and is oblivious to
|
||||
* the new subclass of XPathStylesheetDOM3Exception. Older XPath code
|
||||
* runs as before.
|
||||
* <p>
|
||||
* However, newer DOM3 XPath code upon catching a TransformerException can
|
||||
* can check if the exception is an instance of XPathStylesheetDOM3Exception
|
||||
* and take appropriate action.
|
||||
*
|
||||
* @param msg An error msgkey that corresponds to one of the constants found
|
||||
* in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
|
||||
* a key for a format string.
|
||||
* @param args An array of arguments represented in the format string, which
|
||||
* may be null.
|
||||
*
|
||||
* @throws TransformerException if the current ErrorListoner determines to
|
||||
* throw an exception.
|
||||
*/
|
||||
void errorForDOM3(String msg, Object[] args) throws TransformerException
|
||||
{
|
||||
|
||||
String fmsg = XSLMessages.createXPATHMessage(msg, args);
|
||||
ErrorListener ehandler = this.getErrorListener();
|
||||
|
||||
TransformerException te = new XPathStylesheetDOM3Exception(fmsg, m_sourceLocator);
|
||||
if (null != ehandler)
|
||||
{
|
||||
// TO DO: Need to get stylesheet Locator from here.
|
||||
ehandler.fatalError(te);
|
||||
}
|
||||
else
|
||||
{
|
||||
// System.err.println(fmsg);
|
||||
throw te;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Dump the remaining token queue.
|
||||
* Thanks to Craig for this.
|
||||
|
273
jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/domapi/XPathEvaluatorImpl.java
273
jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/domapi/XPathEvaluatorImpl.java
@ -1,273 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2002-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* $Id: XPathEvaluatorImpl.java,v 1.2.4.1 2005/09/10 04:04:07 jeffsuttor Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xpath.internal.domapi;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
|
||||
import com.sun.org.apache.xpath.internal.XPath;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHMessages;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.xpath.XPathEvaluator;
|
||||
import org.w3c.dom.xpath.XPathException;
|
||||
import org.w3c.dom.xpath.XPathExpression;
|
||||
import org.w3c.dom.xpath.XPathNSResolver;
|
||||
|
||||
/**
|
||||
*
|
||||
* The class provides an implementation of XPathEvaluator according
|
||||
* to the DOM L3 XPath Specification, Working Group Note 26 February 2004.
|
||||
*
|
||||
* <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
|
||||
*
|
||||
* </p>The evaluation of XPath expressions is provided by
|
||||
* <code>XPathEvaluator</code>, which will provide evaluation of XPath 1.0
|
||||
* expressions with no specialized extension functions or variables. It is
|
||||
* expected that the <code>XPathEvaluator</code> interface will be
|
||||
* implemented on the same object which implements the <code>Document</code>
|
||||
* interface in an implementation which supports the XPath DOM module.
|
||||
* <code>XPathEvaluator</code> implementations may be available from other
|
||||
* sources that may provide support for special extension functions or
|
||||
* variables which are not defined in this specification.</p>
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathEvaluator
|
||||
*
|
||||
* @xsl.usage internal
|
||||
*/
|
||||
public final class XPathEvaluatorImpl implements XPathEvaluator {
|
||||
|
||||
/**
|
||||
* This prefix resolver is created whenever null is passed to the
|
||||
* evaluate method. Its purpose is to satisfy the DOM L3 XPath API
|
||||
* requirement that if a null prefix resolver is used, an exception
|
||||
* should only be thrown when an attempt is made to resolve a prefix.
|
||||
*/
|
||||
private class DummyPrefixResolver implements PrefixResolver {
|
||||
|
||||
/**
|
||||
* Constructor for DummyPrefixResolver.
|
||||
*/
|
||||
DummyPrefixResolver() {}
|
||||
|
||||
/**
|
||||
* @exception DOMException
|
||||
* NAMESPACE_ERR: Always throws this exceptionn
|
||||
*
|
||||
* @see com.sun.org.apache.xml.internal.utils.PrefixResolver#getNamespaceForPrefix(String, Node)
|
||||
*/
|
||||
public String getNamespaceForPrefix(String prefix, Node context) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_RESOLVER, null);
|
||||
throw new DOMException(DOMException.NAMESPACE_ERR, fmsg); // Unable to resolve prefix with null prefix resolver.
|
||||
}
|
||||
|
||||
/**
|
||||
* @exception DOMException
|
||||
* NAMESPACE_ERR: Always throws this exceptionn
|
||||
*
|
||||
* @see com.sun.org.apache.xml.internal.utils.PrefixResolver#getNamespaceForPrefix(String)
|
||||
*/
|
||||
public String getNamespaceForPrefix(String prefix) {
|
||||
return getNamespaceForPrefix(prefix,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.sun.org.apache.xml.internal.utils.PrefixResolver#handlesNullPrefixes()
|
||||
*/
|
||||
public boolean handlesNullPrefixes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.sun.org.apache.xml.internal.utils.PrefixResolver#getBaseIdentifier()
|
||||
*/
|
||||
public String getBaseIdentifier() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The document to be searched to parallel the case where the XPathEvaluator
|
||||
* is obtained by casting a Document.
|
||||
*/
|
||||
private final Document m_doc;
|
||||
|
||||
/**
|
||||
* Constructor for XPathEvaluatorImpl.
|
||||
*
|
||||
* @param doc The document to be searched, to parallel the case where''
|
||||
* the XPathEvaluator is obtained by casting the document.
|
||||
*/
|
||||
public XPathEvaluatorImpl(Document doc) {
|
||||
m_doc = doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor in the case that the XPath expression can be evaluated
|
||||
* without needing an XML document at all.
|
||||
*
|
||||
*/
|
||||
public XPathEvaluatorImpl() {
|
||||
m_doc = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a parsed XPath expression with resolved namespaces. This is
|
||||
* useful when an expression will be reused in an application since it
|
||||
* makes it possible to compile the expression string into a more
|
||||
* efficient internal form and preresolve all namespace prefixes which
|
||||
* occur within the expression.
|
||||
*
|
||||
* @param expression The XPath expression string to be parsed.
|
||||
* @param resolver The <code>resolver</code> permits translation of
|
||||
* prefixes within the XPath expression into appropriate namespace URIs
|
||||
* . If this is specified as <code>null</code>, any namespace prefix
|
||||
* within the expression will result in <code>DOMException</code>
|
||||
* being thrown with the code <code>NAMESPACE_ERR</code>.
|
||||
* @return The compiled form of the XPath expression.
|
||||
* @exception XPathException
|
||||
* INVALID_EXPRESSION_ERR: Raised if the expression is not legal
|
||||
* according to the rules of the <code>XPathEvaluator</code>i
|
||||
* @exception DOMException
|
||||
* NAMESPACE_ERR: Raised if the expression contains namespace prefixes
|
||||
* which cannot be resolved by the specified
|
||||
* <code>XPathNSResolver</code>.
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
|
||||
*/
|
||||
public XPathExpression createExpression(
|
||||
String expression,
|
||||
XPathNSResolver resolver)
|
||||
throws XPathException, DOMException {
|
||||
|
||||
try {
|
||||
|
||||
// If the resolver is null, create a dummy prefix resolver
|
||||
XPath xpath = new XPath(expression,null,
|
||||
((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
|
||||
XPath.SELECT);
|
||||
|
||||
return new XPathExpressionImpl(xpath, m_doc);
|
||||
|
||||
} catch (TransformerException e) {
|
||||
// Need to pass back exception code DOMException.NAMESPACE_ERR also.
|
||||
// Error found in DOM Level 3 XPath Test Suite.
|
||||
if(e instanceof XPathStylesheetDOM3Exception)
|
||||
throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
|
||||
else
|
||||
throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts any DOM node to resolve namespaces so that an XPath expression
|
||||
* can be easily evaluated relative to the context of the node where it
|
||||
* appeared within the document. This adapter works like the DOM Level 3
|
||||
* method <code>lookupNamespaceURI</code> on nodes in resolving the
|
||||
* namespaceURI from a given prefix using the current information available
|
||||
* in the node's hierarchy at the time lookupNamespaceURI is called, also
|
||||
* correctly resolving the implicit xml prefix.
|
||||
*
|
||||
* @param nodeResolver The node to be used as a context for namespace
|
||||
* resolution.
|
||||
* @return <code>XPathNSResolver</code> which resolves namespaces with
|
||||
* respect to the definitions in scope for a specified node.
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathEvaluator#createNSResolver(Node)
|
||||
*/
|
||||
public XPathNSResolver createNSResolver(Node nodeResolver) {
|
||||
|
||||
return new XPathNSResolverImpl((nodeResolver.getNodeType() == Node.DOCUMENT_NODE)
|
||||
? ((Document) nodeResolver).getDocumentElement() : nodeResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates an XPath expression string and returns a result of the
|
||||
* specified type if possible.
|
||||
*
|
||||
* @param expression The XPath expression string to be parsed and
|
||||
* evaluated.
|
||||
* @param contextNode The <code>context</code> is context node for the
|
||||
* evaluation of this XPath expression. If the XPathEvaluator was
|
||||
* obtained by casting the <code>Document</code> then this must be
|
||||
* owned by the same document and must be a <code>Document</code>,
|
||||
* <code>Element</code>, <code>Attribute</code>, <code>Text</code>,
|
||||
* <code>CDATASection</code>, <code>Comment</code>,
|
||||
* <code>ProcessingInstruction</code>, or <code>XPathNamespace</code>
|
||||
* node. If the context node is a <code>Text</code> or a
|
||||
* <code>CDATASection</code>, then the context is interpreted as the
|
||||
* whole logical text node as seen by XPath, unless the node is empty
|
||||
* in which case it may not serve as the XPath context.
|
||||
* @param resolver The <code>resolver</code> permits translation of
|
||||
* prefixes within the XPath expression into appropriate namespace URIs
|
||||
* . If this is specified as <code>null</code>, any namespace prefix
|
||||
* within the expression will result in <code>DOMException</code>
|
||||
* being thrown with the code <code>NAMESPACE_ERR</code>.
|
||||
* @param type If a specific <code>type</code> is specified, then the
|
||||
* result will be coerced to return the specified type relying on
|
||||
* XPath type conversions and fail if the desired coercion is not
|
||||
* possible. This must be one of the type codes of
|
||||
* <code>XPathResult</code>.
|
||||
* @param result The <code>result</code> specifies a specific result
|
||||
* object which may be reused and returned by this method. If this is
|
||||
* specified as <code>null</code>or the implementation does not reuse
|
||||
* the specified result, a new result object will be constructed and
|
||||
* returned.For XPath 1.0 results, this object will be of type
|
||||
* <code>XPathResult</code>.
|
||||
* @return The result of the evaluation of the XPath expression.For XPath
|
||||
* 1.0 results, this object will be of type <code>XPathResult</code>.
|
||||
* @exception XPathException
|
||||
* INVALID_EXPRESSION_ERR: Raised if the expression is not legal
|
||||
* according to the rules of the <code>XPathEvaluator</code>i
|
||||
* <br>TYPE_ERR: Raised if the result cannot be converted to return the
|
||||
* specified type.
|
||||
* @exception DOMException
|
||||
* NAMESPACE_ERR: Raised if the expression contains namespace prefixes
|
||||
* which cannot be resolved by the specified
|
||||
* <code>XPathNSResolver</code>.
|
||||
* <br>WRONG_DOCUMENT_ERR: The Node is from a document that is not
|
||||
* supported by this XPathEvaluator.
|
||||
* <br>NOT_SUPPORTED_ERR: The Node is not a type permitted as an XPath
|
||||
* context node.
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathEvaluator#evaluate(String, Node, XPathNSResolver, short, XPathResult)
|
||||
*/
|
||||
public Object evaluate(
|
||||
String expression,
|
||||
Node contextNode,
|
||||
XPathNSResolver resolver,
|
||||
short type,
|
||||
Object result)
|
||||
throws XPathException, DOMException {
|
||||
|
||||
XPathExpression xpathExpression = createExpression(expression, resolver);
|
||||
|
||||
return xpathExpression.evaluate(contextNode, type, result);
|
||||
}
|
||||
|
||||
}
|
185
jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/domapi/XPathExpressionImpl.java
185
jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/domapi/XPathExpressionImpl.java
@ -1,185 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2002-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* $Id: XPathExpressionImpl.java,v 1.2.4.1 2005/09/10 04:06:55 jeffsuttor Exp $
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.org.apache.xpath.internal.domapi;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.XPath;
|
||||
import com.sun.org.apache.xpath.internal.XPathContext;
|
||||
import com.sun.org.apache.xpath.internal.objects.XObject;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHMessages;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.xpath.XPathException;
|
||||
import org.w3c.dom.xpath.XPathExpression;
|
||||
import org.w3c.dom.xpath.XPathNamespace;
|
||||
|
||||
/**
|
||||
*
|
||||
* The class provides an implementation of XPathExpression according
|
||||
* to the DOM L3 XPath Specification, Working Group Note 26 February 2004.
|
||||
*
|
||||
* <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
|
||||
*
|
||||
* <p>The <code>XPathExpression</code> interface represents a parsed and resolved
|
||||
* XPath expression.</p>
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathExpression
|
||||
*
|
||||
* @xsl.usage internal
|
||||
*/
|
||||
class XPathExpressionImpl implements XPathExpression {
|
||||
|
||||
/**
|
||||
* The xpath object that this expression wraps
|
||||
*/
|
||||
final private XPath m_xpath;
|
||||
|
||||
/**
|
||||
* The document to be searched to parallel the case where the XPathEvaluator
|
||||
* is obtained by casting a Document.
|
||||
*/
|
||||
final private Document m_doc;
|
||||
|
||||
/**
|
||||
* Constructor for XPathExpressionImpl.
|
||||
*
|
||||
* @param xpath The wrapped XPath object.
|
||||
* @param doc The document to be searched, to parallel the case where''
|
||||
* the XPathEvaluator is obtained by casting the document.
|
||||
*/
|
||||
XPathExpressionImpl(XPath xpath, Document doc) {
|
||||
m_xpath = xpath;
|
||||
m_doc = doc;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method provides an implementation XPathResult.evaluate according
|
||||
* to the DOM L3 XPath Specification, Working Group Note 26 February 2004.
|
||||
*
|
||||
* <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
|
||||
*
|
||||
* <p>Evaluates this XPath expression and returns a result.</p>
|
||||
* @param contextNode The <code>context</code> is context node for the
|
||||
* evaluation of this XPath expression.If the XPathEvaluator was
|
||||
* obtained by casting the <code>Document</code> then this must be
|
||||
* owned by the same document and must be a <code>Document</code>,
|
||||
* <code>Element</code>, <code>Attribute</code>, <code>Text</code>,
|
||||
* <code>CDATASection</code>, <code>Comment</code>,
|
||||
* <code>ProcessingInstruction</code>, or <code>XPathNamespace</code>
|
||||
* node.If the context node is a <code>Text</code> or a
|
||||
* <code>CDATASection</code>, then the context is interpreted as the
|
||||
* whole logical text node as seen by XPath, unless the node is empty
|
||||
* in which case it may not serve as the XPath context.
|
||||
* @param type If a specific <code>type</code> is specified, then the
|
||||
* result will be coerced to return the specified type relying on
|
||||
* XPath conversions and fail if the desired coercion is not possible.
|
||||
* This must be one of the type codes of <code>XPathResult</code>.
|
||||
* @param result The <code>result</code> specifies a specific result
|
||||
* object which may be reused and returned by this method. If this is
|
||||
* specified as <code>null</code>or the implementation does not reuse
|
||||
* the specified result, a new result object will be constructed and
|
||||
* returned.For XPath 1.0 results, this object will be of type
|
||||
* <code>XPathResult</code>.
|
||||
* @return The result of the evaluation of the XPath expression.For XPath
|
||||
* 1.0 results, this object will be of type <code>XPathResult</code>.
|
||||
* @exception XPathException
|
||||
* TYPE_ERR: Raised if the result cannot be converted to return the
|
||||
* specified type.
|
||||
* @exception DOMException
|
||||
* WRONG_DOCUMENT_ERR: The Node is from a document that is not supported
|
||||
* by the XPathEvaluator that created this
|
||||
* <code>XPathExpression</code>.
|
||||
* <br>NOT_SUPPORTED_ERR: The Node is not a type permitted as an XPath
|
||||
* context node.
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathExpression#evaluate(Node, short, XPathResult)
|
||||
* @xsl.usage internal
|
||||
*/
|
||||
public Object evaluate(
|
||||
Node contextNode,
|
||||
short type,
|
||||
Object result)
|
||||
throws XPathException, DOMException {
|
||||
|
||||
// If the XPathEvaluator was determined by "casting" the document
|
||||
if (m_doc != null) {
|
||||
|
||||
// Check that the context node is owned by the same document
|
||||
if ((contextNode != m_doc) && (!contextNode.getOwnerDocument().equals(m_doc))) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_DOCUMENT, null);
|
||||
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, fmsg);
|
||||
}
|
||||
|
||||
// Check that the context node is an acceptable node type
|
||||
short nodeType = contextNode.getNodeType();
|
||||
if ((nodeType != Document.DOCUMENT_NODE) &&
|
||||
(nodeType != Document.ELEMENT_NODE) &&
|
||||
(nodeType != Document.ATTRIBUTE_NODE) &&
|
||||
(nodeType != Document.TEXT_NODE) &&
|
||||
(nodeType != Document.CDATA_SECTION_NODE) &&
|
||||
(nodeType != Document.COMMENT_NODE) &&
|
||||
(nodeType != Document.PROCESSING_INSTRUCTION_NODE) &&
|
||||
(nodeType != XPathNamespace.XPATH_NAMESPACE_NODE)) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_NODETYPE, null);
|
||||
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, fmsg);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// If the type is not a supported type, throw an exception and be
|
||||
// done with it!
|
||||
if (!XPathResultImpl.isValidType(type)) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] {new Integer(type)});
|
||||
throw new XPathException(XPathException.TYPE_ERR,fmsg); // Invalid XPath type argument: {0}
|
||||
}
|
||||
|
||||
// Cache xpath context?
|
||||
XPathContext xpathSupport = new XPathContext();
|
||||
|
||||
// if m_document is not null, build the DTM from the document
|
||||
if (null != m_doc) {
|
||||
xpathSupport.getDTMHandleFromNode(m_doc);
|
||||
}
|
||||
|
||||
XObject xobj = null;
|
||||
try {
|
||||
xobj = m_xpath.execute(xpathSupport, contextNode, null);
|
||||
} catch (TransformerException te) {
|
||||
// What should we do here?
|
||||
throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,te.getMessageAndLocation());
|
||||
}
|
||||
|
||||
// Create a new XPathResult object
|
||||
// Reuse result object passed in?
|
||||
// The constructor will check the compatibility of type and xobj and
|
||||
// throw an exception if they are not compatible.
|
||||
return new XPathResultImpl(type,xobj,contextNode, m_xpath);
|
||||
}
|
||||
|
||||
}
|
63
jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/domapi/XPathNSResolverImpl.java
63
jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/domapi/XPathNSResolverImpl.java
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2002-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* $Id: XPathNSResolverImpl.java,v 1.2.4.1 2005/09/10 04:13:19 jeffsuttor Exp $
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xpath.internal.domapi;
|
||||
|
||||
import com.sun.org.apache.xml.internal.utils.PrefixResolverDefault;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.xpath.XPathNSResolver;
|
||||
|
||||
/**
|
||||
*
|
||||
* The class provides an implementation XPathNSResolver according
|
||||
* to the DOM L3 XPath Specification, Working Group Note 26 February 2004.
|
||||
*
|
||||
* <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
|
||||
*
|
||||
* <p>The <code>XPathNSResolver</code> interface permit <code>prefix</code>
|
||||
* strings in the expression to be properly bound to
|
||||
* <code>namespaceURI</code> strings. <code>XPathEvaluator</code> can
|
||||
* construct an implementation of <code>XPathNSResolver</code> from a node,
|
||||
* or the interface may be implemented by any application.</p>
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathNSResolver
|
||||
* @xsl.usage internal
|
||||
*/
|
||||
class XPathNSResolverImpl extends PrefixResolverDefault implements XPathNSResolver {
|
||||
|
||||
/**
|
||||
* Constructor for XPathNSResolverImpl.
|
||||
* @param xpathExpressionContext
|
||||
*/
|
||||
public XPathNSResolverImpl(Node xpathExpressionContext) {
|
||||
super(xpathExpressionContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.xpath.XPathNSResolver#lookupNamespaceURI(String)
|
||||
*/
|
||||
public String lookupNamespaceURI(String prefix) {
|
||||
return super.getNamespaceForPrefix(prefix);
|
||||
}
|
||||
|
||||
}
|
324
jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/domapi/XPathNamespaceImpl.java
324
jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/domapi/XPathNamespaceImpl.java
@ -1,324 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2002-2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* $Id: XPathNamespaceImpl.java,v 1.2.4.1 2005/09/10 04:10:02 jeffsuttor Exp $
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.org.apache.xpath.internal.domapi;
|
||||
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.xpath.XPathNamespace;
|
||||
|
||||
import org.w3c.dom.UserDataHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* The <code>XPathNamespace</code> interface is returned by
|
||||
* <code>XPathResult</code> interfaces to represent the XPath namespace node
|
||||
* type that DOM lacks. There is no public constructor for this node type.
|
||||
* Attempts to place it into a hierarchy or a NamedNodeMap result in a
|
||||
* <code>DOMException</code> with the code <code>HIERARCHY_REQUEST_ERR</code>
|
||||
* . This node is read only, so methods or setting of attributes that would
|
||||
* mutate the node result in a DOMException with the code
|
||||
* <code>NO_MODIFICATION_ALLOWED_ERR</code>.
|
||||
* <p>The core specification describes attributes of the <code>Node</code>
|
||||
* interface that are different for different node node types but does not
|
||||
* describe <code>XPATH_NAMESPACE_NODE</code>, so here is a description of
|
||||
* those attributes for this node type. All attributes of <code>Node</code>
|
||||
* not described in this section have a <code>null</code> or
|
||||
* <code>false</code> value.
|
||||
* <p><code>ownerDocument</code> matches the <code>ownerDocument</code> of the
|
||||
* <code>ownerElement</code> even if the element is later adopted.
|
||||
* <p><code>prefix</code> is the prefix of the namespace represented by the
|
||||
* node.
|
||||
* <p><code>nodeName</code> is the same as <code>prefix</code>.
|
||||
* <p><code>nodeType</code> is equal to <code>XPATH_NAMESPACE_NODE</code>.
|
||||
* <p><code>namespaceURI</code> is the namespace URI of the namespace
|
||||
* represented by the node.
|
||||
* <p><code>adoptNode</code>, <code>cloneNode</code>, and
|
||||
* <code>importNode</code> fail on this node type by raising a
|
||||
* <code>DOMException</code> with the code <code>NOT_SUPPORTED_ERR</code>.In
|
||||
* future versions of the XPath specification, the definition of a namespace
|
||||
* node may be changed incomatibly, in which case incompatible changes to
|
||||
* field values may be required to implement versions beyond XPath 1.0.
|
||||
* <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.
|
||||
*
|
||||
* This implementation wraps the DOM attribute node that contained the
|
||||
* namespace declaration.
|
||||
* @xsl.usage internal
|
||||
*/
|
||||
|
||||
class XPathNamespaceImpl implements XPathNamespace {
|
||||
|
||||
// Node that XPathNamespaceImpl wraps
|
||||
final private Node m_attributeNode;
|
||||
|
||||
/**
|
||||
* Constructor for XPathNamespaceImpl.
|
||||
*/
|
||||
XPathNamespaceImpl(Node node) {
|
||||
m_attributeNode = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.sun.org.apache.xalan.internal.dom3.xpath.XPathNamespace#getOwnerElement()
|
||||
*/
|
||||
public Element getOwnerElement() {
|
||||
return ((Attr)m_attributeNode).getOwnerElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getNodeName()
|
||||
*/
|
||||
public String getNodeName() {
|
||||
return "#namespace";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getNodeValue()
|
||||
*/
|
||||
public String getNodeValue() throws DOMException {
|
||||
return m_attributeNode.getNodeValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#setNodeValue(String)
|
||||
*/
|
||||
public void setNodeValue(String arg0) throws DOMException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getNodeType()
|
||||
*/
|
||||
public short getNodeType() {
|
||||
return XPathNamespace.XPATH_NAMESPACE_NODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getParentNode()
|
||||
*/
|
||||
public Node getParentNode() {
|
||||
return m_attributeNode.getParentNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getChildNodes()
|
||||
*/
|
||||
public NodeList getChildNodes() {
|
||||
return m_attributeNode.getChildNodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getFirstChild()
|
||||
*/
|
||||
public Node getFirstChild() {
|
||||
return m_attributeNode.getFirstChild();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getLastChild()
|
||||
*/
|
||||
public Node getLastChild() {
|
||||
return m_attributeNode.getLastChild();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getPreviousSibling()
|
||||
*/
|
||||
public Node getPreviousSibling() {
|
||||
return m_attributeNode.getPreviousSibling();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getNextSibling()
|
||||
*/
|
||||
public Node getNextSibling() {
|
||||
return m_attributeNode.getNextSibling();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getAttributes()
|
||||
*/
|
||||
public NamedNodeMap getAttributes() {
|
||||
return m_attributeNode.getAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getOwnerDocument()
|
||||
*/
|
||||
public Document getOwnerDocument() {
|
||||
return m_attributeNode.getOwnerDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#insertBefore(Node, Node)
|
||||
*/
|
||||
public Node insertBefore(Node arg0, Node arg1) throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#replaceChild(Node, Node)
|
||||
*/
|
||||
public Node replaceChild(Node arg0, Node arg1) throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#removeChild(Node)
|
||||
*/
|
||||
public Node removeChild(Node arg0) throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#appendChild(Node)
|
||||
*/
|
||||
public Node appendChild(Node arg0) throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#hasChildNodes()
|
||||
*/
|
||||
public boolean hasChildNodes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#cloneNode(boolean)
|
||||
*/
|
||||
public Node cloneNode(boolean arg0) {
|
||||
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#normalize()
|
||||
*/
|
||||
public void normalize() {
|
||||
m_attributeNode.normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#isSupported(String, String)
|
||||
*/
|
||||
public boolean isSupported(String arg0, String arg1) {
|
||||
return m_attributeNode.isSupported(arg0, arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getNamespaceURI()
|
||||
*/
|
||||
public String getNamespaceURI() {
|
||||
|
||||
// For namespace node, the namespaceURI is the namespace URI
|
||||
// of the namespace represented by the node.
|
||||
return m_attributeNode.getNodeValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getPrefix()
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return m_attributeNode.getPrefix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#setPrefix(String)
|
||||
*/
|
||||
public void setPrefix(String arg0) throws DOMException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#getLocalName()
|
||||
*/
|
||||
public String getLocalName() {
|
||||
|
||||
// For namespace node, the local name is the same as the prefix
|
||||
return m_attributeNode.getPrefix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.Node#hasAttributes()
|
||||
*/
|
||||
public boolean hasAttributes() {
|
||||
return m_attributeNode.hasAttributes();
|
||||
}
|
||||
|
||||
public String getBaseURI ( ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public short compareDocumentPosition(Node other) throws DOMException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private String textContent;
|
||||
|
||||
public String getTextContent() throws DOMException {
|
||||
return textContent;
|
||||
}
|
||||
|
||||
public void setTextContent(String textContent) throws DOMException {
|
||||
this.textContent = textContent;
|
||||
}
|
||||
|
||||
public boolean isSameNode(Node other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String lookupPrefix(String namespaceURI) {
|
||||
return ""; //PENDING
|
||||
}
|
||||
|
||||
public boolean isDefaultNamespace(String namespaceURI) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String lookupNamespaceURI(String prefix) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isEqualNode(Node arg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object getFeature(String feature, String version) {
|
||||
return null; //PENDING
|
||||
}
|
||||
|
||||
public Object setUserData(String key,
|
||||
Object data,
|
||||
UserDataHandler handler) {
|
||||
return null; //PENDING
|
||||
}
|
||||
|
||||
public Object getUserData(String key) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,512 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 2002-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* $Id: XPathResultImpl.java,v 1.2.4.1 2005/09/10 04:18:54 jeffsuttor Exp $
|
||||
*/
|
||||
|
||||
|
||||
package com.sun.org.apache.xpath.internal.domapi;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.XPath;
|
||||
import com.sun.org.apache.xpath.internal.objects.XObject;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
|
||||
import com.sun.org.apache.xpath.internal.res.XPATHMessages;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.events.Event;
|
||||
import org.w3c.dom.events.EventListener;
|
||||
import org.w3c.dom.events.EventTarget;
|
||||
import org.w3c.dom.traversal.NodeIterator;
|
||||
import org.w3c.dom.xpath.XPathException;
|
||||
import org.w3c.dom.xpath.XPathResult;
|
||||
|
||||
/**
|
||||
*
|
||||
* The class provides an implementation XPathResult according
|
||||
* to the DOM L3 XPath Specification, Working Group Note 26 February 2004.
|
||||
*
|
||||
* <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
|
||||
*
|
||||
* <p>The <code>XPathResult</code> interface represents the result of the
|
||||
* evaluation of an XPath expression within the context of a particular
|
||||
* node. Since evaluation of an XPath expression can result in various
|
||||
* result types, this object makes it possible to discover and manipulate
|
||||
* the type and value of the result.</p>
|
||||
*
|
||||
* <p>This implementation wraps an <code>XObject</code>.
|
||||
*
|
||||
* @see com.sun.org.apache.xpath.internal.objects.XObject
|
||||
* @see org.w3c.dom.xpath.XPathResult
|
||||
*
|
||||
* @xsl.usage internal
|
||||
*/
|
||||
class XPathResultImpl implements XPathResult, EventListener {
|
||||
|
||||
/**
|
||||
* The wrapped XObject
|
||||
*/
|
||||
final private XObject m_resultObj;
|
||||
|
||||
/**
|
||||
* The xpath object that wraps the expression used for this result.
|
||||
*/
|
||||
final private XPath m_xpath;
|
||||
|
||||
/**
|
||||
* This the type specified by the user during construction. Typically
|
||||
* the constructor will be called by com.sun.org.apache.xpath.internal.XPath.evaluate().
|
||||
*/
|
||||
final private short m_resultType;
|
||||
|
||||
private boolean m_isInvalidIteratorState = false;
|
||||
|
||||
/**
|
||||
* Only used to attach a mutation event handler when specified
|
||||
* type is an iterator type.
|
||||
*/
|
||||
final private Node m_contextNode;
|
||||
|
||||
/**
|
||||
* The iterator, if this is an iterator type.
|
||||
*/
|
||||
private NodeIterator m_iterator = null;;
|
||||
|
||||
/**
|
||||
* The list, if this is a snapshot type.
|
||||
*/
|
||||
private NodeList m_list = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for XPathResultImpl.
|
||||
*
|
||||
* For internal use only.
|
||||
*/
|
||||
XPathResultImpl(short type, XObject result, Node contextNode, XPath xpath) {
|
||||
// Check that the type is valid
|
||||
if (!isValidType(type)) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] {new Integer(type)});
|
||||
throw new XPathException(XPathException.TYPE_ERR,fmsg); // Invalid XPath type argument: {0}
|
||||
}
|
||||
|
||||
// Result object should never be null!
|
||||
if (null == result) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_EMPTY_XPATH_RESULT, null);
|
||||
throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,fmsg); // Empty XPath result object
|
||||
}
|
||||
|
||||
this.m_resultObj = result;
|
||||
this.m_contextNode = contextNode;
|
||||
this.m_xpath = xpath;
|
||||
|
||||
// If specified result was ANY_TYPE, determine XObject type
|
||||
if (type == ANY_TYPE) {
|
||||
this.m_resultType = getTypeFromXObject(result);
|
||||
} else {
|
||||
this.m_resultType = type;
|
||||
}
|
||||
|
||||
// If the context node supports DOM Events and the type is one of the iterator
|
||||
// types register this result as an event listener
|
||||
if (((m_resultType == XPathResult.ORDERED_NODE_ITERATOR_TYPE) ||
|
||||
(m_resultType == XPathResult.UNORDERED_NODE_ITERATOR_TYPE))) {
|
||||
addEventListener();
|
||||
|
||||
}// else can we handle iterator types if contextNode doesn't support EventTarget??
|
||||
|
||||
// If this is an iterator type get the iterator
|
||||
if ((m_resultType == ORDERED_NODE_ITERATOR_TYPE) ||
|
||||
(m_resultType == UNORDERED_NODE_ITERATOR_TYPE) ||
|
||||
(m_resultType == ANY_UNORDERED_NODE_TYPE) ||
|
||||
(m_resultType == FIRST_ORDERED_NODE_TYPE)) {
|
||||
|
||||
try {
|
||||
m_iterator = m_resultObj.nodeset();
|
||||
} catch (TransformerException te) {
|
||||
// probably not a node type
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INCOMPATIBLE_TYPES, new Object[] {m_xpath.getPatternString(), getTypeString(getTypeFromXObject(m_resultObj)),getTypeString(m_resultType)});
|
||||
throw new XPathException(XPathException.TYPE_ERR, fmsg); // "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be coerced into the specified XPathResultType of {2}."},
|
||||
}
|
||||
|
||||
// If user requested ordered nodeset and result is unordered
|
||||
// need to sort...TODO
|
||||
// if ((m_resultType == ORDERED_NODE_ITERATOR_TYPE) &&
|
||||
// (!(((DTMNodeIterator)m_iterator).getDTMIterator().isDocOrdered()))) {
|
||||
//
|
||||
// }
|
||||
|
||||
// If it's a snapshot type, get the nodelist
|
||||
} else if ((m_resultType == UNORDERED_NODE_SNAPSHOT_TYPE) ||
|
||||
(m_resultType == ORDERED_NODE_SNAPSHOT_TYPE)) {
|
||||
try {
|
||||
m_list = m_resultObj.nodelist();
|
||||
} catch (TransformerException te) {
|
||||
// probably not a node type
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INCOMPATIBLE_TYPES, new Object[] {m_xpath.getPatternString(), getTypeString(getTypeFromXObject(m_resultObj)),getTypeString(m_resultType)});
|
||||
throw new XPathException(XPathException.TYPE_ERR, fmsg); // "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be coerced into the specified XPathResultType of {2}."},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.xpath.XPathResult#getResultType()
|
||||
*/
|
||||
public short getResultType() {
|
||||
return m_resultType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The value of this number result.
|
||||
* @exception XPathException
|
||||
* TYPE_ERR: raised if <code>resultType</code> is not
|
||||
* <code>NUMBER_TYPE</code>.
|
||||
* @see org.w3c.dom.xpath.XPathResult#getNumberValue()
|
||||
*/
|
||||
public double getNumberValue() throws XPathException {
|
||||
if (getResultType() != NUMBER_TYPE) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
|
||||
throw new XPathException(XPathException.TYPE_ERR,fmsg);
|
||||
// "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a number"
|
||||
} else {
|
||||
try {
|
||||
return m_resultObj.num();
|
||||
} catch (Exception e) {
|
||||
// Type check above should prevent this exception from occurring.
|
||||
throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The value of this string result.
|
||||
* @exception XPathException
|
||||
* TYPE_ERR: raised if <code>resultType</code> is not
|
||||
* <code>STRING_TYPE</code>.
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathResult#getStringValue()
|
||||
*/
|
||||
public String getStringValue() throws XPathException {
|
||||
if (getResultType() != STRING_TYPE) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_STRING, new Object[] {m_xpath.getPatternString(), m_resultObj.getTypeString()});
|
||||
throw new XPathException(XPathException.TYPE_ERR,fmsg);
|
||||
// "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a string."
|
||||
} else {
|
||||
try {
|
||||
return m_resultObj.str();
|
||||
} catch (Exception e) {
|
||||
// Type check above should prevent this exception from occurring.
|
||||
throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.xpath.XPathResult#getBooleanValue()
|
||||
*/
|
||||
public boolean getBooleanValue() throws XPathException {
|
||||
if (getResultType() != BOOLEAN_TYPE) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
|
||||
throw new XPathException(XPathException.TYPE_ERR,fmsg);
|
||||
// "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."
|
||||
} else {
|
||||
try {
|
||||
return m_resultObj.bool();
|
||||
} catch (TransformerException e) {
|
||||
// Type check above should prevent this exception from occurring.
|
||||
throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The value of this single node result, which may be <code>null</code>.
|
||||
* @exception XPathException
|
||||
* TYPE_ERR: raised if <code>resultType</code> is not
|
||||
* <code>ANY_UNORDERED_NODE_TYPE</code> or
|
||||
* <code>FIRST_ORDERED_NODE_TYPE</code>.
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
|
||||
*/
|
||||
public Node getSingleNodeValue() throws XPathException {
|
||||
|
||||
if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
|
||||
(m_resultType != FIRST_ORDERED_NODE_TYPE)) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
|
||||
throw new XPathException(XPathException.TYPE_ERR,fmsg);
|
||||
// "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
|
||||
// This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
|
||||
}
|
||||
|
||||
NodeIterator result = null;
|
||||
try {
|
||||
result = m_resultObj.nodeset();
|
||||
} catch (TransformerException te) {
|
||||
throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
|
||||
}
|
||||
|
||||
if (null == result) return null;
|
||||
|
||||
Node node = result.nextNode();
|
||||
|
||||
// Wrap "namespace node" in an XPathNamespace
|
||||
if (isNamespaceNode(node)) {
|
||||
return new XPathNamespaceImpl(node);
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.xpath.XPathResult#getInvalidIteratorState()
|
||||
*/
|
||||
public boolean getInvalidIteratorState() {
|
||||
return m_isInvalidIteratorState;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of nodes in the result snapshot. Valid values for
|
||||
* snapshotItem indices are <code>0</code> to
|
||||
* <code>snapshotLength-1</code> inclusive.
|
||||
* @exception XPathException
|
||||
* TYPE_ERR: raised if <code>resultType</code> is not
|
||||
* <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
|
||||
* <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathResult#getSnapshotLength()
|
||||
*/
|
||||
public int getSnapshotLength() throws XPathException {
|
||||
|
||||
if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
|
||||
(m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_GET_SNAPSHOT_LENGTH, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
|
||||
throw new XPathException(XPathException.TYPE_ERR,fmsg);
|
||||
// "The method getSnapshotLength cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
|
||||
}
|
||||
|
||||
return m_list.getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates and returns the next node from the node set or
|
||||
* <code>null</code>if there are no more nodes.
|
||||
* @return Returns the next node.
|
||||
* @exception XPathException
|
||||
* TYPE_ERR: raised if <code>resultType</code> is not
|
||||
* <code>UNORDERED_NODE_ITERATOR_TYPE</code> or
|
||||
* <code>ORDERED_NODE_ITERATOR_TYPE</code>.
|
||||
* @exception DOMException
|
||||
* INVALID_STATE_ERR: The document has been mutated since the result was
|
||||
* returned.
|
||||
* @see org.w3c.dom.xpath.XPathResult#iterateNext()
|
||||
*/
|
||||
public Node iterateNext() throws XPathException, DOMException {
|
||||
if ((m_resultType != UNORDERED_NODE_ITERATOR_TYPE) &&
|
||||
(m_resultType != ORDERED_NODE_ITERATOR_TYPE)) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_ITERATOR_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
|
||||
throw new XPathException(XPathException.TYPE_ERR, fmsg);
|
||||
// "The method iterateNext cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
|
||||
// This method applies only to types UNORDERED_NODE_ITERATOR_TYPE and ORDERED_NODE_ITERATOR_TYPE."},
|
||||
}
|
||||
|
||||
if (getInvalidIteratorState()) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_DOC_MUTATED, null);
|
||||
throw new DOMException(DOMException.INVALID_STATE_ERR,fmsg); // Document mutated since result was returned. Iterator is invalid.
|
||||
}
|
||||
|
||||
Node node = m_iterator.nextNode();
|
||||
if(null == node)
|
||||
removeEventListener(); // JIRA 1673
|
||||
// Wrap "namespace node" in an XPathNamespace
|
||||
if (isNamespaceNode(node)) {
|
||||
return new XPathNamespaceImpl(node);
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>index</code>th item in the snapshot collection. If
|
||||
* <code>index</code> is greater than or equal to the number of nodes in
|
||||
* the list, this method returns <code>null</code>. Unlike the iterator
|
||||
* result, the snapshot does not become invalid, but may not correspond
|
||||
* to the current document if it is mutated.
|
||||
* @param index Index into the snapshot collection.
|
||||
* @return The node at the <code>index</code>th position in the
|
||||
* <code>NodeList</code>, or <code>null</code> if that is not a valid
|
||||
* index.
|
||||
* @exception XPathException
|
||||
* TYPE_ERR: raised if <code>resultType</code> is not
|
||||
* <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
|
||||
* <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
|
||||
*
|
||||
* @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
|
||||
*/
|
||||
public Node snapshotItem(int index) throws XPathException {
|
||||
|
||||
if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
|
||||
(m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
|
||||
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
|
||||
throw new XPathException(XPathException.TYPE_ERR, fmsg);
|
||||
// "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
|
||||
// This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
|
||||
}
|
||||
|
||||
Node node = m_list.item(index);
|
||||
|
||||
// Wrap "namespace node" in an XPathNamespace
|
||||
if (isNamespaceNode(node)) {
|
||||
return new XPathNamespaceImpl(node);
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the specified type is one of the supported types.
|
||||
* @param type The specified type
|
||||
*
|
||||
* @return true If the specified type is supported; otherwise, returns false.
|
||||
*/
|
||||
static boolean isValidType( short type ) {
|
||||
switch (type) {
|
||||
case ANY_TYPE:
|
||||
case NUMBER_TYPE:
|
||||
case STRING_TYPE:
|
||||
case BOOLEAN_TYPE:
|
||||
case UNORDERED_NODE_ITERATOR_TYPE:
|
||||
case ORDERED_NODE_ITERATOR_TYPE:
|
||||
case UNORDERED_NODE_SNAPSHOT_TYPE:
|
||||
case ORDERED_NODE_SNAPSHOT_TYPE:
|
||||
case ANY_UNORDERED_NODE_TYPE:
|
||||
case FIRST_ORDERED_NODE_TYPE: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.w3c.dom.events.EventListener#handleEvent(Event)
|
||||
*/
|
||||
public void handleEvent(Event event) {
|
||||
|
||||
if (event.getType().equals("DOMSubtreeModified")) {
|
||||
// invalidate the iterator
|
||||
m_isInvalidIteratorState = true;
|
||||
|
||||
// deregister as a listener to reduce computational load
|
||||
removeEventListener();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a request type, return the equivalent string.
|
||||
* For diagnostic purposes.
|
||||
*
|
||||
* @return type string
|
||||
*/
|
||||
private String getTypeString(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case ANY_TYPE: return "ANY_TYPE";
|
||||
case ANY_UNORDERED_NODE_TYPE: return "ANY_UNORDERED_NODE_TYPE";
|
||||
case BOOLEAN_TYPE: return "BOOLEAN";
|
||||
case FIRST_ORDERED_NODE_TYPE: return "FIRST_ORDERED_NODE_TYPE";
|
||||
case NUMBER_TYPE: return "NUMBER_TYPE";
|
||||
case ORDERED_NODE_ITERATOR_TYPE: return "ORDERED_NODE_ITERATOR_TYPE";
|
||||
case ORDERED_NODE_SNAPSHOT_TYPE: return "ORDERED_NODE_SNAPSHOT_TYPE";
|
||||
case STRING_TYPE: return "STRING_TYPE";
|
||||
case UNORDERED_NODE_ITERATOR_TYPE: return "UNORDERED_NODE_ITERATOR_TYPE";
|
||||
case UNORDERED_NODE_SNAPSHOT_TYPE: return "UNORDERED_NODE_SNAPSHOT_TYPE";
|
||||
default: return "#UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an XObject, determine the corresponding DOM XPath type
|
||||
*
|
||||
* @return type string
|
||||
*/
|
||||
private short getTypeFromXObject(XObject object) {
|
||||
switch (object.getType()) {
|
||||
case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE;
|
||||
case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE;
|
||||
case XObject.CLASS_NUMBER: return NUMBER_TYPE;
|
||||
case XObject.CLASS_STRING: return STRING_TYPE;
|
||||
// XPath 2.0 types
|
||||
// case XObject.CLASS_DATE:
|
||||
// case XObject.CLASS_DATETIME:
|
||||
// case XObject.CLASS_DTDURATION:
|
||||
// case XObject.CLASS_GDAY:
|
||||
// case XObject.CLASS_GMONTH:
|
||||
// case XObject.CLASS_GMONTHDAY:
|
||||
// case XObject.CLASS_GYEAR:
|
||||
// case XObject.CLASS_GYEARMONTH:
|
||||
// case XObject.CLASS_TIME:
|
||||
// case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings?
|
||||
|
||||
case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE;
|
||||
case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ?
|
||||
default: return ANY_TYPE; // throw exception ?
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a node, determine if it is a namespace node.
|
||||
*
|
||||
* @param node
|
||||
*
|
||||
* @return boolean Returns true if this is a namespace node; otherwise, returns false.
|
||||
*/
|
||||
private boolean isNamespaceNode(Node node) {
|
||||
|
||||
if ((null != node) &&
|
||||
(node.getNodeType() == Node.ATTRIBUTE_NODE) &&
|
||||
(node.getNodeName().startsWith("xmlns:") || node.getNodeName().equals("xmlns"))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add m_contextNode to Event Listner to listen for Mutations Events
|
||||
*
|
||||
*/
|
||||
private void addEventListener(){
|
||||
if(m_contextNode instanceof EventTarget)
|
||||
((EventTarget)m_contextNode).addEventListener("DOMSubtreeModified",this,true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove m_contextNode to Event Listner to listen for Mutations Events
|
||||
*
|
||||
*/
|
||||
private void removeEventListener(){
|
||||
if(m_contextNode instanceof EventTarget)
|
||||
((EventTarget)m_contextNode).removeEventListener("DOMSubtreeModified",this,true);
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file and, per its terms, should not be removed:
|
||||
*
|
||||
* Copyright (c) 2002 World Wide Web Consortium,
|
||||
* (Massachusetts Institute of Technology, Institut National de
|
||||
* Recherche en Informatique et en Automatique, Keio University). All
|
||||
* Rights Reserved. This program is distributed under the W3C's Software
|
||||
* Intellectual Property License. This program is distributed in the
|
||||
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE.
|
||||
* See W3C License http://www.w3.org/Consortium/Legal/ for more details.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.xpath.internal.domapi;
|
||||
|
||||
import javax.xml.transform.SourceLocator;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
/**
|
||||
*
|
||||
* A new exception to add support for DOM Level 3 XPath API.
|
||||
* This class is needed to throw a org.w3c.dom.DOMException with proper error code in
|
||||
* createExpression method of XPathEvaluatorImpl (a DOM Level 3 class).
|
||||
*
|
||||
* This class extends TransformerException because the error message includes information
|
||||
* about where the XPath problem is in the stylesheet as well as the XPath expression itself.
|
||||
*
|
||||
* @xsl.usage internal
|
||||
*/
|
||||
final public class XPathStylesheetDOM3Exception extends TransformerException {
|
||||
public XPathStylesheetDOM3Exception(String msg, SourceLocator arg1)
|
||||
{
|
||||
super(msg, arg1);
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<!--
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
-->
|
||||
<!--
|
||||
* Copyright 2000-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
-->
|
||||
<!-- $Id: package.html,v 1.1.4.1 2005/09/07 22:27:28 jeffsuttor Exp $ -->
|
||||
<html>
|
||||
<title>XPath domapi Package.</title>
|
||||
<body>
|
||||
<p>Implements DOM Level 3 XPath API<p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user