Example usage for org.dom4j Element getTextTrim

List of usage examples for org.dom4j Element getTextTrim

Introduction

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

Prototype

String getTextTrim();

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.wabacus.config.ConfigLoadManager.java

License:Open Source License

public static List<String> getListConfigFilePaths(List lstFileElements) {
    if (lstFileElements == null || lstFileElements.size() == 0)
        return null;
    List<String> lstResults = new ArrayList<String>();
    Element eleTmp;
    for (int i = 0, len = lstFileElements.size(); i < len; i++) {
        eleTmp = (Element) lstFileElements.get(i);
        String filepathTmp = eleTmp.getTextTrim();
        if (filepathTmp == null || filepathTmp.trim().equals(""))
            continue;
        String pattern = eleTmp.attributeValue("pattern");
        boolean isPattern = pattern != null && pattern.toLowerCase().trim().equals("true");
        if (isPattern) {
            boolean isClasspathType = false;
            if (Tools.isDefineKey("classpath", filepathTmp)) {
                filepathTmp = Tools.getRealKeyByDefine("classpath", filepathTmp).trim();
                while (filepathTmp.startsWith("/")) {
                    filepathTmp = filepathTmp.substring(1).trim();
                }//from   w  ww. j a  v a2  s . c  o m
                isClasspathType = true;
            } else if (Tools.isDefineKey("absolute", filepathTmp)) {
                filepathTmp = Tools.getRealKeyByDefine("absolute", filepathTmp).trim();
                filepathTmp = FilePathAssistant.getInstance().standardFilePath(filepathTmp);
            } else if (Tools.isDefineKey("relative", filepathTmp)) {//?
                filepathTmp = Tools.getRealKeyByDefine("relative", filepathTmp).trim();
                filepathTmp = WabacusAssistant.getInstance().getRealFilePath(Config.webroot_abspath,
                        filepathTmp);
            } else {
                filepathTmp = WabacusAssistant.getInstance().getRealFilePath(Config.configpath, filepathTmp);
                if (Tools.isDefineKey("classpath", Config.configpath))
                    isClasspathType = true;
            }
            String recursive = eleTmp.attributeValue("recursive");
            boolean isRecursive = recursive != null && recursive.toLowerCase().trim().equals("true");
            FilePathAssistant.getInstance().getLstFilesByPath(lstResults, filepathTmp, isClasspathType,
                    isRecursive);
        } else {
            if (Tools.isDefineKey("classpath", filepathTmp)) {
                filepathTmp = Tools.getRealKeyByDefine("classpath", filepathTmp).trim();
                while (filepathTmp.startsWith("/")) {
                    filepathTmp = filepathTmp.substring(1).trim();
                }
                filepathTmp = "classpath{" + filepathTmp + "}";//classpath
            } else if (Tools.isDefineKey("absolute", filepathTmp)) {
                filepathTmp = Tools.getRealKeyByDefine("absolute", filepathTmp).trim();
                filepathTmp = FilePathAssistant.getInstance().standardFilePath(filepathTmp);
            } else if (Tools.isDefineKey("relative", filepathTmp)) {
                filepathTmp = Tools.getRealKeyByDefine("relative", filepathTmp).trim();
                filepathTmp = WabacusAssistant.getInstance().getRealFilePath(Config.webroot_abspath,
                        filepathTmp);
            } else {
                filepathTmp = WabacusAssistant.getInstance().getRealFilePath(Config.configpath, filepathTmp);
                if (Tools.isDefineKey("classpath", Config.configpath)) {
                    filepathTmp = "classpath{" + filepathTmp + "}";
                }
            }
            if (!lstResults.contains(filepathTmp))
                lstResults.add(filepathTmp);
        }
    }
    return lstResults;
}

From source file:com.wifi.util.msg.MessageBuilder.java

@SuppressWarnings("unchecked")
public AppMessage buildAppMessage() throws DocumentException {
    AppMessage msg = new AppMessage();
    try {//from   ww w . j  a  va  2 s .c  om
        Document document = DocumentHelper.parseText(this.xmlText);
        Element rootElt = document.getRootElement();
        if (!rootElt.getName().equals(AppMessage.MESSAGE_TAG)) {
            System.err.println("The xml message tag is incorrect!" + rootElt.getName());
            return null;
        }

        Element headElt = rootElt.element(AppMessage.HEADER_TAG);
        if (headElt == null) {
            System.err.println("The message content is incorrect [no message header]!");
            return null;
        }

        MessageHeader header = new MessageHeader();

        header.setDevMac(headElt.elementTextTrim(MessageHeader.DEV_MAC_TAG));
        header.setHwId(headElt.elementTextTrim(MessageHeader.HW_ID_TAG));
        header.setLicense(headElt.elementTextTrim(MessageHeader.LICENSE_TAG));
        header.setMagic(headElt.elementTextTrim(MessageHeader.MAGIC_TAG));
        header.setMsgId(headElt.elementTextTrim(MessageHeader.MSG_ID_TAG));
        header.setSrcIp(headElt.elementTextTrim(MessageHeader.SRC_IP_TAG));
        header.setTargetIp(headElt.elementTextTrim(MessageHeader.TARGET_IP_TAG));
        msg.setHeader(header);
        System.out.println(header);

        Element bodyElt = rootElt.element(AppMessage.BODY_TAG);
        if (bodyElt == null) {
            System.out.println("The message doesn't exists message body!");
        } else {
            MessageBody body = new MessageBody();
            Map<String, String> map = new HashMap<>();
            Iterator<Element> bdyIterator = bodyElt.elementIterator();
            while (bdyIterator.hasNext()) {
                Element element = bdyIterator.next();
                map.put(element.getName(), element.getTextTrim());
            }
            body.setItemsMap(map);
            msg.setBody(body);
            System.out.println(body);
        }

    } catch (Exception e) {
        System.err.println("parse error: " + e.getMessage());
        return null;
    }

    return msg;
}

