List of usage examples for org.jdom2 Element getValue
@Override
public String getValue()
From source file:com.github.theholywaffle.lolchatapi.LolStatus.java
License:Open Source License
/** * This constructor is not intended for usage. * //from www .j a v a 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.github.theholywaffle.lolchatapi.LolStatus.java
License:Open Source License
private String get(XMLProperty p) { final Element child = getElement(p); if (child == null) { return ""; }/*from ww w . j a v a2 s .co m*/ return child.getValue(); }
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); }//from ww w. j a v a 2 s . c om } } 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 {//from w ww .j av a2s . co 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 a v a 2 s. c om <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.UFTTestUtil.java
License:Open Source License
/** * Extract test description from UFT GUI test. * Note : UFT API test doesn't contain description * @param dirPath path of UFT test//from w ww . j a va2 s . com * @return test description */ public static String getTestDescription(FilePath dirPath) { String desc; try { if (!dirPath.exists()) { return null; } FilePath tspTestFile = new FilePath(dirPath, "Test.tsp"); InputStream is = new FileInputStream(tspTestFile.getRemote()); String xmlContent = decodeXmlContent(is); SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, null, null); Document document = saxBuilder.build(new StringReader(xmlContent)); Element rootElement = document.getRootElement(); Element descElement = rootElement.getChild("Description"); desc = descElement.getValue(); } catch (Exception e) { return null; } return desc; }
From source file:com.oagsoft.grafo.util.XMLLoader.java
public static Grafo leerArchivoXml(String nomArch) { SAXBuilder builder = new SAXBuilder(); Grafo g = null;// w ww. j a va2 s .com try { Document document = (Document) builder.build(new File(nomArch)); Element rootNode = document.getRootElement(); Element nV = rootNode.getChild("numero-vertices"); int numVertices = Integer.parseInt(nV.getValue().trim()); g = new Grafo(numVertices); Element ad = rootNode.getChild("adyacencias"); List<Element> hijos = ad.getChildren("adyacencia"); for (Element hijo : hijos) { int nIni = Integer.parseInt(hijo.getChildTextTrim("nodo-inicial")); int nFin = Integer.parseInt(hijo.getChildTextTrim("nodo-final")); g.adyacencia(nIni, nFin); } // System.out.println("Hay " + hijos.size()+ " adyacencias"); } catch (JDOMException | IOException ex) { System.out.println(ex.getMessage()); } return g; }
From source file:com.oagsoft.wazgle.tools.XMLLoader.java
public static Grafo<GraphicNode> leerArchivoXml(String nomArch) { SAXBuilder builder = new SAXBuilder(); Grafo<GraphicNode> g = null;/*w ww .j a va2 s. co m*/ try { Document document = (Document) builder.build(new File(nomArch)); Element rootNode = document.getRootElement(); Element nV = rootNode.getChild("numero-vertices"); int numVertices = Integer.parseInt(nV.getValue().trim()); g = new Grafo(numVertices); Element nodos = rootNode.getChild("nodos"); List<Element> hijos = nodos.getChildren("nodo"); for (Element hijo : hijos) { int id = Integer.parseInt(hijo.getChildTextTrim("id")); int coorX = Integer.parseInt(hijo.getChildTextTrim("coor-x")); int coorY = Integer.parseInt(hijo.getChildTextTrim("coor-y")); GraphicNode nodo = new GraphicNode(id, new Point(coorX, coorY), 10, false); g.adVertice(nodo); } Element adyacencias = rootNode.getChild("adyacencias"); List<Element> ad = adyacencias.getChildren("adyacencia"); for (Element hijo : ad) { int vIni = Integer.parseInt(hijo.getChildTextTrim("nodo-inicial")); int vFinal = Integer.parseInt(hijo.getChildTextTrim("nodo-final")); GraphicNode nIni = g.getVertice(vIni); GraphicNode nFin = g.getVertice(vFinal); g.adyacencia(nIni, nFin); } // System.out.println("Hay " + hijos.size()+ " adyacencias"); } catch (JDOMException | IOException ex) { System.out.println(ex.getMessage()); } return g; }
From source file:com.rometools.modules.itunes.io.ITunesParser.java
License:Open Source License
@Override public com.rometools.rome.feed.module.Module parse(final Element element, final Locale locale) { AbstractITunesObject module = null;/* w w w .j a v a 2 s .c o m*/ if (element.getName().equals("channel")) { final FeedInformationImpl feedInfo = new FeedInformationImpl(); module = feedInfo; // Now I am going to get the channel specific tags final Element owner = element.getChild("owner", ns); if (owner != null) { final Element name = owner.getChild("name", ns); if (name != null) { feedInfo.setOwnerName(name.getValue().trim()); } final Element email = owner.getChild("email", ns); if (email != null) { feedInfo.setOwnerEmailAddress(email.getValue().trim()); } } final Element image = element.getChild("image", ns); if (image != null && image.getAttributeValue("href") != null) { try { final URL imageURL = new URL(image.getAttributeValue("href").trim()); feedInfo.setImage(imageURL); } catch (final MalformedURLException e) { LOG.debug("Malformed URL Exception reading itunes:image tag: {}", image.getAttributeValue("href")); } } final List<Element> categories = element.getChildren("category", ns); for (final Element element2 : categories) { final Element category = element2; if (category != null && category.getAttribute("text") != null) { final Category cat = new Category(); cat.setName(category.getAttribute("text").getValue().trim()); final Element subcategory = category.getChild("category", ns); if (subcategory != null && subcategory.getAttribute("text") != null) { final Subcategory subcat = new Subcategory(); subcat.setName(subcategory.getAttribute("text").getValue().trim()); cat.setSubcategory(subcat); } feedInfo.getCategories().add(cat); } } } else if (element.getName().equals("item")) { final EntryInformationImpl entryInfo = new EntryInformationImpl(); module = entryInfo; // Now I am going to get the item specific tags final Element duration = element.getChild("duration", ns); if (duration != null && duration.getValue() != null) { final Duration dur = new Duration(duration.getValue().trim()); entryInfo.setDuration(dur); } } if (module != null) { // All these are common to both Channel and Item final Element author = element.getChild("author", ns); if (author != null && author.getText() != null) { module.setAuthor(author.getText()); } final Element block = element.getChild("block", ns); if (block != null) { module.setBlock(true); } final Element explicit = element.getChild("explicit", ns); if (explicit != null && explicit.getValue() != null && explicit.getValue().trim().equalsIgnoreCase("yes")) { module.setExplicit(true); } final Element keywords = element.getChild("keywords", ns); if (keywords != null) { final StringTokenizer tok = new StringTokenizer(getXmlInnerText(keywords).trim(), ","); final String[] keywordsArray = new String[tok.countTokens()]; for (int i = 0; tok.hasMoreTokens(); i++) { keywordsArray[i] = tok.nextToken(); } module.setKeywords(keywordsArray); } final Element subtitle = element.getChild("subtitle", ns); if (subtitle != null) { module.setSubtitle(subtitle.getTextTrim()); } final Element summary = element.getChild("summary", ns); if (summary != null) { module.setSummary(summary.getTextTrim()); } } return module; }
From source file:com.thoughtworks.go.config.ConfigCipherUpdater.java
License:Apache License
public void migrate() { File cipherFile = systemEnvironment.getDESCipherFile(); String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(timeProvider.currentTime()); File backupCipherFile = new File(systemEnvironment.getConfigDir(), "cipher.original." + timestamp); File configFile = new File(systemEnvironment.getCruiseConfigFile()); File backupConfigFile = new File(configFile.getParentFile(), configFile.getName() + ".original." + timestamp); try {//from w w w .j a v a 2 s . com if (!cipherFile.exists() || !FileUtils.readFileToString(cipherFile, UTF_8).equals(FLAWED_VALUE)) { return; } LOGGER.info("Found unsafe cipher {} on server, Go will make an attempt to rekey", FLAWED_VALUE); FileUtils.copyFile(cipherFile, backupCipherFile); LOGGER.info("Old cipher was successfully backed up to {}", backupCipherFile.getAbsoluteFile()); FileUtils.copyFile(configFile, backupConfigFile); LOGGER.info("Old config was successfully backed up to {}", backupConfigFile.getAbsoluteFile()); String oldCipher = FileUtils.readFileToString(backupCipherFile, UTF_8); new DESCipherProvider(systemEnvironment).resetCipher(); String newCipher = FileUtils.readFileToString(cipherFile, UTF_8); if (newCipher.equals(oldCipher)) { LOGGER.warn("Unable to generate a new safe cipher. Your cipher is unsafe."); FileUtils.deleteQuietly(backupCipherFile); FileUtils.deleteQuietly(backupConfigFile); return; } Document document = new SAXBuilder().build(configFile); List<String> encryptedAttributes = Arrays.asList("encryptedPassword", "encryptedManagerPassword"); List<String> encryptedNodes = Arrays.asList("encryptedValue"); XPathFactory xPathFactory = XPathFactory.instance(); for (String attributeName : encryptedAttributes) { XPathExpression<Element> xpathExpression = xPathFactory .compile(String.format("//*[@%s]", attributeName), Filters.element()); List<Element> encryptedPasswordElements = xpathExpression.evaluate(document); for (Element element : encryptedPasswordElements) { Attribute encryptedPassword = element.getAttribute(attributeName); encryptedPassword.setValue(reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), encryptedPassword.getValue())); LOGGER.debug("Replaced encrypted value at {}", element.toString()); } } for (String nodeName : encryptedNodes) { XPathExpression<Element> xpathExpression = xPathFactory.compile(String.format("//%s", nodeName), Filters.element()); List<Element> encryptedNode = xpathExpression.evaluate(document); for (Element element : encryptedNode) { element.setText( reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), element.getValue())); LOGGER.debug("Replaced encrypted value at {}", element.toString()); } } try (FileOutputStream fileOutputStream = new FileOutputStream(configFile)) { XmlUtils.writeXml(document, fileOutputStream); } LOGGER.info("Successfully re-encrypted config"); } catch (Exception e) { LOGGER.error("Re-keying of cipher failed with error: [{}]", e.getMessage(), e); if (backupCipherFile.exists()) { try { FileUtils.copyFile(backupCipherFile, cipherFile); } catch (IOException e1) { LOGGER.error( "Could not replace the cipher file [{}] with original one [{}], please do so manually. Error: [{}]", cipherFile.getAbsolutePath(), backupCipherFile.getAbsolutePath(), e.getMessage(), e); bomb(e1); } } } }