Example usage for javax.xml.transform.dom DOMResult DOMResult

List of usage examples for javax.xml.transform.dom DOMResult DOMResult

Introduction

In this page you can find the example usage for javax.xml.transform.dom DOMResult DOMResult.

Prototype

public DOMResult() 

Source Link

Document

Zero-argument default constructor.

Usage

From source file:org.f2o.absurdum.puck.gui.PuckFrame.java

private void openSource(StreamSource s) throws TransformerException {
    Transformer t = TransformerFactory.newInstance().newTransformer();
    DOMResult r = new DOMResult();
    t.transform(s, r);//  w w w .  jav  a 2s . com
    GraphElementPanel.emptyQueue();
    graphPanel.clear();
    propPanel.clear();
    JSyntaxBSHCodeFrame.closeAllInstances();
    WorldPanel wp = new WorldPanel(graphPanel);
    WorldNode wn = new WorldNode(wp);
    graphPanel.setWorldNode(wn);
    wp.initFromXML(((Document) r.getNode()).getFirstChild());
    //revalidate(); //only since java 1.7
    //invalidate();
    //validate();
    split.revalidate(); //JComponents do have it before java 1.7 (not JFrame)
}

From source file:org.finra.jtaf.ewd.impl.DefaultExtWebDriver.java

@Override
public String evaluateXpath(String xpath) throws Exception {
    XPathFactory xpathFac = XPathFactory.newInstance();
    XPath theXpath = xpathFac.newXPath();

    String html = getHtmlSource();
    html = html.replaceAll(">\\s+<", "><");
    InputStream input = new ByteArrayInputStream(html.getBytes());

    XMLReader reader = new Parser();
    reader.setFeature(Parser.namespacesFeature, false);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();

    DOMResult result = new DOMResult();
    transformer.transform(new SAXSource(reader, new InputSource(input)), result);

    Node htmlNode = result.getNode(); // This code gets a Node from the
    // result./*ww w  .j a  v  a  2s .  co  m*/
    return (String) theXpath.evaluate(xpath, htmlNode, XPathConstants.STRING);
}

From source file:org.finra.jtaf.ewd.widget.element.Element.java

/**
 * Get the list of nodes which satisfy the xpath expression passed in
 * /*from  w  ww  .j  ava2s  . c o  m*/
 * @param xpath
 *            the input xpath expression
 * @return the nodeset of matching elements
 * @throws Exception
 */
private NodeList getNodeListUsingJavaXPath(String xpath) throws Exception {
    XPathFactory xpathFac = XPathFactory.newInstance();
    XPath theXpath = xpathFac.newXPath();

    String html = getGUIDriver().getHtmlSource();
    html = html.replaceAll(">\\s+<", "><");
    InputStream input = new ByteArrayInputStream(html.getBytes());

    XMLReader reader = new Parser();
    reader.setFeature(Parser.namespacesFeature, false);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();

    DOMResult result = new DOMResult();
    transformer.transform(new SAXSource(reader, new InputSource(input)), result);

    Node htmlNode = result.getNode(); // This code gets a Node from the
    // result.
    NodeList nodes = (NodeList) theXpath.evaluate(xpath, htmlNode, XPathConstants.NODESET);

    return nodes;
}

