Author: mriou
Date: Wed May 28 10:48:33 2008
New Revision: 661028

URL: http://svn.apache.org/viewvc?rev=661028&view=rev
Log:
ODE-296 Support XSLT's document() function. Patch from Ciaran Jessup.

Modified:
    
ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/explang/EvaluationContext.java
    
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/JaxpFunctionResolver.java
    
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
    
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
    
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
    ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ASSIGN.java
    
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/BpelRuntimeContext.java
    
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ExprEvaluationContextImpl.java
    
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PropertyAliasEvaluationContext.java
    
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java
    
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/CoreBpelTest.java

Modified: 
ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/explang/EvaluationContext.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/explang/EvaluationContext.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/explang/EvaluationContext.java
 (original)
+++ 
ode/trunk/bpel-api/src/main/java/org/apache/ode/bpel/explang/EvaluationContext.java
 Wed May 28 10:48:33 2008
@@ -18,6 +18,8 @@
  */
 package org.apache.ode.bpel.explang;
 
+import java.net.URI;
+
 import org.apache.ode.bpel.common.FaultException;
 import org.apache.ode.bpel.o.OExpression;
 import org.apache.ode.bpel.o.OLink;
@@ -100,4 +102,11 @@
      * using this evaluation context.
      */
     boolean narrowTypes();
+    
+       /**
+        * Retrieves the base URI that the BPEL Process execution contextis 
running relative to.
+        * 
+        * @return URI - the URI representing the absolute physical file path 
location that this process is defined within.
+        */
+       URI getBaseResourceURI();    
 }

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=661028&r1=661027&r2=661028&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
 Wed May 28 10:48:33 2008
@@ -89,7 +89,7 @@
             } else if (Constants.EXT_FUNCTION_GETLINKSTATUS.equals(localName)) 
{
                 return new GetLinkStatus();
             } else if 
(Constants.EXT_FUNCTION_DOXSLTRANSFORM.equals(localName)) {
-                return new DoXslTransform();
+                return new DoXslTransform(_ectx);
             } else {
                 throw new WrappedResolverException("Unknown BPEL function: " + 
functionName);
             }
