*/
public static List parseProcessDefinitions(InputSource toParse)
throws ImportException {
List resultList = new ArrayList();
List processDefs = new ArrayList();
CollectingErrorHandler eh = new CollectingErrorHandler();
Document doc = null;
try {
SAXParserFactory spf = SAXParserFactory.newInstance ();
spf.setValidating (true);
spf.setNamespaceAware (true);
maybeSetFeature
(spf, "http://xml.org/sax/features/namespace-prefixes", eh);
SAXParser sp = spf.newSAXParser();
maybeSetProperty
(sp, "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema", eh);
maybeSetProperty
(sp, "http://java.sun.com/xml/jaxp/properties/schemaSource",
schemaUris(), eh);
SAXHandler sh = new SAXHandler ();
XMLFilter filter = new XmlnsUrisPatcher ();
filter.setParent(sp.getXMLReader());
filter.setContentHandler(sh);
filter.setDTDHandler(sh);
filter.setEntityResolver(sh);
filter.setErrorHandler(eh);
// build Document
filter.parse(toParse);
doc = sh.getDocument();
Element root = doc.getRootElement();
if (root == null || !root.getName().equals ("Package")
|| !root.getNamespaceURI().equals (XPDLUtil.XPDL_NS)) {
eh.add (new PrioritizedMessage
(PrioritizedMessage.Priority.ERROR,
"ImportMessages#package.missing"));
} else if (eh.getErrors().size() == 0
&& eh.getFatalErrors().size() == 0) {
ProcDefValidator procDefValidator = new ProcDefValidator();
procDefValidator.validate(doc, eh);
processDefs = AbstractProcessDefinitionDirectory
.getProcessDefinitionsFromXPDL(doc);
}
} catch (JDOMException e) {
eh.add (new PrioritizedMessage (PrioritizedMessage.Priority.ERROR,
e.getMessage()));
} catch (IOException e) {
eh.add (new PrioritizedMessage (PrioritizedMessage.Priority.ERROR,
e.getMessage()));
} catch (IllegalArgumentException e) {
eh.add (new PrioritizedMessage (PrioritizedMessage.Priority.ERROR,
e.getMessage()));
} catch (JaxenException e) {
DefaultProcessDefinition.logger.error (e.getMessage(), e);
throw new IllegalArgumentException
("Cannot traverse XPDL-JDOM: " + e.getMessage());
} catch (SAXException e) {
eh.add (new PrioritizedMessage (PrioritizedMessage.Priority.ERROR,
e.getMessage()));
} catch (ParserConfigurationException e) {
eh.add (new PrioritizedMessage (PrioritizedMessage.Priority.ERROR,
e.getMessage()));
}
List pms = eh.getMessages();
if (eh.getErrors().size() > 0 || eh.getFatalErrors().size() > 0) {
throw new ImportException
("There have been problems while parsing XPDL", pms);
}
// the first element of the result list is list of prioritized messages
resultList.add(pms);