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.magnet.mmx.server.plugin.mmxmgmt.util.MMXMessageUtil.java

License:Apache License

/**
 * Check if the message is a server ack message.
 * @param message/*from w w  w  .  j ava 2  s. co m*/
 * @return
 */
private static boolean isServerAckMessage(Message message) {
    Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_SIGNAL);
    if (mmx == null) {
        return false;
    }
    Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
    String json = internalMeta != null ? internalMeta.getText() : null;
    if (json == null) {
        return false;
    }
    JsonElement jsonElement = new JsonParser().parse(json);
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return false;
    }
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    boolean serverAck = jsonObject.has(MMXServerConstants.SERVER_ACK_KEY);
    return serverAck;
}

From source file:com.mgmtp.perfload.core.client.web.io.XmlRequestFlowReader.java

License:Apache License

/**
 * Reads the XML resource transforming it into an objewct tree.
 * /*from ww  w  .j a va2  s.  c o m*/
 * @return the request flow instance
 */
public RequestFlow readFlow() throws ParserConfigurationException, SAXException, DocumentException {
    Element root = loadDocument().getRootElement();

    @SuppressWarnings("unchecked")
    List<Element> requests = root.elements();
    List<RequestTemplate> templates = newArrayListWithCapacity(requests.size());

    for (Element requestElem : requests) {
        String type = requestElem.attributeValue("type");
        String skip = defaultString(emptyToNull(requestElem.attributeValue("skip")), "false");
        String uri = requestElem.attributeValue("uri");
        String uriAlias = emptyToNull(requestElem.attributeValue("uriAlias"));
        String validateResponse = defaultString(emptyToNull(requestElem.attributeValue("validateResponse")),
                "true");

        @SuppressWarnings("unchecked")
        List<Element> params = requestElem.elements("param");
        SetMultimap<String, String> paramsMultiMap = HashMultimap.create(params.size(), 3);
        for (Element paramElem : params) {
            String key = paramElem.attributeValue("name");
            String value = paramElem.getText();
            paramsMultiMap.put(key, value);
        }

        @SuppressWarnings("unchecked")
        List<Element> headers = requestElem.elements("header");
        SetMultimap<String, String> headersMultiMap = HashMultimap.create(headers.size(), 3);
        for (Element headerElem : headers) {
            String key = headerElem.attributeValue("name");
            String value = headerElem.getText();
            headersMultiMap.put(key, value);
        }

        Element bodyElement = requestElem.element("body");
        Body body = null;
        if (bodyElement != null) {
            String bodyContent = emptyToNull(bodyElement.getText());
            String resPath = bodyElement.attributeValue("resourcePath");
            String resourceType = bodyElement.attributeValue("resourceType");

            checkState(bodyContent != null ^ (resPath != null && resourceType != null),
                    "Must specify either body content or resource path and type. [" + requestElem.asXML()
                            + "]");

            if (bodyContent != null) {
                body = Body.create(bodyContent);
            } else {
                body = Body.create(resPath, resourceType);
            }
        }

        @SuppressWarnings("unchecked")
        List<Element> headerExtractions = requestElem.elements("headerExtraction");
        List<HeaderExtraction> extractHeadersList = newArrayListWithCapacity(headerExtractions.size());
        for (Element extractHeaderElem : headerExtractions) {
            String name = extractHeaderElem.attributeValue("name");
            String placeholderName = extractHeaderElem.attributeValue("placeholderName");
            extractHeadersList.add(new HeaderExtraction(name, placeholderName));
        }

        @SuppressWarnings("unchecked")
        List<Element> detailExtractions = requestElem.elements("detailExtraction");
        List<DetailExtraction> extractDetailsList = newArrayListWithCapacity(detailExtractions.size());
        for (Element extractDetailElem : detailExtractions) {
            String name = extractDetailElem.attributeValue("name");

            String groupIndexString = extractDetailElem.attributeValue("groupIndex");
            //            int groupIndex = groupIndexString != null ? Integer.parseInt(groupIndexString) : 1;

            String defaultValue = extractDetailElem.attributeValue("defaultValue");

            String indexedString = extractDetailElem.attributeValue("indexed");
            //            boolean indexed = indexedString != null ? Boolean.parseBoolean(indexedString) : false;

            String failIfNotFoundString = extractDetailElem.attributeValue("failIfNotFound");
            //            boolean failIfNotFound = failIfNotFoundString == null || Boolean.valueOf(failIfNotFoundString);

            String pattern = extractDetailElem.getText().trim();

            DetailExtraction ed = new DetailExtraction(name, pattern, groupIndexString, defaultValue,
                    indexedString, failIfNotFoundString);
            extractDetailsList.add(ed);
        }

        templates.add(new RequestTemplate(type, skip, uri, uriAlias, headersMultiMap, paramsMultiMap, body,
                extractHeadersList, extractDetailsList, validateResponse));
    }

    return new RequestFlow(resourceName, templates);
}

