Search in sources :

Example 1 with TransformDefinition

use of org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition 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 TransformDefinition

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

the class PipelineDefintionTest method setupTransformDefinition.

private TransformDefinition setupTransformDefinition() {
    TransformDefinition tdef = new TransformDefinition();
    pldef.addTransformDef(tdef);
    return tdef;
}
Also used : TransformDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition)

Example 3 with TransformDefinition

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

the class PipelineDefintionTest method testRemoveTransformDefintion.

@Test
public void testRemoveTransformDefintion() throws Exception {
    TransformDefinition tdef = setupTransformDefinition();
    assertEquals(1, pldef.getTransformDefs().size());
    pldef.removeTransformDef(tdef);
    assertEquals(0, pldef.getTransformDefs().size());
}
Also used : TransformDefinition(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition) Test(org.junit.Test)

Example 4 with TransformDefinition

use of org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition 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)

Aggregations

TransformDefinition (org.eclipse.wst.xsl.jaxp.debug.invoker.TransformDefinition)4 URL (java.net.URL)2 PipelineDefinition (org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition)2 Test (org.junit.Test)2 Document (org.w3c.dom.Document)2 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 DOMResult (javax.xml.transform.dom.DOMResult)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 TypedValue (org.eclipse.wst.xsl.jaxp.debug.invoker.TypedValue)1 LaunchAttribute (org.eclipse.wst.xsl.launching.config.LaunchAttribute)1 LaunchTransform (org.eclipse.wst.xsl.launching.config.LaunchTransform)1 InputSource (org.xml.sax.InputSource)1