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; }
private int getCurrentSchemaVersion(String content) { try { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new ByteArrayInputStream(content.getBytes())); Element root = document.getRootElement(); String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion); return Integer.parseInt(currentVersion); } catch (Exception e) { throw bomb(e); } }
@SuppressWarnings( "unchecked" ) private void appendElement( Element source, Element target ) { for ( Iterator<Attribute> itr = source.getAttributes().iterator(); itr.hasNext(); ) { Attribute a = itr.next(); itr.remove(); Attribute mergedAtt = target.getAttribute( a.getName(), a.getNamespace() ); if ( mergedAtt == null ) { target.setAttribute( a ); } } for ( Iterator<Element> itr = source.getChildren().iterator(); itr.hasNext(); ) { Content n = itr.next(); itr.remove(); target.addContent( n ); } }
private void addBreakers(Element element) { Element messages = new Element("messages"); Element message = new Element("message"); String breakerNames = StringUtils.join(breakers, ", "); message.setAttribute("text", breakerNames); message.setAttribute("kind", "Breakers"); messages.addContent(message); element.addContent(messages); }
private void parseDOMTree(Document document) throws UnsupportedEncodingException { Element infoElement = document.getRootElement(); Element entryElement = infoElement.getChild("entry"); String encodedUrl = entryElement.getChildTextTrim("url"); Element repositoryElement = entryElement.getChild("repository"); String root = repositoryElement.getChildTextTrim("root"); String encodedPath = StringUtils.replace(encodedUrl, root, ""); this.path = URLDecoder.decode(encodedPath, ENCODING); this.root = root; this.encodedUrl = encodedUrl; }
private void writeOneEntry( InvDataset ds, OutputStream out, StringBuffer mess) throws IOException { Element rootElem = new Element("DIF", defNS); Document doc = new Document(rootElem); writeDataset( ds, rootElem, mess); rootElem.addNamespaceDeclaration(defNS); rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS); rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS); // Output the document, use standard formatter XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat()); fmt.output( doc, out); }
public static void loadFormat(String folderPath, List<MessageObject> list) throws JDOMException, IOException{ File file = FileUtil.getFile(folderPath); if(!file.exists() || file.isFile()){ return ; } folderPath = file.getPath(); String[] xmlFileNames = file.list(); for(String xmlFileName : xmlFileNames){ Document doc = new SAXBuilder().build(new File(folderPath, xmlFileName)); Element root = doc.getRootElement(); if(!"messages".equals(root.getName())){ continue; } for(Element message : root.getChildren()){ list.add(new MessageObject(message)); } } } }
public GeniaPosParser(File xmlFile) throws IOException, JDOMException { this(); SAXBuilder builder = new SAXBuilder(); builder.setDTDHandler(null); root = builder.build(xmlFile).getRootElement(); articles = root.getChildren("article").iterator(); outputter = new XMLOutputter(); }
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Attribute version = rssRoot.getAttribute("version"); return rssRoot.getName().equals("rss") && version != null && version.getValue().equals(getRSSVersion()); }
private static double[] readCalibration( final File source ) throws JDOMException, IOException { final SAXBuilder sb = new SAXBuilder(); final Document document = sb.build( source ); final Element root = document.getRootElement(); final double[] calibration = new double[ 3 ]; final Element settings = root.getChild( "Settings" ); final Element imageData = settings.getChild( "ImageData" ); calibration[ 0 ] = imageData.getAttribute( "pixelwidth" ).getDoubleValue(); calibration[ 1 ] = imageData.getAttribute( "pixelheight" ).getDoubleValue(); calibration[ 2 ] = imageData.getAttribute( "voxeldepth" ).getDoubleValue(); return calibration; }
private Modification parseLogEntry(Element logEntry, String path) throws ParseException { Element logEntryPaths = logEntry.getChild("paths"); if (logEntryPaths == null) { /* Path-based access control forbids us from learning * details of this log entry, so skip it. */ return null; } Date modifiedTime = convertDate(logEntry.getChildText("date")); String author = logEntry.getChildText("author"); String comment = logEntry.getChildText("msg"); String revision = logEntry.getAttributeValue("revision"); Modification modification = new Modification(author, comment, null, modifiedTime, revision); List paths = logEntryPaths.getChildren("path"); for (Iterator iterator = paths.iterator(); iterator.hasNext();) { Element node = (Element) iterator.next(); if (underPath(path, node.getText())) { ModifiedAction action = convertAction(node.getAttributeValue("action")); modification.createModifiedFile(node.getText(), null, action); } } return modification; }
public void readTable() throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(); doc = builder.build(robbxml); Element root = doc.getRootElement(); int count = makeTable(root.getChildren("sequence")); System.out.println(" robb count= "+count); } catch (JDOMException e) { throw new IOException(e.getMessage()); } }
return; Document document = new SAXBuilder().build(configFile); List<String> encryptedAttributes = Arrays.asList("encryptedPassword", "encryptedManagerPassword"); List<String> encryptedNodes = Arrays.asList("encryptedValue"); 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()); 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());
SAXBuilder builder = new SAXBuilder(); builder.setExpandEntities(false); Document document = builder.build(inputStream); Element root = document.getRootElement(); List<Element> serviceExceptions = root.getChildren("ServiceException");
private boolean isGetCoverageWcsDoc(String url) throws JDOMException, IOException { byte[] result = TestOnLocalServer.getContent(url+baloney+"&request=GetCapabilities", 200, ContentType.xml); Reader in = new StringReader( new String(result, CDM.utf8Charset)); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(in); boolean isName = doc.getRootElement().getName().equals("WCS_Capabilities"); boolean isNamespace = doc.getRootElement().getNamespaceURI().equals(NS_WCS.getURI()); return (isName && isNamespace); }
@Test public void shouldListAllArtifactsWhenArtifactsNotPurged() throws Exception { HtmlRenderer renderer = new HtmlRenderer("context"); DirectoryEntries directoryEntries = new DirectoryEntries(); directoryEntries.add(new FolderDirectoryEntry("cruise-output", "", new DirectoryEntries())); directoryEntries.add(new FolderDirectoryEntry("some-artifact", "", new DirectoryEntries())); directoryEntries.render(renderer); Element document = getRenderedDocument(renderer); assertThat(document.getChildren().size(), is(2)); Element cruiseOutputElement = (Element) document.getChildren().get(0); assertThat(cruiseOutputElement.getChild("div").getChild("span").getChild("a").getTextNormalize(), is("cruise-output")); Element artifactElement = (Element) document.getChildren().get(1); assertThat(artifactElement.getChild("div").getChild("span").getChild("a").getTextNormalize(), is("some-artifact")); }
private static Element elementFor(Class<?> aClass, ConfigCache configCache) { final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(aClass, AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null) { final Element element = new Element(attributeAwareConfigTag.value(), namespaceFor(attributeAwareConfigTag)); element.setAttribute(attributeAwareConfigTag.attribute(), attributeAwareConfigTag.attributeValue()); return element; } ConfigTag configTag = annotationFor(aClass, ConfigTag.class); if (configTag == null) throw bomb(format("Cannot get config tag for {0}", aClass)); return new Element(configTag.value(), namespaceFor(configTag)); }
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()); } }
public String peekNextChild() { List list = currentElement.getChildren(); if (null == list || list.isEmpty()) { return null; } return decodeNode(((Element) list.get(0)).getName()); } }
private Document createEmptyCruiseConfigDocument() { Element root = new Element("cruise"); Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS); root.addNamespaceDeclaration(xsiNamespace); registry.registerNamespacesInto(root); root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace); String xsds = registry.xsds(); if (!xsds.isEmpty()) { root.setAttribute("schemaLocation", xsds, xsiNamespace); } root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION)); return new Document(root); }