List of usage examples for org.jdom2 Element getAttributes
public List<Attribute> getAttributes()
This returns the complete set of attributes for this element, as a List
of Attribute
objects in no particular order, or an empty list if there are none.
From source file:org.yawlfoundation.yawl.resourcing.util.DataSchemaBuilder.java
License:Open Source License
/** * Clones a set of attributes. Needs to be done this way to (i) break the * parental attachment to the attribute; and (ii) to fix any errant namespace * prefixes/* w w w . j ava2s . c o m*/ * @param element the element with the attributes to clone * @param defNS the default namespace * @return the List of clone attributes */ private List<Attribute> cloneAttributes(Element element, Namespace defNS) { String prefix = element.getNamespacePrefix(); List<Attribute> cloned = new ArrayList<Attribute>(); for (Attribute attribute : element.getAttributes()) { String value = getAttributeValue(attribute, prefix, defNS); Attribute copy = new Attribute(attribute.getName(), value); cloned.add(copy); } return cloned; }
From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java
License:Open Source License
/** * merges content of two elements recursively into element minor following * content will be copied: Text, Element, Attribute if conflicts, minor will * be overwrite with content of major/*from w w w.j a v a2 s. c o m*/ * * @param minor * @param major */ public static boolean mergeElements(Element minor, Element major) throws Exception { // logger.debug("minor: " + Utils.element2String(minor, false)); // logger.debug("major: " + Utils.element2String(major, false)); boolean changed = false; if (minor == null) { minor = major; // logger.debug("set minor = " + Utils.element2String(major, false)); changed = true; } else if (major != null) { if (!minor.getText().equals(major.getText())) { minor.setText(major.getText()); // logger.debug("minor.setText("+major.getText()+")"); changed = true; } for (Attribute a : (List<Attribute>) major.getAttributes()) { Attribute aCopy = (Attribute) Utils.deepCopy(a); if (minor.getAttribute(a.getName()) == null || !minor.getAttributeValue(a.getName()).equals(a.getValue())) { minor.setAttribute(aCopy.detach()); // logger.debug("minor.setAttribute("+Utils.toString(a)+")"); changed = true; } } for (Element e : (List<Element>) major.getChildren()) { Element eCopy = (Element) Utils.deepCopy(e); List<Element> minorChildren = minor.getChildren(e.getName()); // logger.debug("minorChildren: " + Utils.toString(minorChildren)); // logger.debug("e: " + Utils.toString(e)); Element firstInList = existInList(minorChildren, e); if (firstInList == null) { // logger.debug("minor.addContent: " + // Utils.toString(eCopy.detach())); minor = minor.addContent(eCopy.detach()); // logger.debug("minor.addContent("+Utils.element2String(e, // false)+")"); changed = true; } else { changed = mergeElements(firstInList, eCopy) || changed; } } } return changed; }
From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java
License:Open Source License
private YDecomposition createDecomposition(Element decompElem) { Namespace schemaInstanceNS = decompElem.getNamespace("xsi"); String xsiType = _decompElem.getAttributeValue("type", schemaInstanceNS); String id = _decompElem.getAttributeValue("id"); String elementName = _decompElem.getName(); if ("NetFactsType".equals(xsiType) || "rootNet".equals(elementName)) { _decomposition = new YNet(id, _specificationParser.getSpecification()); parseNet((YNet) _decomposition, decompElem); } else if ("WebServiceGatewayFactsType".equals(xsiType)) { _decomposition = new YAWLServiceGateway(id, _specificationParser.getSpecification()); parseWebServiceGateway((YAWLServiceGateway) _decomposition, decompElem); }//from www .ja v a2 s.c o m /** * AJH: Added to support XML attribute pass-thru from specification into task output data doclet. * Load element attributes */ for (Attribute attr : decompElem.getAttributes()) { String attname = attr.getName(); boolean isXsiNS = attr.getNamespace() == schemaInstanceNS; //don't add the standard YAWL schema attributes to the pass through list. if (!("id".equals(attname) || ("type".equals(attname) && isXsiNS))) { String value = attr.getValue(); if (value.startsWith("dynamic{")) { _decomposition.setAttribute(attr.getName(), new DynamicValue(value, _decomposition)); } else _decomposition.setAttribute(attr.getName(), value); } } parseDecompositionRoles(_decomposition, decompElem); _decomposition.setLogPredicate(parseLogPredicate(decompElem, _yawlNS)); // added for resourcing parseExternalInteraction(_decomposition, decompElem); parseCodelet(_decomposition, decompElem); return _decomposition; }
From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java
License:Open Source License
/** * Adds variable specific information to the YParameter argument (in & out var). * @param localVariableElem/* w w w. j a v a 2 s .c o m*/ * @param variable */ public static void parseLocalVariable(Element localVariableElem, YVariable variable, Namespace ns, boolean version2) { //parse & set the initial value variable.setInitialValue(JDOMUtil.decodeEscapes(localVariableElem.getChildText("initialValue", ns))); String name; String dataType; String namespace = null; //if version is beta 2 vars are stored in different format if (version2) { name = localVariableElem.getAttributeValue("name"); dataType = localVariableElem.getChildText("type", ns); if (null != dataType) { namespace = dataType.startsWith("xs") ? "http://www.w3.org/2001/XMLSchema" : null; //if data type is of QName form eliminate the first bit as it is useless for //version 2 anyway if (dataType.indexOf(':') != -1) { dataType = dataType.substring(dataType.indexOf(':') + 1); } } if (null == namespace) variable.setUntyped(true); } else { //must be version 3 or greater name = localVariableElem.getChildText("name", ns); dataType = localVariableElem.getChildText("type", ns); namespace = localVariableElem.getChildText("namespace", ns); //check to see if the variable is untyped variable.setUntyped(localVariableElem.getChild("isUntyped", ns) != null); // set mandatory (default is false) variable.setMandatory(localVariableElem.getChild("mandatory", ns) != null); //set the element name if it uses one String elementName; elementName = localVariableElem.getChildText("element", ns); variable.setElementName(elementName); // set ordering (if schema 2.1 or later) String orderingStr = localVariableElem.getChildText("index", ns); if (StringUtil.isIntegerString(orderingStr)) { variable.setOrdering(new Integer(orderingStr)); } variable.getAttributes().fromJDOM(localVariableElem.getAttributes()); variable.getAttributes().transformDynamicValues(variable); } //the variable either is data typed xor linked to an element declaration variable.setDataTypeAndName(dataType, name, namespace); }
From source file:projetxml.model.DownloadOmdb.java
/** * return map about Omdb information//from w w w . j a v a 2 s. c o m * @return map about Omdb information * @throws JDOMException * @throws IOException */ public Map<String, String> getInfos() throws JDOMException, IOException { //Rcupration de la liste des attributs Map<String, String> informations = new HashMap<>(); //On creer un fichier qui sert de relai pour stocker //temporairement les informations //C'est plus simple comme a File f = new File("intermediaire.xml"); //Ajout du string //Conversion sous la forme d'un xml try { FileWriter fw = new FileWriter(f); BufferedWriter output = new BufferedWriter(fw); output.write(this.infos); output.flush(); output.close(); } catch (IOException e) { } //Rcupration de la balise movie Document document = new SAXBuilder().build(f); //Il se peut que l'url ne contienne pas de "movie" //Il va donc lever une exception //On l'attrape donc pour eviter que l'appli plante try { Element movie = document.getRootElement().getChild("movie"); for (Attribute a : movie.getAttributes()) { informations.put(a.getName(), a.getValue()); } } catch (Exception e) { } //Suppresion du file f.delete(); //Rcupration de tous les attributs sous la forme d'une map return informations; }
From source file:qtiscoringengine.CustomOperatorRegistry.java
License:Open Source License
private static String getOperatorType(Element customOperatorNode) { for (Attribute attribute : customOperatorNode.getAttributes()) { if ("CLASS".equalsIgnoreCase(attribute.getName())) { return attribute.getValue(); }//w w w . jav a 2s . c o m } return ""; }
From source file:qtiscoringengine.ISECustomExpression.java
License:Open Source License
private static String getOperatorType(Element customOperatorNode) { for (Attribute attribute : customOperatorNode.getAttributes()) { if (StringUtils.equalsIgnoreCase(attribute.getName(), "CLASS")) { return attribute.getValue(); }//w ww. j ava 2 s.c o m } return ""; }
From source file:recparser.idmef.IdmefParser.java
License:Open Source License
public void listChildren(Element current, Object o, Element parent) { if (o != null) { Object object;/*from ww w.ja va2 s .co m*/ String contentName = current.getName(); Address address = null; //Si es Address generamos una nueva instancia if (contentName.equals("Address")) { address = new Address(); object = address; } else { object = o; } //get the attributes of the current element and add them to the corresponding object of idmefModel package List attribute_list = current.getAttributes(); Iterator it_attribute = attribute_list.iterator(); while (it_attribute.hasNext()) { Attribute attribute = (Attribute) it_attribute.next(); addAttribute(current, attribute, object); } //get the contents of the current element and add them to the corresponding object of idmefModel package List contents = current.getContent(); Iterator it_contents = contents.iterator(); while (it_contents.hasNext()) { Object child = it_contents.next(); if (child instanceof Text) { Text t = (Text) child; String contentValue = t.getTextTrim(); if (!("".equals(contentValue))) { addContent(parent, contentName, contentValue, object); } } } if (contentName.equals("Address")) { if (o instanceof IntrusionTarget) { IntrusionTarget target = (IntrusionTarget) o; target.setNode(address); } else if (o instanceof IntrusionSource) { IntrusionSource source = (IntrusionSource) o; source.setNode(address); } } //get the children of the current element and call the method recursively. List children = current.getChildren(); Iterator iterator = children.iterator(); while (iterator.hasNext()) { Element child = (Element) iterator.next(); ; listChildren(child, object, current); } } }
From source file:ru.iteco.xmldoc.ConfigEx.java
License:Open Source License
public Map<String, String> getElementMap(Element el) { Map<String, String> result = new LinkedHashMap<String, String>(); for (Attribute attr : el.getAttributes()) { if (attr.getName().equals("class")) // ? result.put("_class", attr.getValue()); result.put(attr.getName(), attr.getValue()); }/* w w w. ja v a2s. com*/ result.put("description", getPreviousComment(el)); result.put("source", new XMLOutputter().outputString(el).trim()); result.put("elementname", el.getName()); return result; }
From source file:ru.iteco.xmldoc.Scope.java
License:Open Source License
public Scope(Element element) { Element scopeEl = element.getParentElement(); if (scopeEl.getName() != "scope") System.out.println("Where is scope ? Parent el :" + scopeEl.getName()); else {/*from w ww. java 2 s. c o m*/ List<Attribute> scopes = scopeEl.getAttributes(); for (Attribute sc : scopes) { String tmp_val = sc.getValue(); String[] tmp_vals = tmp_val.split(","); for (String v : tmp_vals) { add(sc.getName(), v.trim()); } } } }