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:com.izforge.izpack.util.xmlmerge.mapper.NamespaceFilterMapper.java
License:Open Source License
/** * Filters an element's attributes./*w w w . j av a2 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:com.izforge.izpack.util.xmlmerge.matcher.AbstractAttributeMatcher.java
License:Open Source License
@Override public boolean matches(Element originalElement, Element patchElement) { if (super.matches(originalElement, patchElement)) { List<Attribute> origAttList = originalElement.getAttributes(); List<Attribute> patchAttList = patchElement.getAttributes(); if (origAttList.size() == 0 && patchAttList.size() == 0) { return true; }/*from www .j a va 2s .c o m*/ if (origAttList.size() != patchAttList.size()) { return false; } for (Attribute origAttribute : origAttList) { if (getAttributeName() == null || (getAttributeName() != null && equalsString(origAttribute.getQualifiedName(), getAttributeName(), ignoreCaseAttributeName()))) { for (Attribute patchAttribute : patchAttList) { if (ignoreCaseAttributeName()) { if (origAttribute.getQualifiedName() .equalsIgnoreCase(patchAttribute.getQualifiedName())) { return equalsString(origAttribute.getValue(), patchAttribute.getValue(), ignoreCaseAttributeValue()); } } else { if (origAttribute.getQualifiedName().equals(patchAttribute.getQualifiedName())) { return equalsString(origAttribute.getValue(), patchAttribute.getValue(), ignoreCaseAttributeValue()); } } } } } } return false; }
From source file:com.novell.ldapchai.impl.edir.value.nspmComplexityRules.java
License:Open Source License
private static List<Policy> readComplexityPoliciesFromXML(final String input) { final List<Policy> returnList = new ArrayList<Policy>(); try {// w w w . jav a 2 s . c o m final SAXBuilder builder = new SAXBuilder(); final Document doc = builder.build(new StringReader(input)); final Element rootElement = doc.getRootElement(); final List policyElements = rootElement.getChildren("Policy"); for (final Object policyNode : policyElements) { final Element policyElement = (Element) policyNode; final List<RuleSet> returnRuleSets = new ArrayList<RuleSet>(); for (final Object ruleSetObjects : policyElement.getChildren("RuleSet")) { final Element loopRuleSet = (Element) ruleSetObjects; final Map<Rule, String> returnRules = new HashMap<Rule, String>(); int violationsAllowed = 0; final org.jdom2.Attribute violationsAttribute = loopRuleSet.getAttribute("ViolationsAllowed"); if (violationsAttribute != null && violationsAttribute.getValue().length() > 0) { violationsAllowed = Integer.parseInt(violationsAttribute.getValue()); } for (final Object ruleObject : loopRuleSet.getChildren("Rule")) { final Element loopRuleElement = (Element) ruleObject; final List ruleAttributes = loopRuleElement.getAttributes(); for (final Object attributeObject : ruleAttributes) { final org.jdom2.Attribute loopAttribute = (org.jdom2.Attribute) attributeObject; final Rule rule = Rule.valueOf(loopAttribute.getName()); final String value = loopAttribute.getValue(); returnRules.put(rule, value); } } returnRuleSets.add(new RuleSet(violationsAllowed, returnRules)); } returnList.add(new Policy(returnRuleSets)); } } catch (JDOMException e) { LOGGER.debug("error parsing stored response record: " + e.getMessage()); } catch (IOException e) { LOGGER.debug("error parsing stored response record: " + e.getMessage()); } catch (NullPointerException e) { LOGGER.debug("error parsing stored response record: " + e.getMessage()); } catch (IllegalArgumentException e) { LOGGER.debug("error parsing stored response record: " + e.getMessage()); } return returnList; }
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
private static void processServers(Element servers) { List<Server> serverList = new ArrayList<>(); if (servers == null) { List<Server> empty = Collections.emptyList(); Server.processServers(empty);/* w ww .j av a 2 s .c o m*/ return; } for (Element server : servers.getChildren()) { if (!SERVER.equals(server.getName().toLowerCase())) continue; String name = null; for (Attribute attr : server.getAttributes()) { if (NAME.equals(attr.getName().toLowerCase())) name = attr.getValue(); } if (name == null) { LoggerFactory.getLogger(LouieProperties.class) .error("A server was missing it's 'name' attribute and will be skipped!"); continue; } Server prop = new Server(name); for (Element serverProp : server.getChildren()) { String propName = serverProp.getName().toLowerCase(); String propValue = serverProp.getTextTrim(); if (null != propName) switch (propName) { case HOST: prop.setHost(propValue); break; case DISPLAY: prop.setDisplay(propValue); break; case LOCATION: prop.setLocation(propValue); break; case GATEWAY: prop.setGateway(propValue); break; case IP: prop.setIp(propValue); break; case EXTERNAL_IP: prop.setExternalIp(propValue); break; case CENTRAL_AUTH: prop.setCentralAuth(Boolean.parseBoolean(propValue)); break; case PORT: prop.setPort(Integer.parseInt(propValue)); break; case SECURE: prop.setSecure(Boolean.parseBoolean(propValue)); break; case TIMEZONE: prop.setTimezone(propValue); break; case CUSTOM: for (Element child : serverProp.getChildren()) { prop.addCustomProperty(child.getName(), child.getTextTrim()); } break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected server property {}:{}", propName, propValue); break; } } serverList.add(prop); } Server.processServers(serverList); }
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
private static void processServices(Element services, boolean internal) { if (services == null) return;/*from w w w. java2 s.com*/ for (Element elem : services.getChildren()) { if (DEFAULT.equalsIgnoreCase(elem.getName())) { processServiceDefaults(elem); break; } } List<ServiceProperties> servicesList = new ArrayList<>(); for (Element service : services.getChildren()) { String elementName = service.getName(); if (!SERVICE.equalsIgnoreCase(elementName)) { if (!DEFAULT.equalsIgnoreCase(elementName)) { LoggerFactory.getLogger(LouieProperties.class).warn("Unknown {} element: {}", SERVICE_PARENT, elementName); } continue; } String serviceName = null; Boolean enable = null; for (Attribute attr : service.getAttributes()) { String propName = attr.getName().toLowerCase(); String propValue = attr.getValue(); if (null != propName) switch (propName) { case NAME: serviceName = propValue; break; case ENABLE: enable = Boolean.valueOf(propValue); break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected service attribute {}:{}", propName, propValue); break; } } if (serviceName == null) { LoggerFactory.getLogger(LouieProperties.class) .error("A service was missing it's 'name' attribute and will be skipped"); continue; } ServiceProperties prop = new ServiceProperties(serviceName); if (enable != null) { prop.setEnable(enable); } for (Element serviceProp : service.getChildren()) { String propName = serviceProp.getName().toLowerCase(); String propValue = serviceProp.getTextTrim(); if (null != propName) switch (propName) { case CACHING: prop.setCaching(Boolean.valueOf(propValue)); break; case READ_ONLY: prop.setReadOnly(Boolean.valueOf(propValue)); break; case PROVIDER_CL: prop.setProviderClass(propValue); break; case RESPECTED_GROUPS: AccessManager.loadServiceAccess(serviceName, serviceProp); break; case RESERVED: if (internal) prop.setReserved(Boolean.valueOf(propValue)); break; case LAYERS: processServiceLayers(serviceProp, prop); break; case CUSTOM: for (Element child : serviceProp.getChildren()) { prop.addCustomProp(child.getName(), child.getTextTrim()); } break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected server property {}:{}", propName, propValue); } } servicesList.add(prop); } ServiceProperties.processServices(servicesList); }
From source file:com.rometools.opml.io.impl.OPML10Parser.java
License:Apache License
protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException { if (!e.getName().equals("outline")) { throw new RuntimeException("Not an outline element."); }/* w ww . j a v a 2 s . c o m*/ final Outline outline = new Outline(); outline.setText(e.getAttributeValue("text")); outline.setType(e.getAttributeValue("type")); outline.setTitle(e.getAttributeValue("title")); final List<org.jdom2.Attribute> jAttributes = e.getAttributes(); final ArrayList<Attribute> attributes = new ArrayList<Attribute>(); for (int i = 0; i < jAttributes.size(); i++) { final org.jdom2.Attribute a = jAttributes.get(i); if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") && !a.getName().equals("type")) { attributes.add(new Attribute(a.getName(), a.getValue())); } } outline.setAttributes(attributes); try { outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); } catch (final Exception ex) { LOG.warn("Unable to parse isBreakpoint value", ex); if (validate) { throw new FeedException("Unable to parse isBreakpoint value", ex); } } try { outline.setComment(readBoolean(e.getAttributeValue("isComment"))); } catch (final Exception ex) { LOG.warn("Unable to parse isComment value", ex); if (validate) { throw new FeedException("Unable to parse isComment value", ex); } } final List<Element> children = e.getChildren("outline"); outline.setModules(parseItemModules(e, locale)); outline.setChildren(parseOutlines(children, validate, locale)); return outline; }
From source file:com.rometools.rome.io.impl.OPML10Parser.java
License:Apache License
protected Outline parseOutline(final Element e, final boolean validate, final Locale locale) throws FeedException { if (!e.getName().equals("outline")) { throw new RuntimeException("Not an outline element."); }/*w ww . ja v a 2 s . c o m*/ final Outline outline = new Outline(); outline.setText(e.getAttributeValue("text")); outline.setType(e.getAttributeValue("type")); outline.setTitle(e.getAttributeValue("title")); final List<org.jdom2.Attribute> jAttributes = e.getAttributes(); final ArrayList<Attribute> attributes = new ArrayList<Attribute>(); for (int i = 0; i < jAttributes.size(); i++) { final org.jdom2.Attribute a = jAttributes.get(i); if (!a.getName().equals("isBreakpoint") && !a.getName().equals("isComment") && !a.getName().equals("title") && !a.getName().equals("text") && !a.getName().equals("type")) { attributes.add(new Attribute(a.getName(), a.getValue())); } } outline.setAttributes(attributes); try { outline.setBreakpoint(readBoolean(e.getAttributeValue("isBreakpoint"))); } catch (final Exception ex) { if (validate) { throw new FeedException("Unable to parse isBreakpoint value", ex); } } try { outline.setComment(readBoolean(e.getAttributeValue("isComment"))); } catch (final Exception ex) { if (validate) { throw new FeedException("Unable to parse isComment value", ex); } } final List<Element> children = e.getChildren("outline"); outline.setModules(parseItemModules(e, locale)); outline.setChildren(parseOutlines(children, validate, locale)); return outline; }
From source file:com.swordlord.gozer.builder.Parser.java
License:Open Source License
@SuppressWarnings("unchecked") private void parseElement(Element element, ObjectBase parent) { if (!_objectTags.containsKey(element.getName())) { String msg = MessageFormat.format("Element {0} unknown, parsing aborted.", element.getName()); LOG.error(msg);//w ww . j a va 2 s .c o m return; } ObjectBase ob = instantiateClass(_objectTags.get(element.getName())); if (ob == null) { String msg = MessageFormat.format("Class for {0} could not be instantiated, parsing aborted.", element); LOG.error(msg); return; } if (element.getText() != null) { ob.setContent(element.getText()); } List attributes = element.getAttributes(); Iterator itAttributes = attributes.iterator(); while (itAttributes.hasNext()) { Attribute attr = (Attribute) itAttributes.next(); ob.putAttribute(attr.getName(), attr.getValue()); } if (parent != null) { ob.inheritParent(parent); parent.putChild(ob); } else { _objectTree.setRoot(ob); } List children = element.getChildren(); Iterator itChildren = children.iterator(); while (itChildren.hasNext()) { parseElement((Element) itChildren.next(), ob); } }
From source file:Contabilidad.CodeBase64.java
public void limpia(String ruta) { try {//w w w . j a v a 2s . com org.jdom2.Document doc = new SAXBuilder().build(ruta); Element rootNode = doc.getRootElement(); List list = rootNode.getContent(); for (int i = 0; i < list.size(); i++) { Content elementos = (Content) list.get(i); if (elementos.getCType() == Content.CType.Element) { Element aux = (Element) elementos; if (aux.getName().compareToIgnoreCase("Addenda") == 0) { List list2 = aux.getContent(); for (int j = 0; j < list2.size(); j++) { Content elementos2 = (Content) list2.get(j); if (elementos2.getCType() == Content.CType.Element) { Element aux2 = (Element) elementos2; if (aux2.getName().compareToIgnoreCase("FactDocMX") == 0) { list2.remove(aux2); } if (aux2.getName().compareToIgnoreCase("ECFD") == 0) { Namespace NP = Namespace.getNamespace("", ""); aux2.setNamespace(NP); List list3 = aux2.getContent(); for (int k = 0; k < list3.size(); k++) { Content elementos3 = (Content) list3.get(k); if (elementos3.getCType() == Content.CType.Element) { Element aux3 = (Element) elementos3; aux3.setNamespace(NP); List list4 = aux3.getContent(); for (int l = 0; l < list4.size(); l++) { Content elementos4 = (Content) list4.get(l); if (elementos4.getCType() == Content.CType.Element) { Element aux4 = (Element) elementos4; aux4.setNamespace(NP); List list5 = aux4.getContent(); for (int m = 0; m < list5.size(); m++) { Content elementos5 = (Content) list5.get(m); if (elementos5.getCType() == Content.CType.Element) { Element aux5 = (Element) elementos5; aux5.setNamespace(NP); List list6 = aux5.getContent(); for (int n = 0; n < list6.size(); n++) { Content elementos6 = (Content) list6.get(n); if (elementos6 .getCType() == Content.CType.Element) { Element aux6 = (Element) elementos6; aux6.setNamespace(NP); List list7 = aux6.getContent(); for (int p = 0; p < list7.size(); p++) { Content elementos7 = (Content) list7.get(p); if (elementos7 .getCType() == Content.CType.Element) { Element aux7 = (Element) elementos7; aux7.setNamespace(NP); List list8 = aux7.getContent(); for (int q = 0; q < list8.size(); q++) { Content elementos8 = (Content) list8 .get(q); if (elementos8 .getCType() == Content.CType.Element) { Element aux8 = (Element) elementos8; aux8.setNamespace(NP); } } } } } } } } } } } } List atributos = aux2.getAttributes(); for (int a = 0; a < atributos.size(); a++) { Attribute at = (Attribute) atributos.get(a); if (at.getName().compareToIgnoreCase("schemaLocation") == 0) aux2.removeAttribute(at); } } } } } } } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { outputter.output(doc, new FileOutputStream(ruta)); } catch (IOException e) { System.out.println(e); } } catch (Exception e) { e.printStackTrace(); } }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.AbstractModule.java
License:Apache License
protected void replaceElement(final Element toReplace, final String replacementName) { assert toReplace != null && replacementName != null; assert !replacementName.isEmpty(); final Element parent = toReplace.getParentElement(); assert parent != null; final Element replacement = new Element(replacementName); replacement.addContent(toReplace.removeContent()); final List<Attribute> attributes = toReplace.getAttributes(); for (Attribute attribute : attributes) { replacement.setAttribute(attribute.detach()); }//from w ww. j ava2 s .c o m final int parentIndex = parent.indexOf(toReplace); parent.removeContent(parentIndex); parent.addContent(parentIndex, replacement); LOGGER.log(Level.FINE, "{0} replaced with {1}", new Object[] { toReplace, replacementName }); }