Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

In this page you can find the example usage for org.dom4j Element getText.

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.globalsight.terminology.util.GSEntryParse.java

License:Apache License

/**
 * Gets the entry's concept ID.// ww  w  .ja v a  2  s  .c o  m
 * 
 * @return 0 if the entry has no ID yet, else a positive number.
 */
public String getConceptId(Entry p_entry) throws TermbaseException {
    Document dom = p_entry.getDom();
    Element root = dom.getRootElement();
    Element concept = root.element("concept");

    if (concept == null || concept.getText().length() == 0) {
        return null;
    } else {
        return concept.getText();
    }
}

From source file:com.globalsight.terminology.util.HtmlUtil.java

License:Apache License

static public String xmlToHtmlConceptGrp(Element p_node, MappingContext p_context) {
    StringBuffer result = new StringBuffer("<DIV class=\"vconceptGrp\"><SPAN class=\"vfakeConceptGrp\">");

    Element temp = (Element) p_node.selectSingleNode("concept");
    String id = temp != null ? temp.getText() : null;

    if (id != null && Integer.parseInt(id) > 0) {
        result.append("<SPAN class=\"vconceptlabel\">");
        result.append(p_context.mapEntry());
        result.append("</SPAN><SPAN class=\"vconcept\">" + id + "</SPAN>");
    } else {//from  w w w .  ja va 2  s .c  om
        result.append("<SPAN class=\"vconceptlabel\">");
        result.append(p_context.mapNewEntry());
        result.append("</SPAN><SPAN class=\"vconcept\"></SPAN>");
    }

    result.append("</SPAN>");

    result.append(xmlToHtmlTransacGrp(p_node.selectNodes("transacGrp"), p_context));
    result.append(xmlToHtmlDescripGrp(p_node.selectNodes("descripGrp"), p_context));
    result.append(xmlToHtmlSourceGrp(p_node.selectNodes("sourceGrp"), p_context));
    result.append(xmlToHtmlNoteGrp(p_node.selectNodes("noteGrp"), p_context));
    result.append(xmlToHtmlLanguageGrp(p_node.selectNodes("languageGrp"), p_context));

    result.append("</DIV>");

    return result.toString();
}

From source file:com.globalsight.terminology.util.HtmlUtil.java

License:Apache License

static public String xmlToHtmlTerm(Element p_node, MappingContext p_context) {
    StringBuffer result = new StringBuffer();

    result.append("<SPAN class=\"vtermlabel\">");
    result.append(p_context.mapTerm(null));
    result.append("</SPAN>");

    result.append("<SPAN class=\"vterm\">");
    result.append(p_node.getText());
    result.append("</SPAN>");

    return result.toString();
}

From source file:com.globalsight.util.file.XliffFileUtil.java

License:Apache License

