Search in sources :

Example 1 with ConfigurationException

use of org.eclipse.wst.xsl.jaxp.debug.invoker.internal.ConfigurationException 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 2 with ConfigurationException

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

the class PipelineDefinition method configure.

/**
 * Configure the invoker from this.
 *
 * @param invoker
 *            the invoker to configure
 * @throws ConfigurationException
 *             if an exception occurs during configuration
 */
public void configure(IProcessorInvoker invoker) throws ConfigurationException {
    Map<String, Object> attVals = new ConcurrentHashMap<String, Object>();
    for (Iterator<TypedValue> iter = attributes.iterator(); iter.hasNext(); ) {
        TypedValue att = iter.next();
        Object value;
        try {
            value = att.createValue();
        } catch (CreationException e) {
            throw new ConfigurationException(e.getMessage(), e);
        }
        attVals.put(att.name, value);
    }
    invoker.setAttributes(attVals);
    for (Iterator<TransformDefinition> iter = transformDefs.iterator(); iter.hasNext(); ) {
        TransformDefinition tdef = iter.next();
        Map<String, Object> params = setParams(tdef);
        URL url = getStyleSheetURL(tdef);
        Properties properties = tdef.getOutputProperties();
        URIResolver resolver = getResolver(tdef);
        addStyleSheet(invoker, tdef, params, url, properties, resolver);
    }
}
Also used : URIResolver(javax.xml.transform.URIResolver) CreationException(org.eclipse.wst.xsl.jaxp.debug.invoker.internal.CreationException) Properties(java.util.Properties) URL(java.net.URL) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(org.eclipse.wst.xsl.jaxp.debug.invoker.internal.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with ConfigurationException

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

the class PipelineDefinition method getResolver.

private URIResolver getResolver(TransformDefinition tdef) throws ConfigurationException {
    URIResolver resolver = null;
    if (tdef.getResolverClass() != null) {
        try {
            Class resolverClass = Class.forName(tdef.getResolverClass());
            resolver = (URIResolver) resolverClass.newInstance();
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
            throw new ConfigurationException(Messages.getString("PipelineDefinition.10") + tdef.getResolverClass(), // $NON-NLS-1$
            null);
        } catch (ClassNotFoundException e) {
        }
    }
    return resolver;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(org.eclipse.wst.xsl.jaxp.debug.invoker.internal.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) URIResolver(javax.xml.transform.URIResolver)

Aggregations

ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 URIResolver (javax.xml.transform.URIResolver)3 ConfigurationException (org.eclipse.wst.xsl.jaxp.debug.invoker.internal.ConfigurationException)3 URL (java.net.URL)2 Properties (java.util.Properties)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Source (javax.xml.transform.Source)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 SAXSource (javax.xml.transform.sax.SAXSource)1 IProcessorInvoker (org.eclipse.wst.xsl.jaxp.debug.invoker.IProcessorInvoker)1 PipelineDefinition (org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition)1