List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:com.tactfactory.harmony.ProjectContext.java
License:Open Source License
/** * Extract Project NameSpace from AndroidManifest file. * * @param manifest Manifest File// w w w.ja va 2 s.co m * @return Project Name Space */ public static void loadNameSpaceFromManifest(final File manifest) { String result = null; SAXBuilder builder; Document doc; if (manifest.exists()) { // Make engine builder = new SAXBuilder(); try { // Load XML File doc = builder.build(manifest); // Load Root element final Element rootNode = doc.getRootElement(); // Get Name Space from package declaration result = rootNode.getAttributeValue("package"); result = result.replaceAll("\\.", HarmonyContext.DELIMITER); } catch (final JDOMException e) { ConsoleUtils.displayError(e); } catch (final IOException e) { ConsoleUtils.displayError(e); } } if (result != null) { ApplicationMetadata.INSTANCE.setProjectNameSpace(result.trim()); } }
From source file:com.tactfactory.harmony.ProjectContext.java
License:Open Source License
/** * Extract Project Name from configuration file. * * @param config Configuration file/* w w w . j av a2 s . co m*/ * @return Project Name Space */ public static void loadProjectNameFromConfig(final File config) { String result = null; SAXBuilder builder; Document doc; if (config.exists()) { // Make engine builder = new SAXBuilder(); try { // Load XML File doc = builder.build(config); // Load Root element final Element rootNode = doc.getRootElement(); result = rootNode.getAttribute("name").getValue(); } catch (final JDOMException e) { ConsoleUtils.displayError(e); } catch (final IOException e) { ConsoleUtils.displayError(e); } } if (result != null) { ApplicationMetadata.INSTANCE.setName(result.trim()); } }
From source file:com.thoughtworks.go.config.FullConfigSaveFlow.java
License:Apache License
protected void validateDocument(Document document) throws Exception { LOGGER.debug("[Config Save] In XSD validation: Starting."); writer.verifyXsdValid(document);//from ww w .j a v a 2s.com 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."); }
From source file:com.thoughtworks.go.config.GoConfigMigration.java
License:Apache License
private int getCurrentSchemaVersion(String content) { try {// ww w . j av a 2s . co m 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); } }
From source file:com.thoughtworks.go.config.MagicalGoConfigXmlLoader.java
License:Apache License
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();/* w w w . j av a 2 s . co m*/ }
From source file:com.thoughtworks.go.config.MagicalGoConfigXmlWriter.java
License:Apache License
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"); }/*www .ja v a2s . c om*/ 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."); }
From source file:com.thoughtworks.go.config.MagicalGoConfigXmlWriter.java
License:Apache License
public Document documentFrom(CruiseConfig config) { Document document = createEmptyCruiseConfigDocument(); write(config, document.getRootElement(), configCache, registry); return document; }
From source file:com.thoughtworks.go.domain.materials.mercurial.HgModificationSplitter.java
License:Apache License
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)); }//from ww w . j a v a 2 s . c o m return modifications; }
From source file:com.thoughtworks.go.server.service.lookups.CommandSnippetXmlParser.java
License:Apache License
public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) { try {// w ww. ja v a2s . c om 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()); } }
From source file:com.thoughtworks.go.util.SvnLogXmlParser.java
License:Apache License
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); }/*from w w w. ja va 2 s . com*/ } return modifications; }