@@ -181,7 +181,12 @@
     }
 
     public class DoXslTransform implements XPathFunction {
-        public Object evaluate(List args) throws XPathFunctionException {
+       private EvaluationContext _ectx;        
+        public DoXslTransform(EvaluationContext ectx) {
+               this._ectx= ectx;
+               }
+
+               public Object evaluate(List args) throws XPathFunctionException 
{
             if (args.size() < 2 || (args.size() % 2) != 0)
                 throw new XPathFunctionException(new FaultException(new 
QName(Namespaces.ODE_EXTENSION_NS, "doXslTransformInvalidSource"), "Invalid 
arguments"));
 
@@ -264,7 +269,7 @@
             // of the transformation is just a string.
             StringWriter writerResult = new StringWriter();
             StreamResult result = new StreamResult(writerResult);
-            XslRuntimeUriResolver resolver = new 
XslRuntimeUriResolver(_oxpath);
+            XslRuntimeUriResolver resolver = new 
XslRuntimeUriResolver(_oxpath, _ectx.getBaseResourceURI());
             XslTransformHandler.getInstance().cacheXSLSheet(xslUri, 
xslSheet.sheetBody, resolver);
             try {
                 XslTransformHandler.getInstance().transform(xslUri, source, 
result, parametersMap, resolver);

Modified: 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
 (original)
+++ 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/elang/xpath20/runtime/XslRuntimeUriResolver.java
 Wed May 28 10:48:33 2008
@@ -19,14 +19,24 @@
 
 package org.apache.ode.bpel.elang.xpath20.runtime;
 
+import org.apache.ode.bpel.compiler.api.CompilationException;
 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;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.xml.transform.URIResolver;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.stream.StreamSource;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.StringReader;
 
 /**
@@ -36,15 +46,67 @@
  */
 public class XslRuntimeUriResolver implements URIResolver {
 
-  private OXPath10Expression _expr;
+    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.xslSheets.get(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 {
+            File f = new File(resolvedURI);
+            if (!f.exists()) return null;
+            is = new FileInputStream(f);
+            return new String(StreamUtils.read(is));
+        } catch (IOException e) {
+            __log.info("Couldn't load XSL resource " + docUri);
+        } finally {
+            try {
+                if (is != null) is.close();
+            } catch (Exception ex) {
+                // No worries.
+            }
+        }
+        return null;
+    }
+
+
 
-  public XslRuntimeUriResolver(OXPath10Expression expr) {
-    _expr = expr;
-  }
-
-  public Source resolve(String href, String base) throws TransformerException {
-    URI uri = URI.create(href);
-    OXslSheet sheet = _expr.xslSheets.get(uri);
-    return new StreamSource(new StringReader(sheet.sheetBody));
-  }
 }

Modified: 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
 (original)
+++ 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
 Wed May 28 10:48:33 2008
@@ -19,6 +19,7 @@
 package org.apache.ode.bpel.engine;
 
 import java.io.InputStream;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -178,6 +179,15 @@
     }
 
     /**
+     * Retrives the base URI to use for local resource resolution.
+     * 
+     * @return URI - instance representing the absolute file path to the 
physical location of the process definition folder.
+     */
+    public URI getBaseResourceURI() {
+       return this._pconf.getBaseURI();
+    }
+    
+    /**
      * Intiialize the external variable configuration/engine manager. This is 
called from hydration logic, so it 
      * is possible to change the external variable configuration at runtime.
      * 

Modified: 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
 (original)
+++ 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
 Wed May 28 10:48:33 2008
@@ -20,6 +20,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
@@ -1223,4 +1224,8 @@
                return vrp;
        }
 
+       public URI getBaseResourceURI() {
+               return _bpelProcess.getBaseResourceURI();
+       }
+
 }

Modified: 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ASSIGN.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ASSIGN.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ASSIGN.java 
(original)
+++ 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ASSIGN.java 
Wed May 28 10:48:33 2008
@@ -21,6 +21,7 @@
 import java.util.List;
 
 import javax.xml.namespace.QName;
+import java.net.URI;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -674,6 +675,10 @@
         public boolean narrowTypes() {
             return false;
         }
+
+               public URI getBaseResourceURI() {
+                       return _ctx.getBaseResourceURI();
+               }
     }
 
 }

Modified: 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/BpelRuntimeContext.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/BpelRuntimeContext.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/BpelRuntimeContext.java
 (original)
+++ 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/BpelRuntimeContext.java
 Wed May 28 10:48:33 2008
@@ -21,6 +21,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.net.URI;
 
 import javax.wsdl.Operation;
 import javax.xml.namespace.QName;
@@ -274,4 +275,11 @@
                public Node value;
                public Node reference;
        }
+       
+       /**
+        * Retrieves the base URI that this BPEL Process instance is running 
relative to.
+        * 
+        * @return URI - the URI representing the absolute physical file path 
location that this process is defined within.
+        */
+       URI getBaseResourceURI();
 }

Modified: 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ExprEvaluationContextImpl.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ExprEvaluationContextImpl.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ExprEvaluationContextImpl.java
 (original)
+++ 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/ExprEvaluationContextImpl.java
 Wed May 28 10:48:33 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.ode.bpel.runtime;
 
+import java.net.URI;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -125,4 +126,8 @@
                _native.sendEvent(se);
        }
 
+       public URI getBaseResourceURI() {
+               return _native.getBaseResourceURI();
+       }
+
 }

Modified: 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PropertyAliasEvaluationContext.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PropertyAliasEvaluationContext.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PropertyAliasEvaluationContext.java
 (original)
+++ 
ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PropertyAliasEvaluationContext.java
 Wed May 28 10:48:33 2008
@@ -18,6 +18,8 @@
  */
 package org.apache.ode.bpel.runtime;
 
+import java.net.URI;
+
 import org.apache.ode.bpel.common.FaultException;
 import org.apache.ode.bpel.explang.EvaluationContext;
 import org.apache.ode.bpel.o.OElementVarType;
@@ -87,5 +89,9 @@
     public boolean narrowTypes() {
         return true;
     }
+    
+    public URI getBaseResourceURI() {
+       return null;
+    }
 
 }

Modified: 
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java
 (original)
+++ 
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/elang/xpath20/runtime/XPath20ExpressionRuntimeTest.java
 Wed May 28 10:48:33 2008
@@ -36,6 +36,8 @@
 import org.w3c.dom.NodeList;
 
 import javax.xml.namespace.QName;
+
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -152,4 +154,8 @@
         Expression exp = new Expression(e);
         return (OXPath20ExpressionBPEL20)_compiler.compileLValue(exp);
     }
+    @Override
+    public URI getBaseResourceURI() {
+       return null;
+    }
 }

Modified: 
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/CoreBpelTest.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/CoreBpelTest.java?rev=661028&r1=661027&r2=661028&view=diff
==============================================================================
--- 
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/CoreBpelTest.java
 (original)
+++ 
ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/CoreBpelTest.java
 Wed May 28 10:48:33 2008
@@ -20,6 +20,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.net.URI;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
@@ -450,5 +451,10 @@
                // TODO Auto-generated method stub
                return null;
        }
+       
+       public URI getBaseResourceURI() {
+               // TODO Auto-generated method stub
+               return null;
+       }
 
 }


Reply via email to