List of usage examples for org.dom4j Element attributeIterator
Iterator<Attribute> attributeIterator();
From source file:org.springframework.extensions.config.xml.elementreader.GenericElementReader.java
License:Apache License
/** * Creates a ConfigElementImpl object from the given element. * /*from ww w .ja v a 2s.co m*/ * @param element The element to parse * @return The GenericConfigElement representation of the given element */ @SuppressWarnings("unchecked") protected GenericConfigElement createConfigElement(Element element) { // get the name and value of the given element String name = element.getName(); // create the config element object and populate with value // and attributes GenericConfigElement configElement = new GenericConfigElement(name); if ((element.hasContent()) && (element.hasMixedContent() == false)) { String value = element.getTextTrim(); if (value != null && value.length() > 0) { if (propertyConfigurer != null) { value = propertyConfigurer.resolveValue(value); } configElement.setValue(value); } } Iterator<Attribute> attrs = element.attributeIterator(); while (attrs.hasNext()) { Attribute attr = attrs.next(); String attrName = attr.getName(); String attrValue = attr.getValue(); if (propertyConfigurer != null) { attrValue = propertyConfigurer.resolveValue(attrValue); } configElement.addAttribute(attrName, attrValue); } return configElement; }
From source file:org.talend.mdm.webapp.base.server.util.XmlUtil.java
License:Open Source License
public static void iterateAttribute(Element element, AttributeProcess attributeProcess) { // iterate through attributes of element for (Iterator<?> i = element.attributeIterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); // do something attributeProcess.process(attribute); }//from ww w. j av a 2 s . co m }
From source file:org.unitime.banner.ant.MergeXml.java
License:Apache License
private void merge(Element target, Element source) { for (Iterator i = source.attributeIterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); target.addAttribute(attribute.getName(), attribute.getValue()); }// w w w. j av a 2 s . c o m for (Iterator i = source.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); if (node instanceof Element) { Element element = (Element) node; if ("property".equals(element.getName())) { String name = element.attributeValue("name", "noname"); Element targetProperty = null; for (Iterator j = target.elementIterator("property"); j.hasNext();) { Element property = (Element) j.next(); if (name.equals(property.attributeValue("name"))) { targetProperty = property; break; } } if (targetProperty != null) { target.remove(targetProperty); } if (element.getText() != null && element.getText().trim().length() > 0) { target.addElement("property").addAttribute("name", name).setText(element.getText()); } } else { if (target.elements(element.getName()).size() == 1 && source.elements(element.getName()).size() == 1) merge(target.element(element.getName()), element); else merge(target.addElement(element.getName()), element); } } else if (node instanceof Comment) { Comment comment = (Comment) node; target.addComment(comment.getText()); } else if (node instanceof CDATA) { CDATA data = (CDATA) node; target.add((CDATA) data.clone()); } else if (node instanceof Text) { Text text = (Text) node; if (text.getText() != null && text.getText().trim().length() > 0) target.addText(text.getText()); } else if (node instanceof Namespace) { } else { log("Unknown node " + node); } } }
From source file:org.unitime.commons.ant.LowercaseTableNames.java
License:Open Source License
private void convert(Element element) { for (Iterator<Attribute> i = element.attributeIterator(); i.hasNext();) { Attribute attribute = i.next(); for (String name : sAttributes) { if (name.equals(attribute.getName())) { if (!attribute.getValue().equals(attribute.getValue().toLowerCase())) { info(" -- converting " + name + " " + attribute.getValue() + " to " + attribute.getValue().toLowerCase()); }//from w w w . j av a 2 s. co m attribute.setValue(attribute.getValue().toLowerCase()); } } for (String name : sFormulas) { if (name.equals(attribute.getName())) { if (!lowerFormula(attribute.getValue()).equals(attribute.getValue())) { info(" -- converting " + name + ": " + attribute.getValue()); info(" -- into : " + lowerFormula(attribute.getValue())); } attribute.setValue(lowerFormula(attribute.getValue())); } } } if (element.getName().equals("param")) { for (String name : sAttributes) { if (name.equals(element.attributeValue("name", ""))) { if (!element.getText().equals(element.getText().toLowerCase())) { info(" -- converting " + name + " " + element.getText() + " to " + element.getText().toLowerCase()); } element.setText(element.getText().toLowerCase()); } } } for (Iterator<Element> i = element.elementIterator(); i.hasNext();) { convert(i.next()); } }
From source file:org.unitime.timetable.gwt.server.MenuServlet.java
License:Open Source License
private void merge(Element menu, Element custom) { if ("remove".equals(custom.getName())) { menu.getParent().remove(menu);/* w ww .ja v a2 s . c o m*/ return; } for (Iterator<Attribute> i = custom.attributeIterator(); i.hasNext();) { Attribute a = i.next(); menu.addAttribute(a.getName(), a.getValue()); } for (Iterator<Element> i = custom.elementIterator(); i.hasNext();) { Element e = i.next(); if ("parameter".equals(e.getName())) { for (Iterator<Element> j = menu.elementIterator("parameter"); j.hasNext();) { menu.remove(j.next()); } menu.add(e.createCopy()); continue; } if ("condition".equals(e.getName())) { menu.add(e.createCopy()); continue; } if ("new-condition".equals(e.getName())) { for (Iterator<Element> j = menu.elementIterator("condition"); j.hasNext();) { menu.remove(j.next()); } Element f = e.createCopy(); f.setName("condition"); menu.add(f); continue; } String name = e.attributeValue("name"); Element x = null; if (name != null) { for (Iterator<Element> j = menu.elementIterator(); j.hasNext();) { Element f = j.next(); if (name.equals(f.attributeValue("name"))) { x = f; break; } } } if (x != null) { merge(x, e); } else { int pos = Integer.parseInt(e.attributeValue("position", "-1")); if (pos >= 0) { List<Element> after = new ArrayList<Element>(); for (Iterator<Element> j = menu.elementIterator(); j.hasNext();) { Element f = j.next(); if ("condition".equals(f.getName())) continue; if (pos > 0) { pos--; } else { after.add(f); menu.remove(f); } } menu.add(e.createCopy()); for (Element f : after) menu.add(f); } else menu.add(e.createCopy()); } } }
From source file:org.xmldb.core.trasformers.ObjectTrasformers.java
License:Apache License
public T trasformModel(Element element) { try {/*from ww w. j a v a2 s. c om*/ T t = (T) persistenceClass.getClazz().newInstance(); Iterator<Attribute> itAttr = element.attributeIterator(); Map<String, String> bean = new HashMap<String, String>(); while (itAttr.hasNext()) { Attribute a = itAttr.next(); bean.put(a.getName(), a.getValue()); } Iterator<Element> it = element.elementIterator(); while (it.hasNext()) { Element e = it.next(); bean.put(e.getName(), e.getText()); } //TODO settare le collection in automatico Map<String, String> properties = new HashMap<String, String>(); for (String property : bean.keySet()) { Class c = PropertyUtils.getPropertyType(t, property); LogHelper.debug("---------------the field " + property + " is " + c, this.getClass()); if (java.util.Collection.class.isAssignableFrom(c)) { LogHelper.debug("---------------the field " + property + " is collection---------", this.getClass()); //bean.remove(property); } else { properties.put(property, bean.get(property)); } } BeanUtils.populate(t, properties); return t; } catch (Exception e) { throw new XmlDBRuntimeException(e); } }
From source file:org.zenonpagetemplates.onePhaseImpl.PageTemplateImpl.java
License:Open Source License
@SuppressWarnings("unchecked") AttributesImpl getAttributes(Element element, Expressions expressions) throws PageTemplateException { AttributesImpl attributes = new AttributesImpl(); for (Iterator<Attribute> i = element.attributeIterator(); i.hasNext();) { Attribute attribute = i.next(); Namespace namespace = attribute.getNamespace(); String name = attribute.getName(); // Handle ZPT attributes if (TAL_NAMESPACE_URI.equals(namespace.getURI())) { // tal:define if (name.equals(TAL_DEFINE)) { expressions.define = attribute.getValue(); }// ww w . jav a 2s . co m // tal:condition else if (name.equals(TAL_CONDITION)) { expressions.condition = attribute.getValue(); } // tal:repeat else if (name.equals(TAL_REPEAT)) { expressions.repeat = attribute.getValue(); } // tal:content else if (name.equals(TAL_CONTENT)) { expressions.content = attribute.getValue(); } // tal:replace else if (name.equals(TAL_REPLACE)) { if (expressions.omitTag == null) { expressions.omitTag = VOID_STRING; } expressions.content = attribute.getValue(); } // tal:attributes else if (name.equals(TAL_ATTRIBUTES)) { expressions.attributes = attribute.getValue(); } // tal:omit-tag else if (name.equals(TAL_OMIT_TAG)) { expressions.omitTag = attribute.getValue(); } // tal:on-error else if (name.equals(TAL_ON_ERROR)) { expressions.onError = attribute.getValue(); } // tal:tag else if (name.equals(TAL_TAG)) { expressions.tag = attribute.getValue(); } // error else { throw new PageTemplateException( "Unknown tal attribute: " + name + " in '" + this.template.getName() + "' template"); } } else if (METAL_NAMESPACE_URI.equals(namespace.getURI())) { // metal:use-macro if (name.equals(METAL_USE_MACRO)) { expressions.useMacro = attribute.getValue(); } // metal:define-slot else if (name.equals(METAL_DEFINE_SLOT)) { expressions.defineSlot = attribute.getValue(); } // metal:define-macro // metal:fill-slot else if (name.equals(METAL_DEFINE_MACRO) || name.equals(METAL_FILL_SLOT)) { // these are ignored here, as they don't affect processing of current // template, but are called from other templates } // error else { throw new PageTemplateException( "Unknown metal attribute: " + name + " in '" + this.template.getName() + "' template"); } } else if (I18N_NAMESPACE_URI.equals(namespace.getURI())) { // i18n:domain if (name.equals(I18N_DOMAIN)) { expressions.i18nDomain = attribute.getValue(); } // i18n:define else if (name.equals(I18N_DEFINE)) { expressions.i18nDefine = attribute.getValue(); } // i18n:content else if (name.equals(I18N_CONTENT)) { expressions.i18nContent = attribute.getValue(); } // i18n:replace else if (name.equals(I18N_REPLACE)) { if (expressions.omitTag == null) { expressions.omitTag = VOID_STRING; } expressions.i18nContent = attribute.getValue(); } // i18n:attributes else if (name.equals(I18N_ATTRIBUTES)) { expressions.i18nAttributes = attribute.getValue(); } // i18n:params else if (name.equals(I18N_PARAMS)) { expressions.i18nParams = attribute.getValue(); } // i18n:on-error else if (name.equals(I18N_ON_ERROR)) { expressions.i18nOnError = attribute.getValue(); } // error else { throw new PageTemplateException( "Unknown i18n attribute: " + name + " in '" + this.template.getName() + "' template"); } } // Pass on all other attributes else { attributes.addAttribute(namespace.getURI(), name, attribute.getQualifiedName(), CDATA, attribute.getValue()); } } return attributes; }
From source file:org.zenonpagetemplates.twoPhasesImpl.ZPTDocumentFactory.java
License:Open Source License
@SuppressWarnings("unchecked") static private void mapAttributes(Element element, ZPTElement zptElement, ZPTDocument zptDocument) throws PageTemplateException { String talOmitTag = null;/*from w w w. java 2s. com*/ boolean isReplace = false; for (Iterator<Attribute> i = element.attributeIterator(); i.hasNext();) { Attribute attribute = i.next(); Namespace namespace = attribute.getNamespace(); String name = attribute.getName(); String namespacePrefix = namespace.getPrefix(); // Handle ZPT attributes if (TwoPhasesPageTemplate.TAL_NAMESPACE_URI.equals(namespace.getURI())) { // tal:define if (name.equals(TwoPhasesPageTemplate.TAL_DEFINE)) { zptElement.addDynamicAttribute(new TALDefine(namespacePrefix, attribute.getValue())); } // tal:condition else if (name.equals(TwoPhasesPageTemplate.TAL_CONDITION)) { zptElement.addDynamicAttribute(new TALCondition(namespacePrefix, attribute.getValue())); } // tal:repeat else if (name.equals(TwoPhasesPageTemplate.TAL_REPEAT)) { zptElement.addDynamicAttribute(new TALRepeat(namespacePrefix, attribute.getValue())); } // tal:content else if (name.equals(TwoPhasesPageTemplate.TAL_CONTENT)) { zptElement.addDynamicAttribute(new TALContent(namespacePrefix, attribute.getValue())); } // tal:replace else if (name.equals(TwoPhasesPageTemplate.TAL_REPLACE)) { isReplace = true; zptElement.addDynamicAttribute(new TALContent(namespacePrefix, attribute.getValue())); } // tal:attributes else if (name.equals(TwoPhasesPageTemplate.TAL_ATTRIBUTES)) { zptElement.addDynamicAttribute(new TALAttributes(namespacePrefix, attribute.getValue())); } // tal:omit-tag else if (name.equals(TwoPhasesPageTemplate.TAL_OMIT_TAG)) { talOmitTag = attribute.getValue(); } // tal:on-error else if (name.equals(TwoPhasesPageTemplate.TAL_ON_ERROR)) { zptElement.addDynamicAttribute(new TALOnError(namespacePrefix, attribute.getValue())); } // tal:tag else if (name.equals(TwoPhasesPageTemplate.TAL_TAG)) { zptElement.addDynamicAttribute(new TALTag(namespacePrefix, attribute.getValue())); } // error else { throw new PageTemplateException("Unknown TAL attribute: " + name + " in template"); } } else if (TwoPhasesPageTemplate.METAL_NAMESPACE_URI.equals(namespace.getURI())) { // metal:use-macro if (name.equals(TwoPhasesPageTemplate.METAL_USE_MACRO)) { zptElement.addDynamicAttribute(new METALUseMacro(namespacePrefix, attribute.getValue())); } // metal:define-slot else if (name.equals(TwoPhasesPageTemplate.METAL_DEFINE_SLOT)) { zptElement.addDynamicAttribute(new METALDefineSlot(namespacePrefix, attribute.getValue())); } // metal:define-macro else if (name.equals(TwoPhasesPageTemplate.METAL_DEFINE_MACRO)) { zptElement.addDynamicAttribute(new METALDefineMacro(namespacePrefix, attribute.getValue())); } // metal:fill-slot else if (name.equals(TwoPhasesPageTemplate.METAL_FILL_SLOT)) { zptElement.addDynamicAttribute(new METALFillSlot(namespacePrefix, attribute.getValue())); } // error else { throw new PageTemplateException("Unknown metal attribute: " + name + " in template"); } } else if (TwoPhasesPageTemplate.I18N_NAMESPACE_URI.equals(namespace.getURI())) { // i18n:domain if (name.equals(TwoPhasesPageTemplate.I18N_DOMAIN)) { zptElement.addDynamicAttribute(new I18NDomain(namespacePrefix, attribute.getValue())); } // i18n:define else if (name.equals(TwoPhasesPageTemplate.I18N_DEFINE)) { zptElement.addDynamicAttribute(new I18NDefine(namespacePrefix, attribute.getValue())); } // i18n:content else if (name.equals(TwoPhasesPageTemplate.I18N_CONTENT)) { zptElement.addDynamicAttribute(new I18NContent(namespacePrefix, attribute.getValue())); } // i18n:replace else if (name.equals(TwoPhasesPageTemplate.I18N_REPLACE)) { isReplace = true; zptElement.addDynamicAttribute(new I18NContent(namespacePrefix, attribute.getValue())); } // i18n:attributes else if (name.equals(TwoPhasesPageTemplate.I18N_ATTRIBUTES)) { zptElement.addDynamicAttribute(new I18NAttributes(namespacePrefix, attribute.getValue())); } // i18n:params else if (name.equals(TwoPhasesPageTemplate.I18N_PARAMS)) { zptElement.addDynamicAttribute(new I18NParams(namespacePrefix, attribute.getValue())); } // i18n:on-error else if (name.equals(TwoPhasesPageTemplate.I18N_ON_ERROR)) { zptElement.addDynamicAttribute(new I18NOnError(namespacePrefix, attribute.getValue())); } // error else { throw new PageTemplateException("Unknown i18n attribute: " + name + " in template"); } } // Pass on all other attributes else { zptElement.addStaticAttribute(new StaticAttributeImpl(namespacePrefix, name, attribute.getValue())); } } // Add omit-tag if (talOmitTag != null) { zptElement.addDynamicAttribute(new TALOmitTag(zptDocument.getTALPrefix(), talOmitTag)); } else if (isReplace) { zptElement.addDynamicAttribute(new TALOmitTag(zptDocument.getTALPrefix(), VOID_STRING)); } }