Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

In this page you can find the example usage for org.jdom2 Element getChildText.

Prototype

public String getChildText(final String cname) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:com.rometools.modules.photocast.io.Parser.java

License:Open Source License

@Override
public Module parse(final Element element, final Locale locale) {
    if (element.getName().equals("channel") || element.getName().equals("feed")) {
        return new PhotocastModuleImpl();
    } else if (element.getChild("metadata", Parser.NS) == null
            && element.getChild("image", Parser.NS) == null) {
        return null;
    }//ww w  .ja v a 2  s .com
    final PhotocastModule pm = new PhotocastModuleImpl();
    final List<Element> children = element.getChildren();
    final Iterator<Element> it = children.iterator();
    while (it.hasNext()) {
        final Element e = it.next();
        if (!e.getNamespace().equals(Parser.NS)) {
            continue;
        }
        if (e.getName().equals("photoDate")) {
            try {
                pm.setPhotoDate(Parser.PHOTO_DATE_FORMAT.parse(e.getText()));
            } catch (final Exception ex) {
                LOG.warn("Unable to parse photoDate: " + e.getText(), ex);
            }
        } else if (e.getName().equals("cropDate")) {
            try {
                pm.setCropDate(Parser.CROP_DATE_FORMAT.parse(e.getText()));
            } catch (final Exception ex) {
                LOG.warn("Unable to parse cropDate: " + e.getText(), ex);
            }
        } else if (e.getName().equals("thumbnail")) {
            try {
                pm.setThumbnailUrl(new URL(e.getText()));
            } catch (final Exception ex) {
                LOG.warn("Unable to parse thumnail: " + e.getText(), ex);
            }
        } else if (e.getName().equals("image")) {
            try {
                pm.setImageUrl(new URL(e.getText()));
            } catch (final Exception ex) {
                LOG.warn("Unable to parse image: " + e.getText(), ex);
            }
        } else if (e.getName().equals("metadata")) {
            String comments = "";
            PhotoDate photoDate = null;
            if (e.getChildText("PhotoDate") != null) {
                try {
                    photoDate = new PhotoDate(Double.parseDouble(e.getChildText("PhotoDate")));
                } catch (final Exception ex) {
                    LOG.warn("Unable to parse PhotoDate: " + e.getText(), ex);
                }
            }
            if (e.getChildText("Comments") != null) {
                comments = e.getChildText("Comments");
            }
            pm.setMetadata(new Metadata(photoDate, comments));
        }
    }
    return pm;
}

From source file:com.rometools.opml.io.impl.OPML10Parser.java

License:Apache License

/**
 * Parses an XML document (JDOM Document) into a feed bean.
 * <p>//from  w w  w . j a v  a2 s .  com
 *
 * @param document XML document (JDOM) to parse.
 * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED).
 * @return the resulting feed bean.
 * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type.
 * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
 */
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale)
        throws IllegalArgumentException, FeedException {
    final Opml opml = new Opml();
    opml.setFeedType("opml_1.0");

    final Element root = document.getRootElement();
    final Element head = root.getChild("head");

    if (head != null) {
        opml.setTitle(head.getChildText("title"));

        if (head.getChildText("dateCreated") != null) {
            opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US));
        }

        if (head.getChildText("dateModified") != null) {
            opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US));
        }

        opml.setOwnerName(head.getChildTextTrim("ownerName"));
        opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
        opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));

        try {
            opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowBottom", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowBottom", nfe);
            }
        }

        try {
            opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowLeft", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowLeft", nfe);
            }
        }

        try {
            opml.setWindowRight(readInteger(head.getChildText("windowRight")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowRight", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowRight", nfe);
            }
        }

        try {
            opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowLeft", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowLeft", nfe);
            }
        }

        try {
            opml.setWindowTop(readInteger(head.getChildText("windowTop")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowTop", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowTop", nfe);
            }
        }

        try {
            opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse expansionState", nfe);
            if (validate) {
                throw new FeedException("Unable to parse expansionState", nfe);
            }
        }
    }

    opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
    opml.setModules(parseFeedModules(root, locale));

    return opml;
}

From source file:com.rometools.rome.io.impl.OPML10Parser.java

License:Apache License