From source file:com.zia.freshdocs.cmis.CMISParser10.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from www.j a va 2  s . com
public NodeRef[] parseChildren(InputStream is) {
    NodeRef[] children = null;

    HashMap<String, String> nsMap = new HashMap<String, String>();
    nsMap.put("atom", ATOM_NS);
    nsMap.put("cmis", CMIS_NS);

    DocumentFactory factory = new DocumentFactory();
    factory.setXPathNamespaceURIs(nsMap);

    SAXReader reader = new SAXReader();
    reader.setDocumentFactory(factory);

    try {
        Document document = reader.read(is);
        List<Element> entries = (List<Element>) document.selectNodes("/atom:feed/atom:entry");
        int numEntries = entries.size();
        children = new NodeRef[numEntries];

        Element entry;
        NodeRef nodeRef;

        // Iterate over each entry element and find corresponding attrs
        for (int i = 0; i < numEntries; i++) {
            nodeRef = new NodeRef();
            children[i] = nodeRef;

            entry = entries.get(i);

            // Get either the node uuid or src uri and content type
            Element id = entry.element("id");
            String uuid = id.getTextTrim().replace(URN_UUID, "");
            nodeRef.setContent(uuid);

            Element content = entry.element("content");
            String contentType = content.attributeValue("type");

            if (contentType != null) {
                nodeRef.setContentType(contentType);
                nodeRef.setContent(content.attributeValue("src"));
            }

            List<Element> cmisProperties = entry.selectNodes(".//cmis:properties/*");
            int numProperties = cmisProperties.size();
            Element cmisProperty;

            // Iterate over each property and populate associated field in NodeRef
            for (int j = 0; j < numProperties; j++) {
                cmisProperty = cmisProperties.get(j);
                String attrValue = cmisProperty.attributeValue("propertyDefinitionId");

                if (attrValue == null) {
                    continue;
                }

                if (attrValue.equals("cmis:name")) {
                    nodeRef.setName(cmisProperty.elementTextTrim("value"));
                }

                if (attrValue.equals("cmis:baseTypeId")) {
                    String typeId = cmisProperty.elementTextTrim("value");
                    nodeRef.setFolder(typeId != null && typeId.equals("cmis:folder"));
                }

                if (attrValue.equals("cmis:lastModificationDate")) {
                    nodeRef.setLastModificationDate(cmisProperty.elementTextTrim("value"));
                }

                if (attrValue.equals("cmis:lastModifiedBy")) {
                    nodeRef.setLastModifiedBy(cmisProperty.elementTextTrim("value"));
                }

                if (attrValue.equals("cmis:versionLabel")) {
                    nodeRef.setVersion(cmisProperty.elementTextTrim("value"));
                }

                if (attrValue.equals("cmis:createdBy")) {
                    nodeRef.setCreateBy(cmisProperty.elementTextTrim("value"));
                }

                if (attrValue.equals("cmis:objectId")) {
                    nodeRef.setObjectId(cmisProperty.elementTextTrim("value"));
                }

                if (attrValue.equals("cmis:parentId")) {
                    nodeRef.setParentId(cmisProperty.elementTextTrim("value"));
                }

                if (attrValue.equals("cmis:contentStreamLength")) {
                    nodeRef.setContentLength(Long.valueOf(cmisProperty.elementTextTrim("value")));
                }
            }
        }
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return children;
}

From source file:com.zimbra.common.soap.Soap11Protocol.java

License:Open Source License

public SoapFaultException soapFault(Element fault) {
    if (!isFault(fault))
        return new SoapFaultException("not a soap fault ", fault);

    Element code = fault.getOptionalElement(FAULTCODE);
    boolean isReceiversFault = RECEIVER_CODE.equals(code == null ? null : code.getQName());

    String reasonValue;/*from  ww w . j ava 2s .  c om*/
    Element faultString = fault.getOptionalElement(FAULTSTRING);
    if (faultString != null)
        reasonValue = faultString.getTextTrim();
    else
        reasonValue = "unknown reason";

    Element detail = fault.getOptionalElement(DETAIL);

    return new SoapFaultException(reasonValue, detail, isReceiversFault, fault);
}

From source file:com.zimbra.common.soap.Soap12Protocol.java

License:Open Source License

/** Given an Element that represents a fault (i.e,. isFault returns 
 *  true on it), construct a SoapFaultException from it. 
 *
 * @return new SoapFaultException/*from   w ww .  j  ava 2  s  . c o m*/
 * @throws ServiceException */
public SoapFaultException soapFault(Element fault) {
    if (!isFault(fault))
        return new SoapFaultException("not a soap fault ", fault);

    boolean isReceiversFault = false;
    Element code = fault.getOptionalElement(CODE);
    if (code != null) {
        Element value = code.getOptionalElement(VALUE);
        isReceiversFault = RECEIVER_CODE.getQualifiedName().equals(value == null ? null : value.getTextTrim());
    }

    String reasonValue;
    Element reason = fault.getOptionalElement(REASON);
    Element reasonText = (reason == null ? null : reason.getOptionalElement(TEXT));
    if (reasonText != null)
        reasonValue = reasonText.getTextTrim();
    else
        reasonValue = "unknown reason";

    Element detail = fault.getOptionalElement(DETAIL);

    return new SoapFaultException(reasonValue, detail, isReceiversFault, fault);
}

From source file:com.zimbra.common.soap.SoapProtocol.java

License:Open Source License

/**
 * Walk the passed-in Fault element, find Arguments (see ServiceException.Argument ) of type ItemID
 * and update them so that they contain the target account ID
 *
 * @param element//from   w ww  .j a va 2s .c  om
 * @param remoteAccountId
 */
public void updateArgumentsForRemoteFault(Element element, String remoteAccountId) {
    if (!isFault(element)) {
        return;
    }

    // We are going to proxy a REMOTE fault through, therefore we must
    // patch any arguments of type ITEMID so that they have the appropriate account info
    for (Element arg : element.getPathElementList(ZIMBRA_ERROR_ELEMENT)) {
        String type = arg.getAttribute("t", "UNKNOWN");
        if (type.equals(ServiceException.Argument.Type.IID.toString())) {
            String value = arg.getTextTrim();
            if (value.indexOf(":") < 0) {
                arg.setText(remoteAccountId + ":" + value);
            }
        }
    }
}

From source file:com.zimbra.common.soap.SoapTestHarness.java

License:Open Source License

private void doEcho(Element e) {
    System.out.println(e.getTextTrim());
}

From source file:com.zving.framework.Config.java

public static void loadConfig() {
    SAXReader reader = new SAXReader(false);
    try {//  w  w w  .j a  va  2  s . c o m
        configFileName = getRealConfigFileName();
        File f = new File(configFileName);
        if (!(f.exists())) {
            LogUtil.warn("?" + configFileName + "!");
            isDatabaseConfiged = false;
            return;
        }
        Document doc = reader.read(f);
        Element root = doc.getRootElement();
        Element application = root.element("application");
        List elements = application.elements();
        for (int i = 0; i < elements.size(); ++i) {
            Element ele = (Element) elements.get(i);
            configMap.put("App." + ele.attributeValue("name"), ele.getTextTrim());
        }
        Element databases = root.element("databases");
        if (databases != null) {
            List dbs = databases.elements();
            for (int i = 0; i < dbs.size(); ++i) {
                Element ele = (Element) dbs.get(i);
                String dbname = ele.attributeValue("name").trim();
                List configs = ele.elements();
                for (int k = 0; k < configs.size(); ++k) {
                    ele = (Element) configs.get(k);
                    String attr = ele.attributeValue("name");
                    String value = ele.getTextTrim();
                    if ((attr.equalsIgnoreCase("Password")) && (value.startsWith("$KEY"))) {
                        value = EncryptUtil.decrypt3DES(value.substring(4), "27jrWz3sxrVbR+pnyg6j");
                    }

                    configMap.put("Database." + dbname + "." + attr, value);
                }
            }
            isDatabaseConfiged = true;
            return;
        }
        isDatabaseConfiged = false;
    } catch (Exception e) {
        e.printStackTrace();
        isDatabaseConfiged = false;
    }
}

From source file:cz.fi.muni.xkremser.editor.server.newObject.MonographBuilder.java

License:Open Source License

private void updateLanguages(Document doc, XPath xpath) {
    List<? extends Node> nodes = xpath.selectNodes(doc);
    for (Node languageNode : nodes) {
        Element languageEl = (Element) languageNode;
        String originalLang = languageEl.getTextTrim();
        languageEl.clearContent();/*w  w w  .j  a v a 2s.  co  m*/
        languageEl.addText(transformLanguage(originalLang));
    }
}

From source file:cz.fi.muni.xkremser.editor.server.newObject.MonographBuilder.java

License:Open Source License

private void addPhysicalLocation(Document modsDoc, MarcSpecificMetadata marc) {
    String location = marc.getLocation();
    if (location != null) {
        Element locationEl = (Element) locationXpath.selectSingleNode(modsDoc);
        Element shelfLocatorEl = (Element) shelfLocatorXpath.selectSingleNode(locationEl);
        String shelfLocatorStr = shelfLocatorEl.getTextTrim();
        shelfLocatorEl.detach();//from  www. jav  a2  s  .  c  o  m
        Element physicalLocationEl = locationEl.addElement(new QName("physicalLocation", Namespaces.mods));
        physicalLocationEl.addText(location);
        shelfLocatorEl = locationEl.addElement(new QName("shelfLocator", Namespaces.mods));
        shelfLocatorEl.addText(shelfLocatorStr);
    }
}