Author: veithen
Date: Sun May 24 21:06:58 2009
New Revision: 778235
URL: http://svn.apache.org/viewvc?rev=778235&view=rev
Log:
SYNAPSE-489: Added support for the <resource> element in the XSLT mediator.
This allows to resolve xsl:import and xsl:include from the repository.
Added:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java
(with props)
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java?rev=778235&r1=778234&r2=778235&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java
Sun May 24 21:06:58 2009
@@ -37,6 +37,7 @@
* <property name="string" (value="literal" | expression="xpath")/>*
* <feature name="string" value="true| false" />*
* <attribute name="string" value="string" />*
+ * <resource location="..." key="..."/>*
* </transform>
* </pre>
*/
@@ -103,6 +104,8 @@
transformMediator.addAllProperties(
MediatorPropertyFactory.getMediatorProperties(elem));
+
transformMediator.setResourceMap(ResourceMapFactory.createResourceMap(elem));
+
return transformMediator;
}
}
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java?rev=778235&r1=778234&r2=778235&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java
Sun May 24 21:06:58 2009
@@ -81,6 +81,9 @@
}
}
serializeMediatorProperties(xslt, mediator.getAttributes(),
ATTRIBUTE_Q);
+
+ ResourceMapSerializer.serializeResourceMap(xslt,
mediator.getResourceMap());
+
if (parent != null) {
parent.addChild(xslt);
}
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=778235&r1=778234&r2=778235&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
Sun May 24 21:06:58 2009
@@ -39,6 +39,8 @@
import org.apache.synapse.util.jaxp.SourceBuilderFactory;
import org.apache.synapse.util.jaxp.StreamResultBuilderFactory;
import org.apache.synapse.util.jaxp.StreamSourceBuilderFactory;
+import org.apache.synapse.util.resolver.CustomJAXPURIResolver;
+import org.apache.synapse.util.resolver.ResourceMap;
import org.apache.synapse.util.xpath.SourceXPathSupport;
import org.apache.synapse.util.xpath.SynapseXPath;
@@ -143,6 +145,11 @@
= new ArrayList<MediatorProperty>();
/**
+ * A resource map used to resolve xsl:import and xsl:include.
+ */
+ private ResourceMap resourceMap;
+
+ /**
* The Template instance used to create a Transformer object. This is
thread-safe
*
* @see javax.xml.transform.Templates
@@ -225,6 +232,9 @@
if (reCreate || cachedTemplates == null) {
// Set an error listener (SYNAPSE-307).
transFact.setErrorListener(new ErrorListenerImpl(synLog,
"stylesheet parsing"));
+ // Allow xsl:import and xsl:include resolution
+ transFact.setURIResolver(new CustomJAXPURIResolver(resourceMap,
+ synCtx.getConfiguration()));
try {
cachedTemplates = transFact.newTemplates(
SynapseConfigUtils.getStreamSource(synCtx.getEntry(xsltKey)));
@@ -503,7 +513,14 @@
public void setTargetPropertyName(String targetPropertyName) {
this.targetPropertyName = targetPropertyName;
}
-
+
+ public ResourceMap getResourceMap() {
+ return resourceMap;
+ }
+
+ public void setResourceMap(ResourceMap resourceMap) {
+ this.resourceMap = resourceMap;
+ }
}
Added:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java?rev=778235&view=auto
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java
(added)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java
Sun May 24 21:06:58 2009
@@ -0,0 +1,70 @@
+/*
+ * 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.synapse.util.resolver;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.synapse.config.SynapseConfigUtils;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.xml.sax.InputSource;
+
+/**
+ * Class that adapts a {...@link ResourceMap} to JAXP's {...@link URIResolver}.
+ */
+public class CustomJAXPURIResolver implements URIResolver {
+ private final ResourceMap resourceMap;
+ private final SynapseConfiguration synCfg;
+
+ /**
+ * Constructor.
+ *
+ * @param resourceMap the resource map; may be null if no resource map is
configured
+ * @param synCfg the Synapse configuration
+ */
+ public CustomJAXPURIResolver(ResourceMap resourceMap, SynapseConfiguration
synCfg) {
+ this.resourceMap = resourceMap;
+ this.synCfg = synCfg;
+ }
+
+ /**
+ * Resolve an xsl:import or xsl:include.
+ * This method will first attempt to resolve the location using the
configured
+ * {...@link ResourceMap} object. If this fails (because no {...@link
ResourceMap} is
+ * configured or because {...@link
ResourceMap#resolve(SynapseConfiguration, String)}
+ * returns null, it will resolve the location using
+ * {...@link SynapseConfigUtils#resolveRelativeURI(String, String)}.
+ */
+ public Source resolve(String href, String base) throws
TransformerException {
+ Source result = null;
+ if (resourceMap != null) {
+ InputSource is = resourceMap.resolve(synCfg, href);
+ if (is != null) {
+ result = new StreamSource(is.getByteStream());
+ }
+ }
+ if (result == null) {
+ result = new
StreamSource(SynapseConfigUtils.resolveRelativeURI(base, href));
+ }
+ return result;
+ }
+}
Propchange:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml?rev=778235&r1=778234&r2=778235&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml
(original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml Sun May
24 21:06:58 2009
@@ -1381,6 +1381,7 @@
<property name="string" (value="literal" | expression="xpath")/>*
<feature name="string" value="true | false" />*
<attribute name="string" value="string" />*
+ <resource location="..." key="..."/>*
</xslt></pre>
<p>
The <xslt> mediator applies the specified XSLT transformation to
the
@@ -1416,6 +1417,11 @@
The 'attribute' element allows to define attributes which should be
explicitly
set to the TransformerFactory.
</p>
+ <p>
+ Finally, the 'resource' element can be used to resolve XSLT imports and
includes from the
+ repository. It works in exactly the same way as the corresponding
element in a
+ <proxy> definition.
+ </p>
<h4>
<a name="xquery" id="xquery">XQuery</a>
</h4>