List of usage examples for org.jdom2 Namespace getPrefix
public String getPrefix()
Namespace
. From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
private void setNamespaceIfUndefined(Namespace namespace) { if (!nsMap.containsKey(namespace.getPrefix())) { nsMap.put(namespace.getPrefix(), namespace); }/*from ww w . j a v a 2 s . c om*/ }
From source file:org.openconcerto.xml.JDOM2Utils.java
License:Open Source License
/** * Analyse la chaine passe et retourne la liste correspondante. * /*from ww w .jav a2 s . c o m*/ * @param xml une chaine contenant de l'XML. * @param namespaces les namespaces utiliss dans la chaine. * @return la liste correspondant la chaine passe. * @throws JDOMException si l'xml n'est pas bien form. */ public static List<Content> parseString(String xml, Namespace[] namespaces) throws JDOMException { // construit le dummy pour dclarer les namespaces String dummy = "<dummy"; for (int i = 0; i < namespaces.length; i++) { Namespace ns = namespaces[i]; dummy += " xmlns:" + ns.getPrefix() + "=\"" + ns.getURI() + "\""; } xml = dummy + ">" + xml + "</dummy>"; return parseStringDocument(xml).getRootElement().removeContent(); }
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 a2 s . c o m 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.xflatdb.xflat.convert.converters.JAXBPojoConverter.java
License:Apache License
private XPathExpression<Object> makeIdSelector(Class<?> clazz) { IdAccessor accessor = IdAccessor.forClass(clazz); if (!accessor.hasId()) { return null; }/* w w w . j a va2 s. c om*/ Namespace ns = null; StringBuilder ret = new StringBuilder(clazz.getSimpleName()); XmlAttribute attribute = (XmlAttribute) accessor.getIdPropertyAnnotation(XmlAttribute.class); if (attribute != null) { ret.append("/@"); if (attribute.namespace() != null) { ns = Namespace.getNamespace("id", attribute.namespace()); ret.append(ns.getPrefix()).append(":"); } if (attribute.name() != null) { ret.append(attribute.name()); } else { ret.append(accessor.getIdPropertyName()); } } else { ret.append("/"); XmlElement element = (XmlElement) accessor.getIdPropertyAnnotation(XmlElement.class); if (element != null) { if (element.namespace() != null) { ns = Namespace.getNamespace("id", attribute.namespace()); ret.append(ns.getPrefix()).append(":"); } if (element.name() != null) { ret.append(element.name()); } else { ret.append(accessor.getIdPropertyName()); } } else { ret.append(accessor.getIdPropertyName()); } } if (ns == null) { return XPathFactory.instance().compile(ret.toString()); } return XPathFactory.instance().compile(ret.toString(), Filters.fpassthrough(), null, ns); }
From source file:org.yawlfoundation.yawl.resourcing.jsf.dynform.DynFormFieldAssembler.java
License:Open Source License
private String getElementDataType(Element eField, Namespace ns) { String type = eField.getAttributeValue("type"); if (type == null && eField.getChildren().isEmpty()) { type = ns.getPrefix() + ":string"; // default type for element }//www . j av a 2s.com return type; }
From source file:org.yawlfoundation.yawl.resourcing.util.DataSchemaBuilder.java
License:Open Source License
/** * Gets an attribute value, fixing its namespace prefix (if any) * @param attribute the attribute to get the value for * @param prefix the correct namespace prefix * @param defNS the default namespace/*from w ww. j a v a 2 s .co m*/ * @return the attribute's value with the prefix corrected if required */ private String getAttributeValue(Attribute attribute, String prefix, Namespace defNS) { String value = attribute.getValue(); if (prefix.length() > 0) { value = value.replaceFirst(prefix, defNS.getPrefix()); } return value; }
From source file:org.yawlfoundation.yawl.resourcing.util.DataSchemaBuilder.java
License:Open Source License
/** * Attaches a prefix to a type name/*from w ww . j av a 2s . c o m*/ * @param type the type name * @param ns the namespace * @return the type name prefixed with the namespace's prefix */ private String prefix(String type, Namespace ns) { return String.format("%s:%s", ns.getPrefix(), type); }
From source file:org.yawlfoundation.yawl.scheduling.PlanningGraphCreator.java
License:Open Source License
@SuppressWarnings("unchecked") /**/* ww w. j a v a 2 s . 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; }