public HashMap<String, String> parseInfoToGetUUID(String output, String queryURL, SAXBuilder builder) { HashMap<String, String> uidToUrlMap = new HashMap<>(); try { Document document = builder.build(new StringReader(output)); Element root = document.getRootElement(); List<Element> entries = root.getChildren("entry"); for (Element entry : entries) { uidToUrlMap.put(queryURL, entry.getChild("repository").getChild("uuid").getValue()); } } catch (Exception e) { throw new RuntimeException(e); } return uidToUrlMap; }
public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) { try { Document document = buildXmlDocument(xmlContent, CommandSnippet.class.getResource("command-snippet.xsd")); CommandSnippetComment comment = getComment(document); Element execTag = document.getRootElement(); String commandName = execTag.getAttributeValue("command"); List<String> arguments = new ArrayList<>(); for (Object child : execTag.getChildren()) { Element element = (Element) child; arguments.add(element.getValue()); } return new CommandSnippet(commandName, arguments, comment, fileName, relativeFilePath); } catch (Exception e) { String errorMessage = String.format("Reason: %s", e.getMessage()); LOGGER.info("Could not load command '{}'. {}", fileName, errorMessage); return CommandSnippet.invalid(fileName, errorMessage, new EmptySnippetComment()); } }
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());
private static List<String> getXPathValues(String xpathString, JXPathContext context) { List values = null; try { values = context.selectNodes(xpathString); } catch (RuntimeException e) { throw new RuntimeException("Error reading xpath " + xpathString, e); } List<String> ls = null; if (values == null) { ls = new ArrayList<String>(); } else { ls = new ArrayList<String>(values.size()); for (int i = 0; i < values.size(); i++) { Object value = values.get(i); String unwrappedValue = ""; if (value instanceof org.jdom2.Attribute) { unwrappedValue = ((org.jdom2.Attribute) value).getValue(); } else if (value instanceof org.jdom2.Element) { unwrappedValue = ((org.jdom2.Element) value).getValue(); } ls.add(unwrappedValue); } } return ls; } }
/** * @return the element value. * @see org.jdom2.Element#getValue() */ public String getValue() { return element.getValue(); }
/** * Parses the content of a minsize, maxsize or prefsize tag and converts it into an Dimension object. * @param pElement The tag element. * @return The specified size as a Dimension object. */ protected Dimension parseSizeTag(Element pElement) { String[] size = pElement.getValue().split(","); return new Dimension(Integer.parseInt(size[0]), Integer.parseInt(size[1])); }
private String get(XMLProperty p) { final Element child = getElement(p); if (child == null) { return ""; } return child.getValue(); }
private static String getVal(Element el, String nodeName) { try { return el.getChild(nodeName, BAMS).getValue(); } catch (Exception e) { // System.out.println(nodeName+" "+e); return null; } } }
static String getValue(Element root, String... childs) { Element element = root; int index = 0; while (element != null && index < childs.length) { String childName = childs[index++]; element = element.getChild(childName); } return element != null ? element.getValue() : null; }
private static String getElementString(final Element elem) { final Element value = elem.getChild("value"); return value.getValue(); }
private static int getElementInt(final Element elem) { final Element value = elem.getChild("value"); return Integer.parseInt(value.getValue()); }
private static double getElementDouble(final Element elem) { final Element value = elem.getChild("value"); return Double.parseDouble(value.getValue()); }
public void dump(PrintStream p, String indent) { String inner = indent + " "; p.println(indent + "<ContextMaker name='" + getName() + "'>"); for (Element e : contextValues) { p.println(indent+"<"+indent+e.getName()+">"+e.getValue()+"</"+indent+e.getName()+">"); } p.println(indent + "</ContextMaker>"); } }
private static double[] getElementArray(final Element elem) { final Element value = elem.getChild("value"); final Element ptr = value.getChild("parameter"); final Element val = ptr.getChild("value"); String str = val.getValue(); str = str.replace("[","").replace("]",""); return stringToDoubleArray(str, ","); }
protected List<String> parseRevision(URI resource, String requestUrl, Model model, ValueFactory valueFactory, Element revisions, Context context) throws RepositoryException { List<String> followUp = Collections.emptyList(); if (revisions == null) return followUp; final Element rev = revisions.getChild("rev"); if (rev == null) return followUp; final Resource subject = resource; if (context == Context.META && "0".equals(rev.getAttributeValue("parentid"))) { // This is the first revision, so we use the creation date addLiteralTriple(subject, Namespaces.NS_DC_TERMS + "created", rev.getAttributeValue("timestamp"), Namespaces.NS_XSD + "dateTime", model, valueFactory); } if (context == Context.CONTENT && rev.getValue() != null && rev.getValue().trim().length() > 0) { final String content = rev.getValue().trim(); final Matcher m = REDIRECT_PATTERN.matcher(content); if (((Element) revisions.getParent()).getAttribute("redirect") != null && m.find()) { followUp = Collections.singletonList(buildApiPropQueryUrl(requestUrl, m.group(1), "info", getDefaultParams("info", null), Context.REDIRECT)); } else { addLiteralTriple(subject, Namespaces.NS_RSS_CONTENT + "encoded", content, Namespaces.NS_XSD + "string", model, valueFactory); } } return followUp; }
private void readProperties(Representation resource, Element element) { List<Element> properties = element.getChildren(); for (Element property : properties) { if (!property.getName().matches("(link|resource)")) { if (property.getAttribute("nil", XSI_NAMESPACE) != null) { resource.withProperty(property.getName(), null); } else { resource.withProperty(property.getName(), property.getValue()); } } } }
static StoredValue readPropertyValue( final StoredConfigReference storedConfigReference, final Element settingElement ) { final String key = storedConfigReference.getRecordID(); LOGGER.trace( () -> "parsing property key=" + key + ", profile=" + storedConfigReference.getProfileID() ); if ( settingElement.getChild( StoredConfiguration.XML_ELEMENT_DEFAULT ) != null ) { return new StringValue( settingElement.getValue() ); } return null; }
public void run() { Thread.currentThread().setName(getName()); while (running()) { Object o = sp.in(in, timeout); if (o != null) { Context ctx = new Context(); ctx.put(contextName, o); if (contextValues != null) { for (Element e : contextValues) { ctx.put(e.getName(),e.getValue()); } } sp.out(out, ctx); } } }
@Override public void processContent(Book book, Key key, Element ele) { String refstr = ele.getValue(); try { if (ele.getAttribute(OSISUtil.OSIS_ATTR_REF) == null) { Passage ref = PassageKeyFactory.instance().getKey(KeyUtil.getVersification(key), refstr, key); String osisname = ref.getOsisRef(); ele.setAttribute(OSISUtil.OSIS_ATTR_REF, osisname); } } catch (NoSuchKeyException ex) { DataPolice.report(book, key, "scripRef has no passage attribute, unable to guess: (" + refstr + ") due to " + ex.getMessage()); } } }
@Test public void testGetCapabilites() throws IOException, JDOMException { String endpoint = TestOnLocalServer.withHttpPath(dataset1+"&request=GetCapabilities"); byte[] result = TestOnLocalServer.getContent(endpoint, 200, ContentType.xml); Reader in = new StringReader( new String(result, CDM.utf8Charset)); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(in); //XPathExpression<Element> xpath = XPathFactory.instance().compile("ns:/WCS_Capabilities/ContentMetadata/CoverageOfferingBrief", Filters.element(), null, NS_WCS); XPathExpression<Element> xpath = XPathFactory.instance().compile("//wcs:CoverageOfferingBrief", Filters.element(), null, NS_WCS); List<Element> elements = xpath.evaluate(doc); for (Element emt : elements) { logger.debug("XPath has result: {}", emt.getContent()); } assertEquals(7, elements.size()); XPathExpression<Element> xpath2 = XPathFactory.instance().compile("//wcs:CoverageOfferingBrief/wcs:name", Filters.element(), null, NS_WCS); List<String> names = new ArrayList<>(); for (Element elem : xpath2.evaluate(doc)) { logger.debug(" {}=={}", elem.getName(), elem.getValue()); names.add(elem.getValue()); } Assert.assertEquals(7, names.size()); assert names.contains("Relative_humidity_height_above_ground"); assert names.contains("Pressure_reduced_to_MSL"); }