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, final Namespace ns) 

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.eds.Model.XMLProcessor.java

License:Apache License

private Result constructRecord(Element xmlRecord, Boolean parse) {
    Result result = new Result();

    // Get Record Id
    String resultId = xmlRecord.getChildText("ResultId", xmlRecord.getNamespace());
    result.setResultId(resultId);//  ww w . j  a va2 s .  c  o m

    // Get Header Info
    Element header = xmlRecord.getChild("Header", xmlRecord.getNamespace());
    if (null != header) {
        String dbId = header.getChildText("DbId", header.getNamespace());
        String dbLabel = header.getChildText("DbLabel", header.getNamespace());
        String an = header.getChildText("An", header.getNamespace());
        String pubType = header.getChildText("PubType", header.getNamespace());
        String pubTypeId = header.getChildText("PubTypeId", header.getNamespace());

        result.setDbId(dbId);
        result.setDbLabel(dbLabel);
        result.setPubTypeID(pubTypeId);
        result.setAn(an);
        result.setPubType(pubType);
    }
    // Get PLink
    String pLink = xmlRecord.getChildText("PLink", xmlRecord.getNamespace());
    result.setpLink(pLink);

    // Get ImageInfo
    Element imageInfo = xmlRecord.getChild("ImageInfo", xmlRecord.getNamespace());

    if (imageInfo != null) {
        List<Element> coverArts = imageInfo.getChildren();
        for (int b = 0; b < coverArts.size(); b++) {
            Element coverArt = (Element) coverArts.get(b);
            if (null != coverArt) {
                BookJacket bookJacket = new BookJacket();
                String size = coverArt.getChildText("Size", coverArt.getNamespace());
                String target = coverArt.getChildText("Target", coverArt.getNamespace());
                bookJacket.setSize(size);
                bookJacket.setTarget(target);
                result.getBookJacketList().add(bookJacket);
            }
        }
    }

    // Get Custom Links
    Element customLinks = xmlRecord.getChild("CustomLinks", xmlRecord.getNamespace());
    if (customLinks != null) {
        List<Element> customLinksList = customLinks.getChildren();
        for (int c = 0; c < customLinksList.size(); c++) {
            Element cl = (Element) customLinksList.get(c);
            if (null != cl) {
                String clurl = cl.getChildText("Url", cl.getNamespace());
                String name = cl.getChildText("Name", cl.getNamespace());
                String category = cl.getChildText("Category", cl.getNamespace());
                String text = cl.getChildText("Text", cl.getNamespace());
                String icon = cl.getChildText("Icon", cl.getNamespace());
                String mouseOverText = cl.getChildText("MouseOverText", cl.getNamespace());

                CustomLink customLink = new CustomLink();
                customLink.setUrl(clurl);
                customLink.setName(name);
                customLink.setCategory(category);
                customLink.setText(text);
                customLink.setIcon(icon);
                customLink.setMouseOverText(mouseOverText);
                result.getCustomLinkList().add(customLink);
            }
        }
    }

    // Get Full Text Info
    Element fullText = xmlRecord.getChild("FullText", xmlRecord.getNamespace());
    result.setHtmlAvailable("0");
    result.setPdfAvailable("0");
    if (null != fullText) {
        Element text = fullText.getChild("Text", fullText.getNamespace());
        if (null != text) {
            // 0 - embedded full text is not available
            // 1 - full text is available
            // -1 - database not configured to provide full text to
            // guests
            String htmlAvailable = text.getChildText("Availability", fullText.getNamespace());
            if (null != htmlAvailable && !htmlAvailable.isEmpty() && htmlAvailable.equals("1")) {
                result.setHtmlAvailable("1");
                String htmlFullTextValue = text.getChildText("Value", fullText.getNamespace());
                if (null != htmlFullTextValue && !htmlFullTextValue.isEmpty()) {
                    if (parse)
                        htmlFullTextValue = Jsoup.parse(htmlFullTextValue).text().toString();
                    // translate data to valid HTML tags
                    htmlFullTextValue = TransDataToHTML.transDataToHTML(htmlFullTextValue);
                }
                result.setHtmlFullText(htmlFullTextValue);
            }
            result.setHtmlAvailable(htmlAvailable);
        }
        // determine whether or not there are full text links
        Element linkElement = fullText.getChild("Links", fullText.getNamespace());
        if (null != linkElement) {
            List<Element> links = linkElement.getChildren();
            if (null != links && 0 < links.size()) {
                ArrayList<Link> otherLinks = new ArrayList<Link>();
                for (int j = 0; j < links.size(); j++) {
                    Element link = (Element) links.get(j);
                    String type = link.getChildText("Type", link.getNamespace());
                    String url = link.getChildText("Url", link.getNamespace());
                    if (null != type && type.equals("pdflink")) {
                        result.setPdfAvailable("1");
                        result.setPdfLink(url);
                    } else if (null != type && !type.isEmpty()) {
                        Link otherFTLink = new Link();
                        otherFTLink.setType(type);
                        otherFTLink.setUrl(url);
                        otherLinks.add(otherFTLink);
                    }
                }
                if (!otherLinks.isEmpty())
                    result.setOtherFullTextLinks(otherLinks);
            }
        }
    }
    // Process Items
    Element items = xmlRecord.getChild("Items", xmlRecord.getNamespace());
    if (null != items) {
        List<Element> itemList = items.getChildren();
        for (int j = 0; j < itemList.size(); j++) {
            Element itemElement = (Element) itemList.get(j);
            Item item = new Item();
            String label = itemElement.getChildText("Label", itemElement.getNamespace());
            String group = itemElement.getChildText("Group", itemElement.getNamespace());
            String itemData = itemElement.getChildText("Data", itemElement.getNamespace());

            if (parse)
                itemData = Jsoup.parse(itemData).text().toString();
            // translate data to valid HTML tags
            itemData = TransDataToHTML.transDataToHTML(itemData);
            item.setLabel(label);
            item.setGroup(group);
            item.setData(itemData);
            result.getItemList().add(item);
        }
    }
    return result;
}