From source file:org.fireflow.pdl.fpdl.test.service.callback.TheCallbackServiceProcessTest1.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireflowRuntimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??/*from   w  w w .  ja  va2s .c om*/
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {
                ProcessDescriptor descriptor = stmt.uploadProcessObject(process, 0);
                ((ProcessDescriptorImpl) descriptor).setPublishState(true);
                stmt.updateProcessDescriptor(descriptor);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    //TODO WorkflowServer?webservice

    /*
    WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    try {
       callbackManager.publishAllCallbackServices();
    } catch (WebservicePublishException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
    }
    */

    //3???      
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //??
            try {

                ProcessInstance processInstance = stmt.startProcess(process.getId(), bizId, null);

                if (processInstance != null) {
                    processInstanceId = processInstance.getId();
                }

            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (WorkflowProcessNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvalidOperationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //JaxwsWebservice      
    Environment env = fireflowRuntimeContext.getEngineModule(Environment.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;
        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"http://www.fireflow.org/junit/callbackservice\">"
            + "<cal:id>" + bizId + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");

    Assert.assertEquals(responseResult, response2);

    this.assertResult(session);
}

From source file:org.fireflow.pdl.fpdl.test.service.callback.WebserviceStartProcessTest.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(fireflowRuntimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??/*from  w  ww  .java2  s  .c om*/
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {

                ProcessDescriptor descriptor = stmt.uploadProcessObject(process, 0);
                ((ProcessDescriptorImpl) descriptor).setPublishState(true);
                stmt.updateProcessDescriptor(descriptor);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    //TODO WorkflowServer?webservice

    //      WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    //      try {
    //         callbackManager.publishAllCallbackServices();
    //      } catch (WebservicePublishException e1) {
    //         // TODO Auto-generated catch block
    //         e1.printStackTrace();
    //      }

    //JaxwsWebservice      
    Environment env = fireflowRuntimeContext.getEngineModule(Environment.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;

        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"" + targetNsUri + "\">" + "<cal:id>" + bizId
            + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");
    String response1 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response1");
    Assert.assertEquals(responseResult, response2);

    Assert.assertNotNull(response1);

    this.processInstanceId = response1;

    this.assertResult(session);
}

From source file:org.fireflow.pdl.fpdl20.test.service.callback.TheCallbackServiceProcessTest1.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(runtimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??/*from  ww  w .  j a  v a 2s.c  o  m*/
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {

                stmt.uploadProcessObject(process, true, null, null);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    try {
        callbackManager.publishAllCallbackServices();
    } catch (WebservicePublishException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    //3???      
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //??
            try {

                ProcessInstance processInstance = stmt.startProcess(process.getId(), bizId, null);

                if (processInstance != null) {
                    processInstanceId = processInstance.getId();
                }

            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (WorkflowProcessNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvalidOperationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //JaxwsWebservice      
    Environment env = runtimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;
        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"http://www.fireflow.org/junit/callbackservice\">"
            + "<cal:id>" + bizId + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");

    Assert.assertEquals(responseResult, response2);

    this.assertResult(session);
}

From source file:org.fireflow.pdl.fpdl20.test.service.callback.WebserviceStartProcessTest.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(runtimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??/*from w w w.  j a  v  a 2 s.c  om*/
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {

                stmt.uploadProcessObject(process, true, null, null);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    try {
        callbackManager.publishAllCallbackServices();
    } catch (WebservicePublishException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    //JaxwsWebservice      
    Environment env = runtimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;

        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"" + targetNsUri + "\">" + "<cal:id>" + bizId
            + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");
    String response1 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response1");
    Assert.assertEquals(responseResult, response2);

    Assert.assertNotNull(response1);

    this.processInstanceId = response1;

    this.assertResult(session);
}

From source file:org.fireflow.service.callback.ProcessServiceProvider.java

public Source invoke(Source request) {
    Expression correlation = callbackService.getCorrelation();

    final QName responseRootElementQName = new QName(callbackService.getTargetNamespaceUri(),
            this.serviceBinding.getOperationName() + "Response");

    //??/*ww w .  j  a v a 2 s.c om*/
    /*
    try{
       Transformer transformer = transformerFactory.newTransformer();
       transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
       transformer.setOutputProperty(
       "{http://xml.apache.org/xslt}indent-amount", "2");
       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
       // transformer.transform()  XML Source? Result
       transformer.transform(request, new StreamResult(
       outputStream));
       System.out.println( outputStream.toString());
    }catch(Exception e){
       e.printStackTrace();
    }
    */

    final Document requestDOM;
    try {
        Transformer transformer = transformerFactory.newTransformer();
        DOMResult domResult = new DOMResult();
        transformer.transform(request, domResult);
        requestDOM = (Document) domResult.getNode();//reuqestDOM   
    } catch (TransformerException e) {
        throw new WebServiceException("Can NOT transform request to DOM.", e);
    }

    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(workflowRuntimeContext,
            FireWorkflowSystem.getInstance());
    if (!startNewProcess) {//?
        if (correlation == null || StringUtils.isEmpty(correlation.getBody())) {
            throw new WebServiceException(
                    "The correlation can NOT be empty; the callbackservice is " + callbackService.getName());
        }
        //1?serviceIdservice versioncandidate activityInstance
        WorkflowQuery<ActivityInstance> query = session.createWorkflowQuery(ActivityInstance.class);
        List<ActivityInstance> candidates = query
                .add(Restrictions.eq(ActivityInstanceProperty.SERVICE_ID, callbackService.getId()))
                .add(Restrictions.eq(ActivityInstanceProperty.SERVICE_VERSION, callbackService.getVersion()))
                .add(Restrictions.eq(ActivityInstanceProperty.STATE, ActivityInstanceState.RUNNING)).list();

        //2??correlation
        //correlationbool?processVars.var1==xpath(requestDom,'method1Request/id')
        ProcessInstance theProcessInstance = null;
        ActivityInstance theActivityInstance = null;
        if (candidates != null && candidates.size() > 0) {
            for (ActivityInstance activityInstance : candidates) {
                ProcessInstance processInstance = activityInstance.getProcessInstance(session);
                ((WorkflowSessionLocalImpl) session).setCurrentProcessInstance(processInstance);
                ((WorkflowSessionLocalImpl) session).setCurrentActivityInstance(activityInstance);

                Map<String, Object> varContext = ScriptEngineHelper.fulfillScriptContext(session,
                        workflowRuntimeContext, processInstance, activityInstance);
                varContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

                Object result = ScriptEngineHelper.evaluateExpression(workflowRuntimeContext, correlation,
                        varContext);
                if (result != null && (result instanceof Boolean)) {
                    if ((Boolean) result) {
                        theActivityInstance = activityInstance;
                        theProcessInstance = processInstance;
                        break;
                    }
                }

            }
        }

        final ActivityInstance theMatchedActivityInstance = theActivityInstance;//?activityInstance
        final ProcessInstance theMatchedProcessInstance = theProcessInstance;

        if (theMatchedActivityInstance != null) {

            //1?currentProcessInstanceCurrentActivityInstance
            ((WorkflowSessionLocalImpl) session).setCurrentActivityInstance(theMatchedActivityInstance);
            ((WorkflowSessionLocalImpl) session).setCurrentProcessInstance(theMatchedProcessInstance);

            try {
                this.transactionTemplate.execute(new TransactionCallback() {
                    public Object doInTransaction(TransactionStatus status) {
                        //2????
                        List<Assignment> inputAssignments_ = serviceBinding.getInputAssignments();
                        Map<String, Object> scriptContext = new HashMap<String, Object>();
                        scriptContext.put(ScriptContextVariableNames.INPUTS, requestDOM);
                        try {
                            ScriptEngineHelper.assignOutputToVariable(session, workflowRuntimeContext,
                                    theMatchedProcessInstance, theMatchedActivityInstance, inputAssignments_,
                                    scriptContext);
                        } catch (ScriptException e) {
                            throw new RuntimeException(
                                    "Can NOT assign inputs to process instance varialbes,the callback service is  "
                                            + callbackService.getName(),
                                    e);
                        }

                        //3?closeActivity?   
                        ActivityInstanceManager actInstMgr = workflowRuntimeContext.getEngineModule(
                                ActivityInstanceManager.class, theMatchedProcessInstance.getProcessType());
                        actInstMgr.onServiceCompleted(session, theMatchedActivityInstance);

                        return null;
                    }

                });
            } catch (TransactionException e) {
                throw new WebServiceException(e);
            }
            //4?
            try {
                Map<String, Object> allTheVars = ScriptEngineHelper.fulfillScriptContext(session,
                        workflowRuntimeContext, theMatchedProcessInstance, theMatchedActivityInstance);
                List<Assignment> outputAssignments = serviceBinding.getOutputAssignments();
                Document doc = DOMInitializer.generateDocument(callbackService.getXmlSchemaCollection(),
                        responseRootElementQName);
                allTheVars.put(ScriptContextVariableNames.OUTPUTS, doc);
                Map<String, Object> tmp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                        outputAssignments, allTheVars);
                Document resultDOM = (Document) tmp.get(ScriptContextVariableNames.OUTPUTS);

                return new DOMSource(resultDOM);
            } catch (ScriptException e) {
                throw new WebServiceException(
                        "Can NOT assign process instance varialbes to output,the callback service is  "
                                + callbackService.getName(),
                        e);
            } catch (ParserConfigurationException e) {
                throw new WebServiceException(
                        "Can NOT init output DOM,the callback service is  " + callbackService.getName(), e);
            }
        } else {
            throw new WebServiceException(
                    "Process instance NOT found for the conditions as follows,service id='"
                            + callbackService.getId() + "' and service version='" + callbackService.getVersion()
                            + "' and correlation='" + correlation.getBody() + "'");
        }
    }

    else {//??

        //1????bizId
        final Map<String, Object> processVars;
        final String bizId;
        try {
            List<Assignment> inputAssignments_ = serviceBinding.getInputAssignments();
            Map<String, Object> scriptContext = new HashMap<String, Object>();
            scriptContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

            Map<String, Object> temp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                    inputAssignments_, scriptContext);
            processVars = (Map<String, Object>) temp.get(ScriptContextVariableNames.PROCESS_VARIABLES);

            Map<String, Object> varContext = new HashMap<String, Object>();
            varContext.put(ScriptContextVariableNames.INPUTS, requestDOM);

            Object result = ScriptEngineHelper.evaluateExpression(workflowRuntimeContext, correlation,
                    varContext);
            bizId = result == null ? null : result.toString();
        } catch (ScriptException e) {
            throw new WebServiceException(
                    "Can NOT assign inputs to process instance varialbes,the callback service is  "
                            + callbackService.getName(),
                    e);
        }

        //2???
        ProcessInstance processInstance = null;
        try {
            processInstance = (ProcessInstance) transactionTemplate.execute(new TransactionCallback() {
                public Object doInTransaction(TransactionStatus status) {
                    WorkflowStatement stmt = session.createWorkflowStatement(processType);

                    ProcessInstance procInst = null;
                    try {
                        procInst = stmt.startProcess(processId, bizId, processVars);
                    } catch (InvalidModelException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);
                    } catch (WorkflowProcessNotFoundException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);

                    } catch (InvalidOperationException e1) {
                        throw new RuntimeException("Start process instance error! The callback service is "
                                + callbackService.getName() + "; the process is " + processId, e1);

                    }
                    return procInst;
                }

            });
        } catch (TransactionException e) {
            throw new WebServiceException(e);
        }

        //3?
        try {
            Map<String, Object> allTheVars = ScriptEngineHelper.fulfillScriptContext(session,
                    workflowRuntimeContext, processInstance, null);
            List<Assignment> outputAssignments = serviceBinding.getOutputAssignments();
            //  ?DOM
            Document doc = DOMInitializer.generateDocument(callbackService.getXmlSchemaCollection(),
                    responseRootElementQName);
            allTheVars.put(ScriptContextVariableNames.OUTPUTS, doc);
            Map<String, Object> tmp = ScriptEngineHelper.resolveAssignments(workflowRuntimeContext,
                    outputAssignments, allTheVars);
            Document resultDOM = (Document) tmp.get(ScriptContextVariableNames.OUTPUTS);

            return new DOMSource(resultDOM);
        } catch (ScriptException e) {
            throw new WebServiceException(
                    "Can NOT assign process instance varialbes to output,the callback service is  "
                            + callbackService.getName(),
                    e);
        } catch (ParserConfigurationException e) {
            throw new WebServiceException(
                    "Can NOT init output DOM,the callback service is  " + callbackService.getName(), e);
        }

    }

}

From source file:org.geoserver.wfs.xslt.config.TransformRepositoryTest.java

@Test
public void testTransform() throws Exception {
    TransformInfo info = new TransformInfo();
    info.setName("test");
    info.setSourceFormat("application/xml");
    info.setOutputFormat("text/plain");
    info.setFileExtension("txt");
    info.setXslt("test-tx.xslt");

    repo.putTransformInfo(info);/*from   w  ww .j av a2 s.  com*/
    repo.putTransformSheet(info, getClass().getResourceAsStream("test.xslt"));

    Transformer transformer = repo.getTransformer(info);
    InputStream is = getClass().getResourceAsStream("sample.xml");
    StreamSource source = new StreamSource(is);
    DOMResult result = new DOMResult();
    transformer.transform(source, result);
    Document dom = (Document) result.getNode();
    XMLAssert.assertXpathEvaluatesTo("12", "count(/html/body/table/tr/td)", dom);
    XMLAssert.assertXpathEvaluatesTo("1", "count(/html/body/table/tr[td='museum'])", dom);
    XMLAssert.assertXpathEvaluatesTo("1", "count(/html/body/table/tr[td='-74.0104611,40.70758763'])", dom);
}

From source file:org.ikasan.filetransfer.xml.transform.DefaultXSLTransformer.java

/**
 * Performs the transformation to the output result as Document.
 *
 * @param in - the XML document as <code>Source</code>.
 * @return String//from   ww  w  . j  a va2s .c  om
 * @throws TransformerException 
 * @throws IOException 
 */
public Document transformToDocument(Source in) throws TransformerException, IOException {
    // Create a Writer instance to hold transformation result
    DOMResult out = new DOMResult();

    // Transformation
    this.transform(in, out);

    // Here is the newly transformed document
    return (Document) out.getNode();
}