You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by va...@apache.org on 2011/01/09 19:32:45 UTC
svn commit: r1056996 - in /ode/trunk/bpel-runtime/src:
main/java/org/apache/ode/bpel/elang/
main/java/org/apache/ode/bpel/elang/xpath10/runtime/
main/java/org/apache/ode/bpel/elang/xpath20/runtime/
test/java/org/apache/ode/bpel/elang/
Author: vanto
Date: Sun Jan 9 18:32:45 2011
New Revision: 1056996
URL: http://svn.apache.org/viewvc?rev=1056996&view=rev
Log:
fixes ODE-904: document() in XSLT can now load remote URLs.
Added:
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java (with props)
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java (with props)
Removed:
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/XslRuntimeUriResolver.java
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
Modified:
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
Added: ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java?rev=1056996&view=auto
==============================================================================
--- ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java (added)
+++ ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java Sun Jan 9 18:32:45 2011
@@ -0,0 +1,111 @@
+/*
+ * 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
+ *
+ * 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.
+ */
+
+package org.apache.ode.bpel.elang;
+
+import java.io.InputStream;
+import java.io.StringReader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import org.apache.ode.bpel.o.OXslSheet;
+import org.apache.ode.utils.StreamUtils;
+import org.apache.ode.utils.fs.FileUtils;
+
+/**
+ * Used to give the Xsl processor a way to access included XSL sheets
+ * by using the maps of sheets pre-processed at compilation time and
+ * stored in the OXPath10Expression.
+ */
+public class XslRuntimeUriResolver implements URIResolver {
+
+ private static final Log __log = LogFactory.getLog(XslRuntimeUriResolver.class);
+
+ private OXPath10Expression _expr;
+ private final URI _baseResourceURI;
+
+ public XslRuntimeUriResolver(OXPath10Expression expr, URI baseResourceURI) {
+ _expr = expr;
+ _baseResourceURI= baseResourceURI;
+ }
+
+ public Source resolve(String href, String base) throws TransformerException {
+ String result;
+ URI uri;
+ try {
+ uri = new URI(FileUtils.encodePath(href));
+ } catch (URISyntaxException e) {
+ return null;
+ }
+
+ OXslSheet sheet = _expr.getXslSheet(uri);
+ if( sheet != null) {
+ result = sheet.sheetBody;
+ } else {
+ result = getResourceAsString(uri);
+ }
+
+ if( result != null ) {
+ return new StreamSource(new StringReader(result));
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Given a URI this function will attempt to retrieve the resource declared at that URI location
+ * as a string. (Hopefully everything's character encodings are all ok...) This URI can be
+ * defined as being relative to the executing process instance's physical file location.
+ *
+ * @param docUri - the URI to resolve
+ * @return String - the resource contents, or null if none found.
+ */
+ private String getResourceAsString(URI docUri) {
+ URI resolvedURI = _baseResourceURI.resolve(docUri);
+ InputStream is = null;
+
+ try {
+ // treat URI as URL and try to load it.
+ URL url = resolvedURI.toURL();
+ is = url.openStream();
+
+ // and read it to a buffer.
+ return new String(StreamUtils.read(is));
+ } catch (Exception e) {
+ __log.warn("Couldn't load XSL resource " + docUri, e);
+ } finally {
+ try {
+ if (is != null) is.close();
+ } catch (Exception ex) {
+ // No worries.
+ }
+ }
+ return null;
+ }
+
+}
Propchange: ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java?rev=1056996&r1=1056995&r2=1056996&view=diff
==============================================================================
--- ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java (original)
+++ ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath10/runtime/JaxenContexts.java Sun Jan 9 18:32:45 2011
@@ -18,9 +18,21 @@
*/
package org.apache.ode.bpel.elang.xpath10.runtime;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMSource;
+
+import net.sf.saxon.dom.NodeWrapper;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.elang.XslRuntimeUriResolver;
import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
import org.apache.ode.bpel.elang.xpath10.o.OXPath10ExpressionBPEL20;
import org.apache.ode.bpel.explang.EvaluationContext;
@@ -33,7 +45,6 @@ import org.apache.ode.bpel.o.OVarType;
import org.apache.ode.bpel.o.OXsdTypeVarType;
import org.apache.ode.bpel.o.OXslSheet;
import org.apache.ode.utils.DOMUtils;
-import org.apache.ode.utils.xsd.XSTypes;
import org.apache.ode.utils.xsl.XslTransformHandler;
import org.jaxen.Context;
import org.jaxen.Function;
@@ -42,21 +53,9 @@ import org.jaxen.FunctionContext;
import org.jaxen.UnresolvableException;
import org.jaxen.VariableContext;
import org.jaxen.XPathFunctionContext;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-import javax.xml.namespace.QName;
-import javax.xml.transform.dom.DOMSource;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import net.sf.saxon.dom.NodeWrapper;
/**
Modified: ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java?rev=1056996&r1=1056995&r2=1056996&view=diff
==============================================================================
--- ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java (original)
+++ ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java Sun Jan 9 18:32:45 2011
@@ -46,6 +46,7 @@ import org.apache.commons.httpclient.URI
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.common.FaultException;
+import org.apache.ode.bpel.elang.XslRuntimeUriResolver;
import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
import org.apache.ode.bpel.elang.xpath10.o.OXPath10ExpressionBPEL20;
import org.apache.ode.bpel.elang.xpath20.compiler.Constants;
Added: ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java
URL: http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java?rev=1056996&view=auto
==============================================================================
--- ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java (added)
+++ ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java Sun Jan 9 18:32:45 2011
@@ -0,0 +1,48 @@
+package org.apache.ode.bpel.elang;
+
+import java.net.URI;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
+import static org.junit.Assert.*;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.internal.matchers.StringContains.containsString;
+
+public class URIResolverTest {
+
+ @Test
+ public void testResolveExistingFile() throws Exception {
+ OXPath10Expression expr = new OXPath10Expression(null, null, null, null);
+ URI baseResourceURI = getClass().getResource("/xpath20/").toURI();
+ XslRuntimeUriResolver resolver = new XslRuntimeUriResolver(expr, baseResourceURI);
+ StreamSource ss = (StreamSource)resolver.resolve("variables.xml", null);
+ String result = IOUtils.toString(ss.getReader());
+
+ assertThat(result, containsString("<variables>"));
+ }
+
+ @Test
+ public void testResolveNonExistingFile() throws Exception {
+ OXPath10Expression expr = new OXPath10Expression(null, null, null, null);
+ URI baseResourceURI = getClass().getResource("/xpath20/").toURI();
+ XslRuntimeUriResolver resolver = new XslRuntimeUriResolver(expr, baseResourceURI);
+
+ assertNull(resolver.resolve("variablesa.xml", null));
+ }
+
+ @Test
+ @Ignore("automated tests should not rely on remote connections.")
+ public void testResolveURL() throws Exception {
+ OXPath10Expression expr = new OXPath10Expression(null, null, null, null);
+ URI baseResourceURI = getClass().getResource("/xpath20/").toURI();
+ XslRuntimeUriResolver resolver = new XslRuntimeUriResolver(expr, baseResourceURI);
+ StreamSource ss = (StreamSource)resolver.resolve("http://ode.apache.org/", null);
+ String result = IOUtils.toString(ss.getReader());
+
+ assertThat(result, containsString("Orchestration Director Engine"));
+ }
+
+}
Propchange: ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native