List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
From source file:org.workflow.WorkflowParser.java
License:Apache License
private void modifyXmlFile(String path) { try {//from ww w. j a v a 2 s . co m SAXBuilder builder = new SAXBuilder(); //parse using builder to get DOM representation of the XML file Document dom = builder.build(new File(path)); Element root = dom.getRootElement(); List<Element> list = root.getChildren(); for (Element node : list) { switch (node.getName().toLowerCase()) { case "job": double runtime; if (node.getAttributeValue("runtime") != null) { Attribute att = node.getAttribute("runtime"); att.setValue("20"); node.removeAttribute("runtime"); node.setAttribute(att); } break; default: break; } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.xcri.core.Catalog.java
License:Open Source License
@Override public void fromXml(Element element) throws InvalidElementException { super.fromXml(element); ///*from w w w. ja v a2 s. c o m*/ // Add generated // if (element.getAttribute("generated") != null) { try { Date date = new Date(); date = DatatypeConverter.parseDateTime(element.getAttributeValue("generated")).getTime(); this.setGenerated(date); // // Time and Year? // if (!element.getAttributeValue("generated").contains("T") || element.getAttributeValue("generated").split("T")[1].length() != 9) { log.warn("catalog: @generated contains date but not time:" + element.getAttributeValue("generated")); } } catch (Exception e) { log.error("catalog: @generated contains invalid date:" + element.getAttributeValue("generated")); throw new InvalidElementException( "catalog: @generated contains invalid date:" + element.getAttributeValue("generated")); } } else { this.setGenerated(new Date()); } // // Add children // ArrayList<Provider> providers = new ArrayList<Provider>(); for (Element providerElement : Lax.getChildrenQuietly(element, "provider", Namespaces.XCRI_NAMESPACE_NS, log)) { Provider provider = new Provider(); provider.fromXml(providerElement); provider.setParent(this); providers.add(provider); } this.setProviders(providers.toArray(new Provider[providers.size()])); }
From source file:org.xcri.types.TemporalType.java
License:Open Source License
@Override public void fromXml(Element element) throws InvalidElementException { super.fromXml(element); /*/* w w w . j a va 2 s .co m*/ * If a Temporal Element does not contain text content, an Aggregator MUST treat the element as in error and ignore the element. */ if (this.getValue() == null || this.getValue().trim().length() == 0) throw new InvalidElementException(this.getName() + ": temporal element has no text content"); if (element.getAttribute("dtf") != null) { try { Date date = new Date(); date = DatatypeConverter.parseDateTime(element.getAttributeValue("dtf")).getTime(); this.setDtf(date); } catch (Exception e) { /* * If a Temporal Element has a @dtf attribute, and the value of the attribute does not contain a valid date or time according * to [W3C-DTF], an Aggregator MUST treat the element as in error and ignore the element. */ throw new InvalidElementException( this.getName() + ": temporal element has @dtf attribute with invalid W3C-DTF date"); } } }
From source file:org.yawlfoundation.yawl.elements.YTask.java
License:Open Source License
protected boolean isPopulatedEmptyTypeFlag(String expression) { Element elem = getElementForXQuery(_net.getInternalDataDocument(), expression); return (elem != null) && (elem.getAttribute("__emptyComplexTypeFlag__") != null); }
From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java
License:Open Source License
private static String getAttributeValue(Element e, String attr) { return e.getAttribute(attr) == null ? null : e.getAttribute(attr).getValue(); }
From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java
License:Open Source License
public static void addAttributeValue(Element e, String attr, String value, String... args) { // logger.debug("e="+e+", attr=" + attr+", value=" + value+", args=" + // args);/*w w w. j a v a 2s. co m*/ try { String json = e.getAttribute(attr) == null ? "[]" : e.getAttribute(attr).getValue(); if (!json.startsWith("[")) json = String.format("[%s]", json); JSONArray jsonArr = new JSONArray(json); // value already exist? for (int i = 0; i < jsonArr.length(); i++) { JSONObject jsonObj = jsonArr.getJSONObject(i); if (jsonObj.has(value)) { // logger.debug("AttributeValue already exist: " + value); return; } } Map valueAndArgs = new TreeMap(); valueAndArgs.put(value, args); JSONObject jsonObj = new JSONObject(valueAndArgs); jsonArr.put(jsonObj); e.setAttribute(attr, jsonArr.toString()); } catch (Exception e1) { logger.error("cannot add Attribute", e1); } }
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 a 2 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:password.pwm.config.PwmSetting.java
License:Open Source License
public Map<String, String> getOptions() { final Element settingElement = PwmSettingXml.readSettingXml(this); final Element optionsElement = settingElement.getChild("options"); final Map<String, String> returnList = new LinkedHashMap<>(); if (optionsElement != null) { final List<Element> optionElements = optionsElement.getChildren("option"); if (optionElements != null) { for (Element optionElement : optionElements) { if (optionElement.getAttribute("value") == null) { throw new IllegalStateException( "option element is missing 'value' attribute for key " + this.getKey()); }/* w ww .ja v a2 s . c o m*/ returnList.put(optionElement.getAttribute("value").getValue(), optionElement.getValue()); } } } return Collections.unmodifiableMap(returnList); }
From source file:password.pwm.config.PwmSetting.java
License:Open Source License
public boolean isRequired() { final Element settingElement = PwmSettingXml.readSettingXml(this); final Attribute requiredAttribute = settingElement.getAttribute("required"); return requiredAttribute != null && "true".equalsIgnoreCase(requiredAttribute.getValue()); }
From source file:password.pwm.config.PwmSetting.java
License:Open Source License
public boolean isHidden() { final Element settingElement = PwmSettingXml.readSettingXml(this); final Attribute requiredAttribute = settingElement.getAttribute("hidden"); return requiredAttribute != null && "true".equalsIgnoreCase(requiredAttribute.getValue()); }