use of org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl in project kie-wb-common by kiegroup.
the class BPMFinderServiceImpl method parse.
protected Optional<Definitions> parse(FileUtils.ScanResult process) {
org.uberfire.java.nio.file.Path formPath = process.getFile();
try {
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new DroolsResourceFactoryImpl());
resourceSet.getPackageRegistry().put(DroolsPackage.eNS_URI, DroolsPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new Bpmn2ResourceFactoryImpl());
resourceSet.getPackageRegistry().put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.setEncoding("UTF-8");
Map<String, Object> options = new HashMap<String, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.load(ioService.newInputStream(formPath), options);
DocumentRoot root = (DocumentRoot) outResource.getContents().get(0);
return Optional.of(root.getDefinitions());
} catch (Exception ex) {
logger.warn("Error reading process '" + process.getFile().getFileName(), ex);
}
return Optional.empty();
}
use of org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl in project kie-wb-common by kiegroup.
the class DefaultProfileImpl method getDefinitions.
private Definitions getDefinitions(String xml) {
try {
DroolsFactoryImpl.init();
BpsimFactoryImpl.init();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new Bpmn2ResourceFactoryImpl());
resourceSet.getPackageRegistry().put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
Resource resource = resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
resource.load(is, Collections.EMPTY_MAP);
resource.load(Collections.EMPTY_MAP);
return ((DocumentRoot) resource.getContents().get(0)).getDefinitions();
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
Aggregations