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/10 00:22:22 UTC
svn commit: r1057054 - in /ode/branches/ode-1.3.5.x/bpel-runtime/src:
main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java
test/java/org/apache/ode/bpel/elang/URIResolverTest.java
Author: vanto
Date: Sun Jan 9 23:22:22 2011
New Revision: 1057054
URL: http://svn.apache.org/viewvc?rev=1057054&view=rev
Log:
fixing ODE-472, thanks to Alexey Ousov for the patch!
Modified:
ode/branches/ode-1.3.5.x/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java
ode/branches/ode-1.3.5.x/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java
Modified: ode/branches/ode-1.3.5.x/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java
URL: http://svn.apache.org/viewvc/ode/branches/ode-1.3.5.x/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java?rev=1057054&r1=1057053&r2=1057054&view=diff
==============================================================================
--- ode/branches/ode-1.3.5.x/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java (original)
+++ ode/branches/ode-1.3.5.x/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java Sun Jan 9 23:22:22 2011
@@ -55,7 +55,6 @@ public class XslRuntimeUriResolver imple
}
public Source resolve(String href, String base) throws TransformerException {
- String result;
URI uri;
try {
uri = new URI(FileUtils.encodePath(href));
@@ -65,13 +64,17 @@ public class XslRuntimeUriResolver imple
OXslSheet sheet = _expr.getXslSheet(uri);
if( sheet != null) {
- result = sheet.sheetBody;
- } else {
- result = getResourceAsString(uri);
- }
-
+ String result = sheet.sheetBody;
+ if (result != null) {
+ return new StreamSource(new StringReader(result));
+ } else {
+ return null;
+ }
+ }
+
+ InputStream result = getResourceAsStream(uri);
if( result != null ) {
- return new StreamSource(new StringReader(result));
+ return new StreamSource(result);
} else {
return null;
}
@@ -79,13 +82,13 @@ public class XslRuntimeUriResolver imple
/**
* 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.
+ * as a stream. This URI can be defined as being relative to the executing process instance's
+ * physical file location or can point to an HTTP(S) resource.
*
* @param docUri - the URI to resolve
- * @return String - the resource contents, or null if none found.
+ * @return stream - the resource contents, or null if none found.
*/
- private String getResourceAsString(URI docUri) {
+ private InputStream getResourceAsStream(URI docUri) {
URI resolvedURI = _baseResourceURI.resolve(docUri);
InputStream is = null;
@@ -95,15 +98,9 @@ public class XslRuntimeUriResolver imple
is = url.openStream();
// and read it to a buffer.
- return new String(StreamUtils.read(is));
+ return 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;
}
Modified: ode/branches/ode-1.3.5.x/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java
URL: http://svn.apache.org/viewvc/ode/branches/ode-1.3.5.x/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java?rev=1057054&r1=1057053&r2=1057054&view=diff
==============================================================================
--- ode/branches/ode-1.3.5.x/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java (original)
+++ ode/branches/ode-1.3.5.x/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java Sun Jan 9 23:22:22 2011
@@ -1,16 +1,19 @@
package org.apache.ode.bpel.elang;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
import java.net.URI;
-import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.Source;
-import org.apache.commons.io.IOUtils;
import org.apache.ode.bpel.elang.xpath10.o.OXPath10Expression;
-import static org.junit.Assert.*;
+import org.apache.ode.utils.DOMUtils;
import org.junit.Ignore;
import org.junit.Test;
-
-import static org.junit.matchers.JUnitMatchers.containsString;
+import org.w3c.dom.Document;
public class URIResolverTest {
@@ -19,10 +22,10 @@ public class URIResolverTest {
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());
+ Source source = resolver.resolve("variables.xml", null);
+ Document doc = DOMUtils.sourceToDOM(source);
- assertThat(result, containsString("<variables>"));
+ assertThat(DOMUtils.domToString(doc), containsString("<variables>"));
}
@Test
@@ -35,15 +38,25 @@ public class URIResolverTest {
}
@Test
+ public void testEncoding() throws Exception {
+ OXPath10Expression expr = new OXPath10Expression(null, null, null, null);
+ URI baseResourceURI = getClass().getResource("/xslt/").toURI();
+ XslRuntimeUriResolver resolver = new XslRuntimeUriResolver(expr, baseResourceURI);
+
+ Document doc = DOMUtils.sourceToDOM(resolver.resolve("test.xml", null));
+ assertEquals("Prova lettere accentate: à è ì ò ù", doc.getDocumentElement().getTextContent().trim());
+ }
+
+ @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());
+ Source source = resolver.resolve("https://svn.apache.org/repos/asf/ode/trunk/bpel-schemas/src/main/xsd/pmapi.xsd", null);
+ Document doc = DOMUtils.sourceToDOM(source);
- assertThat(result, containsString("Orchestration Director Engine"));
+ assertThat(DOMUtils.domToString(doc), containsString("activity-info"));
}
}