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.xpn.xwiki.tool.xar.XarMojo.java

License:Open Source License

/**
 * Gets the list of document names from a 'package.xml'-like document.
 * /*  ww  w .  j ava  2 s  .c o m*/
 * @param file the XML document to parse
 * @return the list of document names contained in the XML document
 * @throws Exception if the XML document is invalid or it contains no document list or it doesn't exist
 */
protected static Collection<String> getDocumentNamesFromXML(File file) throws Exception {
    Collection<String> result = new LinkedList<String>();
    SAXReader reader = new SAXReader();
    Document domdoc;
    domdoc = reader.read(file);

    Element filesElement = domdoc.getRootElement().element(FILES_TAG);

    if (filesElement == null) {
        throw new Exception("The supplied document contains no document list ");
    }

    Collection elements = filesElement.elements(FILE_TAG);
    for (Object item : elements) {
        if (item instanceof Element) {
            Element currentElement = (Element) item;
            String documentName = currentElement.getText();
            result.add(documentName);
        }
    }

    return result;
}

From source file:com.xpn.xwiki.tool.xar.XWikiDocument.java

License:Open Source License

/**
 * Parse xml file to extract documents informations.
 * /*  w w  w  .j  a va  2  s.c o  m*/
 * @param file the xml file.
 * @throws DocumentException error when parsing XML file.
 */
public void fromXML(File file) throws DocumentException {
    SAXReader reader = new SAXReader();
    Document domdoc = reader.read(file);

    Element docel = domdoc.getRootElement();

    Element elementName = docel.element("name");
    if (elementName != null) {
        this.name = elementName.getText();
    }

    Element elementSpace = docel.element("web");
    if (elementSpace != null) {
        this.space = elementSpace.getText();
    }

    Element elementLanguage = docel.element("language");
    if (elementLanguage != null) {
        this.language = elementLanguage.getText();
    }

    Element elementDefaultLanguage = docel.element("defaultLanguage");
    if (elementDefaultLanguage != null) {
        this.defaultLanguage = elementDefaultLanguage.getText();
    }
}

From source file:com.yinghua.translation.rest.PhoneResourceRESTService.java

License:Apache License

/**
 * /*from www.jav  a 2 s  .c  o m*/
 * 
 * @param params
 * @return
 */
@POST
@Path("/weixinNotify")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public String weixinNotify(String params) {
    String req = null;
    Document reqDoc = DocumentHelper.createDocument();
    Element reqRoot = reqDoc.addElement("xml");
    Element reqCode = reqRoot.addElement("return_code");
    try {
        Document doc = DocumentHelper.parseText(params);
        Element root = doc.getRootElement();
        Element returnCode = root.element("return_code");
        if ("SUCCESS".equals(returnCode.getText())) {
            String orderNo = root.elementText("out_trade_no");
            MemberOrder order = memberOrderBean.findByOrderNo(orderNo);
            if (order != null && "SUCCESS".equals(root.elementText("result_code"))) {
                if (order.getState() != OrderStatus.FINISHED) {//????
                    order.setState(OrderStatus.FINISHED);
                    if (System.currentTimeMillis() >= order.getServiceTime().getTime()) {
                        Account account = accountBean.findByMemberNo(order.getMemberNumber());
                        int addCall = order.getSurplusCallDuration() + account.getSurplusCallDuration();
                        account.setSurplusCallDuration(addCall);
                        accountBean.updateAccount(account);
                        order.setUseState(OrderUseStatus.USING);
                    }
                    memberOrderBean.updateOrder(order);
                    System.out.println("orderNo:" + order.getOrderNo() + "|orderState:" + order.getState()
                            + "|orderUseState:" + order.getUseState());
                }
            } else {
                System.out.println("??");
            }

            PayWeixinLog pwl = new PayWeixinLog();
            pwl.setAppid(root.elementText("appid"));
            pwl.setMchId(root.elementText("mch_id"));
            if (root.element("device_info") != null)
                pwl.setDeviceInfo(root.elementText("device_info"));
            pwl.setNonceStr(root.elementText("nonce_str"));
            pwl.setSign(root.elementText("sign"));
            pwl.setResultCode(root.elementText("result_code"));
            if (root.element("err_code") != null)
                pwl.setErrCode(root.elementText("err_code"));
            if (root.element("err_code_des") != null)
                pwl.setErrCodeDes(root.elementText("err_code_des"));
            pwl.setOpenid(root.elementText("openid"));
            if (root.element("is_subscribe") != null)
                pwl.setIsSubscribe(root.elementText("is_subscribe"));
            pwl.setTradeType(root.elementText("trade_type"));
            pwl.setBankType(root.elementText("bank_type"));
            pwl.setTotalFee(Integer.parseInt(root.elementText("total_fee")));
            if (root.element("fee_type") != null)
                pwl.setFeeType(root.elementText("fee_type"));
            if (root.element("cash_fee") != null)
                pwl.setCashFee(Integer.parseInt(root.elementText("cash_fee")));
            if (root.element("cash_fee_type") != null)
                pwl.setCashFeeType(root.elementText("cash_fee_type"));
            pwl.setTransationId(root.elementText("transation_id"));
            pwl.setOutTradeNo(root.elementText("out_trade_no"));
            if (root.element("attach") != null)
                pwl.setAttach(root.elementText("attach"));
            pwl.setTimeEnd(root.elementText("time_end"));
            payWeixinLogBean.createPayWeixinLog(pwl);

            reqCode.setText("SUCCESS");
        } else {
            reqCode.setText("FAIL");
            Element returnMsg = root.element("return_msg");
            returnMsg.setText(root.elementText("retrun_msg"));
        }
    } catch (Exception e) {
        e.printStackTrace();
        reqCode.setText("FAIL");
        Element reqMsg = reqRoot.addElement("return_msg");
        reqMsg.setText("");
    }
    req = reqDoc.asXML();
    return req;
}

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

License:Open Source License

public static int asInt(Element e) {
    return Integer.parseInt(e.getText());
}

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

License:Open Source License

public static long asLong(Element e) {
    return Long.parseLong(e.getText());
}

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

License:Open Source License

public static String asString(Element e) {
    return e.getText();
}

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

License:Open Source License

public static boolean asBoolean(Element e) {
    return e.getText().equals("1");
}

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

License:Open Source License

public static String getString(Element parent, String name) throws ServiceException {
    Element e = parent.element(name);
    if (e == null)
        throw ServiceException.INVALID_REQUEST("missing required element: " + name, null);
    return e.getText();
}

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

License:Open Source License

public static String getString(Element parent, String name, String defaultValue) {
    Element e = parent.element(name);
    if (e == null)
        return defaultValue;
    return e.getText();
}

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

License:Open Source License

private Element expandProps(Element doc) throws HarnessException {
    for (Element e : doc.listElements()) {
        expandProps(e);//w  ww  .  j  av  a  2s  . c  o m
    }
    for (Element.Attribute attr : doc.listAttributes()) {
        String text = attr.getValue();
        if (text.indexOf("${") != -1)
            attr.setValue(expandAllProps(text));
    }
    String text = doc.getText();
    if (text.indexOf("${") != -1)
        doc.setText(expandAllProps(text));
    return doc;
}