Run Application View Source Code

Orbeon Forms Apps

Orbeon Forms Source Code Viewer

Loading...
An error has occurred

You may want to try one of the following:

  • Close this dialog and continue to use this page.
  • Reload this page. Note that you will lose any unsaved changes.
  • If the above does not work, try reloading the page yourself. Note that you will lose any unsaved changes:

    • With Firefox and Safari: hold down the shift key and click the Reload button in your browser toolbar.
    • With Internet Explorer: hold down the control key and click the Reload button in your browser toolbar.
  • Return home.
Help
View as text View as text View as formatted XML View as formatted XML Download Download
CallXSLT.java 3,402
input.xml 2,786
page-flow.xml 821
transform.xsl 1,926
view.xpl 1,296
$xforms-template-label$
/**
 *  Copyright (C) 2007 Orbeon, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify it under the terms of the
 *  GNU Lesser General Public License as published by the Free Software Foundation; either version
 *  2.1 of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Lesser General Public License for more details.
 *
 *  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
 */

import org.dom4j.Document;
import org.dom4j.QName;
import org.orbeon.oxf.common.OXFException;
import org.orbeon.oxf.pipeline.api.PipelineContext;
import org.orbeon.oxf.processor.*;
import org.orbeon.oxf.processor.generator.DOMGenerator;
import org.orbeon.oxf.processor.generator.URLGenerator;
import org.orbeon.oxf.util.PipelineUtils;
import org.orbeon.oxf.xml.TransformerUtils;
import org.orbeon.oxf.xml.XMLConstants;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

/**
 * This class shows how you can call a processor and handle its inputs and outputs with the pipeline API.
 */
public class CallXSLT extends SimpleProcessor {

    public CallXSLT() {
        addOutputInfo(new ProcessorInputOutputInfo(OUTPUT_DATA));
    }

    public void generateMyoutput(PipelineContext pipelineContext, ContentHandler contentHandler) throws SAXException {

        // Define the name of the processor (this is a QName)
        final QName processorName = new QName("xslt", XMLConstants.OXF_PROCESSORS_NAMESPACE);

        // Get a factory for this processor
        final ProcessorFactory processorFactory = ProcessorFactoryRegistry.lookup(processorName);

        if (processorFactory == null)
            throw new OXFException("Cannot find processor factory with name '"
                    + processorName.getNamespacePrefix() + ":" + processorName.getName() + "'");

        // Create processor
        final Processor processor = processorFactory.createInstance();

        // Connect inputs (one from URL, the other one from a DOM)
        final URLGenerator urlGeneratorConfig = new URLGenerator("oxf:/apps/java-api/transform.xsl");
        PipelineUtils.connect(urlGeneratorConfig, "data", processor, "config");

        final Document dataInputDocument = readInputAsDOM4J(pipelineContext, "myinput");
        final DOMGenerator domGeneratorData = PipelineUtils.createDOMGenerator(dataInputDocument, "data input", DOMGenerator.ZeroValidity, DOMGenerator.DefaultContext);
        PipelineUtils.connect(domGeneratorData, "data", processor, "data");

        // Connect outputs
        final DOMSerializer domSerializerData = new DOMSerializer();
        PipelineUtils.connect(processor, "data", domSerializerData, "data");

        // Execute processor by running serializer
        final PipelineContext newPipelineContext = new PipelineContext(); // here we decide to use our own PipelineContext
        domSerializerData.start(newPipelineContext);

        // Get result as a dom4j Document
        final Document result = domSerializerData.getDocument(newPipelineContext); // must use same PipelineContext as start()

        // Serialize result to output
        TransformerUtils.writeDom4j(result, contentHandler);
    }
}

Orbeon Forms 3.7.0beta1.200808261006