/** * @since 1.4.5 */ public JDom2Reader(Document document, NameCoder nameCoder) { super(document.getRootElement(), nameCoder); }
/** * @since 1.4.5 */ public JDom2Reader(Document document) { super(document.getRootElement()); }
private List<Modification> parseDOMTree(Document document) throws ParseException { List<Modification> modifications = new ArrayList<>(); Element rootElement = document.getRootElement(); List logEntries = rootElement.getChildren("changeset"); for (Iterator iterator = logEntries.iterator(); iterator.hasNext();) { Element changeset = (Element) iterator.next(); modifications.add(parseChangeset(changeset)); } return modifications; }
protected void validateDocument(Document document) throws Exception { LOGGER.debug("[Config Save] In XSD validation: Starting."); writer.verifyXsdValid(document); LOGGER.debug("[Config Save] In XSD validation: Done."); LOGGER.debug("[Config Save] In DOM validation: Starting."); MagicalGoConfigXmlLoader.validateDom(document.getRootElement(), configElementImplementationRegistry); LOGGER.debug("[Config Save] In DOM validation: Done."); }
private List<Modification> parseDOMTree(Document document, String path) throws ParseException { List<Modification> modifications = new ArrayList<>(); Element rootElement = document.getRootElement(); List logEntries = rootElement.getChildren("logentry"); for (Iterator iterator = logEntries.iterator(); iterator.hasNext();) { Element logEntry = (Element) iterator.next(); Modification modification = parseLogEntry(logEntry, path); if (modification != null) { modifications.add(modification); } } return modifications; }
public Document documentFrom(CruiseConfig config) { Document document = createEmptyCruiseConfigDocument(); write(config, document.getRootElement(), configCache, registry); return document; }
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; }
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); } }
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 void write(CruiseConfig configForEdit, OutputStream output, boolean skipPreprocessingAndValidation) throws Exception { LOGGER.debug("[Serializing Config] Starting to write. Validation skipped? {}", skipPreprocessingAndValidation); MagicalGoConfigXmlLoader loader = new MagicalGoConfigXmlLoader(configCache, registry); if (!configForEdit.getOrigin().isLocal()) { throw new GoConfigInvalidException(configForEdit, "Attempted to save merged configuration with patials"); } if (!skipPreprocessingAndValidation) { loader.preprocessAndValidate(configForEdit); LOGGER.debug("[Serializing Config] Done with cruise config validators."); } Document document = createEmptyCruiseConfigDocument(); write(configForEdit, document.getRootElement(), configCache, registry); LOGGER.debug("[Serializing Config] XSD and DOM validation."); verifyXsdValid(document); MagicalGoConfigXmlLoader.validateDom(document.getRootElement(), registry); LOGGER.info("[Serializing Config] Generating config partial."); XmlUtils.writeXml(document, output); LOGGER.debug("[Serializing Config] Finished writing config partial."); }
private Element parseInputStream(InputStream inputStream) throws Exception { Element rootElement = buildXmlDocument(inputStream, GoConfigSchema.getCurrentSchema(), registry.xsds()).getRootElement(); validateDom(rootElement, registry); return rootElement; }
private Element elementFor(String content) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); return builder.build(new ByteArrayInputStream(content.getBytes())).getRootElement(); } }
private Element getRenderedDocument(HtmlRenderer renderer) throws JDOMException, IOException { String renderedString = "<div>" + renderer.asString() + "</div>"; return new SAXBuilder().build(new StringReader(renderedString)).getRootElement(); }
public <T> T fromXmlPartial(InputStream inputStream, Class<T> o) throws Exception { Document document = new SAXBuilder().build(inputStream); Element element = document.getRootElement(); return classParser(element, o, configCache, new GoCipher(), registry, new ConfigReferenceElements()).parse(); }
@Test public void exportPreferences_setsVersionToLatest() throws Exception { Document document = exportPreferences(false, Collections.<String>emptySet()); assertEquals(Integer.toString(Settings.VERSION), document.getRootElement().getAttributeValue("version")); }
@Test public void exportPreferences_exportsGlobalSettingsWhenRequested() throws Exception { Document document = exportPreferences(true, Collections.<String>emptySet()); assertNotNull(document.getRootElement().getChild("global")); }
@Test public void exportPreferences_ignoresGlobalSettingsWhenRequested() throws Exception { Document document = exportPreferences(false, Collections.<String>emptySet()); assertNull(document.getRootElement().getChild("global")); }
@Test public void exportPreferences_producesXML() throws Exception { Document document = exportPreferences(false, Collections.<String>emptySet()); assertEquals("k9settings", document.getRootElement().getName()); }
@Test public void exportPreferences_setsFormatTo1() throws Exception { Document document = exportPreferences(false, Collections.<String>emptySet()); assertEquals("1", document.getRootElement().getAttributeValue("format")); }