001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.component.xslt;
018    
019    import java.util.Map;
020    
021    import org.apache.camel.Endpoint;
022    import org.apache.camel.Exchange;
023    import org.apache.camel.builder.xml.XsltBuilder;
024    import org.apache.camel.component.ResourceBasedComponent;
025    import org.apache.camel.converter.jaxp.XmlConverter;
026    import org.apache.camel.impl.ProcessorEndpoint;
027    import org.springframework.core.io.Resource;
028    
029    /**
030     * An <a href="http://activemq.apache.org/camel/xslt.html">XSLT Component</a>
031     * for performing XSLT transforms of messages
032     *
033     * @version $Revision: 41334 $
034     */
035    public class XsltComponent extends ResourceBasedComponent {
036        private XmlConverter xmlConverter;
037    
038        public XmlConverter getXmlConverter() {
039            return xmlConverter;
040        }
041    
042        public void setXmlConverter(XmlConverter xmlConverter) {
043            this.xmlConverter = xmlConverter;
044        }
045    
046        protected Endpoint<Exchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
047            Resource resource = resolveMandatoryResource(remaining);
048            if (log.isDebugEnabled()) {
049                log.debug(this + " using schema resource: " + resource);
050            }
051            XsltBuilder xslt = newInstance(XsltBuilder.class);
052    
053            // lets allow the converter to be configured
054            XmlConverter converter = null;
055            String converterName = getAndRemoveParameter(parameters, "converter", String.class);
056            if (converterName != null) {
057                converter = mandatoryLookup(converterName, XmlConverter.class);
058            }
059            if (converter == null) {
060                converter = getXmlConverter();
061            }
062            if (converter != null) {
063                xslt.setConverter(converter);
064            }
065    
066            xslt.setTransformerInputStream(resource.getInputStream());
067            configureXslt(xslt, uri, remaining, parameters);
068            return new ProcessorEndpoint(uri, this, xslt);
069        }
070    
071        protected void configureXslt(XsltBuilder xslt, String uri, String remaining, Map parameters) throws Exception {
072            setProperties(xslt, parameters);
073        }
074    }