List of usage examples for org.jdom2 Namespace getURI
public String getURI()
Namespace
. From source file:org.rascalmpl.library.lang.xml.DOM.java
License:Open Source License
private IConstructor convertNamespace(Namespace ns) { if (ns == Namespace.NO_NAMESPACE) { return vf.constructor(Factory.Namespace_none); }//from ww w . j a v a2s. c om IString prefix = vf.string(ns.getPrefix()); IString uri = vf.string(ns.getURI()); IConstructor nscon = vf.constructor(Factory.Namespace_namespace, prefix, uri); return nscon; }
From source file:org.yawlfoundation.yawl.scheduling.PlanningGraphCreator.java
License:Open Source License
@SuppressWarnings("unchecked") /**//from w w w. j a va 2s. c o m * TODO@tbe: determine order of activities, store them as utilisation relations and sort * activities according to utilisation relations */ public Collection<Element> getActivityElements(String caseId) throws IOException, JDOMException, JaxenException { Element element = SchedulingService.getInstance().getSpecificationForCase(caseId); Document doc = new Document(element); Map<String, String> map = new HashMap<String, String>(); map.put("bla", element.getNamespace().getURI()); for (Object o : element.getAdditionalNamespaces()) { Namespace ns = (Namespace) o; map.put(ns.getPrefix(), ns.getURI()); } org.jaxen.XPath xp = new JDOMXPath("//bla:expression/@query"); xp.setNamespaceContext(new SimpleNamespaceContext(map)); List<Attribute> list = xp.selectNodes(doc); List<String> activityNames = new ArrayList<String>(); for (Attribute e : list) { String value = e.getValue(); int startIndex = value.indexOf("<" + XML_ACTIVITYNAME + ">"); int endIndex = value.indexOf("</" + XML_ACTIVITYNAME + ">"); while (startIndex >= 0 && endIndex > startIndex) { if (!value.startsWith("<" + XML_EVENT_RECEIVE + ">")) { String activityName = value.substring(startIndex + lenActName, endIndex).trim(); // ignore XPath expressions if (!activityName.contains("/") && !activityNames.contains(activityName)) { activityNames.add(activityName); } } value = value.substring(endIndex + lenActName); startIndex = value.indexOf("<" + XML_ACTIVITYNAME + ">"); endIndex = value.indexOf("</" + XML_ACTIVITYNAME + ">"); } } //TODO@tbe: sort activities, only until order of activities can be determined from process model final List<String> possibleActivities = Utils .parseCSV(PropertyReader.getInstance().getSchedulingProperty("possibleActivitiesSorted")); Collections.sort(activityNames, new Comparator<String>() { public int compare(String a1, String a2) { if (possibleActivities.indexOf(a1) < 0) { return -1; // set missing activities at beginning } else if (possibleActivities.indexOf(a2) < 0) { return 1; // set missing activities at beginning } else { return possibleActivities.indexOf(a1) - possibleActivities.indexOf(a2); } } }); logger.debug("activityNames: " + Utils.toString(activityNames)); Collection<Element> activities = new ArrayList<Element>(); Element preRelation = null; // relation of previous activity for (int i = 0; i < activityNames.size(); i++) { String activityName = activityNames.get(i); if (i > 0) { preRelation.getChild(XML_OTHERACTIVITYNAME).setText(activityName); } Element activity = FormGenerator.getTemplate(XML_ACTIVITY); activities.add(activity); activity.getChild(XML_ACTIVITYNAME).setText(activityName); if (i < activityNames.size() - 1) { preRelation = FormGenerator.getTemplate(XML_UTILISATIONREL); activity.addContent(preRelation); } } return activities; }