List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:com.rometools.rome.io.impl.RSS20wNSParser.java
License:Open Source License
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); return defaultNS != null && defaultNS.equals(getRSSNamespace()) && super.isMyType(document); }
From source file:com.s13g.themetools.keystyler.controller.ThemeLoader.java
License:Apache License
/** * Parses the ZIP file and the skins.xml therein to produce the final Theme model file. * * @param themeFile the file that contains the theme. * @param skinsXml the skinsXML stream that contains the skin specification. * @return The valid Theme model, if the file could be parses, null otherwise. * @throws JDOMException if the skins.xml cannot be parsed. * @throws IOException if the theme file could not be read, */// w ww . j av a2 s .co m private static Theme parse(File themeFile, InputStream skinsXml) throws JDOMException, IOException { Document document = sSaxBuilder.build(skinsXml); if (document == null) { System.err.println("Could not get document - " + themeFile.getAbsolutePath()); return null; } Element root = document.getRootElement(); if (root == null) { System.err.println("Could not get root element - " + themeFile.getAbsolutePath()); return null; } String name = root.getAttributeValue("name"); ThemeStyle style = new ThemeStyle(); Element background = root.getChild("background"); Element backgroundImage = background.getChild("image"); // NOTE: According to the example, background can also have two colors defined instead of an // image. This currently does not support such themes. So we simply don't supply a background; if (backgroundImage != null) { style.setItemName(Entry.BACKGROUND_IMAGE, backgroundImage.getText()); } else { System.err.println("Theme does not have background/image. Skipping."); } Element keyBackground = root.getChild("key-background"); style.setItemName(Entry.KEY_BACKGROUND_NORMAL, keyBackground.getChildText("normal")); style.setItemName(Entry.KEY_BACKGROUND_PRESSED, keyBackground.getChildText("pressed")); Element modKeyBackground = root.getChild("mod-key-background"); style.setItemName(Entry.MOD_KEY_BACKGROUND_NORMAL, modKeyBackground.getChildText("normal")); style.setItemName(Entry.MOD_KEY_BACKGROUND_PRESSED, modKeyBackground.getChildText("pressed")); style.setItemName(Entry.MOD_KEY_BACKGROUND_NORMAL_OFF, modKeyBackground.getChildText("normal-off")); style.setItemName(Entry.MOD_KEY_BACKGROUND_PRESSED_OFF, modKeyBackground.getChildText("pressed-off")); style.setItemName(Entry.MOD_KEY_BACKGROUND_NORMAL_ON, modKeyBackground.getChildText("normal-on")); style.setItemName(Entry.MOD_KEY_BACKGROUND_PRESSED_ON, modKeyBackground.getChildText("pressed-on")); Element symbols = root.getChild("symbols"); style.setItemName(Entry.SYMBOLS_DELETE, symbols.getChildText("delete")); style.setItemName(Entry.SYMBOLS_RETURN, symbols.getChildText("return")); style.setItemName(Entry.SYMBOLS_SEARCH, symbols.getChildText("search")); style.setItemName(Entry.SYMBOLS_SHIFT, symbols.getChildText("shift")); style.setItemName(Entry.SYMBOLS_SHIFT_LOCKED, symbols.getChildText("shift-locked")); style.setItemName(Entry.SYMBOLS_SPACE, symbols.getChildText("space")); style.setItemName(Entry.SYMBOLS_MIC, symbols.getChildText("mic")); Element colors = root.getChild("colors"); style.setItemName(Entry.COLORS_LABEL, colors.getChildText("label")); style.setItemName(Entry.COLORS_ALT_LABEL, colors.getChildText("alt-label")); style.setItemName(Entry.COLORS_MOD_LABEL, colors.getChildText("mod-label")); return new Theme(name, themeFile, style); }
From source file:com.seleniumtests.util.squashta.TaScriptGenerator.java
License:Apache License
/** * Search for tests in TestNG files/*w ww . jav a2 s. co m*/ * @param path * @param application * @return */ public List<SquashTaTestDef> parseTestNgXml() { // look for feature file into data folder File dir = Paths.get(srcPath, "data", application, "testng").toFile(); if (!dir.exists()) { return new ArrayList<>(); } File[] testngFiles = dir.listFiles((d, filename) -> filename.endsWith(".xml")); List<SquashTaTestDef> testDefs = new ArrayList<>(); for (File testngFile : testngFiles) { Document doc; SAXBuilder sxb = new SAXBuilder(); sxb.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); try { doc = sxb.build(testngFile); } catch (Exception e) { logger.error(String.format("Fichier %s illisible: %s", testngFile, e.getMessage())); return testDefs; } Element suite = doc.getRootElement(); if (!"suite".equalsIgnoreCase(suite.getName())) { continue; } for (Element test : suite.getChildren("test")) { readTestTag(test, testDefs, testngFile); } } return testDefs; }
From source file:com.speedment.codgen.example.uml.Generate.java
License:Open Source License
public static void main(String... params) { final Generator gen = new JavaGenerator(new JavaTransformFactory(), new UMLTransformFactory()); final URL umlPath = Generate.class.getResource(PATH + "ExampleUML.cdg"); try {/*from w w w . java 2s . c o m*/ final SAXBuilder jdomBuilder = new SAXBuilder(); final Document doc = jdomBuilder.build(umlPath); final Element classDiagram = doc.getRootElement(); //gen.metaOn(classDiagram.getChild("ClassDiagramRelations").getChildren() System.out.println(gen.metaOn(classDiagram.getChild("ClassDiagramComponents").getChildren(), File.class) .map(Meta::getResult).flatMap(gen::metaOn).map(Meta::getResult) .collect(joining("\n----------------------------------\n"))); } catch (JDOMException ex) { Logger.getLogger(Generate.class.getName()).log(Level.SEVERE, "Failed to parse XML structure.", ex); } catch (IOException ex) { Logger.getLogger(Generate.class.getName()).log(Level.SEVERE, "Could not load file '" + umlPath.toExternalForm() + "'.", ex); } }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected void fillContentElement(Element contentElement, Content content) throws FeedException { if (content.getType() != null) { Attribute typeAttribute = new Attribute("type", content.getType()); contentElement.setAttribute(typeAttribute); }// w ww .jav a2 s . c om String mode = content.getMode(); if (mode != null) { Attribute modeAttribute = new Attribute("mode", content.getMode().toString()); contentElement.setAttribute(modeAttribute); } if (content.getValue() != null) { if (mode == null || mode.equals(Content.ESCAPED)) { contentElement.addContent(content.getValue()); } else if (mode.equals(Content.BASE64)) { contentElement.addContent(Base64.encode(content.getValue())); } else if (mode.equals(Content.XML)) { StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(content.getValue()); tmpDocString.append("</tmpdoc>"); StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (Exception ex) { throw new FeedException("Invalid XML", ex); } List children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } } }
From source file:com.sun.syndication.io.impl.Atom03Parser.java
License:Open Source License
public boolean isMyType(Document document) { Element rssRoot = document.getRootElement(); Namespace defaultNS = rssRoot.getNamespace(); return (defaultNS != null) && defaultNS.equals(getAtomNamespace()); }
From source file:com.sun.syndication.io.impl.Atom03Parser.java
License:Open Source License
public WireFeed parse(Document document, boolean validate) throws IllegalArgumentException, FeedException { if (validate) { validateFeed(document);/*www .jav a2 s.c o m*/ } Element rssRoot = document.getRootElement(); return parseFeed(rssRoot); }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
protected void fillContentElement(Element contentElement, Content content) throws FeedException { String type = content.getType(); String atomType = type;/* ww w . j a v a2s.co m*/ if (type != null) { // Fix for issue #39 "Atom 1.0 Text Types Not Set Correctly" // we're not sure who set this value, so ensure Atom types are used if ("text/plain".equals(type)) atomType = Content.TEXT; else if ("text/html".equals(type)) atomType = Content.HTML; else if ("application/xhtml+xml".equals(type)) atomType = Content.XHTML; Attribute typeAttribute = new Attribute("type", atomType); contentElement.setAttribute(typeAttribute); } String href = content.getSrc(); if (href != null) { Attribute srcAttribute = new Attribute("src", href); contentElement.setAttribute(srcAttribute); } if (content.getValue() != null) { if (atomType != null && (atomType.equals(Content.XHTML) || (atomType.indexOf("/xml")) != -1 || (atomType.indexOf("+xml")) != -1)) { StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(content.getValue()); tmpDocString.append("</tmpdoc>"); StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (Exception ex) { throw new FeedException("Invalid XML", ex); } List children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } else { // must be type html, text or some other non-XML format // JDOM will escape property for XML contentElement.addContent(content.getValue()); } } }
From source file:com.sun.syndication.io.impl.Atom10Generator.java
License:Open Source License
/** * Utility method to serialize an entry to writer. *///from www. ja v a 2 s. c o m public static void serializeEntry(Entry entry, Writer writer) throws IllegalArgumentException, FeedException, IOException { // Build a feed containing only the entry List entries = new ArrayList(); entries.add(entry); Feed feed1 = new Feed(); feed1.setFeedType("atom_1.0"); feed1.setEntries(entries); // Get Rome to output feed as a JDOM document WireFeedOutput wireFeedOutput = new WireFeedOutput(); Document feedDoc = wireFeedOutput.outputJDom(feed1); // Grab entry element from feed and get JDOM to serialize it Element entryElement = (Element) feedDoc.getRootElement().getChildren().get(0); XMLOutputter outputter = new XMLOutputter(); outputter.output(entryElement, writer); }
From source file:com.sun.syndication.io.impl.Atom10Parser.java
License:Open Source License
/** * Parse entry from reader.// www.j a v a 2 s . com */ public static Entry parseEntry(Reader rd, String baseURI) throws JDOMException, IOException, IllegalArgumentException, FeedException { // Parse entry into JDOM tree SAXBuilder builder = new SAXBuilder(); Document entryDoc = builder.build(rd); Element fetchedEntryElement = entryDoc.getRootElement(); fetchedEntryElement.detach(); // Put entry into a JDOM document with 'feed' root so that Rome can handle it Feed feed = new Feed(); feed.setFeedType("atom_1.0"); WireFeedOutput wireFeedOutput = new WireFeedOutput(); Document feedDoc = wireFeedOutput.outputJDom(feed); feedDoc.getRootElement().addContent(fetchedEntryElement); if (baseURI != null) { feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE); } WireFeedInput input = new WireFeedInput(); Feed parsedFeed = (Feed) input.build(feedDoc); return (Entry) parsedFeed.getEntries().get(0); }