List of usage examples for org.jdom2 Element getName
public String getName()
From source file:com.github.lucapino.sheetmaker.renderer.SettingsElement.java
public SettingsElement(Element settingsElement) { this.name = settingsElement.getName(); this.separator = settingsElement.getAttributeValue(SEPARATOR); this.maximumValues = settingsElement.getAttributeValue(MAXIMUM_VALUES); }
From source file:com.github.lucapino.sheetmaker.renderer.TemplateSettings.java
public TemplateSettings(Element settingsElement) { for (Element setting : settingsElement.getChildren()) { SettingsElement element = new SettingsElement(setting); settingsElements.put(setting.getName(), element); }/*www. ja v a2 s .co m*/ starsRatingFilename = settingsElement.getChild(RATING).getAttributeValue(RATING_FILENAME); }
From source file:com.github.theholywaffle.lolchatapi.LolStatus.java
License:Open Source License
/** * This constructor is not intended for usage. * /*from ww w . j a va 2 s .c o m*/ * @param xml * An XML string * @throws JDOMException * Is thrown when the xml string is invalid * @throws IOException * Is thrown when the xml string is invalid */ public LolStatus(String xml) throws JDOMException, IOException { outputter.setFormat(outputter.getFormat().setExpandEmptyElements(false)); final SAXBuilder saxBuilder = new SAXBuilder(); doc = saxBuilder.build(new StringReader(xml)); for (final Element e : doc.getRootElement().getChildren()) { boolean found = false; for (final XMLProperty p : XMLProperty.values()) { if (p.name().equals(e.getName())) { found = true; } } if (!found) { System.err.println( "XMLProperty \"" + e.getName() + "\" value: \"" + e.getValue() + "\" not implemented yet!"); } } }
From source file:com.hp.application.automation.tools.octane.actions.UFTParameterFactory.java
License:Apache License
public static String convertResourceMtrAsJSON(InputStream resourceMtrInputStream) throws IOException { //TODO: Check is exists poiFS = new POIFSFileSystem(resourceMtrInputStream); DirectoryNode root = poiFS.getRoot(); for (Entry entry : root) { String name = entry.getName(); if (name.equals("ComponentInfo")) { if (entry instanceof DirectoryEntry) { System.out.println(entry); } else if (entry instanceof DocumentEntry) { byte[] content = new byte[((DocumentEntry) entry).getSize()]; poiFS.createDocumentInputStream("ComponentInfo").read(content); String fromUnicodeLE = StringUtil.getFromUnicodeLE(content); xmlData = fromUnicodeLE.substring(fromUnicodeLE.indexOf('<')).replaceAll("\u0000", ""); // System.out.println(xmlData); }// ww w .j av a 2s . c o m } } try { SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, (SAXHandlerFactory) null, (JDOMFactory) null); Document document = null; document = saxBuilder.build(new StringReader(xmlData)); Element classElement = document.getRootElement(); List<Element> studentList = classElement.getChildren(); ObjectMapper mapper = new ObjectMapper(); ArrayList<UFTParameter> uftParameters = new ArrayList<UFTParameter>(); UFTParameter uftParameter = new UFTParameter(); for (int temp = 0; temp < studentList.size(); temp++) { Element tag = studentList.get(temp); if ("ArgumentsCollection".equalsIgnoreCase(tag.getName())) { List<Element> children = tag.getChildren(); for (int i = 0; i < children.size(); i++) { Element element = children.get(i); List<Element> elements = element.getChildren(); for (int j = 0; j < elements.size(); j++) { Element element1 = elements.get(j); switch (element1.getName()) { case "ArgName": uftParameter.setArgName(element1.getValue()); break; case "ArgDirection": uftParameter.setArgDirection(Integer.parseInt(element1.getValue())); break; case "ArgDefaultValue": uftParameter.setArgDefaultValue(element1.getValue()); break; case "ArgType": uftParameter.setArgType(element1.getValue()); break; case "ArgIsExternal": uftParameter.setArgIsExternal(Integer.parseInt(element1.getValue())); break; default: logger.warning( String.format("Element name %s didn't match any case", element1.getName())); break; } } uftParameters.add(uftParameter); } return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(uftParameters); } } } catch (Exception e) { logger.severe(e.getMessage()); } return null; }
From source file:com.hpe.application.automation.tools.octane.actions.UFTParameterFactory.java
License:Open Source License
public static String convertResourceMtrAsJSON(InputStream resourceMtrInputStream) throws IOException { //String QTPFileParameterFileName = "resource.mtr"; //InputStream is = paths.get(0).getParent().child("Action0").child(QTPFileParameterFileName).read(); String xmlData = UFTTestUtil.decodeXmlContent(resourceMtrInputStream); try {//w w w.j a v a2 s . c o m SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, null, null); Document document = saxBuilder.build(new StringReader(xmlData)); Element rootElement = document.getRootElement(); List<Element> rootChildrenElements = rootElement.getChildren(); ArrayList<UFTParameter> uftParameters = new ArrayList<>(); for (int temp = 0; temp < rootChildrenElements.size(); temp++) { Element tag = rootChildrenElements.get(temp); if ("ArgumentsCollection".equalsIgnoreCase(tag.getName())) { List<Element> children = tag.getChildren(); for (int i = 0; i < children.size(); i++) { UFTParameter uftParameter = new UFTParameter(); Element element = children.get(i); List<Element> elements = element.getChildren(); for (int j = 0; j < elements.size(); j++) { Element element1 = elements.get(j); switch (element1.getName()) { case "ArgName": uftParameter.setArgName(element1.getValue()); break; case "ArgDirection": uftParameter.setArgDirection(Integer.parseInt(element1.getValue())); break; case "ArgDefaultValue": uftParameter.setArgDefaultValue(element1.getValue()); break; case "ArgType": uftParameter.setArgType(element1.getValue()); break; case "ArgIsExternal": uftParameter.setArgIsExternal(Integer.parseInt(element1.getValue())); break; default: logger.warning( String.format("Element name %s didn't match any case", element1.getName())); break; } } uftParameters.add(uftParameter); } ObjectMapper mapper = new ObjectMapper(); String result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(uftParameters); return result; } } } catch (Exception e) { logger.severe(e.getMessage()); } return null; }
From source file:com.hpe.application.automation.tools.octane.actions.UFTParameterFactory.java
License:Open Source License
public static Collection<UFTParameter> convertApiTestXmlToArguments(File parametersFile, boolean isInputParameters) throws IOException { /*<TestParameters> <Schema>//w w w .j av a 2 s.c o m <xsd:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:types="http://hp.vtd.schemas/types/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xs:import schemaLocation="../../../dat/schemas/Types.xsd" namespace="http://hp.vtd.schemas/types/v1.0" /> <xs:element types:displayName="Parameters" name="Arguments"> <xs:complexType> <xs:sequence> <xs:element types:masked="false" name="StartParam1" type="xs:long"> <xs:annotation> <xs:documentation /> </xs:annotation> </xs:element> <xs:element types:masked="false" name="endParam1" type="xs:string"> <xs:annotation> <xs:documentation /> </xs:annotation> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xsd:schema> </Schema> <Values> <Arguments> <StartParam1>1</StartParam1> <endParam1>f</endParam1> </Arguments> </Values> </TestParameters>*/ try { SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, null, null); Document document = saxBuilder.build(parametersFile); Element rootElement = document.getRootElement(); Map<String, UFTParameter> uftParametersMap = new HashMap<>(); List<Element> argElements = getHierarchyChildElement(rootElement, "Schema", "schema", "element", "complexType", "sequence").getChildren(); for (Element argElement : argElements) { String name = argElement.getAttributeValue("name"); String type = argElement.getAttributeValue("type").replace("xs:", ""); int direction = isInputParameters ? 0 : 1; UFTParameter parameter = new UFTParameter(); parameter.setArgName(name); parameter.setArgType(type); parameter.setArgDirection(direction); uftParametersMap.put(parameter.getArgName(), parameter); } //getArg default values List<Element> argDefValuesElements = getHierarchyChildElement(rootElement, "Values", "Arguments") .getChildren(); for (Element argElement : argDefValuesElements) { UFTParameter parameter = uftParametersMap.get(argElement.getName()); if (parameter != null) { parameter.setArgDefaultValue(argElement.getValue()); } } return uftParametersMap.values(); } catch (Exception e) { logger.severe(e.getMessage()); } return Collections.emptySet(); }
From source file:com.hpe.application.automation.tools.octane.actions.UFTParameterFactory.java
License:Open Source License
private static Element getHierarchyChildElement(Element root, String... childPath) { Element parent;// w ww.ja va 2s .c o m Element found = root; for (int i = 0; i < childPath.length; i++) { parent = found; found = null; String elementName = childPath[i]; for (Element child : parent.getChildren()) { if (child.getName().equals(elementName)) { found = child; break; } } } return found; }
From source file:com.init.octo.schema.XsdAll.java
License:Open Source License
/** * This method builds a ALL element/*from w ww . j av a 2s . co m*/ * * @param root - the ALL element that defines this element * @param cache - a list of pre-defined XML types */ public boolean build(Element root, XSDCache cache, String parentName) { log.debug("" + indent + ": " + "Build representation of a ALL"); id = root.getAttributeValue(XSDSchema.ID_ATT); maxOccurs = root.getAttributeValue(XSDSchema.MAXOCCURS_ATT); minOccurs = root.getAttributeValue(XSDSchema.MINOCCURS_ATT); group = new LinkedList<XMLType>(); Element element; String elementName; for (Iterator<?> i = (root.getChildren()).iterator(); i.hasNext();) { element = (Element) i.next(); elementName = element.getName(); log.debug("" + indent + ": " + "Child element <" + elementName + "> found"); /** process the child elements that define this element... **/ if (elementName.equals(XSDSchema.ANNOTATION)) { annotation = element.getTextTrim(); } else if (elementName.equals(XSDSchema.ELEMENT)) { log.debug("" + indent + ": " + "Adding element to the list of child elements"); XSDElement e = new XSDElement(indent + 1); if (e.build(element, cache, parentName) != true) { log.error("Error building an element - " + element); return (false); } group.add(e); } else { log.warn("" + indent + ": " + "Unexpected element <" + elementName + "> found and ignored"); } } // end for all child elements of this <ALL> tag log.debug("" + indent + ": " + "ALL built"); return (true); }
From source file:com.init.octo.schema.XSDAttribute.java
License:Open Source License
/** * This method builds the element definition * * @param root - the schema element that defines this element * @param cache - a list of pre-defined XML types *//*from www .ja v a2 s .c om*/ //log.debug("Build representation of an Attribute"); public boolean build(Element root, XSDCache cache, String parentName) { this.parentName = parentName; name = root.getAttributeValue(XSDSchema.NAME_ATT); ref = root.getAttributeValue(XSDSchema.REF_ATT); type = root.getAttributeValue(XSDSchema.TYPE_ATT); defaultAtt = root.getAttributeValue(XSDSchema.DEFAULT_ATT); use = root.getAttributeValue(XSDSchema.USE_ATT); if (use == null) { use = "optional"; } if (defaultAtt == null) { defaultAtt = ""; } if (notEmpty(name)) { cache.putAttribute(name, this); } if (notEmpty(ref)) { XSDAttribute refAtt = (XSDAttribute) cache.getAttribute(ref); if (refAtt == null) { log.warn("Referenced attribute not found [" + ref + "]"); return (true); } name = refAtt.getName(); use = refAtt.getUse(); defaultAtt = refAtt.getDefault(); type = refAtt.getType(); return (true); } for (Element child : root.getChildren()) { String childElementType = child.getName(); if (childElementType.equals(XSDSchema.ANNOTATION)) { annotation = child.getTextTrim(); } else if (childElementType.equals(XSDSchema.SIMPLETYPE)) { if (elementType != null) { throw new XmlSchemaException("Cannot define the type of an attribute more than once"); } elementType = new XSDElementTypeSimple(); elementType.build(child, cache, parentName); } } // end for all child elements of this <element> tag log.debug("Attribute built"); return true; }
From source file:com.init.octo.schema.XSDAttributeGroup.java
License:Open Source License
/** * This method builds the element definition * * @param root// ww w. ja va2 s . c o m * - the schema element that defines this element * @param cache * - a list of pre-defined XML types */ public boolean build(Element root, XSDCache cache, String parentName) { log.debug("Build representation of an AttributeGroup"); id = root.getAttributeValue(XSDSchema.ID_ATT); name = root.getAttributeValue(XSDSchema.NAME_ATT); ref = root.getAttributeValue(XSDSchema.REF_ATT); if (name != null && name.equals("") == false) { cache.putAttributeGroup(name, this); } if (ref != null && ref.equals("") == false) { XSDAttributeGroup refAttGroup = (XSDAttributeGroup) cache.getAttributeGroup(ref); if (refAttGroup == null) { log.debug("Referenced attribute group not found [" + ref + "]"); return (true); } attributeList = refAttGroup.getAttributeList(); return (true); } log.debug("AttributeGroup <" + name + ">"); Element element; String elementName; attributeList = new ArrayList<XSDAttributeType>(); for (Iterator<?> i = (root.getChildren()).iterator(); i.hasNext();) { element = (Element) i.next(); elementName = element.getName(); log.debug("Child element <" + elementName + "> found"); /** process the child elements that define this element... **/ if (elementName.equals(XSDSchema.ANNOTATION)) { } else if (elementName.equals(XSDSchema.ATTRIBUTE)) { XSDAttribute attribute = new XSDAttribute(); if (attribute.build(element, cache, parentName) != true) { log.error("Error building an attribute object"); return (false); } attributeList.add(attribute); } else if (elementName.equals(XSDSchema.ATTRIBUTEGROUP)) { XSDAttributeGroup group = new XSDAttributeGroup(); if (group.build(element, cache, parentName) != true) { log.error("Error building a sub-attribute-group object"); return (false); } attributeList.add(group); } else { log.warn("Unexpected element <" + elementName + "> found and ignored"); } } // end for all child elements of this <element> tag log.debug("Attribute built"); return (true); }