From source file:com.eds.Response.XMLProcessor.java

License:Apache License

private Record constructRecord(Element xmlRecord, Boolean parse) {
    Record record = new Record();

    // Get Record Id
    String resultId = xmlRecord.getChildText("ResultId", xmlRecord.getNamespace());
    record.setResultId(resultId);//from w  ww  .j  a va  2s . com

    // Get Header Info
    Element header = xmlRecord.getChild("Header", xmlRecord.getNamespace());
    if (null != header) {
        String dbId = header.getChildText("DbId", header.getNamespace());
        String dbLabel = header.getChildText("DbLabel", header.getNamespace());
        String an = header.getChildText("An", header.getNamespace());
        String pubType = header.getChildText("PubType", header.getNamespace());
        String pubTypeId = header.getChildText("PubTypeId", header.getNamespace());

        record.setDbId(dbId);
        record.setDbLabel(dbLabel);
        record.setPubTypeId(pubTypeId);
        record.setAn(an);
        record.setPubType(pubType);
    }
    // Get PLink
    String pLink = xmlRecord.getChildText("PLink", xmlRecord.getNamespace());
    record.setpLink(pLink);

    // Get ImageInfo

    Element imageInfo = xmlRecord.getChild("ImageInfo", xmlRecord.getNamespace());

    if (imageInfo != null) {
        List<Element> coverArts = imageInfo.getChildren();
        for (int b = 0; b < coverArts.size(); b++) {
            Element coverArt = (Element) coverArts.get(b);
            if (null != coverArt) {
                BookJacket bookJacket = new BookJacket();
                String size = coverArt.getChildText("Size", coverArt.getNamespace());
                String target = coverArt.getChildText("Target", coverArt.getNamespace());
                bookJacket.setSize(size);
                bookJacket.setTarget(target);
                record.getBookJacketList().add(bookJacket);
            }
        }
    }

    // Get Custom Links
    Element customLinks = xmlRecord.getChild("CustomLinks", xmlRecord.getNamespace());
    if (customLinks != null) {
        List<Element> customLinksList = customLinks.getChildren();
        for (int c = 0; c < customLinksList.size(); c++) {
            Element cl = (Element) customLinksList.get(c);
            if (null != cl) {
                String clurl = cl.getChildText("Url", cl.getNamespace());
                String name = cl.getChildText("Name", cl.getNamespace());
                String category = cl.getChildText("Category", cl.getNamespace());
                String text = cl.getChildText("Text", cl.getNamespace());
                String icon = cl.getChildText("Icon", cl.getNamespace());
                String mouseOverText = cl.getChildText("MouseOverText", cl.getNamespace());

                CustomLink customLink = new CustomLink();
                customLink.setUrl(clurl);
                customLink.setName(name);
                customLink.setCategory(category);
                customLink.setText(text);
                customLink.setIcon(icon);
                customLink.setMouseOverText(mouseOverText);
                record.getCustomLinkList().add(customLink);
            }
        }
    }

    // Get Full Text Info
    Element fullText = xmlRecord.getChild("FullText", xmlRecord.getNamespace());
    if (null != fullText) {
        Element htmlFullText = fullText.getChild("Text", fullText.getNamespace());
        if (null != htmlFullText) {
            String availability = htmlFullText.getChildText("Availability", fullText.getNamespace());
            record.setHtml(availability);
        }
    }

    // Process Items
    Element items = xmlRecord.getChild("Items", xmlRecord.getNamespace());
    if (null != items) {
        List<Element> itemList = items.getChildren();
        for (int j = 0; j < itemList.size(); j++) {
            Element itemElement = (Element) itemList.get(j);
            Item item = new Item();
            String label = itemElement.getChildText("Label", itemElement.getNamespace());
            String group = itemElement.getChildText("Group", itemElement.getNamespace());
            String itemData = itemElement.getChildText("Data", itemElement.getNamespace());

            if (parse)
                itemData = Jsoup.parse(itemData).text().toString();
            // translate data to valid HTML tags
            itemData = TransDataToHTML.transDataToHTML(itemData);
            item.setLabel(label);
            item.setGroup(group);
            item.setData(itemData);
            record.getItemList().add(item);
        }
    }
    return record;
}

