List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname)
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 w w .j a v a 2s . c om 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.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 ww.j a va 2 s .co 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.RSS091UserlandGenerator.java
License:Open Source License
protected void checkChannelConstraints(Element eChannel) throws FeedException { checkNotNullAndLength(eChannel, "title", 1, 100); checkNotNullAndLength(eChannel, "description", 1, 500); checkNotNullAndLength(eChannel, "link", 1, 500); checkNotNullAndLength(eChannel, "language", 2, 5); checkLength(eChannel, "rating", 20, 500); checkLength(eChannel, "copyright", 1, 100); checkLength(eChannel, "pubDate", 1, 100); checkLength(eChannel, "lastBuildDate", 1, 100); checkLength(eChannel, "docs", 1, 500); checkLength(eChannel, "managingEditor", 1, 100); checkLength(eChannel, "webMaster", 1, 100); Element skipHours = eChannel.getChild("skipHours"); if (skipHours != null) { List hours = skipHours.getChildren(); for (int i = 0; i < hours.size(); i++) { Element hour = (Element) hours.get(i); int value = Integer.parseInt(hour.getText().trim()); if (isHourFormat24()) { if ((value < 1) || (value > 24)) { throw new FeedException("Invalid hour value " + value + ", it must be between 1 and 24"); }//ww w .j a v a 2 s . co m } else { if ((value < 0) || (value > 23)) { throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23"); } } } } }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
public void addActivity(ManifestActivity activity) { ConsoleUtils.displayDebug(String.format("Add activity %s to manifest.", activity.getName())); // Load Root element final Element rootNode = this.getDocument().getRootElement(); // Load Name space (required for manipulate attributes) final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); // Find Application Node Element findActivity = null;/*from ww w. j av a 2s . c om*/ // Find a element final Element applicationNode = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION); if (applicationNode != null) { findActivity = this.findActivityNamed(activity.getName(), ns); // If not found Node, create it if (findActivity == null) { applicationNode.addContent(activity.toElement(ns)); // Clean manifest applicationNode.sortChildren(ABC_COMPARATOR); } } }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Sets the application-level theme./*from w w w. j ava 2s . c o m*/ * @param theme The theme to set */ public void setApplicationTheme(String theme) { final Element rootNode = this.getDocument().getRootElement(); final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION); appElem.setAttribute(ManifestConstants.ATTRIBUTE_THEME, theme, ns); }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Adds a service to the manifest.//from w w w . j a va 2 s . com * @param serviceName The service name * @param label The service label * @param exported If the service is exported */ public void addService(final String serviceName, final String label, final boolean exported) { // Load Root element final Element rootNode = this.getDocument().getRootElement(); // Load Name space (required for manipulate attributes) final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION); boolean setService = true; for (Element elem : appElem.getChildren(ManifestConstants.ELEMENT_SERVICE)) { if (elem.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns).equals(serviceName)) { setService = false; break; } } if (setService) { final Element permissionElem = new Element(ManifestConstants.ELEMENT_SERVICE); permissionElem.setAttribute(ManifestConstants.ATTRIBUTE_NAME, serviceName, ns); permissionElem.setAttribute(ManifestConstants.ATTRIBUTE_LABEL, label, ns); permissionElem.setAttribute(ManifestConstants.ATTRIBUTE_EXPORTED, String.valueOf(exported), ns); appElem.addContent(permissionElem); } }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Adds a content provider to the manifest.xml * @param name The name of the provider//from ww w .j ava 2s. co m * @param label The label of the provider * @param authorities The authorities of the provider * @param description The description of the provider * @param exported The exported state of the provider */ public void addProvider(final String name, final String label, final String authorities, final String description, final boolean exported) { // Load Root element final Element rootNode = this.getDocument().getRootElement(); // Load Name space (required for manipulate attributes) final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION); boolean setProvider = true; for (Element elem : appElem.getChildren(ManifestConstants.ELEMENT_PROVIDER)) { if (elem.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns).equals(name)) { setProvider = false; break; } } if (setProvider) { final Element providerElem = new Element(ManifestConstants.ELEMENT_PROVIDER); providerElem.setAttribute(ManifestConstants.ATTRIBUTE_NAME, name, ns); providerElem.setAttribute(ManifestConstants.ATTRIBUTE_AUTHORITIES, authorities, ns); providerElem.setAttribute(ManifestConstants.ATTRIBUTE_LABEL, label, ns); providerElem.setAttribute(ManifestConstants.ATTRIBUTE_DESCRIPTION, description, ns); providerElem.setAttribute(ManifestConstants.ATTRIBUTE_EXPORTED, String.valueOf(exported), ns); appElem.addContent(providerElem); } }
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Get all services from the manifest./*from w ww. jav a 2 s. c om*/ * @return List of service name. */ public List<String> getServices() { List<String> result = new ArrayList<String>(); // Load Root element final Element rootNode = this.getDocument().getRootElement(); final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION); // Load Name space (required for manipulate attributes) final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); for (Element elem : appElem.getChildren(ManifestConstants.ELEMENT_SERVICE)) { result.add(elem.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns)); } return result; }
From source file:com.thoughtworks.go.domain.materials.mercurial.HgModificationSplitter.java
License:Apache License
private Modification parseChangeset(Element changeset) { Date modifiedTime = DateUtils.parseRFC822(changeset.getChildText("date")); String author = org.apache.commons.lang3.StringEscapeUtils.unescapeXml(changeset.getChildText("author")); String comment = org.apache.commons.lang3.StringEscapeUtils.unescapeXml(changeset.getChildText("desc")); String revision = changeset.getChildText("node"); Modification modification = new Modification(author, comment, null, modifiedTime, revision); Element files = changeset.getChild("files"); List<File> modifiedFiles = parseFiles(files, "modified"); List<File> addedFiles = parseFiles(files, "added"); List<File> deletedFiles = parseFiles(files, "deleted"); modifiedFiles.removeAll(addedFiles); modifiedFiles.removeAll(deletedFiles); addModificationFiles(modification, ModifiedAction.added, addedFiles); addModificationFiles(modification, ModifiedAction.deleted, deletedFiles); addModificationFiles(modification, ModifiedAction.modified, modifiedFiles); return modification; }
From source file:com.thoughtworks.go.domain.materials.mercurial.HgModificationSplitter.java
License:Apache License
private List<File> parseFiles(Element filesElement, String fileType) { List files = filesElement.getChild(fileType).getChildren("file"); List<File> modifiedFiles = new ArrayList<>(); for (Iterator iterator = files.iterator(); iterator.hasNext();) { Element node = (Element) iterator.next(); modifiedFiles.add(new File(org.apache.commons.lang3.StringEscapeUtils.unescapeXml(node.getText()))); }/*from w ww . ja va2 s . c o m*/ return modifiedFiles; }