List of usage examples for org.jdom2 Element setAttributes
public Element setAttributes(final Collection<? extends Attribute> newAttributes)
This sets the attributes of the element.
From source file:com.c4om.autoconf.ulysses.extra.svrlmultipathinterpreter.PartialNodeGenerator.java
License:Apache License
/** * This method generates a XML element (as a JDOM2 element) from a XPath path token of the form * \/<i>qualified name</i>[<i>attributesFilter</i>] * @param pathToken the path token//www. j ava2s. c o m * @param namespaces a {@link Collection} of {@link Namespace} objects, describing the known prefix-namespace mappings * @return a {@link Element} object as described by the pathToken * @throws IllegalArgumentException if the path token is invalid and/or there are errors at the filter as described by {@link JDOMUtils#generateAttributeListFromFilter(String, Collection)} * @throws IndexOutOfBoundsException if the filter specifies an attribute count token and its number does not match the number of attributes, as described by {@link JDOMUtils#generateAttributeListFromFilter(String, Collection)} * @see JDOMUtils#generateAttributeListFromFilter(String, Collection) */ private static Element generateElementFromPathToken(String pathToken, Collection<Namespace> namespaces) { Pattern pattern = Pattern.compile("^" + REGEXP_PATH_TOKEN + "$"); Matcher matcher = pattern.matcher(pathToken); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid path token: " + pathToken); } String name = matcher.group("name"); String pref = matcher.group("pref"); String filter = matcher.group("filter"); if (filter != null && !filter.matches(REGEXP_ATTRIBUTES_FILTER)) { throw new IllegalArgumentException("Invalid path filter: " + filter); } Namespace namespace = JDOMUtils.solveNamespaceForPrefix(pref, namespaces); //Namespace not found if (namespace == null) { throw new IllegalArgumentException( "Namespace prefix '" + pref + "' at path token is not defined at namespaces parameter."); } Element result = new Element(name, namespace); if (filter != null) { List<Attribute> attributeList = JDOMUtils.generateAttributeListFromFilter(filter, namespaces); result.setAttributes(attributeList); } return result; }
From source file:com.izforge.izpack.util.xmlmerge.action.FullMergeAction.java
License:Open Source License
/** * Adds attributes from in element to out element. * * @param out out element/*from ww w . ja va 2 s. c o m*/ * @param in in element */ private void addAttributes(Element out, Element in) { LinkedHashMap<String, Attribute> allAttributes = new LinkedHashMap<String, Attribute>(); List<Attribute> outAttributes = new ArrayList<Attribute>(out.getAttributes()); List<Attribute> inAttributes = new ArrayList<Attribute>(in.getAttributes()); for (Attribute attr : outAttributes) { attr.detach(); allAttributes.put(attr.getQualifiedName(), attr); logger.fine("adding attr from out:" + attr); } for (Attribute attr : inAttributes) { attr.detach(); allAttributes.put(attr.getQualifiedName(), attr); logger.fine("adding attr from in:" + attr); } out.setAttributes(new ArrayList<Attribute>(allAttributes.values())); }
From source file:org.yawlfoundation.yawl.elements.YTask.java
License:Open Source License
public Element getStartingDataSnapshot() throws YDataStateException, YStateException, YQueryException { logger.debug("--> getStartingDataSnapshot"); if (null == getDecompositionPrototype()) return null; Element dataForChildCase = produceDataRootElement(); List<YParameter> inputParams = new ArrayList<YParameter>( _decompositionPrototype.getInputParameters().values()); Collections.sort(inputParams); for (YParameter parameter : inputParams) { String inputParamName = parameter.getPreferredName(); String expression = _dataMappingsForTaskStarting.get(inputParamName); if (this.isMultiInstance() && inputParamName.equals(_multiInstAttr.getMIFormalInputParam())) { if (_multiInstanceSpecificParamsIterator == null) continue; Element specificMIData = (Element) _multiInstanceSpecificParamsIterator.next(); if (specificMIData != null) { if (YEngine.getInstance().generateUIMetaData()) { // Add in attributes for input parameter specificMIData.setAttributes(parameter.getAttributes().toJDOM()); }//from ww w.ja v a 2 s. c om dataForChildCase.addContent(specificMIData.detach()); } } else { Element result = ExternalDBGatewayFactory.isExternalDBMappingExpression(expression) ? performExternalDataExtraction(expression, parameter) : performDataExtraction(expression, parameter); if (result != null) { if (YEngine.getInstance().generateUIMetaData()) { result.setAttributes(parameter.getAttributes().toJDOM()); } dataForChildCase.addContent(result.clone()); } } } if (YEngine.getInstance().generateUIMetaData()) { /** * AJH: Add in task level attributes for specifcation to XMLdoclet pass-thru. * Note that we skip processing of the YAWL standard task attributes as we only * pass-thru the additional (user interface hints) attributes. */ for (String attrName : getDecompositionPrototype().getAttributes().keySet()) { String attrValue = getDecompositionPrototype().getAttributes().get(attrName); if (!STANDARD_TASK_ATTRIBUTES.contains("/" + attrName + "/")) { dataForChildCase.setAttribute(attrName, attrValue); } } } logger.debug("<-- getStartingDataSnapshot"); return dataForChildCase; }
From source file:org.yawlfoundation.yawl.resourcing.util.DataSchemaBuilder.java
License:Open Source License
/** * Creates a new element with the same name and attributes as the old one * @param element the elment to clone/*from w w w . j av a2 s . c o m*/ * @param defNS the default namespace * @return the cloned element */ private Element cloneElement(Element element, Namespace defNS) { Element cloned = new Element(element.getName(), defNS); cloned.setAttributes(cloneAttributes(element, defNS)); return cloned; }
From source file:org.yawlfoundation.yawl.util.JDOMUtil.java
License:Open Source License
public static Element stripAttributes(Element e) { e.setAttributes(null); for (Element child : e.getChildren()) { stripAttributes(child); // recurse }//from www.j a va2 s . c o m return e; }