From source file:com.mgmtp.perfload.core.common.config.XmlConfigReader.java

License:Apache License

private PropertiesMap readProperties(final Element testplan) {
    PropertiesMap properties = new PropertiesMap();
    Element element = testplan.element("properties");
    if (element != null) {
        @SuppressWarnings("unchecked")
        List<Element> propsElems = element.elements();
        for (Element propsElem : propsElems) {
            String name = propsElem.attributeValue("name");
            String value = propsElem.getText();
            properties.put(name, value);
        }/*www  . j  ava 2s. c  om*/
    }
    return properties;
}

From source file:com.mindquarry.desktop.model.conversation.ConversationTransformer.java

License:Open Source License

@Path("//topic")
public void topic(Node node) {
    if (node instanceof Element) {
        Element element = (Element) node;
        conversation.setTopic(element.getText());
    }//  ww w . j  a  va 2  s  .  co m
}

From source file:com.mindquarry.desktop.model.conversation.ParticipantTransformer.java

License:Open Source License

@Path("//name")
public void name(Node node) {
    if (node instanceof Element) {
        Element element = (Element) node;
        participant.setName(element.getText());
    }//w ww  .ja  v  a2  s  .com
}

From source file:com.mobileStore.sms.CCPRestSmsSDK.java

License:Open Source License

/**
 * @description xml??map/*  ww w  . ja v  a 2  s  .  co m*/
 * @param xml
 * @return Map
 */
private static HashMap<String, Object> xmlToMap(String xml) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    Document doc = null;
    try {
        doc = DocumentHelper.parseText(xml); // XML
        Element rootElt = doc.getRootElement(); // ?
        HashMap<String, Object> hashMap2 = new HashMap<String, Object>();
        for (Iterator i = rootElt.elementIterator(); i.hasNext();) {
            Element e = (Element) i.next();
            if ("statusCode".equals(e.getName()) || "statusMsg".equals(e.getName()))
                map.put(e.getName(), e.getText());
            else {
                if ("SubAccount".equals(e.getName()) || "totalCount".equals(e.getName())
                        || "token".equals(e.getName()) || "downUrl".equals(e.getName())) {
                    if (!"SubAccount".equals(e.getName())) {
                        hashMap2.put(e.getName(), e.getText());
                    } else {
                        ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
                        HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                        for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                            Element e2 = (Element) i2.next();
                            hashMap3.put(e2.getName(), e2.getText());
                            arrayList.add(hashMap3);
                        }
                        hashMap2.put("SubAccount", arrayList);
                    }
                    map.put("data", hashMap2);
                } else {

                    HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                    for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                        Element e2 = (Element) i2.next();
                        // hashMap2.put(e2.getName(),e2.getText());
                        hashMap3.put(e2.getName(), e2.getText());
                    }
                    if (hashMap3.size() != 0) {
                        hashMap2.put(e.getName(), hashMap3);
                    } else {
                        hashMap2.put(e.getName(), e.getText());
                    }
                    map.put("data", hashMap2);
                }
            }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        LoggerUtil.error(e.getMessage());
    } catch (Exception e) {
        LoggerUtil.error(e.getMessage());
        e.printStackTrace();
    }
    return map;
}

From source file:com.neu.utils.io.NetworkToXMLUtil.java

License:Open Source License

public static List<List<String>> unicomFilmXmlRead(String fileName) throws DocumentException {

    List<List<String>> cc = new ArrayList<List<String>>();

    File inputXml = new File(fileName);
    SAXReader saxReader = new SAXReader();

    Document document = saxReader.read(inputXml);

    Element employees = document.getRootElement();
    for (Iterator i = employees.elementIterator(); i.hasNext();) {
        Element employee = (Element) i.next();
        List<String> list = new ArrayList<String>();
        for (Iterator j = employee.elementIterator(); j.hasNext();) {
            Element node = (Element) j.next();
            list.add(node.getText());
        }/*from   w w  w  .  j  a  v  a  2s .c  o  m*/
        cc.add(list);
    }
    return cc;
}

From source file:com.nokia.ant.AtsCondition.java

License:Open Source License

