List of usage examples for org.dom4j Element attributes
List<Attribute> attributes();
From source file:au.gov.ansto.bragg.process.parse.Parse.java
License:Open Source License
protected static PortConfiguration getPortConfiguration(final Element element, final String patternName, final String parentName) throws DocumentException { PortConfiguration configuration = null; String name, type;//from w w w . j a v a 2 s . c o m int dimension = 0; // id = Integer.parseInt(element.attributeValue("id")); name = element.attributeValue("name"); type = element.attributeValue("type"); try { dimension = Integer.parseInt(element.attributeValue("dimension")); } catch (Exception ex) { } if (patternName == "in") configuration = new InConfiguration_(name, dimension, type, parentName); if (patternName == "out") configuration = new OutConfiguration_(name, dimension, type, parentName); if (patternName == "var") { String defaultValue = element.attributeValue("default_value"); String label = element.attributeValue("label"); // System.out.println("var_" + id +": "); int ownerID = 0; if (element.attributeValue("owner") != null) ownerID = Integer.parseInt(element.attributeValue("owner")); String max = element.attributeValue("max"); String min = element.attributeValue("min"); String usage = element.attributeValue("usage"); String options = element.attributeValue("option"); String UIWidth = element.attributeValue("UIwidth"); Map<String, String> attributeMap = new HashMap<String, String>(); List<?> attributes = element.attributes(); for (Object object : attributes) { if (object instanceof Attribute) { Attribute attribute = (Attribute) object; attributeMap.put(attribute.getName(), attribute.getStringValue()); } } configuration = new VarConfiguration_(name, dimension, type, parentName, defaultValue, ownerID, max, min, usage, label, options, UIWidth, attributeMap); } return configuration; }
From source file:com.alibaba.citrus.dev.handler.util.DomUtil.java
License:Open Source License
private static Element copy(org.dom4j.Element dom4jElement, ElementFilter filter) throws Exception { dom4jElement = filter.filter(dom4jElement); if (dom4jElement == null) { return null; }//from ww w . j a v a 2 s .c o m Element element = new Element(dom4jElement.getQualifiedName(), dom4jElement.getNamespaceURI()); for (Object attr : dom4jElement.attributes()) { String name = ((Attribute) attr).getQualifiedName(); String value = ((Attribute) attr).getValue(); element.addAttribute(name, value); } for (Object ns : dom4jElement.declaredNamespaces()) { String name = ((Namespace) ns).getPrefix(); String value = ((Namespace) ns).getURI(); if (isEmpty(name)) { name = "xmlns"; } else { name = "xmlns:" + name; } element.addAttribute(name, value); } for (Object e : dom4jElement.elements()) { Element subElement = copy((org.dom4j.Element) e, filter); if (subElement != null) { element.addSubElement(subElement); } } if (dom4jElement.elements().isEmpty()) { String text = trimToNull(dom4jElement.getText()); if (text != null) { element.setText(text); } } return element; }
From source file:com.arc.cdt.debug.seecode.options.SeeCodeOptionsAugmenter.java
License:Open Source License
/** * Process the "option" element.//from w w w . j a va2 s. co m * * @param e * the "option" element. * @throws DocumentException * @throws ConfigurationException */ private void handleOptionElement(Element e) throws DocumentException, ConfigurationException { List<Attribute> attrs = Cast.toType(e.attributes()); String optionName = null; String propertyName = null; String namePropertyName = null; String seecodeArg = null; String negate = null; String alternatePropertyName = null; String trueValue = null; String falseValue = null; boolean setAsDefaultOnly = false; List<Element> enums = Cast.toType(e.elements()); for (Attribute a : attrs) { String aname = a.getName().toLowerCase(); String value = a.getValue(); if (aname.equals("name")) optionName = value; else if (aname.equals("property")) propertyName = value; else if (aname.equals("seecode")) seecodeArg = value; else if (aname.equals("negate")) negate = value; else if (aname.equalsIgnoreCase("nameProperty")) namePropertyName = value; else if (aname.equalsIgnoreCase("defaultOnly")) { setAsDefaultOnly = !(value.equals("0") || value.equalsIgnoreCase("false")); } else if (aname.equalsIgnoreCase("alternate")) { alternatePropertyName = value; } else if (aname.equalsIgnoreCase("trueValue")) { trueValue = value; } else if (aname.equalsIgnoreCase("falseValue")) { falseValue = value; } else throw new DocumentException("Unknown attribute name: " + aname); } if (optionName == null) { throw new DocumentException("\"name\" missing in \"option\" node"); } IOption option = lookupOption(optionName); if (option == null) { throw new ConfigurationException("Unrecognized option name: " + optionName); } if (seecodeArg == null && enums.size() == 0) { seecodeArg = option.getCommand(); // if (seecodeArg==null) // throw new DocumentException("Option \"" + optionName + // "\" needs 'seecode' attribute"); } if (enums.size() == 0 && namePropertyName != null) { throw new DocumentException("nameProperty only applies to enumID options"); } boolean first = true; for (Element enumElement : enums) { if (!enumElement.getName().equalsIgnoreCase("enum")) { throw new DocumentException("Unrecognized element \"" + enumElement.getName() + "\" under option \"" + optionName + "\""); } String name = null; String scArg = null; String propertyValue = null; String booleanProperty = null; List<Attribute> eattrs = Cast.toType(enumElement.attributes()); boolean isDefault = first; // assume first is default first = false; for (Attribute a : eattrs) { String aname = a.getName(); String value = a.getValue(); if (aname.equals("name")) { name = value; } else if (aname.equals("seecode")) scArg = value; else if (aname.equalsIgnoreCase("propertyvalue")) propertyValue = value; else if (aname.equalsIgnoreCase("property")) booleanProperty = value; else throw new DocumentException("Unknown enumID attribute: " + aname); } try { if (name == null || option.getEnumCommand(name) == null) { throw new DocumentException("Unrecognized enumID id: " + name); } if (scArg == null && propertyValue == null) { scArg = option.getEnumCommand(name); if (scArg == null) throw new DocumentException("Enum \"" + name + "\" needs 'seecode' attribute"); } } catch (BuildException e1) { throw new ConfigurationException(e1.getMessage(), e1); } OptionEnum oe = new OptionEnum(option, name, scArg, propertyValue, booleanProperty, namePropertyName, isDefault); mEnumIdToOptionEnumMap.put(name, oe); mFromSeeCodeEnumMap.put(scArg, oe); } SeeCodeOption sco = new SeeCodeOption(optionName, seecodeArg, "true".equalsIgnoreCase(negate) || "1".equals(negate), propertyName, alternatePropertyName, trueValue, falseValue); mOptions.add(sco); if (seecodeArg != null) { mFromSeeCodeArgMap.put(seecodeArg, sco); } if (propertyName != null) { mFromPropertyMap.put(propertyName, sco); if (setAsDefaultOnly) this.mSetAsDefaultOnly.add(propertyName); } }
From source file:com.arc.cdt.debug.seecode.options.SeeCodeOptionsAugmenter.java
License:Open Source License
/** * Process the "property" element./* w w w. j a v a 2 s.co m*/ * @param e * the "property" element. * @throws DocumentException */ private void handlePropertyElement(Element e) throws DocumentException { List<Attribute> attrs = Cast.toType(e.attributes()); String propertyName = null; String propertyValue = null; for (Attribute a : attrs) { String aname = a.getName().toLowerCase(); String value = a.getValue(); if (aname.equals("name")) { propertyName = value; } else if (aname.equals("value")) { propertyValue = value; } else throw new DocumentException("Unknown attribute under 'property': " + aname); } if (propertyName == null || propertyValue == null) throw new DocumentException("'name' or 'value' attributes missing for element 'property'"); mSetPropertyMap.put(propertyName, propertyValue); }
From source file:com.arc.cdt.debug.seecode.options.SeeCodeOptionsAugmenter.java
License:Open Source License
private void handleDefaultElement(Element e) throws DocumentException { @SuppressWarnings("unchecked") List<Attribute> attrs = e.attributes(); String property = null;//from w w w . j a va 2 s .c o m String defaultValue = null; String option = null; String optionValue = null; for (Attribute a : attrs) { String aname = a.getName().toLowerCase(); String value = a.getValue(); if (aname.equals("property")) { property = value; } else if (aname.equals("value")) { defaultValue = value; } else if (aname.equals("option")) { option = value; } else if (aname.equals("optionvalue")) { optionValue = value; } } if (property == null || defaultValue == null || option == null || optionValue == null) { throw new DocumentException("Attributes on Default element missing"); } mDefaultList.add(new DefaultSpec(property, defaultValue, option, optionValue)); }
From source file:com.arc.xml.AbstractBuilder.java
License:Open Source License
/** * Check that attributes of element are valid and that all required attributes are there Apply attributes that are * valid to the builder via reflection by calling <code>"set<i>Property</i>"</code>. */// w w w .j a v a2s .co m protected void doAttributes(Element e, IBinding binding) throws SAXException { List<Attribute> attrs = Cast.toType(e.attributes()); for (Attribute a : attrs) { IAttributeDef adef = binding.getAttribute(a.getName()); if (adef == null) unknownAttribute(e, binding, a); else try { setAttribute(e, a.getName(), adef, a.getValue()); } catch (NoSuchMethodException x) { error(e, "Can't set attribute " + adef.getName()); } } /* * Look for missing required attributes */ for (IAttributeDef a : binding.getAttributes().values()) { if (a.isRequired() && e.attributeValue(a.getName()) == null && !accessedByAlias(e, binding, a)) error(e, "Required attribute \"" + a.getName() + "\" for tag \"" + binding.getTagName() + "\" is missing"); } }
From source file:com.arc.xml.AbstractBuilder.java
License:Open Source License
/** * Return true if there is an attribute definition in element "e" that references attribute definition "a". Used to * diagnose missing required attributes. *///w ww . jav a 2 s. c om static boolean accessedByAlias(Element e, IBinding binding, IAttributeDef adef) { List<Attribute> attrs = Cast.toType(e.attributes()); for (Attribute a : attrs) { IAttributeDef ad = binding.getAttribute(a.getName()); if (adef == ad) return true; } return false; }
From source file:com.christophermrossi.jpt.PageTemplateImpl.java
License:Open Source License
/** * With all of our namespace woes, getting an XPath expression * to work has proven futile, so we'll recurse through the tree * ourselves to find what we need.// w w w .jav a2 s . c om */ private void findSlots(Element element, Map slots) { //System.err.println( "element: " + element.getName() ); for (Iterator i = element.attributes().iterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); //System.err.println( "\t" + attribute.getName() + "\t" + attribute.getQualifiedName() ); } // Look for our attribute //String qualifiedAttributeName = this.metalNamespacePrefix + ":fill-slot"; //String name = element.attributeValue( qualifiedAttributeName ); String name = element.attributeValue("fill-slot"); if (name != null) { slots.put(name, new SlotImpl(element)); } // Recurse into child elements for (Iterator i = element.elementIterator(); i.hasNext();) { findSlots((Element) i.next(), slots); } }
From source file:com.cladonia.xml.xdiff.XmlElementNode.java
License:Open Source License
protected Line parseStartTag(Vector lines, Line current, Element elem) { boolean localInsertElement = false; boolean localDeleteElement = false; StyledElement styledElement = new StyledElement(); if (insertElement || insideInsertChain(parent)) { localInsertElement = true;//w w w . ja v a 2s .c om styledElement.addString(INSERT_OPEN_BRACKET); currentColor = COLOR_GREEN; } else if (deleteElement || insideDeleteChain(parent)) { localDeleteElement = true; styledElement.addString(DELETE_OPEN_BRACKET); currentColor = Color.RED; } else if (merged || insideInsertMergeChain(getXmlElementNodeParent())) { styledElement.addString(MERGED_OPEN_BRACKET); currentColor = COLOR_MERGED; } else { styledElement.addString(OPEN_BRACKET); currentColor = Color.BLACK; } styledElement.addString(new ElementName(elem.getQualifiedName())); current.addStyledElement(styledElement); Namespace ns = elem.getNamespace(); if (ns != null) { XElement parent = (XElement) elem.getParent(); if (parent != null) { Namespace prev = parent.getNamespaceForPrefix(ns.getPrefix()); if (prev == null || !ns.equals(prev)) { StyledElement sns = formatNamespace(ns); if (sns != null) { if (current.length() + sns.length() + 1 > MAX_LINE_LENGTH) { current = new Line(); lines.add(current); current.addStyledString(TAB); } else { current.addStyledString(SPACE); } current.addStyledElement(sns); } } } else { StyledElement sns = formatNamespace(ns); if (sns != null) { if (current.length() + sns.length() + 1 > MAX_LINE_LENGTH) { current = new Line(); lines.add(current); current.addStyledString(TAB); } else { current.addStyledString(SPACE); } current.addStyledElement(sns); } } } List namespaces = elem.additionalNamespaces(); if (namespaces != null && namespaces.size() > 0) { Iterator iterator = namespaces.iterator(); for (int i = 0; i < namespaces.size(); i++) { StyledElement sns = formatNamespace((Namespace) iterator.next()); if (sns != null) { if (current.length() + sns.length() + 1 > MAX_LINE_LENGTH) { current = new Line(); lines.add(current); current.addStyledString(TAB); } else { current.addStyledString(SPACE); } current.addStyledElement(sns); } } } List attributes = elem.attributes(); if (attributes != null && attributes.size() > 0) { Iterator iterator = attributes.iterator(); for (int i = 0; i < attributes.size(); i++) { StyledElement sa = formatAttribute((Attribute) iterator.next()); if (current.length() + sa.length() + 1 > MAX_LINE_LENGTH) { current = new Line(); lines.add(current); current.addStyledString(TAB); } else { current.addStyledString(SPACE); } current.addStyledElement(sa); } } if (!elem.hasContent() || hasPIorWhiteSpaceOnly((XElement) elem)) { if (updateElementFrom != null) { // content was blanked, don't add closing slash } else if (localInsertElement) { current.addStyledString(INSERT_SLASH); } else if (localDeleteElement) { current.addStyledString(DELETE_SLASH); } else if (merged || insideInsertMergeChain(getXmlElementNodeParent())) { current.addStyledString(MERGED_SLASH); } else { current.addStyledString(SLASH); } } if (localInsertElement) { current.addStyledString(INSERT_CLOSE_BRACKET); } else if (localDeleteElement) { current.addStyledString(DELETE_CLOSE_BRACKET); } else if (merged || insideInsertMergeChain(getXmlElementNodeParent())) { current.addStyledString(MERGED_CLOSE_BRACKET); } else { current.addStyledString(CLOSE_BRACKET); } currentColor = Color.BLACK; return current; }
From source file:com.devoteam.srit.xmlloader.core.utils.XMLElementAVPParser.java
License:Open Source License
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception { List<Element> result; if (element.getName().equalsIgnoreCase("header") || element.getName().startsWith("send")) { result = xmlElementDefaultParser.replace(element, parameterPool); } else // <avp .../> {/*from w w w . ja v a 2s.c om*/ LinkedList list = new LinkedList<Element>(); List<Attribute> attributes; attributes = element.attributes(); int allowedParameterLength = -1; boolean hasParameter = false; for (Attribute attribute : attributes) { String value = attribute.getValue(); Matcher matcher = Parameter.pattern.matcher(value); while (matcher.find()) { String variableStr = matcher.group(); if (false == parameterPool.isConstant(variableStr)) { Parameter variable = parameterPool.get(variableStr); hasParameter = true; if (variable != null) { if (allowedParameterLength == -1 || allowedParameterLength == 1) { allowedParameterLength = variable.length(); } else if (variable.length() != 1 && allowedParameterLength != variable.length()) { throw new ExecutionException("Invalid length of variables : a variable of length " + allowedParameterLength + " has been found but " + variableStr + " has a length of " + variable.length()); } } } } } if (!hasParameter) { allowedParameterLength = 1; } for (int i = 0; i < allowedParameterLength; i++) { Element newElement = element.createCopy(); List<Attribute> newElementAttributes; newElementAttributes = newElement.attributes(); for (Attribute newAttribute : newElementAttributes) { String value = newAttribute.getValue(); Pattern pattern = Pattern.compile(Parameter.EXPRESSION); Matcher matcher = pattern.matcher(value); int offset = 0; while (matcher.find()) { String before = value.substring(0, matcher.end() + offset - 1); String after = value.substring(matcher.end() + offset - 1); if (parameterPool.exists(matcher.group())) { int index = i; if (parameterPool.get(matcher.group()).length() == 1) { index = 0; } value = before + "(" + index + ")" + after; offset += ((String) "(" + index + ")").length(); } } newAttribute.setValue(value); } List<Element> tempList = xmlElementDefaultParser.replace(newElement, parameterPool); try { for (Element e : tempList) { // MsgDiameterParser.getInstance().doDictionnary(e, "0", false); list.addAll(xmlElementTextOnlyParser.replace(e, parameterPool)); } } catch (Exception e) { throw new ExecutionException("Error while checking parsed variables against dictionary", e); } } result = list; } return result; }