You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2011/10/11 12:55:45 UTC
svn commit: r1181705 - in /santuario/xml-security-java/trunk:
samples/org/apache/xml/security/samples/utils/resolver/
src/main/java/org/apache/xml/security/transforms/implementations/
src/main/java/org/apache/xml/security/utils/
Author: coheigea
Date: Tue Oct 11 10:55:44 2011
New Revision: 1181705
URL: http://svn.apache.org/viewvc?rev=1181705&view=rev
Log:
More work on the Xalan port.
Removed:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHereContext.java
Modified:
santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/utils/resolver/OfflineResolver.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHere.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java
Modified: santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/utils/resolver/OfflineResolver.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/utils/resolver/OfflineResolver.java?rev=1181705&r1=1181704&r2=1181705&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/utils/resolver/OfflineResolver.java (original)
+++ santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/utils/resolver/OfflineResolver.java Tue Oct 11 10:55:44 2011
@@ -21,13 +21,14 @@ package org.apache.xml.security.samples.
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.utils.resolver.ResourceResolverException;
import org.apache.xml.security.utils.resolver.ResourceResolverSpi;
-import org.apache.xml.utils.URI;
import org.w3c.dom.Attr;
/**
@@ -125,14 +126,14 @@ public class OfflineResolver extends Res
}
try {
- URI uriNew = new URI(new URI(BaseURI), uri.getNodeValue());
+ URI uriNew = getNewURI(uri.getNodeValue(), BaseURI);
if (uriNew.getScheme().equals("http")) {
log.debug("I state that I can resolve " + uriNew.toString());
return true;
}
log.debug("I state that I can't resolve " + uriNew.toString());
- } catch (URI.MalformedURIException ex) {
+ } catch (URISyntaxException ex) {
//
}
@@ -150,4 +151,21 @@ public class OfflineResolver extends Res
OfflineResolver._uriMap.put(URI, filename);
OfflineResolver._mimeMap.put(URI, MIME);
}
+
+ private static URI getNewURI(String uri, String baseURI) throws URISyntaxException {
+ URI newUri = null;
+ if (baseURI == null || "".equals(baseURI)) {
+ newUri = new URI(uri);
+ } else {
+ newUri = new URI(baseURI).resolve(uri);
+ }
+
+ // if the URI contains a fragment, ignore it
+ if (newUri.getFragment() != null) {
+ URI uriNewNoFrag =
+ new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
+ return uriNewNoFrag;
+ }
+ return newUri;
+ }
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHere.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHere.java?rev=1181705&r1=1181704&r2=1181705&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHere.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/FuncHere.java Tue Oct 11 10:55:44 2011
@@ -147,7 +147,6 @@ public class FuncHere extends Function {
* @param vars
* @param globalsSize
*/
- @SuppressWarnings("unchecked")
public void fixupVariables(java.util.Vector vars, int globalsSize) {
// do nothing
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java?rev=1181705&r1=1181704&r2=1181705&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java Tue Oct 11 10:55:44 2011
@@ -32,7 +32,6 @@ import org.apache.xml.security.transform
import org.apache.xml.security.utils.CachedXPathFuncHereAPI;
import org.apache.xml.security.utils.Constants;
import org.apache.xml.security.utils.XMLUtils;
-import org.apache.xpath.objects.XObject;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -50,8 +49,7 @@ import org.w3c.dom.Node;
public class TransformXPath extends TransformSpi {
/** Field implementedTransformURI */
- public static final String implementedTransformURI =
- Transforms.TRANSFORM_XPATH;
+ public static final String implementedTransformURI = Transforms.TRANSFORM_XPATH;
/**
* Method engineGetURI
@@ -94,8 +92,8 @@ public class TransformXPath extends Tran
throw new TransformationException("xml.WrongContent", exArgs);
}
Node xpathnode = xpathElement.getChildNodes().item(0);
- String str = CachedXPathFuncHereAPI.getStrFromNode(xpathnode);
- input.setNeedsToBeExpanded(needsCircunvent(str));
+ String str = XMLUtils.getStrFromNode(xpathnode);
+ input.setNeedsToBeExpanded(needsCircumvent(str));
if (xpathnode == null) {
throw new DOMException(
DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath"
@@ -111,10 +109,10 @@ public class TransformXPath extends Tran
}
/**
- * @param str
- * @return true if needs to be circunvent for bug.
+ * @param str
+ * @return true if needs to be circumvent for bug.
*/
- private boolean needsCircunvent(String str) {
+ private boolean needsCircumvent(String str) {
return (str.indexOf("namespace") != -1) || (str.indexOf("name()") != -1);
}
@@ -135,10 +133,10 @@ public class TransformXPath extends Tran
* @see org.apache.xml.security.signature.NodeFilter#isNodeInclude(org.w3c.dom.Node)
*/
public int isNodeInclude(Node currentNode) {
- XObject includeInResult;
try {
- includeInResult = xPathFuncHereAPI.eval(currentNode, xpathnode, str, xpathElement);
- if (includeInResult.bool()) {
+ boolean include =
+ xPathFuncHereAPI.evaluate(currentNode, xpathnode, str, xpathElement);
+ if (include) {
return 1;
}
return 0;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java?rev=1181705&r1=1181704&r2=1181705&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java Tue Oct 11 10:55:44 2011
@@ -84,8 +84,6 @@ public class TransformXPath2Filter exten
List<NodeList> substractNodes = new ArrayList<NodeList>();
List<NodeList> intersectNodes = new ArrayList<NodeList>();
- CachedXPathFuncHereAPI xPathFuncHereAPI = new CachedXPathFuncHereAPI();
-
Element[] xpathElements =
XMLUtils.selectNodes(
transformObject.getElement().getFirstChild(),
@@ -105,6 +103,7 @@ public class TransformXPath2Filter exten
inputDoc = XMLUtils.getOwnerDocument(input.getNodeSet());
}
+ CachedXPathFuncHereAPI xPathFuncHereAPI = new CachedXPathFuncHereAPI();
for (int i = 0; i < xpathElements.length; i++) {
Element xpathElement = xpathElements[i];
@@ -115,7 +114,7 @@ public class TransformXPath2Filter exten
xPathFuncHereAPI.selectNodeList(
inputDoc,
xpathContainer.getXPathFilterTextNode(),
- CachedXPathFuncHereAPI.getStrFromNode(xpathContainer.getXPathFilterTextNode()),
+ XMLUtils.getStrFromNode(xpathContainer.getXPathFilterTextNode()),
xpathContainer.getElement());
if (xpathContainer.isIntersect()) {
intersectNodes.add(subtreeRoots);
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java?rev=1181705&r1=1181704&r2=1181705&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/CachedXPathFuncHereAPI.java Tue Oct 11 10:55:44 2011
@@ -18,45 +18,36 @@
*/
package org.apache.xml.security.utils;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.SourceLocator;
+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.*;
-
-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;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
- *
- * @author $Author$
*/
public class CachedXPathFuncHereAPI {
private static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(CachedXPathFuncHereAPI.class);
- /**
- * XPathContext, and thus DTMManager and DTMs, persists through multiple
- * calls to this object.
- */
- FuncHereContext funcHereContext = null;
- /** Field dtmManager */
DTMManager dtmManager = null;
- XPathContext context = null;
-
String xpathStr=null;
XPath xpath=null;
@@ -71,7 +62,8 @@ public class CachedXPathFuncHereAPI {
* Constructor CachedXPathFuncHereAPI
*/
public CachedXPathFuncHereAPI() {
- this.context = new XPathContext();
+ XPathContext context = new XPathContext();
+ context.setSecureProcessing(true);
this.dtmManager = context.getDTMManager();
}
@@ -88,8 +80,8 @@ public class CachedXPathFuncHereAPI {
* @throws TransformerException
*/
public NodeList selectNodeList(
- Node contextNode, Node xpathnode, String str, Node namespaceNode)
- throws TransformerException {
+ Node contextNode, Node xpathnode, String str, Node namespaceNode
+ ) throws TransformerException {
// Execute the XPath, and have it return the result
XObject list = eval(contextNode, xpathnode, str, namespaceNode);
@@ -97,33 +89,37 @@ public class CachedXPathFuncHereAPI {
// Return a NodeList.
return list.nodelist();
}
+
+ /**
+ * Evaluate an XPath string and return true if the output is to be included or not.
+ * @param contextNode The node to start searching from.
+ * @param xpathnode The XPath node
+ * @param str The XPath expression
+ * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
+ */
+ public boolean evaluate(Node contextNode, Node xpathnode, String str, Node namespaceNode)
+ throws TransformerException {
+ XObject object = eval(contextNode, xpathnode, str, namespaceNode);
+ return object.bool();
+ }
/**
- * Evaluate XPath string to an XObject.
- * XPath namespace prefixes are resolved from the namespaceNode.
- * The implementation of this is a little slow, since it creates
- * a number of objects each time it is called. This could be optimized
- * to keep the same objects around, but then thread-safety issues would arise.
+ * Evaluate an XPath string to an XObject. XPath namespace prefixes are resolved from the
+ * namespaceNode.
*
* @param contextNode The node to start searching from.
- * @param xpathnode
- * @param str
+ * @param xpathnode The XPath node
+ * @param str The XPath expression
* @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
- * @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
- * @see org.apache.xpath.objects.XObject
- * @see org.apache.xpath.objects.XNull
- * @see org.apache.xpath.objects.XBoolean
- * @see org.apache.xpath.objects.XNumber
- * @see org.apache.xpath.objects.XString
- * @see org.apache.xpath.objects.XRTreeFrag
+ * @return An XObject, which can be used to obtain a string, number, nodelist, etc,
+ * should never be null.
*
* @throws TransformerException
*/
- public XObject eval(Node contextNode, Node xpathnode, String str, Node namespaceNode)
- throws TransformerException {
- if (this.funcHereContext == null) {
- this.funcHereContext = new FuncHereContext(xpathnode, this.dtmManager);
- }
+ private XObject eval(Node contextNode, Node xpathnode, String str, Node namespaceNode)
+ throws TransformerException {
+ XPathContext context = new XPathContext(xpathnode);
+ context.setSecureProcessing(true);
// Create an object to resolve namespace prefixes.
// XPath namespaces are resolved from the input context node's document element
@@ -147,9 +143,9 @@ public class CachedXPathFuncHereAPI {
// Execute the XPath, and have it return the result
// return xpath.execute(xpathSupport, contextNode, prefixResolver);
- int ctxtNode = this.funcHereContext.getDTMHandleFromNode(contextNode);
+ int ctxtNode = context.getDTMHandleFromNode(contextNode);
- return xpath.execute(this.funcHereContext, ctxtNode, prefixResolver);
+ return xpath.execute(context, ctxtNode, prefixResolver);
}
private XPath createXPath(String str, PrefixResolver prefixResolver) throws TransformerException {
@@ -171,38 +167,6 @@ public class CachedXPathFuncHereAPI {
return xpath;
}
- /**
- * 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();
- }
-
- return null;
- }
-
private static void fixupFunctionTable() {
boolean installed = false;
if (log.isDebugEnabled()) {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java?rev=1181705&r1=1181704&r2=1181705&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/XMLUtils.java Tue Oct 11 10:55:44 2011
@@ -37,6 +37,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
/**
@@ -681,6 +682,36 @@ public class XMLUtils {
}
return resultSet;
}
+
+ /**
+ * 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
+ StringBuilder sb = new StringBuilder();
+
+ 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();
+ }
+
+ return null;
+ }
/**
* Returns true if the descendantOrSelf is on the descendant-or-self axis
@@ -690,7 +721,7 @@ public class XMLUtils {
* @param descendantOrSelf
* @return true if the node is descendant
*/
- static public boolean isDescendantOrSelf(Node ctx, Node descendantOrSelf) {
+ public static boolean isDescendantOrSelf(Node ctx, Node descendantOrSelf) {
if (ctx == descendantOrSelf) {
return true;
}