/** Read from diamonds and signal if ats failed */
public boolean eval() {
    String bid = project.getProperty("diamonds.build.id");
    if (bid == null)
        log.info("Diamonds not enabled");
    else {/*from   w  w  w. j  a  va2  s .c o  m*/
        boolean testsfound = false;
        log.info("Looking for tests in diamonds");
        SAXReader xmlReader = new SAXReader();

        while (!testsfound) {
            Document antDoc = null;

            try {
                URL url = new URL("http://" + project.getProperty("diamonds.host") + bid + "?fmt=xml");
                antDoc = xmlReader.read(url);
            } catch (Exception e) {
                // We are Ignoring the errors as no need to fail the build.
                log.error("Not able to read the Diamonds URL http://" + project.getProperty("diamonds.host")
                        + bid + "?fmt=xml" + e.getMessage());
            }

            for (Iterator iterator = antDoc.selectNodes("//test/failed").iterator(); iterator.hasNext();) {
                testsfound = true;
                Element e = (Element) iterator.next();
                String failed = e.getText();
                if (!failed.equals("0")) {
                    log.error("ATS tests failed");

                    for (Iterator iterator2 = antDoc.selectNodes("//actual_result").iterator(); iterator2
                            .hasNext();) {
                        Element e2 = (Element) iterator2.next();
                        log.error(e2.getText());
                    }
                    return false;
                }
            }

            int noofdrops = Integer.parseInt(project.getProperty("drop.file.counter"));
            if (noofdrops > 0) {
                int testsrun = antDoc.selectNodes("//test").size();
                if (testsrun < noofdrops) {
                    log.info(testsrun + " test completed, " + noofdrops + " total");
                    testsfound = false;
                }
            }
            if (!testsfound) {
                log.info("Tests not found sleeping for " + sleeptimesecs + " seconds");
                try {
                    Thread.sleep(sleeptimesecs * 1000);
                } catch (InterruptedException e) {
                    // This will not affect the build process so ignoring.
                    log.debug("Interrupted while reading ATS build status " + e.getMessage());
                }
            }
        }
    }
    return true;
}

From source file:com.nokia.ant.conditions.AtsCondition.java

License:Open Source License

/** Read from diamonds and signal if ats failed */
public boolean eval() {
    String bid = getProject().getProperty("diamonds.build.id");
    if (bid == null) {
        log("Diamonds not enabled");
    } else {/* www.j  a  v  a 2 s .co  m*/
        boolean testsfound = false;
        log("Looking for tests in diamonds");
        SAXReader xmlReader = new SAXReader();

        while (!testsfound) {
            Document antDoc = null;

            try {
                URL url = new URL("http://" + getProject().getProperty("diamonds.host") + bid + "?fmt=xml");
                antDoc = xmlReader.read(url);
            } catch (MalformedURLException e) {
                // We are Ignoring the errors as no need to fail the build.
                log("Not able to read the Diamonds URL http://" + getProject().getProperty("diamonds.host")
                        + bid + "?fmt=xml: " + e.getMessage(), Project.MSG_ERR);
            } catch (DocumentException e) {
                log("Not able to read the Diamonds URL http://" + getProject().getProperty("diamonds.host")
                        + bid + "?fmt=xml: " + e.getMessage(), Project.MSG_ERR);
            }

            for (Iterator iterator = antDoc.selectNodes("//test/failed").iterator(); iterator.hasNext();) {
                testsfound = true;
                Element element = (Element) iterator.next();
                String failed = element.getText();
                if (!failed.equals("0")) {
                    log("ATS tests failed", Project.MSG_ERR);

                    for (Iterator iterator2 = antDoc.selectNodes("//actual_result").iterator(); iterator2
                            .hasNext();) {
                        Element resultElement = (Element) iterator2.next();
                        log(resultElement.getText(), Project.MSG_ERR);
                    }
                    return false;
                }
            }

            int noofdrops = Integer.parseInt(getProject().getProperty("drop.file.counter"));
            if (noofdrops > 0) {
                int testsrun = antDoc.selectNodes("//test").size();
                if (testsrun < noofdrops) {
                    log(testsrun + " test completed, " + noofdrops + " total");
                    testsfound = false;
                }
            }
            if (!testsfound) {
                log("Tests not found sleeping for " + sleeptimesecs + " seconds");
                try {
                    Thread.sleep(sleeptimesecs * 1000);
                } catch (InterruptedException e) {
                    // This will not affect the build process so ignoring.
                    log("Interrupted while reading ATS build status " + e.getMessage(), Project.MSG_DEBUG);
                }
            }
        }
    }
    return true;
}

From source file:com.nokia.ant.ModelPropertiesParser.java

License:Open Source License

/**
 * Reads model xml file, changes description format.
 * //from w  w w  .  j  a va2s .  c om
 * @throws DocumentException
 * @throws IOException
 */
public void parsePropertiesDescription() throws IOException, DocumentException {
    SAXReader xmlReader = new SAXReader();
    doc = xmlReader.read(inputPath);
    List importNodes = doc.selectNodes("//description");
    for (Iterator iterator = importNodes.iterator(); iterator.hasNext();) {
        Element importCurrentNode = (Element) iterator.next();
        importCurrentNode.setText(renderWikiModel(importCurrentNode.getText()));
        writeXMLFile();
    }
}