List of usage examples for org.jdom2 Attribute getNamespace
public Namespace getNamespace()
Attribute
's Namespace
. From source file:com.cybernostics.jsp2thymeleaf.api.elements.JspTagElementConverter.java
@Override protected List<Attribute> convertAttributes(JspElementContext node, JSPElementNodeConverter context) { final Map<String, String> emptyMap = new HashMap<>(); Map<String, Object> attMap = new HashMap<>(); final List<Attribute> sourceAtributes = super.convertAttributes(node, context); final List<Attribute> attributes = sourceAtributes.stream().filter((eachAttribute) -> { attMap.put(eachAttribute.getName(), eachAttribute.getValue()); return !attributesToRemove.contains(eachAttribute.getName()); }).collect(Collectors.toList()); Map<String, String> childMap = childAttributeSource.map(i -> i.apply(nodeContext(node, context))) .orElse(emptyMap);//from w ww. ja v a 2s . co m if (!childMap.isEmpty()) { attMap.put("_childAtts", childMap); } attMap.put("__tagname__", convertsTag); final List<Attribute> createdAttributes = newAttributeBuilders.stream() .flatMap(eachBuilder -> eachBuilder.buildNewAttributes(attMap).stream()) .collect(Collectors.toList()); for (Attribute createdAttribute : createdAttributes) { ActiveNamespaces.add(createdAttribute.getNamespace()); } final List<Attribute> allAttributes = ListUtils.union(createdAttributes, attributes); if (isElementEmbeddedInAttribute(node)) { if (this.attributeToUseWhenQuoted.isPresent()) { String attributeToUse = attributeToUseWhenQuoted.get(); allAttributes.stream().filter(it -> it.getName().equals(attributeToUse)) .forEach(it -> it.setName("data-replace-parent-attribute-value")); } } return allAttributes; }
From source file:com.izforge.izpack.util.xmlmerge.mapper.NamespaceFilterMapper.java
License:Open Source License
/** * Filters an element's attributes./*from www . j a v a 2 s . c o m*/ * * @param element An element whose attributes will be filtered * @return The input element whose attributes have been filtered */ private Element filterAttributes(Element element) { Element result = (Element) element.clone(); List<Attribute> attributes = result.getAttributes(); Iterator<Attribute> it = attributes.iterator(); while (it.hasNext()) { Attribute attr = it.next(); if (attr.getNamespace().equals(m_namespace)) { it.remove(); } } return result; }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.AttributeListInferencerImpl.java
License:Apache License
/** * @see AttributeListInferencer#learnAttributeList(List, int) *///from www.j av a 2 s . c o m @Override public void learnAttributeList(List<Attribute> attrList, int documentIndex) { checkNotNull(attrList, "'attrList' must not be null"); if (!firstTime) { //First, we mark as optional any known attribute which does not reoccur for (SchemaAttribute schemaAttribute : knownAttributes.keySet()) { boolean found = false; for (Attribute attribute : attrList) { if (attribute.getName().equals(schemaAttribute.getName()) && attribute.getNamespace().getURI().equals(schemaAttribute.getNamespace())) found = true; } if (!found) schemaAttribute.setOptional(true); } } //Now, we learn the information given by this list of atttributes for (Attribute attribute : attrList) { if (attribute.getNamespaceURI().equals(XSI_NAMESPACE_URI)) continue;//Attributes in the XSI namespace are not extracted. SchemaAttribute schemaAttribute = searchSchemaAttribute(attribute.getNamespaceURI(), attribute.getName()); //New attribute if (schemaAttribute == null) { schemaAttribute = new SchemaAttribute(attribute.getName(), attribute.getNamespaceURI(), true, new SimpleType("")); if (firstTime) schemaAttribute.setOptional(false); SimpleTypeInferencer simpleTypeInferencer = InferencersFactory.getInstance() .getSimpleTypeInferencerInstance(schemaAttribute.getNamespace() + config.getTypeNamesAncestorsSeparator() + schemaAttribute.getName(), config); simpleTypeInferencer.learnValue(attribute.getValue(), attribute.getNamespaceURI(), "@" + attribute.getName()); knownAttributes.put(schemaAttribute, simpleTypeInferencer); } //Already known attribute else { knownAttributes.get(schemaAttribute).learnValue(attribute.getValue(), attribute.getNamespaceURI(), "@" + attribute.getName()); } complexTypeStatisticsEntry.registerAttributeOccurrenceInfoCount(schemaAttribute, documentIndex); complexTypeStatisticsEntry.registerValueOfNodeCount(attribute.getValue(), schemaAttribute, documentIndex); String realPathFiltered = TypesExtractorImpl.filterAndJoinRealPath(TypesExtractorImpl .getRealPathOfAttributeUnfiltered(attribute, config, solvedNamespaceToPrefixMapping)); statistics.registerAttributeOccurrenceAtPathCount(realPathFiltered, documentIndex); statistics.registerValueAtPathCount(realPathFiltered, attribute.getValue(), documentIndex); } firstTime = false; }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
private void setVariablesFromXML(String prefix, Element element, Hashtable predecessors) { String key = getNamespacePrefix(element.getNamespace()) + element.getName(); setVariablesFromXML(prefix, key, element, predecessors); List attributes = element.getAttributes(); for (Object attribute1 : attributes) { Attribute attribute = (Attribute) attribute1; String name = getNamespacePrefix(attribute.getNamespace()) + attribute.getName(); String value = attribute.getValue().replace(BLANK, BLANK_ESCAPED).replace(SLASH, SLASH_ESCAPED); if (value == null || value.length() == 0) { continue; }/*from w w w . ja v a2s . co m*/ key = getNamespacePrefix(element.getNamespace()) + element.getName() + ATTR_SEP + name + ATTR_SEP + value; if (predicates.containsKey(key)) { setVariablesFromXML(prefix, key, element, predecessors); } } }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
private void setVariablesFromXML(String prefix, String key, Element element, Hashtable predecessors) { int pos = 1;//from www .j a va 2 s.c om if (predecessors.containsKey(key)) { pos = (Integer) predecessors.get(key) + 1; } predecessors.put(key, pos); String path = prefix + "/" + key; if (pos > 1) { path = path + "[" + pos + "]"; } // Add element text addVariable(path, element.getText()); // Add value of all attributes List attributes = element.getAttributes(); for (Object attribute1 : attributes) { Attribute attribute = (Attribute) attribute1; String value = attribute.getValue(); if (value != null && value.length() > 0) { addVariable(path + "/@" + getNamespacePrefix(attribute.getNamespace()) + attribute.getName(), value); } } // Add values of all children predecessors = new Hashtable(); List children = element.getChildren(); for (Object aChildren : children) { Element child = (Element) aChildren; setVariablesFromXML(path, child, predecessors); } }
From source file:org.openconcerto.xml.JDOM2Utils.java
License:Open Source License
static String getDiff(Element elem1, Element elem2, final boolean normalizeText) { if (elem1 == elem2) return null; if (!equals(elem1, elem2)) return "element name or namespace"; // ignore attributes order final List<Attribute> attr1 = elem1.getAttributes(); final List<Attribute> attr2 = elem2.getAttributes(); if (attr1.size() != attr2.size()) return "attributes count"; for (final Attribute attr : attr1) { if (!attr.getValue().equals(elem2.getAttributeValue(attr.getName(), attr.getNamespace()))) return "attribute value"; }/*from w ww.j ava2s . c o m*/ // use content order final IPredicate<Content> filter = new IPredicate<Content>() { @Override public boolean evaluateChecked(Content input) { return input instanceof Text || input instanceof Element; } }; // only check Element and Text (also merge them) final Iterator<Content> contents1 = getContent(elem1, filter, true); final Iterator<Content> contents2 = getContent(elem2, filter, true); while (contents1.hasNext() && contents2.hasNext()) { final Content content1 = contents1.next(); final Content content2 = contents2.next(); if (content1.getClass() != content2.getClass()) return "content"; if (content1 instanceof Text) { final String s1 = normalizeText ? ((Text) content1).getTextNormalize() : content1.getValue(); final String s2 = normalizeText ? ((Text) content2).getTextNormalize() : content2.getValue(); if (!s1.equals(s2)) return "text"; } else { final String rec = getDiff((Element) content1, (Element) content2, normalizeText); if (rec != null) return rec; } } if (contents1.hasNext() || contents2.hasNext()) return "content size"; return null; }
From source file:org.rascalmpl.library.lang.xml.DOM.java
License:Open Source License
private IConstructor convertElement(Element e, boolean trim) { IListWriter kids = vf.listWriter(Factory.Node); for (Object o : e.getAttributes()) { Attribute attr = (Attribute) o; IString key = vf.string(attr.getName()); IString val = vf.string(attr.getValue()); kids.insert(vf.constructor(Factory.Node_attribute, convertNamespace(attr.getNamespace()), key, val)); }//from ww w.jav a 2s . co m int len = e.getContentSize(); for (int i = 0; i < len; i++) { try { kids.append(convertContent(e.getContent(i), trim)); } catch (Skip c) { // Ugh, terrible, but I'm in hurry continue; } } IString name = vf.string(e.getName()); return vf.constructor(Factory.Node_element, convertNamespace(e.getNamespace()), name, kids.done()); }
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); }// ww w . ja v a2s . 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; }