Author: ruwan Date: Mon May 25 00:38:24 2009 New Revision: 36699 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=36699
Log: sync up with the synapse trunk Added: branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java Modified: branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java Modified: branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java?rev=36699&r1=36698&r2=36699&view=diff ============================================================================== --- branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java (original) +++ branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorFactory.java Mon May 25 00:38:24 2009 @@ -103,6 +103,8 @@ transformMediator.addAllProperties( MediatorPropertyFactory.getMediatorProperties(elem)); + transformMediator.setResourceMap(ResourceMapFactory.createResourceMap(elem)); + return transformMediator; } } Modified: branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java?rev=36699&r1=36698&r2=36699&view=diff ============================================================================== --- branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java (original) +++ branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/XSLTMediatorSerializer.java Mon May 25 00:38:24 2009 @@ -81,6 +81,9 @@ } } serializeMediatorProperties(xslt, mediator.getAttributes(), ATTRIBUTE_Q); + + ResourceMapSerializer.serializeResourceMap(xslt, mediator.getResourceMap()); + if (parent != null) { parent.addChild(xslt); } Modified: branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=36699&r1=36698&r2=36699&view=diff ============================================================================== --- branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java (original) +++ branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java Mon May 25 00:38:24 2009 @@ -41,6 +41,8 @@ import org.apache.synapse.util.jaxp.StreamSourceBuilderFactory; import org.apache.synapse.util.xpath.SourceXPathSupport; import org.apache.synapse.util.xpath.SynapseXPath; +import org.apache.synapse.util.resolver.ResourceMap; +import org.apache.synapse.util.resolver.CustomJAXPURIResolver; import javax.xml.transform.*; import java.nio.charset.Charset; @@ -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: branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java?pathrev=36699 ============================================================================== --- (empty file) +++ branches/synapse/1.3-wso2v1/modules/core/src/main/java/org/apache/synapse/util/resolver/CustomJAXPURIResolver.java Mon May 25 00:38:24 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; + } +} \ No newline at end of file _______________________________________________ Esb-java-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev
