Example usage for org.dom4j Element getStringValue

List of usage examples for org.dom4j Element getStringValue

Introduction

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

Prototype

String getStringValue();

Source Link

Document

Returns the XPath string-value of this node.

Usage

From source file:cc.warlock.core.client.settings.internal.VariableConfigurationProvider.java

License:Open Source License

@Override
protected void parseChild(Element child) {
    if (child.getName().equals("variable")) {
        String name = child.attributeValue("id");
        String value = child.getStringValue();

        Variable variable = new Variable(this, name, value);
        variables.put(name, variable);/* w  w w .j a  v a 2s. c o m*/
    }
}

From source file:com.ah.ui.actions.hiveap.HiveApFileAction.java

/**
 * Get the image product name and version from the header xml string
 *
 *@param lineStr -//from   ww w .  j a  v a 2 s .c  o  m
 *@return HiveApImageInfo
 */
private HiveApImageInfo getImageInfoHead(String lineStr) {
    try {
        if (!lineStr.startsWith("#!/bin/bash") || !lineStr.contains("<Image-Header")
                || !lineStr.contains("</Image-Header>") || !lineStr.contains("<Firmware>")
                || !lineStr.contains("</Firmware>")) {
            return null;
        }
        HiveApImageInfo info = new HiveApImageInfo();
        SAXReader reader = new SAXReader();
        String docName = lineStr.substring(lineStr.indexOf("<Firmware>"),
                lineStr.indexOf("</Firmware>") + "</Firmware>".length());
        Document doc = reader.read(new StringReader(docName));
        Element roota = doc.getRootElement();
        Iterator<?> iter = roota.elementIterator();
        Element foo;
        while (iter.hasNext()) {
            foo = (Element) iter.next();
            // get product name
            if (foo.getName().equalsIgnoreCase("Product")) {
                info.setProductName(foo.getStringValue());
                // get image version
            } else if (foo.getName().equalsIgnoreCase("Version")) {
                iter = foo.elementIterator();
                while (iter.hasNext()) {
                    foo = (Element) iter.next();
                    if (foo.getName().equalsIgnoreCase("External")) {
                        iter = foo.elementIterator();
                        while (iter.hasNext()) {
                            foo = (Element) iter.next();
                            // get major version
                            if (foo.getName().equalsIgnoreCase("Major")) {
                                info.setMajorVersion(foo.getStringValue());

                                // get minor version
                            } else if (foo.getName().equalsIgnoreCase("Minor")) {
                                info.setMinorVersion(foo.getStringValue());

                                // get release version
                            } else if (foo.getName().equalsIgnoreCase("Release")) {
                                info.setRelVersion(foo.getStringValue());

                                // get patch string
                            } else if (foo.getName().equalsIgnoreCase("Patch")) {
                                try {
                                    info.setImageUid(Integer.parseInt(foo.getStringValue()));
                                } catch (NumberFormatException nfe) {
                                    info.setImageUid(0);
                                }
                            }
                        }
                    }
                }
            }
        }
        String regex = "^\\d+\\.+\\d+r\\d+\\w*$";
        // check the product name and version format
        if ("".equals(info.getProductName()) || !Pattern.matches(regex, info.getImageVersion().trim())) {
            return null;
        }
        com.ah.be.config.image.ImageManager.updateHiveApImageInfo(info);
        return info;
    } catch (Exception ex) {
        log.error("checkImageInfo : ", ex.getMessage());
        return null;
    }
}

From source file:com.amalto.workbench.utils.ResourcesUtil.java

License:Open Source License

public static HashMap<String, String> getResourcesMapFromURI(String uri, TreeObject treeObject) {
    HashMap<String, String> contentMap = new HashMap<String, String>();
    String responseBody = getXMLString(uri, treeObject);
    Document document = parsXMLString(responseBody);
    if (document == null) {
        return contentMap;
    }/*from   w  w w  . j a  va2 s .c om*/
    for (Iterator iterator = document.getRootElement().elementIterator("entry"); iterator.hasNext();) {//$NON-NLS-1$
        Element element = (Element) iterator.next();
        Element nameElement = element.element("name");//$NON-NLS-1$
        Element uriElement = element.element("uri");//$NON-NLS-1$
        if (nameElement != null && uriElement != null) {
            contentMap.put(nameElement.getStringValue(), uriElement.getStringValue());
        } else {
            contentMap.put(element.getStringValue(), uri + "/" + element.getStringValue());//$NON-NLS-1$
        }
    }
    return contentMap;
}

From source file:com.amalto.workbench.utils.ResourcesUtil.java

License:Open Source License

public static List<String> getResourcesNameListFromURI(String uri, TreeObject treeObject) throws Exception {
    List<String> nameList = new ArrayList<String>();
    String responseBody = getXMLString(uri, treeObject);
    // nameList=getNameList(responseBody);
    Document document = parsXMLString(responseBody);
    if (document == null) {
        return nameList;
    }/*from  w w  w  . j  a va2 s.  c o  m*/
    for (Iterator iterator = document.getRootElement().elementIterator("entry"); iterator.hasNext();) {//$NON-NLS-1$
        Element element = (Element) iterator.next();
        Element nameElement = element.element("name");//$NON-NLS-1$

        if (nameElement != null) {
            nameList.add(nameElement.getStringValue());
        } else {
            nameList.add(element.getStringValue());
        }
    }
    return nameList;

}

From source file:com.ctrip.infosec.rule.action.FrozenAccount.java

/**
 * ?//from w  w w  .jav  a  2s .c om
 *
 * @param params
 * @return
 */
private static Map frozenOrNot(Map params) {
    beforeInvoke("FrozenAccount.frozenOrNot");
    Map<String, String> result = new HashMap();
    try {
        StringBuilder content = new StringBuilder();
        content.append("<Uid>").append(params.get("uid")).append("</Uid>");
        content.append("<OperStatus>").append(params.get("operStatus")).append("</OperStatus>");
        content.append("<Oper>").append(params.get("oper")).append("</Oper>");
        content.append("<Remark>").append(params.get("remark")).append("</Remark>");
        String request = "<FULogMessageRequest>" + content.toString() + "</FULogMessageRequest>";

        String xml = ESBClient.requestESB("Payment.CardRisk.InfoSecurity.EnterFULogMessage", request);
        if (xml == null || xml.isEmpty()) {
            return result;
        }
        Document document = DocumentHelper.parseText(xml);

        String xpath = "/Response/FULogMessageResponse";
        List<Element> list = document.selectNodes(xpath);
        if (list == null || list.isEmpty()) {
            /*xpath = "/Response/Header";
             Element header = (Element)document.selectSingleNode(xpath);
             Attribute resultCode = header.attribute("ResultCode");
             Attribute resultMsg = header.attribute("ResultMsg");
             result.put("resultCode",resultCode.getValue());
             result.put("resultMsg",resultMsg.getValue());*/
            result.put("result", xml);
            return result;
        }

        for (Element subElement : list) {
            Iterator iterator = subElement.elements().iterator();
            while (iterator.hasNext()) {
                Element element = (Element) iterator.next();
                result.put(element.getName(), element.getStringValue());
            }
        }
    } catch (Exception ex) {
        fault("FrozenAccount.frozenOrNot");
        logger.error(Contexts.getLogPrefix() + "invoke FrozenAccount.frozenOrNot fault.", ex);
    } finally {
        afterInvoke("FrozenAccount.frozenOrNot");
    }
    return result;
}

From source file:com.devoteam.srit.xmlloader.core.ScenarioReference.java

License:Open Source License

public ScenarioReference(Element elements, Testcase testcase) {
    _name = elements.attributeValue("name");
    _routingName = elements.attributeValue("routingName");
    _description = elements.attributeValue("description");
    String strState = elements.attributeValue("state");
    if (strState != null) {
        _state = Boolean.parseBoolean(strState);
    }// ww w  . ja  v a 2 s  . c om
    _filename = elements.attributeValue("file");
    if (null == _filename) {
        _filename = elements.getStringValue();
    }
    _filename = _filename.trim();
    _testcase = testcase;
}

From source file:com.dtolabs.rundeck.core.cli.util.MvnPomInfoTool.java

License:Apache License

private void processFileResources(Iterator i) {
    SAXReader reader = new SAXReader();

    while (i.hasNext()) {
        FileResource f = (FileResource) i.next();
        try {/* w  w w  . ja  va2  s. c  om*/
            Document doc = reader.read(f.getInputStream());
            //check packaging value
            if (null != doc.selectSingleNode("/project/packaging")) {
                Element e = (Element) doc.selectSingleNode("/project/packaging");
                if (!packaging.equals(e.getStringValue())) {
                    continue;
                }
            } else {
                continue;
            }
            logger.debug("processing pom: " + f.getFile());
            Map fdata = processDocument(doc);
            if (null != fdata) {
                data.put(f.getFile().getAbsolutePath(), fdata);
            }
        } catch (DocumentException e) {
            logger.error("Unable to read file: " + f.getFile() + ": " + e.getMessage());
        } catch (IOException e) {
            logger.error("Unable to read file: " + f.getFile() + ": " + e.getMessage());
        }
    }
}

From source file:com.dtolabs.rundeck.core.cli.util.MvnPomInfoTool.java

