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:19:16 UTC

svn commit: r1057052 - in /ode/trunk: Rakefile bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java

Author: vanto
Date: Sun Jan  9 23:19:16 2011
New Revision: 1057052

URL: http://svn.apache.org/viewvc?rev=1057052&view=rev
Log:
fixing ODE-472, thanks to Alexey Ousov for the patch!

Modified:
    ode/trunk/Rakefile
    ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java
    ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java

Modified: ode/trunk/Rakefile
URL: http://svn.apache.org/viewvc/ode/trunk/Rakefile?rev=1057052&r1=1057051&r2=1057052&view=diff
==============================================================================
--- ode/trunk/Rakefile (original)
+++ ode/trunk/Rakefile Sun Jan  9 23:19:16 2011
@@ -222,10 +222,10 @@ define "ode" do
 
 
     test.with projects("scheduler-simple", "dao-jpa", "dao-hibernate", "bpel-epr"),
-        BACKPORT, COMMONS.pool, COMMONS.lang, DERBY, JAVAX.connector, JAVAX.transaction,
+        BACKPORT, COMMONS.pool, COMMONS.lang, COMMONS.io, DERBY, JAVAX.connector, JAVAX.transaction,
         GERONIMO.transaction, GERONIMO.kernel, GERONIMO.connector, TRANQL, HSQLDB, JAVAX.ejb,
         OPENJPA, XERCES, XALAN, LOG4J, SLF4J,
-        DOM4J, HIBERNATE, SPRING_TEST, COMMONS.io
+        DOM4J, HIBERNATE, SPRING_TEST,
         "tranql:tranql-connector-derby-common:jar:1.1"
 
     package :jar

Modified: 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=1057052&r1=1057051&r2=1057052&view=diff
==============================================================================
--- ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java (original)
+++ ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/XslRuntimeUriResolver.java Sun Jan  9 23:19:16 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/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=1057052&r1=1057051&r2=1057052&view=diff
==============================================================================
--- ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java (original)
+++ ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/URIResolverTest.java Sun Jan  9 23:19:16 2011
@@ -18,17 +18,20 @@
  */
 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 {
 
@@ -37,10 +40,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
@@ -53,15 +56,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"));
     }
 
 }