You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by di...@apache.org on 2005/09/12 20:03:10 UTC
cvs commit: xml-security/src/org/apache/xml/security/utils/resolver/implementations ResolverFragment.java ResolverXPointer.java
dims 2005/09/12 11:03:10
Modified: src/org/apache/xml/security/utils
CachedXPathFuncHereAPI.java
CachedXPathAPIHolder.java
src/org/apache/xml/security/signature Manifest.java
src/org/apache/xml/security/utils/resolver/implementations
ResolverFragment.java ResolverXPointer.java
Log:
Fix xml-security to work with both Xalan 2.6 and Xalan 2.7 (currently the libs directory has Xalan 2.6)
Revision Changes Path
1.14 +115 -48 xml-security/src/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java
Index: CachedXPathFuncHereAPI.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- CachedXPathFuncHereAPI.java 2 Apr 2005 18:47:19 -0000 1.13
+++ CachedXPathFuncHereAPI.java 12 Sep 2005 18:03:10 -0000 1.14
@@ -18,30 +18,35 @@
-import javax.xml.transform.TransformerException;
-
import org.apache.xml.dtm.DTMManager;
+import org.apache.xml.security.transforms.implementations.FuncHere;
import org.apache.xml.security.transforms.implementations.FuncHereContext;
import org.apache.xml.utils.PrefixResolver;
import org.apache.xml.utils.PrefixResolverDefault;
import org.apache.xpath.CachedXPathAPI;
+import org.apache.xpath.Expression;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
+import org.apache.xpath.compiler.FunctionTable;
import org.apache.xpath.objects.XObject;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
+import org.w3c.dom.*;
import org.w3c.dom.traversal.NodeIterator;
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.SourceLocator;
+import javax.xml.transform.TransformerException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
/**
*
* @author $Author$
*/
public class CachedXPathFuncHereAPI {
+ static org.apache.commons.logging.Log log =
+ org.apache.commons.logging.LogFactory.getLog(CachedXPathFuncHereAPI.class.getName());
/**
* XPathContext, and thus DTMManager and DTMs, persists through multiple
* calls to this object.
@@ -50,13 +55,19 @@
/** Field _dtmManager */
DTMManager _dtmManager = null;
-
+
XPathContext _context = null;
-
+
String xpathStr=null;
-
+
XPath xpath=null;
+ static FunctionTable _funcTable = null;
+
+ static {
+ fixupFunctionTable();
+ }
+
/**
* Method getFuncHereContext
* @return the context for this object
@@ -87,7 +98,7 @@
*
* @param previouslyUsed
*/
- public CachedXPathFuncHereAPI(CachedXPathAPI previouslyUsed) {
+ public CachedXPathFuncHereAPI(CachedXPathAPI previouslyUsed) {
this._dtmManager = previouslyUsed.getXPathContext().getDTMManager();
this._context=previouslyUsed.getXPathContext();
}
@@ -254,7 +265,7 @@
throws TransformerException {
// Create the XPath object.
//String str = CachedXPathFuncHereAPI.getStrFromNode(xpathnode);
-
+
// Since we don't have a XML Parser involved here, install some default support
// for things like namespaces, etc.
// (Changed from: XPathContext xpathSupport = new XPathContext();
@@ -281,7 +292,7 @@
_context.reset();
_dtmManager=_context.getDTMManager();
}
- xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
+ xpath = createXPath(str, prefixResolver);
xpathStr=str;
}
@@ -326,18 +337,18 @@
// Create the XPath object.
//String str = CachedXPathFuncHereAPI.getStrFromNode(xpathnode);
if (str!=xpathStr) {
- if (str.indexOf("here()")>0) {
- _context.reset();
- _dtmManager=_context.getDTMManager();
- }
+ if (str.indexOf("here()")>0) {
+ _context.reset();
+ _dtmManager=_context.getDTMManager();
+ }
try {
- xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
+ xpath = createXPath(str, prefixResolver);
} catch (TransformerException ex) {
//Try to see if it is a problem with the classloader.
- Throwable th= ex.getCause();
+ Throwable th= ex.getCause();
if (th instanceof ClassNotFoundException) {
if (th.getMessage().indexOf("FuncHere")>0) {
- throw new RuntimeException(I18n.translate("endorsed.jdk1.4.0")/*,*/+ex);
+ throw new RuntimeException(I18n.translate("endorsed.jdk1.4.0")/*,*/+ex);
}
}
throw ex;
@@ -356,35 +367,91 @@
return xpath.execute(this._funcHereContext, ctxtNode, prefixResolver);
}
- /**
- * Method getStrFromNode
- *
- * @param xpathnode
- * @return the string for the node.
- */
- public static String getStrFromNode(Node xpathnode) {
+ private XPath createXPath(String str, PrefixResolver prefixResolver) throws TransformerException {
+ XPath xpath = null;
+ Class[] classes = new Class[]{String.class, SourceLocator.class, PrefixResolver.class, int.class,
+ ErrorListener.class, FunctionTable.class};
+ Object[] objects = new Object[]{str, null, prefixResolver, new Integer(XPath.SELECT), null, _funcTable};
+ try {
+ Constructor constructor = XPath.class.getConstructor(classes);
+ xpath = (XPath) constructor.newInstance(objects);
+ } catch (Throwable t) {
+ }
+ if (xpath == null) {
+ xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
+ }
+ return xpath;
+ }
- if (xpathnode.getNodeType() == Node.TEXT_NODE) {
+ /**
+ * Method getStrFromNode
+ *
+ * @param xpathnode
+ * @return the string for the node.
+ */
+ public static String getStrFromNode(Node xpathnode) {
+
+ if (xpathnode.getNodeType() == Node.TEXT_NODE) {
+
+ // we iterate over all siblings of the context node because eventually,
+ // the text is "polluted" with pi's or comments
+ StringBuffer sb = new StringBuffer();
+
+ for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
+ currentSibling != null;
+ currentSibling = currentSibling.getNextSibling()) {
+ if (currentSibling.getNodeType() == Node.TEXT_NODE) {
+ sb.append(((Text) currentSibling).getData());
+ }
+ }
+
+ return sb.toString();
+ } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
+ return ((Attr) xpathnode).getNodeValue();
+ } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
+ return ((ProcessingInstruction) xpathnode).getNodeValue();
+ }
- // we iterate over all siblings of the context node because eventually,
- // the text is "polluted" with pi's or comments
- StringBuffer sb = new StringBuffer();
+ return null;
+ }
- for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
- currentSibling != null;
- currentSibling = currentSibling.getNextSibling()) {
- if (currentSibling.getNodeType() == Node.TEXT_NODE) {
- sb.append(((Text) currentSibling).getData());
+ private static void fixupFunctionTable() {
+ boolean installed = false;
+ log.info("Registering Here function");
+ /**
+ * Try to register our here() implementation as internal function.
+ */
+ try {
+ Class []args = {String.class, Expression.class};
+ Method installFunction = FunctionTable.class.getMethod("installFunction", args);
+ if ((installFunction.getModifiers() & Modifier.STATIC) != 0) {
+ Object []params = {"here", new FuncHere()};
+ installFunction.invoke(null, params);
+ installed = true;
}
- }
-
- return sb.toString();
- } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
- return ((Attr) xpathnode).getNodeValue();
- } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
- return ((ProcessingInstruction) xpathnode).getNodeValue();
- }
-
- return null;
- }
+ } catch (Throwable t) {
+ log.debug("Error installing function using the static installFunction method", t);
+ }
+ if(!installed) {
+ try {
+ _funcTable = new FunctionTable();
+ Class []args = {String.class, Class.class};
+ Method installFunction = FunctionTable.class.getMethod("installFunction", args);
+ Object []params = {"here", FuncHere.class};
+ installFunction.invoke(_funcTable, params);
+ installed = true;
+ } catch (Throwable t) {
+ log.debug("Error installing function using the static installFunction method", t);
+ }
+ }
+ if (log.isDebugEnabled()) {
+ if (installed) {
+ log.debug("Registered class " + FuncHere.class.getName()
+ + " for XPath function 'here()' function in internal table");
+ } else {
+ log.debug("Unable to register class " + FuncHere.class.getName()
+ + " for XPath function 'here()' function in internal table");
+ }
+ }
+ }
}
1.11 +0 -106 xml-security/src/org/apache/xml/security/utils/CachedXPathAPIHolder.java
Index: CachedXPathAPIHolder.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/utils/CachedXPathAPIHolder.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CachedXPathAPIHolder.java 17 Aug 2005 11:41:39 -0000 1.10
+++ CachedXPathAPIHolder.java 12 Sep 2005 18:03:10 -0000 1.11
@@ -16,15 +16,7 @@
*/
package org.apache.xml.security.utils;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-
-import org.apache.xml.security.transforms.implementations.FuncHere;
import org.apache.xpath.CachedXPathAPI;
-import org.apache.xpath.Expression;
-import org.apache.xpath.compiler.FuncLoader;
-import org.apache.xpath.compiler.FunctionTable;
-import org.apache.xpath.functions.Function;
import org.w3c.dom.Document;
@@ -68,102 +60,4 @@
}
return cx;
}
- static {
- registerHereFunction();
- }
- /**
- * Class FuncHereLoader
- *
- * @author $Author$
- * @version $Revision$
- */
- public static class FuncHereLoader extends FuncLoader {
-
- /**
- * Constructor FuncHereLoader
- *
- */
- public FuncHereLoader() {
- super(FuncHere.class.getName(), 0);
- }
-
- /**
- * Method getFunction
- * @return a New function
- */
- public Function getFunction() {
- return new FuncHere();
- }
-
- /**
- * Method getName
- * @return the name of the class.
- *
- */
- public String getName() {
- return FuncHere.class.getName();
- }
- }
- /**
- *
- */
- private static void registerHereFunction() {
- log.info("Registering Here function");
- /**
- * Try to register our here() implementation as internal function.
- */
- {
- Class []args={String.class, Expression.class};
- try {
- Method installFunction=FunctionTable.class.getMethod("installFunction",args);
- if ((installFunction.getModifiers() & Modifier.STATIC)!=0) {
- //xalan 1.1
- Object []params={"here",new FuncHere()};
- installFunction.invoke(null, params );
- } else {
- log.warn("Xalan new, install function not installed.");
- //TODO: Right now not a good way to install the function. Let see how this
- //is resolv, latter in xalan.
- }
- } catch (Exception e) {
- //what to do here, just log it
- log.warn("Exception while installing Function",e);
- }
- if (log.isDebugEnabled())
- log.debug("Registered class " + FuncHere.class.getName()
- + " for XPath function 'here()' function in internal table");
-
- /* The following tweak by "Eric Olson" <eg...@alum.mit.edu>
- * is to enable xml-security to play with JDK 1.4 which
- * unfortunately bundles an old version of Xalan
- */
- FuncLoader funcHereLoader = new FuncHereLoader();
-
- try {
- java.lang.reflect.Field mFunctions = FunctionTable.class.getField("m_functions");
- FuncLoader[] m_functions = (FuncLoader[]) mFunctions.get(null);
-
- for (int i = 0; i < m_functions.length; i++) {
- FuncLoader loader = m_functions[i];
-
- if (loader != null) {
- if (log.isDebugEnabled())
- log.debug("Func " + i + " " + loader.getName());
-
- if (loader.getName().equals(funcHereLoader.getName())) {
- m_functions[i] = funcHereLoader;
- }
- }
- }
- } catch (java.lang.NoSuchFieldException e) {
- if (log.isDebugEnabled()) {
- log.debug("Unable to patch xalan function table.", e);
- }
- } catch (Exception e) {
- if (log.isDebugEnabled()) {
- log.debug("Unable to patch xalan function table.", e);
- }
- }
- }
- }
}
1.35 +0 -1 xml-security/src/org/apache/xml/security/signature/Manifest.java
Index: Manifest.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/signature/Manifest.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- Manifest.java 15 May 2005 11:51:43 -0000 1.34
+++ Manifest.java 12 Sep 2005 18:03:10 -0000 1.35
@@ -73,7 +73,6 @@
/** Field _perManifestResolvers */
List _perManifestResolvers = new ArrayList();
- //CachedXPathAPIHolder cx=new CachedXPathAPIHolder();
/**
* Consturts {@link Manifest}
*
1.26 +0 -2 xml-security/src/org/apache/xml/security/utils/resolver/implementations/ResolverFragment.java
Index: ResolverFragment.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/utils/resolver/implementations/ResolverFragment.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- ResolverFragment.java 3 Apr 2005 07:44:13 -0000 1.25
+++ ResolverFragment.java 12 Sep 2005 18:03:10 -0000 1.26
@@ -93,8 +93,6 @@
log.debug("Try to catch an Element with ID " + id + " and Element was " + selectedElem);
}
- //Set resultSet = dereferenceSameDocumentURI(selectedElem);
- //CachedXPathAPIHolder.setDoc(doc);
XMLSignatureInput result = new XMLSignatureInput(selectedElem);
result.setExcludeComments(true);
1.28 +1 -8 xml-security/src/org/apache/xml/security/utils/resolver/implementations/ResolverXPointer.java
Index: ResolverXPointer.java
===================================================================
RCS file: /home/cvs/xml-security/src/org/apache/xml/security/utils/resolver/implementations/ResolverXPointer.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- ResolverXPointer.java 27 Jul 2005 13:30:48 -0000 1.27
+++ ResolverXPointer.java 12 Sep 2005 18:03:10 -0000 1.28
@@ -58,11 +58,6 @@
Node resultNode = null;
Document doc = uri.getOwnerElement().getOwnerDocument();
- // this must be done so that Xalan can catch ALL namespaces
- //XMLUtils.circumventBug2650(doc);
-
- //CachedXPathAPI cXPathAPI = new CachedXPathAPI();
-
String uriStr=uri.getNodeValue();
if (isXPointerSlash(uriStr)) {
resultNode = doc;
@@ -87,8 +82,6 @@
}
- //Set resultSet = XMLUtils.convertNodelistToSet(resultNode);
- //CachedXPathAPIHolder.setDoc(doc);
XMLSignatureInput result = new XMLSignatureInput(resultNode);
result.setMIMEType("text/xml");