Search in sources :

Example 1 with PipelineDefinition

use of org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition in project webtools.sourceediting by eclipse.

the class LaunchHelper method save.

public void save(File file) throws CoreException {
    BufferedWriter writer = null;
    try {
        // ensure it exists
        file.createNewFile();
        writer = new BufferedWriter(new FileWriter(file));
        PipelineDefinition pdef = new PipelineDefinition();
        for (Iterator<?> iter = attributes.getAttributes().iterator(); iter.hasNext(); ) {
            LaunchAttribute att = (LaunchAttribute) iter.next();
            pdef.addAttribute(new TypedValue(att.uri, TypedValue.TYPE_STRING, att.value));
        }
        for (Iterator<?> iter = pipeline.getTransformDefs().iterator(); iter.hasNext(); ) {
            LaunchTransform lt = (LaunchTransform) iter.next();
            TransformDefinition tdef = new TransformDefinition();
            URL url = pathToURL(lt.getLocation());
            tdef.setStylesheetURL(url.toExternalForm());
            tdef.setResolverClass(lt.getResolver());
            for (Iterator<?> iterator = lt.getParameters().iterator(); iterator.hasNext(); ) {
                LaunchAttribute att = (LaunchAttribute) iterator.next();
                tdef.addParameter(new TypedValue(att.uri, TypedValue.TYPE_STRING, att.getResolvedValue()));
            }
            // set the output props for the LAST transform only
            if (!iter.hasNext()) {
                for (Map.Entry<String, String> entry : outputProperties.getProperties().entrySet()) {
                    String name = entry.getKey();
                    String value = entry.getValue();
                    if (name != null && value != null)
                        tdef.setOutputProperty(name, value);
                }
            }
            pdef.addTransformDef(tdef);
        }
        Document doc = pdef.toXML();
        String s = PreferenceUtil.serializeDocument(doc);
        writer.write(s);
    } catch (FileNotFoundException e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, Messages.LaunchHelper_0, e));
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, Messages.LaunchHelper_1, e));
    } catch (ParserConfigurationException e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, "ParserConfigurationException", // $NON-NLS-1$
        e));
    } catch (TransformerException e) {
        throw new CoreException(new Status(IStatus.ERROR, JAXPLaunchingPlugin.PLUGIN_ID, IStatus.ERROR, "TransformerException", // $NON-NLS-1$
        e));
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                JAXPLaunchingPlugin.log(e);
            }
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TransformDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) PipelineDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition) IOException(java.io.IOException) Document(org.w3c.dom.Document) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute) URL(java.net.URL) BufferedWriter(java.io.BufferedWriter) CoreException(org.eclipse.core.runtime.CoreException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Map(java.util.Map) TransformerException(javax.xml.transform.TransformerException) TypedValue(org.eclipse.wst.xsl.jaxp.debug.invoker.TypedValue)

Example 2 with PipelineDefinition

use of org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition in project webtools.sourceediting by eclipse.

the class TestJAXPProcessorInvoker method testSimpleTransform.

@Test
public void testSimpleTransform() throws Exception {
    URL surl = TestJAXPProcessorInvoker.class.getResource("1-input.xml");
    URL xslt = TestJAXPProcessorInvoker.class.getResource("1-transform.xsl");
    PipelineDefinition pipe = new PipelineDefinition();
    TransformDefinition tdef = new TransformDefinition();
    tdef.setStylesheetURL(xslt.toExternalForm());
    pipe.addTransformDef(tdef);
    pipe.configure(invoker);
    InputSource source = new InputSource(surl.openStream());
    DOMResult result = new DOMResult();
    invoker.transform(source, result);
    Document node = (Document) result.getNode();
    assertNotNull("Did not get a result document.", node);
    assertEquals("Missing root-out node name.", "root-out", node.getDocumentElement().getLocalName());
}
Also used : TransformDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition) InputSource(org.xml.sax.InputSource) DOMResult(javax.xml.transform.dom.DOMResult) PipelineDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition) Document(org.w3c.dom.Document) URL(java.net.URL) Test(org.junit.Test)

