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.zimbra.cs.client.soap.LmcSoapRequest.java

License:Open Source License

protected LmcContactAttr parseContactAttr(Element cna) throws ServiceException {
    // get the attributes
    String attrName = DomUtil.getAttr(cna, MailConstants.A_ATTRIBUTE_NAME);
    String attrID = cna.attributeValue(MailConstants.A_ID);
    String ref = cna.attributeValue(MailConstants.A_REF);
    String attrData = cna.getText();

    LmcContactAttr lca = new LmcContactAttr(attrName, attrID, ref, attrData);
    return lca;// w  ww  .j a  v a  2  s . com
}

From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java

License:Open Source License

protected LmcMessage parseMessage(Element msg) throws ServiceException, LmcSoapClientException {
    LmcMessage result = new LmcMessage();

    // get the message attributes
    result.setID(DomUtil.getAttr(msg, MailConstants.A_ID));
    result.setFlags(msg.attributeValue(MailConstants.A_FLAGS));
    String size = msg.attributeValue(MailConstants.A_SIZE);
    if (size != null)
        result.setSize(Integer.parseInt(size));
    result.setContentMatched(msg.attributeValue(MailConstants.A_CONTENTMATCHED));
    result.setDate(msg.attributeValue(MailConstants.A_DATE));
    result.setConvID(msg.attributeValue(MailConstants.A_CONV_ID));
    result.setFolder(msg.attributeValue(MailConstants.A_FOLDER));
    result.setOriginalID(msg.attributeValue(MailConstants.A_ORIG_ID));

    /*/*from  www. j  a  v  a  2 s  .  c  o m*/
       * iterate over subelements. allowed subelements are content (at most
       * 1), subject, fragment, and msg parts. this assumes no particular
       * order is required for correctness.
       */
    ArrayList emailAddrs = new ArrayList();
    for (Iterator it = msg.elementIterator(); it.hasNext();) {
        Element e = (Element) it.next();

        // find out what element it is and go process that
        String elementType = e.getQName().getName();
        if (elementType.equals(MailConstants.E_FRAG)) {
            // fragment
            result.setFragment(e.getText());
        } else if (elementType.equals(MailConstants.E_EMAIL)) {
            // e-mail address
            LmcEmailAddress ea = parseEmailAddress(e);
            emailAddrs.add(ea);
        } else if (elementType.equals(MailConstants.E_SUBJECT)) {
            // subject
            result.setSubject(e.getText());
        } else if (elementType.equals(MailConstants.E_MIMEPART)) {
            // MIME part
            LmcMimePart mp = parseMimePart(e);
            result.addMimePart(mp);
        } else if (elementType.equals(MailConstants.E_MSG_ID_HDR)) {
            // message ID header
            result.setMsgIDHeader(e.getText());
        } else if (elementType.equals(MailConstants.E_INVITE)) {
            // ignore appointment invites for now
        } else {
            // don't know what it is
            throw new LmcSoapClientException("unknown element " + elementType + " within message");
        }
    }

    if (!emailAddrs.isEmpty()) {
        LmcEmailAddress a[] = new LmcEmailAddress[emailAddrs.size()];
        result.setEmailAddresses((LmcEmailAddress[]) emailAddrs.toArray(a));
    }

    return result;
}

From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java

License:Open Source License

/**
 * Add the information in the Element c to the MimePart mp.
 * @param mp//from   w  w w . j av a  2  s.c o m
 * @param c
 */
protected void addContent(LmcMimePart mp, Element c) {
    // XXX need constant
    mp.setContentEncoding(c.attributeValue("cte"));
    mp.setContent(c.getText());
}

From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java

License:Open Source License

protected LmcEmailAddress parseEmailAddress(Element ea) {
    LmcEmailAddress result = new LmcEmailAddress();

    // grab all the attributes
    result.setType(ea.attributeValue(MailConstants.A_ADDRESS_TYPE));
    result.setEmailID(ea.attributeValue(MailConstants.A_ID));
    result.setReferencedID(ea.attributeValue(MailConstants.A_REF));
    result.setPersonalName(ea.attributeValue(MailConstants.A_PERSONAL));
    result.setEmailAddress(ea.attributeValue(MailConstants.A_ADDRESS));
    result.setDisplayName(ea.attributeValue(MailConstants.A_DISPLAY));

    // get the content if any
    result.setContent(ea.getText());

    return result;
}

From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java

License:Open Source License

protected void addPrefToMultiMap(HashMap prefMap, Element e) throws ServiceException {
    String name = DomUtil.getAttr(e, AdminConstants.A_NAME);
    String value = e.getText();
    StringUtil.addToMultiMap(prefMap, name, value);
}

From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java

License:Open Source License

protected LmcNote parseNote(Element n) throws ServiceException {
    LmcNote result = new LmcNote();

    // grab all the attributes
    result.setID(DomUtil.getAttr(n, MailConstants.A_ID));
    result.setTags(n.attributeValue(MailConstants.A_TAGS));
    result.setDate(DomUtil.getAttr(n, MailConstants.A_DATE));
    result.setFolder(DomUtil.getAttr(n, MailConstants.A_FOLDER));
    result.setPosition(DomUtil.getAttr(n, MailConstants.A_BOUNDS));
    result.setColor(DomUtil.getAttr(n, MailConstants.A_COLOR));

    // get the content
    Element c = DomUtil.get(n, MailConstants.E_CONTENT);
    result.setContent(c.getText());

    return result;
}

From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java

License:Open Source License

protected LmcWiki parseWiki(Element wiki) {
    LmcWiki result = new LmcWiki();
    parseDocumentCommon(wiki, result);//from  www. ja  va  2s.  c om

    result.setWikiWord(wiki.attributeValue(MailConstants.A_NAME));

    try {
        Element c = DomUtil.get(wiki, MailConstants.A_BODY);
        result.setContents(c.getText());
    } catch (Exception e) {
    }

    return result;
}

From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java

License:Open Source License

private LmcDocument parseDocumentCommon(Element doc, LmcDocument result) {
    result.setID(doc.attributeValue(MailConstants.A_ID));
    result.setName(doc.attributeValue(MailConstants.A_NAME));
    result.setContentType(doc.attributeValue(MailConstants.A_CONTENT_TYPE));
    result.setFolder(doc.attributeValue(MailConstants.A_FOLDER));
    result.setRev(doc.attributeValue(MailConstants.A_VERSION));
    result.setLastModifiedDate(doc.attributeValue(MailConstants.A_DATE));
    result.setLastEditor(doc.attributeValue(MailConstants.A_LAST_EDITED_BY));
    result.setRestUrl(doc.attributeValue(MailConstants.A_REST_URL));
    result.setCreator(doc.attributeValue(MailConstants.A_CREATOR));
    result.setCreateDate(doc.attributeValue(MailConstants.A_CREATED_DATE));

    for (Iterator it = doc.elementIterator(); it.hasNext();) {
        Element e = (Element) it.next();

        String elementType = e.getQName().getName();
        if (elementType.equals(MailConstants.E_FRAG)) {
            // fragment
            result.setFragment(e.getText());
        }// w w  w . j  a  v  a 2s  . c  o m
    }
    return result;
}

From source file:com.zimbra.cs.dav.client.DavObject.java

License:Open Source License

public DavObject(Element objElem) {
    mProps = new HashMap<Integer, Element>();
    if (!objElem.getQName().equals(DavElements.E_RESPONSE))
        return;//from  w  w w. ja v a2  s  .c  om
    Element href = objElem.element(DavElements.E_HREF);
    if (href != null)
        mHref = href.getText();
    for (Object obj : objElem.elements(DavElements.E_PROPSTAT)) {
        Element propStat = (Element) obj;
        Integer status = null;
        Element statusElem = propStat.element(DavElements.E_STATUS);
        if (statusElem != null)
            status = parseStatusCode(statusElem.getText());
        mProps.put(status, propStat.element(DavElements.E_PROP));
    }
}

From source file:com.zimbra.cs.dav.client.DavObject.java

License:Open Source License

public String getPropertyText(QName prop) {
    Element e = getProperty(prop);
    if (e != null)
        return e.getText();
    return null;//from w w  w . ja  va2s.c  om
}