private static String getItemFromNote(Document p_doc, String item) {
    String result = null;/*from   ww  w .jav  a 2  s.  c  o  m*/
    try {
        Element root = p_doc.getRootElement();
        Element noteElement = root.element(XliffConstants.FILE).element(XliffConstants.HEADER)
                .element(XliffConstants.NOTE);
        String notes = noteElement.getText();
        int index = notes.indexOf(item);
        notes = notes.substring(index);
        notes = notes.substring(0, notes.indexOf("#")).trim();
        notes = notes.substring(notes.indexOf(":") + 1).trim();
        result = notes;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    return result;
}

From source file:com.google.gdt.util.HttpTranslator.java

License:Open Source License

/**
 * parse the response from google server and extracts the desired translated Text
 * @param response/*from   w w w.j av a  2s  .  c  om*/
 * @return translatedText
 */
private String parseResponse(String response) {
    //      System.out.println(response);
    String translatedText = "";
    InputSource is = new InputSource(new StringReader(response));
    SAXReader reader = new SAXReader();
    Document doc = null;
    try {
        doc = reader.read(is);
    } catch (DocumentException e) {
        logger.log(Level.SEVERE, "Not able to parse response : " + response, e);
        return "";
    }

    Element root = doc.getRootElement();
    for (Iterator i = root.elementIterator(); i.hasNext();) {
        Element element = (Element) i.next();
        translatedText += element.getText();
    }
    return translatedText;
}

From source file:com.google.jenkins.flakyTestHandler.junit.FlakyCaseResult.java

License:Open Source License

private static List<FlakyRunInformation> getFlakyRunInformation(List<Element> flakyElements) {
    List<FlakyRunInformation> flakyRunInformation = new ArrayList<FlakyRunInformation>();

    for (Element flakyElement : flakyElements) {
        // Set errorDetails
        String errorDetails = flakyElement.attributeValue("message");

        // Set errorStackTrace
        String errorStackTrace = flakyElement.getText();

        // Set system-out and system-err
        String flakyStdout = flakyElement.elementText("system-out");
        String flakyStderr = flakyElement.elementText("system-err");

        flakyRunInformation/*from   www. j a  v a2  s . c  o m*/
                .add(new FlakyRunInformation(errorDetails, errorStackTrace, flakyStdout, flakyStderr));
    }
    return flakyRunInformation;
}

From source file:com.googlecode.fascinator.redbox.sru.NLAIdentity.java

License:Open Source License

private List<Map<String, String>> getNames(Node node) {
    List<Map<String, String>> nameList = new ArrayList<Map<String, String>>();

    // Any names for this ID
    @SuppressWarnings("unchecked")
    List<Node> names = node.selectNodes("eac:nameEntry");
    for (Node name : names) {
        Map<String, String> nameMap = new HashMap<String, String>();

        String thisDisplay = null;
        String thisFirstName = null;
        String thisSurname = null;
        String title = null;//from   w  ww  . j  a  va 2 s . co  m

        // First name
        Node firstNameNode = name
                .selectSingleNode("eac:part[(@localType=\"forename\") or (@localType=\"givenname\")]");
        if (firstNameNode != null) {
            thisFirstName = firstNameNode.getText();
        }

        // Surname
        Node surnameNode = name
                .selectSingleNode("eac:part[(@localType=\"surname\") or (@localType=\"familyname\")]");
        if (surnameNode != null) {
            thisSurname = surnameNode.getText();
        }

        // Title
        Node titleNode = name.selectSingleNode("eac:part[@localType=\"title\"]");
        if (titleNode != null) {
            title = titleNode.getText();
        }

        // Display Name
        if (thisSurname != null) {
            thisDisplay = thisSurname;
            nameMap.put("surname", thisSurname);
            if (thisFirstName != null) {
                thisDisplay += ", " + thisFirstName;
                nameMap.put("firstName", thisFirstName);
            }
            if (title != null) {
                thisDisplay += " (" + title + ")";
            }
            nameMap.put("displayName", thisDisplay);
        }

        // Last ditch effort... we couldn't find simple name information from
        //  recommended values. So just concatenate what we can see.
        if (thisDisplay == null) {
            // Find every part
            @SuppressWarnings("unchecked")
            List<Node> parts = name.selectNodes("eac:part");
            for (Node part : parts) {
                // Grab the value and type of this value
                Element element = (Element) part;
                String value = element.getText();
                String type = element.attributeValue("localType");
                // Build a display value for this part
                if (type != null) {
                    value += " (" + type + ")";
                }
                // And add to the display name
                if (thisDisplay == null) {
                    thisDisplay = value;
                } else {
                    thisDisplay += ", " + value;
                }
            }
            nameMap.put("displayName", thisDisplay);
        }

        nameList.add(nameMap);
    }

    return nameList;
}

From source file:com.gtrj.docdeal.ui.GalleryFileActivity.java

License:Open Source License

private String parseXml(String xml) {
    try {/*from ww w .  j  av a2 s . c om*/
        File file = new File(ContextString.FilePath + File.separator + "xml.txt");
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        fileOutputStream.write(xml.getBytes());
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        Element totalPageElement = root.element("");
        Element currentPageElement = root.element("?");
        Element pictureElement = root.element("");
        totalPage = Integer.parseInt(totalPageElement.getText());
        String pageNum = currentPageElement.getText();
        String path = Base64Util.decoderBase64FileWithFileName(pictureElement.getText(), pageNum + ".jpg",
                this);
        return path;
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.haulmont.bali.util.Dom4j.java

License:Apache License

public static void loadMap(Element mapElement, Map<String, String> map) {
    Preconditions.checkNotNullArgument(map, "map is null");

    for (Element entryElem : elements(mapElement, "entry")) {
        String key = entryElem.attributeValue("key");
        if (key == null) {
            throw new IllegalStateException("No 'key' attribute");
        }//from w  w w  .j av a  2  s .c o m

        String value = null;
        Element valueElem = entryElem.element("value");
        if (valueElem != null) {
            value = StringEscapeUtils.unescapeXml(valueElem.getText());
        }

        map.put(key, value);
    }
}

From source file:com.haulmont.cuba.core.entity.ScheduledTask.java

License:Apache License

public List<MethodParameterInfo> getMethodParameters() {
    ArrayList<MethodParameterInfo> result = new ArrayList<>();
    String xml = getMethodParamsXml();
    if (!StringUtils.isBlank(xml)) {
        Document doc = Dom4j.readDocument(xml);
        List<Element> elements = Dom4j.elements(doc.getRootElement(), "param");
        for (Element paramEl : elements) {
            String typeName = paramEl.attributeValue("type");
            String name = paramEl.attributeValue("name");
            Object value = paramEl.getText();
            result.add(new MethodParameterInfo(typeName, name, value));
        }//from w ww .ja v a2  s  . c om
    }
    return result;
}