/**
       * Parses an XML document (JDOM Document) into a feed bean.
       * <p>//from  w  w  w.  j a  va2s . c o m
       *
       * @param document XML document (JDOM) to parse.
       * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED).
       * @return the resulting feed bean.
       * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type.
       * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
       */
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale)
        throws IllegalArgumentException, FeedException {
    final Opml opml = new Opml();
    opml.setFeedType("opml_1.0");

    final Element root = document.getRootElement();
    final Element head = root.getChild("head");

    if (head != null) {
        opml.setTitle(head.getChildText("title"));

        if (head.getChildText("dateCreated") != null) {
            opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US));
        }

        if (head.getChildText("dateModified") != null) {
            opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US));
        }

        opml.setOwnerName(head.getChildTextTrim("ownerName"));
        opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
        opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));
    }

    try {
        opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowBottom", nfe);
        }
    }

    try {
        opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
    } catch (final NumberFormatException nfe) {
    }

    try {
        opml.setWindowRight(readInteger(head.getChildText("windowRight")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowRight", nfe);
        }
    }

    try {
        opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowLeft", nfe);
        }
    }

    try {
        opml.setWindowTop(readInteger(head.getChildText("windowTop")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowTop", nfe);
        }
    }

    try {
        opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse expansionState", nfe);
        }
    }

    opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
    opml.setModules(parseFeedModules(root, locale));

    return opml;
}

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,
 *//*from   www. j  a  v  a2 s  . c o  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.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.util.SvnLogXmlParser.java

License:Apache License

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;
    }/*from   w ww . j  a va 2s.  c o  m*/

    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;
}

From source file:com.versionmaintain.files.LastVersionInfosParser.java

License:Apache License

public List<VersionInfo> getVersionInfo() {
    SAXBuilder builder = new SAXBuilder();
    List<VersionInfo> infos = new ArrayList<VersionInfo>();
    try {//from   w  w  w . j av  a2 s.c  om
        Document doc = builder.build(new File(System.getProperty("user.dir") + File.separator + FILE_NAME));
        Element root = doc.getRootElement();
        List<Element> softEles = root.getChildren("software");
        for (Element softEle : softEles) {
            String appName = softEle.getAttribute("name").getValue();
            String versionCode = softEle.getChildText("latest-version-code");
            String versionName = softEle.getChildText("latest-version");

            Element detailEles = softEle.getChild("latest-version-detail");
            List<Element> detailItemEles = detailEles.getChildren("item");
            List<VersionInfoDetail> details = new ArrayList<VersionInfoDetail>();
            for (Element detailItem : detailItemEles) {
                String title = detailItem.getAttributeValue("name");
                List<Element> detailEleList = detailItem.getChildren("detail");
                List<String> detailList = new ArrayList<String>();
                for (Element detailEle : detailEleList) {
                    String strDetail = detailEle.getText();
                    detailList.add(strDetail);
                }
                details.add(new VersionInfoDetail(title, detailList));
            }

            VersionInfo versionInfo = new VersionInfo();
            versionInfo.setAppName(appName);
            versionInfo.setVersion(versionName);
            versionInfo.setVersionCode(Integer.parseInt(versionCode));
            versionInfo.setDetails(details);
            infos.add(versionInfo);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return infos;
}

From source file:com.webfront.model.Config.java

public void getConfig() {
    jdomBuilder = new SAXBuilder();
    try {/*w w w . j  a v  a 2 s  . c  o m*/
        xmlDoc = jdomBuilder.build(getInstallDir() + getFileSep() + configFileName);
        Element docRoot = xmlDoc.getRootElement();
        Element systemNode = docRoot.getChild("system");
        installDir = systemNode.getChildText("installDir");
        tmpDir = systemNode.getChildText("tmpDir");
    } catch (FileNotFoundException ex) {
        //Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JDOMException ex) {
        Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:converter.ConverterBean.java

private String getFullNameMonay(String currencyCode) {
    try {/*from  w w  w .j a va2s  .c om*/
        this.init();
        for (Element e : racineMore.getChildren()) {
            String ccy = e.getChildText("Ccy");
            if (ccy != null && ccy.equals(currencyCode)) {
                return e.getChildText("CtryNm");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return "Undefined";
}

From source file:cz.cesnet.shongo.connector.device.AdobeConnectConnector.java

@Override
public Collection<RoomSummary> listRooms() throws CommandException {
    RequestAttributeList attributes = new RequestAttributeList();
    attributes.add("filter-type", "meeting");

    Element response = execApi("report-bulk-objects", attributes);

    List<RoomSummary> meetings = new ArrayList<RoomSummary>();

    for (Element room : response.getChild("report-bulk-objects").getChildren("row")) {
        if (room.getChildText("name").matches("(?i).*Template")) {
            continue;
        }/* ww w  . j  a va  2s  . com*/

        RoomSummary roomSummary = new RoomSummary();
        roomSummary.setId(room.getAttributeValue("sco-id"));
        roomSummary.setName(room.getChildText("name"));
        roomSummary.setDescription(room.getChildText("description"));
        roomSummary.setAlias(room.getChildText("url"));

        String dateCreated = room.getChildText("date-created");
        if (dateCreated != null) {
            roomSummary.setStartDateTime(DateTime.parse(dateCreated));
        }

        meetings.add(roomSummary);
    }

    return Collections.unmodifiableList(meetings);
}