From source file:com.rometools.modules.sle.io.ModuleParser.java

License:Apache License

/**
 * Parses the XML node (JDOM element) extracting module information.
 * <p>//from ww w  .ja  va  2 s  .c o  m
 *
 * @param element the XML node (JDOM element) to extract module information from.
 * @return a module instance, <b>null</b> if the element did not have module information.
 */
@Override
public Module parse(final Element element, final Locale locale) {
    if (element.getChild("treatAs", NS) == null) {
        return null;
    }

    final SimpleListExtension sle = new SimpleListExtensionImpl();
    sle.setTreatAs(element.getChildText("treatAs", NS));

    final Element listInfo = element.getChild("listinfo", NS);
    ArrayList<Object> values = new ArrayList<Object>();
    for (final Element ge : listInfo.getChildren("group", NS)) {
        final Namespace ns = ge.getAttribute("ns") == null ? element.getNamespace()
                : Namespace.getNamespace(ge.getAttributeValue("ns"));
        final String elementName = ge.getAttributeValue("element");
        final String label = ge.getAttributeValue("label");
        values.add(new Group(ns, elementName, label));
    }

    sle.setGroupFields(values.toArray(new Group[values.size()]));
    values = values.size() == 0 ? values : new ArrayList<Object>();

    for (final Element se : listInfo.getChildren("sort", NS)) {
        LOG.debug("Parse cf:sort {}{}", se.getAttributeValue("element"), se.getAttributeValue("data-type"));
        final Namespace ns = se.getAttributeValue("ns") == null ? element.getNamespace()
                : Namespace.getNamespace(se.getAttributeValue("ns"));
        final String elementName = se.getAttributeValue("element");
        final String label = se.getAttributeValue("label");
        final String dataType = se.getAttributeValue("data-type");
        final boolean defaultOrder = se.getAttributeValue("default") == null ? false
                : new Boolean(se.getAttributeValue("default")).booleanValue();
        values.add(new Sort(ns, elementName, dataType, label, defaultOrder));
    }

    sle.setSortFields(values.toArray(new Sort[values.size()]));
    insertValues(sle, element.getChildren());

    return sle;
}

From source file:com.tactfactory.harmony.dependencies.android.sdk.AndroidSDKManager.java

License:Open Source License

/**
 * Find the latest SDK Tools link./*from www.  ja  va2s.  co m*/
 * 
 * @param platform The user platform
 * @return The latest SDK tools link
 */
public final String findLatestSDKToolsLink(final String platform) {
    String result = null;

    Document document = XMLUtils.getRemoteXML(SDK_URL + XML_REPO_FILE);
    Element root = document.getRootElement();
    Namespace ns = root.getNamespace("sdk");

    Element sdkTool = root.getChild("tool", ns);
    List<Element> sdkArchives = sdkTool.getChild("archives", ns).getChildren();

    for (Element sdkArchive : sdkArchives) {
        if (sdkArchive.getAttribute("os").getValue().equals(platform)) {
            result = SDK_URL + sdkArchive.getChildText("url", ns);
        }
    }

    return result;
}

From source file:DataWeb.Code.java

License:Open Source License