Example 3 with PipelineDefinition

use of org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition in project webtools.sourceediting by eclipse.

the class DebugRunner method main.

/**
 * Expected arguments:
 *
 * <ol>
 * <li>the class name of the invoker
 * <li>the file name of the XML launch configuration file
 * <li>the URL of the source document
 * <li>the file of the output document
 * <li>not used (anything)
 * <li>the class name of the <code>IXSLDebugger</code> instance
 * <li>the port used for requests
 * <li>the port used for debug events
 * <li>the port used for generate events
 * </ol>
 *
 * @param args
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 */
public static void main(String[] args) throws SAXException, ParserConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    // $NON-NLS-1$//$NON-NLS-2$
    log.info("javax.xml.transform.TransformerFactory=" + System.getProperty("javax.xml.transform.TransformerFactory"));
    // $NON-NLS-1$//$NON-NLS-2$
    log.info("java.endorsed.dirs=" + System.getProperty("java.endorsed.dirs"));
    String invokerClassName = args[0];
    File launchFile = new File(args[1]);
    String src = args[2];
    String target = args[3];
    String debuggerClassName = args[5];
    // $NON-NLS-1$
    log.info("src: " + src);
    // $NON-NLS-1$
    log.info("target: " + target);
    // $NON-NLS-1$
    log.info("launchFile: " + launchFile);
    // $NON-NLS-1$
    log.info("debugger: " + debuggerClassName);
    DebugRunner debugRunner = null;
    try {
        final IXSLDebugger debugger = createDebugger(debuggerClassName);
        // create the invoker
        IProcessorInvoker invoker = new JAXPSAXProcessorInvoker() {

            @Override
            protected TransformerFactory createTransformerFactory() {
                TransformerFactory tFactory = super.createTransformerFactory();
                debugger.setTransformerFactory(tFactory);
                return tFactory;
            }

            @Override
            public void addStylesheet(URL stylesheet, Map parameters, Properties outputProperties, URIResolver resolver) throws TransformerConfigurationException {
                InputSource inputsource = new InputSource(stylesheet.toString());
                // if required in future, parse the document with line
                // numbers (to get the end line numbers)
                // XMLReaderWrapper reader = new
                // XMLReaderWrapper(createReader());
                // SAXSource source = new SAXSource(reader,inputsource);
                addStylesheet(new SAXSource(inputsource), resolver, parameters, outputProperties);
            }

            @Override
            protected Transformer addStylesheet(Source source, URIResolver resolver, Map parameters, Properties outputProperties) throws TransformerConfigurationException {
                Transformer transformer = super.addStylesheet(source, resolver, parameters, outputProperties);
                debugger.addTransformer(transformer);
                return transformer;
            }
        };
        if (args.length == 9) {
            int requestPort = Integer.parseInt(args[6]);
            int eventPort = Integer.parseInt(args[7]);
            int generatePort = Integer.parseInt(args[8]);
            // $NON-NLS-1$
            log.debug("requestPort: " + requestPort);
            // $NON-NLS-1$
            log.debug("eventPort: " + eventPort);
            // $NON-NLS-1$
            log.debug("generatePort: " + generatePort);
            try {
                debugRunner = new DebugRunner(requestPort, eventPort, generatePort);
            } catch (Exception e) {
                handleFatalError("Could not instantiate invoker: " + invokerClassName, // $NON-NLS-1$
                e);
            }
        } else {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            debugRunner = new DebugRunner(br, new PrintWriter(System.out), new PrintWriter(System.err), null);
            // $NON-NLS-1$
            System.out.println("xsl>");
        }
        PipelineDefinition pipeline = new PipelineDefinition(launchFile);
        pipeline.configure(invoker);
        debugger.setInvoker(invoker);
        debugger.setSource(new URL(src));
        debugger.setTarget(new FileWriter(new File(target)));
        debugRunner.loop(debugger);
    } catch (IOException e) {
        handleFatalError(e.getMessage(), e);
    } catch (TransformationException e) {
        handleFatalError(e.getMessage(), e);
    } catch (ConfigurationException e) {
        handleFatalError(e.getMessage(), e);
    } finally {
        if (debugRunner != null) {
            try {
                debugRunner.dispose();
            } catch (IOException e) {
                handleFatalError(e.getMessage(), e);
            }
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) Transformer(javax.xml.transform.Transformer) FileWriter(java.io.FileWriter) URIResolver(javax.xml.transform.URIResolver) Properties(java.util.Properties) URL(java.net.URL) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) IProcessorInvoker(org.eclipse.wst.xsl.jaxp.debug.invoker.IProcessorInvoker) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(org.eclipse.wst.xsl.jaxp.debug.invoker.internal.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) PrintWriter(java.io.PrintWriter) TransformationException(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException) TransformerFactory(javax.xml.transform.TransformerFactory) InputStreamReader(java.io.InputStreamReader) PipelineDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition) IOException(java.io.IOException) TransformationException(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(org.eclipse.wst.xsl.jaxp.debug.invoker.internal.ConfigurationException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) JAXPSAXProcessorInvoker(org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker) SAXSource(javax.xml.transform.sax.SAXSource) BufferedReader(java.io.BufferedReader) File(java.io.File) Map(java.util.Map)

Example 4 with PipelineDefinition

use of org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition in project webtools.sourceediting by eclipse.

the class Main method main.

/**
 * The <code>main</code> method called when launching the transformation process.
 * There are 4 required arguments:
 * <ol>
 * <li>The class name of the <code>IProcessorInvoker</code> to use
 * <li>The launch file (serialized <code>PipelineDefinition</code>)
 * <li>The URL of the source XML document
 * <li>The file where output will be written
 * </ol>
 *
 * @param args the 4 required arguments
 */
public static void main(String[] args) {
    // $NON-NLS-1$ //$NON-NLS-2$
    log.info("javax.xml.transform.TransformerFactory=" + System.getProperty("javax.xml.transform.TransformerFactory"));
    // $NON-NLS-1$ //$NON-NLS-2$
    log.info("java.endorsed.dirs=" + System.getProperty("java.endorsed.dirs"));
    String invokerClassName = args[0];
    File launchFile = new File(args[1]);
    String src = args[2];
    String target = args[3];
    // $NON-NLS-1$
    log.info(Messages.getString("Main.4") + launchFile);
    // create the invoker
    IProcessorInvoker invoker = null;
    try {
        Class clazz = Class.forName(invokerClassName);
        invoker = (IProcessorInvoker) clazz.newInstance();
    } catch (Exception e) {
        // $NON-NLS-1$
        handleFatalError(Messages.getString("Main.5") + invokerClassName, e);
    }
    try {
        PipelineDefinition pipeline = new PipelineDefinition(launchFile);
        pipeline.configure(invoker);
        invoker.transform(new URL(src), new StreamResult(new FileOutputStream(new File(target))));
    } catch (Exception e) {
        handleFatalError(e.getMessage(), e);
    }
}
Also used : IProcessorInvoker(org.eclipse.wst.xsl.jaxp.debug.invoker.IProcessorInvoker) StreamResult(javax.xml.transform.stream.StreamResult) FileOutputStream(java.io.FileOutputStream) PipelineDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition) File(java.io.File) URL(java.net.URL)

Aggregations

URL (java.net.URL)4 PipelineDefinition (org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition)4 File (java.io.File)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 Map (java.util.Map)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 IProcessorInvoker (org.eclipse.wst.xsl.jaxp.debug.invoker.IProcessorInvoker)2 TransformDefinition (org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition)2 Document (org.w3c.dom.Document)2 InputSource (org.xml.sax.InputSource)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Properties (java.util.Properties)1 Source (javax.xml.transform.Source)1 Transformer (javax.xml.transform.Transformer)1