Search in sources :

Example 1 with TransformationException

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

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

the class DebugRunner method loop.

/**
 * This method starts the given debugger in its own thread, and blocks while
 * waiting for incoming requests from the request port, until there are no
 * more requests.
 *
 * @param debugger
 *            the debugger to start in a thread
 * @throws TransformationException
 *             if a problem occurred while transforming
 * @throws IOException
 */
public void loop(IXSLDebugger debugger) throws TransformationException, IOException {
    debugger.setEventWriter(eventOut);
    debugger.setGeneratedWriter(generatedStream);
    String inputLine, response;
    // signal we are ready to receive requests
    // $NON-NLS-1$
    eventOut.write("ready\n");
    eventOut.flush();
    // $NON-NLS-1$
    log.debug("entering loop");
    try {
        while ((inputLine = requestIn.readLine()) != null) {
            response = inputLine;
            // $NON-NLS-1$
            log.debug("REQUEST:" + inputLine);
            Thread debuggerThread = null;
            if (DebugConstants.REQUEST_START.equals(inputLine)) {
                // $NON-NLS-1$
                debuggerThread = new Thread(debugger, "debugger");
                debuggerThread.start();
            } else /*
				 * else if (REQUEST_QUIT.equals(inputLine)) { }
				 */
            if (DebugConstants.REQUEST_STEP_INTO.equals(inputLine)) {
                debugger.stepInto();
            } else if (DebugConstants.REQUEST_STEP_OVER.equals(inputLine)) {
                debugger.stepOver();
            } else if (DebugConstants.REQUEST_STEP_RETURN.equals(inputLine)) {
                debugger.stepReturn();
            } else if (DebugConstants.REQUEST_SUSPEND.equals(inputLine)) {
                debugger.suspend();
            } else if (DebugConstants.REQUEST_RESUME.equals(inputLine)) {
                debugger.resume();
            } else if (DebugConstants.REQUEST_STACK.equals(inputLine)) {
                response = debugger.stack();
            } else if (inputLine.startsWith(DebugConstants.REQUEST_VARIABLE)) {
                String data = inputLine.substring(DebugConstants.REQUEST_VARIABLE.length() + 1);
                int id = Integer.parseInt(data);
                Variable var = debugger.getVariable(id);
                // $NON-NLS-1$ //$NON-NLS-2$
                log.debug("var " + id + " = " + var);
                // $NON-NLS-1$
                response = var.getScope() + "&" + var.getName();
            } else if (inputLine.startsWith(DebugConstants.REQUEST_VALUE)) {
                String data = inputLine.substring(DebugConstants.REQUEST_VALUE.length() + 1);
                int id = Integer.parseInt(data);
                Variable var = debugger.getVariable(id);
                // $NON-NLS-1$
                response = var.getType() + "&" + var.getValueFirstLine();
            } else if (inputLine.startsWith(DebugConstants.REQUEST_ADD_BREAKPOINT)) {
                int index = inputLine.lastIndexOf(' ');
                String file = inputLine.substring(DebugConstants.REQUEST_ADD_BREAKPOINT.length() + 1, index);
                String line = inputLine.substring(index + 1);
                BreakPoint breakpoint = new BreakPoint(file, Integer.parseInt(line));
                debugger.addBreakpoint(breakpoint);
            } else if (inputLine.startsWith(DebugConstants.REQUEST_REMOVE_BREAKPOINT)) {
                int index = inputLine.lastIndexOf(' ');
                String file = inputLine.substring(DebugConstants.REQUEST_REMOVE_BREAKPOINT.length() + 1, index);
                String line = inputLine.substring(index + 1);
                BreakPoint breakpoint = new BreakPoint(file, Integer.parseInt(line));
                debugger.removeBreakpoint(breakpoint);
            } else {
                // $NON-NLS-1$
                response = "What?";
            }
            // confirm request
            // $NON-NLS-1$
            log.debug("RESPONSE:" + response);
            // $NON-NLS-1$
            requestOut.write(response + "\n");
            requestOut.flush();
        /*
				 * if (REQUEST_QUIT.equals(inputLine)) {
				 * waitForFinish(debuggerThread); break; }
				 */
        }
    } catch (IOException e) {
        throw new TransformationException(e.getMessage(), e);
    }
    // $NON-NLS-1$
    log.debug("exited loop");
    // $NON-NLS-1$
    eventOut.write("terminated\n");
    eventOut.flush();
}
Also used : TransformationException(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException) IOException(java.io.IOException)

Example 3 with TransformationException

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

the class JAXPSAXProcessorInvoker method transform.

/**
 * Transform using an InputSource rather than a URL
 *
 * @param inputsource the InputSource to use
 * @param res the Result
 * @throws TransformationException if an error occurred during transformation
 */
public void transform(InputSource inputsource, Result res) throws TransformationException {
    try {
        if (th == null) {
            // no stylesheets have been added, so try to use embedded...
            SAXSource saxSource = new SAXSource(inputsource);
            Source src = saxSource;
            String media = null, title = null, charset = null;
            src = tFactory.getAssociatedStylesheet(src, media, title, charset);
            if (src != null) {
                addStylesheet(src, null, Collections.EMPTY_MAP, new Properties());
            } else {
                // $NON-NLS-1$
                throw new TransformationException(Messages.getString("JAXPSAXProcessorInvoker.7") + inputsource.getSystemId());
            }
        }
        th.setResult(res);
        // $NON-NLS-1$
        log.info(Messages.getString("JAXPSAXProcessorInvoker.8"));
        reader.parse(inputsource);
        // $NON-NLS-1$
        log.info(Messages.getString("JAXPSAXProcessorInvoker.9"));
    } catch (Exception e) {
        throw new TransformationException(e.getMessage(), e);
    }
}
Also used : TransformationException(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException) SAXSource(javax.xml.transform.sax.SAXSource) Properties(java.util.Properties) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) TransformerException(javax.xml.transform.TransformerException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) TransformationException(org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

TransformationException (org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Source (javax.xml.transform.Source)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 SAXSource (javax.xml.transform.sax.SAXSource)2 InputSource (org.xml.sax.InputSource)2 SAXException (org.xml.sax.SAXException)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 Map (java.util.Map)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 URIResolver (javax.xml.transform.URIResolver)1