public Code(Element e, Namespace ns) {
    id = e.getAttributeValue("id");
    idProfesor = e.getChildText("idProfesor", ns);
    nombre = e.getChildText("nombre", ns);
    lenguaje = e.getChildText("lenguaje", ns);
    resaltar = e.getChildText("resaltar", ns);

    linea = new ArrayList<String>();
    comentario = new ArrayList<String>();
    for (Element line : e.getChildren("linea", ns))
        linea.add(line.getText());//w  w  w .ja  v a 2s .  c o  m
    for (Element line : e.getChildren("idComentario", ns))
        comentario.add(line.getText());
}

From source file:DataWeb.Comment.java

License:Open Source License

public Comment(Element e, Namespace ns) {
    id = e.getAttributeValue("id");
    idUsuario = e.getChildText("idUsuario", ns);
    texto = e.getChildText("texto", ns);
    calificacion = Integer.parseInt(e.getChildText("calificacion", ns));
    fechaMod = e.getChildText("fechaMod", ns);
}

From source file:DataWeb.Course.java

License:Open Source License

public Course(Element e, Namespace ns) {
    id = e.getAttributeValue("id");
    idProfesor = e.getChildText("idProfesor", ns);
    nombre = e.getChildText("nombre", ns);

    idAlumno = new ArrayList<String>();
    idCodigo = new ArrayList<String>();
    for (Element alumno : e.getChildren("idAlumno", ns))
        idAlumno.add(alumno.getText());/*from   w w  w.j a  va2s  . co  m*/
    for (Element codigo : e.getChildren("idCodigo", ns))
        idCodigo.add(codigo.getText());
}

From source file:DataWeb.User.java

License:Open Source License

public User(Element e, Namespace ns) {
    id = e.getAttributeValue("id");
    usuario = e.getChildText("usuario", ns);
    password = e.getChildText("password", ns);
    nombres = e.getChildText("nombres", ns);
    apPaterno = e.getChildText("apPat", ns);
    apMaterno = e.getChildText("apMat", ns);
    category = e.getChildText("category", ns);

    idCurso = new ArrayList<String>();
    for (Element curso : e.getChildren("idCurso", ns))
        idCurso.add(curso.getText());//from w  w w  .  j a v a2s . co  m
}

From source file:de.hbrs.oryx.yawl.converter.handler.oryx.OryxTaskHandler.java

License:Open Source License

/**
 * Code copied from YDecompositionParser.java licensed under LGPL:
 * //w w  w. j a v  a2s. c  o  m
 * Copyright (c) 2004-2012 The YAWL Foundation. All rights reserved. The YAWL Foundation is a collaboration of individuals and organisations who
 * are committed to improving workflow technology.
 * 
 * @param task
 * @param taskElem
 * @param _yawlNS
 */
private void parseTimerParameters(final YTask task, final Element taskElem, final Namespace _yawlNS) {
    Element timerElem = taskElem.getChild("timer", _yawlNS);
    if (timerElem != null) {
        String netParam = timerElem.getChildText("netparam", _yawlNS);

        // net-level param holds values at runtime
        if (netParam != null) {
            task.setTimerParameters(netParam);
        } else {
            // get the triggering event
            String triggerStr = timerElem.getChildText("trigger", _yawlNS);
            YWorkItemTimer.Trigger trigger = YWorkItemTimer.Trigger.valueOf(triggerStr);

            // expiry is a stringified long value representing a specific
            // datetime
            String expiry = timerElem.getChildText("expiry", _yawlNS);
            if (expiry != null) {
                task.setTimerParameters(trigger, new Date(new Long(expiry)));
            } else {
                // duration type - specified as a Duration?
                String durationStr = timerElem.getChildText("duration", _yawlNS);
                if (durationStr != null) {
                    Duration duration = StringUtil.strToDuration(durationStr);
                    if (duration != null) {
                        task.setTimerParameters(trigger, duration);
                    }
                } else {
                    // ticks / interval durationparams type
                    Element durationElem = timerElem.getChild("durationparams", _yawlNS);
                    String tickStr = durationElem.getChildText("ticks", _yawlNS);
                    String intervalStr = durationElem.getChildText("interval", _yawlNS);
                    YTimer.TimeUnit interval = YTimer.TimeUnit.valueOf(intervalStr);
                    task.setTimerParameters(trigger, new Long(tickStr), interval);
                }
            }
        }
    }
}

From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java

License:Open Source License

/**
 * Extracts the information about the iconPath.
 * //from  w  w w. ja  v  a 2 s .c o m
 * @param yawlVertex
 * @return IconPath as String or Empty String
 */
private String convertIconPath(final Element yawlVertex) {
    if (yawlVertex.getChild("iconpath", yawlNamespace) != null) {
        return yawlVertex.getChildText("iconpath", yawlNamespace);
    }
    return "";
}