Search in sources :

Example 1 with ProcessActionRootNode

use of com.axelor.apps.baml.xml.ProcessActionRootNode in project axelor-open-suite by axelor.

the class BamlParser method createEmptyBamlXml.

public static String createEmptyBamlXml() {
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(ProcessActionRootNode.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        ProcessActionRootNode rootNode = new ProcessActionRootNode();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.marshal(rootNode, byteArrayOutputStream);
        return byteArrayOutputStream.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) ProcessActionRootNode(com.axelor.apps.baml.xml.ProcessActionRootNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with ProcessActionRootNode

use of com.axelor.apps.baml.xml.ProcessActionRootNode in project axelor-open-suite by axelor.

the class BamlParser method parse.

public static ProcessActionRootNode parse(InputStream xml) {
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(ProcessActionRootNode.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(Resources.getResource("xsd/baml.xsd"));
        unmarshaller.setSchema(schema);
        return (ProcessActionRootNode) unmarshaller.unmarshal(xml);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) JAXBContext(javax.xml.bind.JAXBContext) ProcessActionRootNode(com.axelor.apps.baml.xml.ProcessActionRootNode) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 3 with ProcessActionRootNode

use of com.axelor.apps.baml.xml.ProcessActionRootNode in project axelor-open-suite by axelor.

the class BamlServiceImpl method generateGroovyCode.

@Override
public String generateGroovyCode(String xml) throws AxelorException {
    ProcessActionRootNode rootNode = null;
    rootNode = BamlParser.parse(IOUtils.toInputStream(xml, "utf-8"));
    if (rootNode == null) {
        return null;
    }
    List<ProcessActionNode> processActionNodes = rootNode.getProcessActions();
    StringBuilder codeBuilder = new StringBuilder();
    if (processActionNodes != null) {
        ProcessActionNode processActionNode = processActionNodes.get(0);
        generateCode(codeBuilder, processActionNode);
    }
    return codeBuilder.toString();
}
Also used : ProcessActionNode(com.axelor.apps.baml.xml.ProcessActionNode) ProcessActionRootNode(com.axelor.apps.baml.xml.ProcessActionRootNode)

Example 4 with ProcessActionRootNode

use of com.axelor.apps.baml.xml.ProcessActionRootNode in project axelor-open-suite by axelor.

the class TestBamlParser method test.

public void test() {
    InputStream is = ResourceUtils.getResourceStream("BamlTest.xml");
    ProcessActionRootNode rootNode = BamlParser.parse(is);
    List<ProcessActionNode> processActionNodes = rootNode.getProcessActions();
    String script = "";
    if (processActionNodes != null) {
        script = processActionNodes.get(0).toCode(true);
    }
    Context ctx = new Context(User.class);
    GroovyScriptHelper helper = new GroovyScriptHelper(ctx);
    helper.eval(script);
}
Also used : Context(com.axelor.rpc.Context) InputStream(java.io.InputStream) ProcessActionNode(com.axelor.apps.baml.xml.ProcessActionNode) ProcessActionRootNode(com.axelor.apps.baml.xml.ProcessActionRootNode) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper)

Aggregations

ProcessActionRootNode (com.axelor.apps.baml.xml.ProcessActionRootNode)4 ProcessActionNode (com.axelor.apps.baml.xml.ProcessActionNode)2 JAXBContext (javax.xml.bind.JAXBContext)2 Context (com.axelor.rpc.Context)1 GroovyScriptHelper (com.axelor.script.GroovyScriptHelper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1