License:Apache License

Map processDocument(Document doc) {
    HashMap map = new HashMap();
    //discover pom detail
    Node groupNode = doc.selectSingleNode("/project/groupId");
    if (null != groupNode) {
        Element node = (Element) groupNode;
        map.put("groupId", node.getStringValue());
    } else {/*  w ww .  j a va2s.  c o m*/
        return null;
    }
    Node artifactNode = doc.selectSingleNode("/project/artifactId");
    if (null != artifactNode) {
        Element node = (Element) artifactNode;
        map.put("artifactId", node.getStringValue());
    } else {
        return null;
    }
    Node versionNode = doc.selectSingleNode("/project/version");
    if (null != versionNode) {
        Element node = (Element) versionNode;
        map.put("version", node.getStringValue());
    } else {
        return null;
    }
    Node packagingNode = doc.selectSingleNode("/project/packaging");
    if (null != packagingNode) {
        Element node = (Element) packagingNode;
        map.put("packaging", node.getStringValue());
    } else {
        return null;
    }

    return map;
}

From source file:com.github.ipaas.ifw.util.XmlUtil.java

License:Apache License

/**
 * , dom4j Element???map/*w  w w .  ja v  a 2 s  .  c o  m*/
 * 
 * @param container
 *            -- ?dom4j Elementmap
 * @param elem
 *            -- dom4j Element
 * @return -- map
 */
private static Map generateMap(Map container, Element elem) {

    String name = elem.getName();
    Object obj = container.get(name);
    // ????
    if (null != obj) {
        if (!List.class.isInstance(obj)) { // ??,?List(List)
            List<Object> newBean = new LinkedList<Object>();
            newBean.add(obj);
            container.put(name, newBean);
            generateMap(container, elem);
        } else { // ??,List(?elem?List)
            List<Object> bean = (List<Object>) obj;
            if (elem.isTextOnly()) {
                bean.add(elem.getStringValue());
            } else {
                List<Element> subs = elem.elements();
                Map nodes = new LinkedHashMap();
                bean.add(nodes);
                for (Element item : subs) {
                    generateMap(nodes, item);
                }
            }
        }
        return container;
    }
    // ?????
    if (elem.isTextOnly()) { // ?xml,?
        container.put(name, elem.getStringValue());
    } else {
        List<Element> subs = elem.elements();
        Map nodes = new LinkedHashMap();
        container.put(name, nodes);
        for (Element item : subs) {
            generateMap(nodes, item);
        }
    }
    return container;
}

From source file:com.glaf.core.xml.XmlBuilder.java

License:Apache License

protected void processTextNode(Element element, Map<String, DatasetModel> dataSetMap,
        Map<String, Object> dataMap, String systemName, Map<String, Object> params) {
    //LOG.debug("---------------------processTextNode-----------------------");
    if (StringUtils.equals(element.getName(), "foreach")) {
        this.processForEachNode(element, dataSetMap, dataMap, systemName, params);
        return;/*  ww  w. j a va  2  s .c o  m*/
    }
    String dsId = element.attributeValue("DataSetId");
    if (StringUtils.isNotEmpty(dsId)) {
        if (dataMap != null && !dataMap.isEmpty()) {
            params.putAll(dataMap);
        }
        this.processNode(element, dataSetMap, systemName, params);
        return;
    }

    if (element.isTextOnly()) {
        String value = element.getStringValue();
        if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) {
            String text = QueryUtils.replaceBlankParas(value, dataMap);
            element.setText(text);
        }
    }

    List<?> attrs = element.attributes();
    Iterator<?> iter = attrs.iterator();
    while (iter.hasNext()) {
        Attribute attr = (Attribute) iter.next();
        String value = attr.getValue();
        if (StringUtils.contains(value, "#{") && StringUtils.contains(value, "}")) {
            String text = QueryUtils.replaceBlankParas(value, dataMap);
            attr.setValue(text);
        }
    }

    List<?> elements = element.elements();
    Iterator<?> iterator = elements.iterator();
    while (iterator.hasNext()) {
        Element elem = (Element) iterator.next();
        if (StringUtils.equals(elem.getName(), "foreach")) {
            this.processForEachNode(elem, dataSetMap, dataMap, systemName, params);
        } else {
            String dsId2 = elem.attributeValue("DataSetId");
            if (StringUtils.isNotEmpty(dsId2)) {
                if (dataMap != null && !dataMap.isEmpty()) {
                    params.putAll(dataMap);
                }
                this.processNode(elem, dataSetMap, systemName, params);
            } else {
                this.processTextNode(elem, dataSetMap, dataMap, systemName, params);
            }
        }
    }
}