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;
}
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;
}
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();
}
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);
}
Aggregations