Example usage for org.dom4j Node getText

List of usage examples for org.dom4j Node getText

Introduction

In this page you can find the example usage for org.dom4j Node getText.

Prototype

String getText();

Source Link

Document

Returns the text of this node.

Usage

From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java

protected Document imageMessageReceive(Document doc4j, WechatMessage wechatMessage) throws ServiceException {
    Node msgIdNode = doc4j.selectSingleNode("/xml/MsgId");
    Node picUrlNode = doc4j.selectSingleNode("/xml/PicUrl");
    Node mediaIdNode = doc4j.selectSingleNode("/xml/MediaId");
    String msgId = msgIdNode == null ? "" : msgIdNode.getText();
    String picUrl = picUrlNode == null ? "" : picUrlNode.getText();
    String mediaId = mediaIdNode == null ? "" : mediaIdNode.getText();

    Document respDoc4j;//from  w  w w. java 2s.  com
    WechatNormalImageMessageRequest imageMessage = new WechatNormalImageMessageRequest();
    try {
        BeanUtils.copyProperties(imageMessage, wechatMessage);
    } catch (IllegalAccessException | InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    imageMessage.setMsgId(msgId);
    imageMessage.setPicUrl(picUrl);
    imageMessage.setMediaId(mediaId);
    respDoc4j = messageRecive(imageMessage);
    return respDoc4j;
}

From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java

protected Document textMessageReceive(Document doc4j, WechatMessageBaseRequest wechatMessage)
        throws ServiceException {
    Node msgIdNode = doc4j.selectSingleNode("/xml/MsgId");
    Node contentNode = doc4j.selectSingleNode("/xml/Content");
    String msgId = msgIdNode == null ? "" : msgIdNode.getText();
    String content = contentNode == null ? "" : contentNode.getText();
    WechatNormalTextMessageRequest textMessage = new WechatNormalTextMessageRequest();
    try {/*  ww  w. j  a va  2s  .  c o m*/
        BeanUtils.copyProperties(textMessage, wechatMessage);
    } catch (IllegalAccessException | InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    textMessage.setMsgId(msgId);
    textMessage.setContent(content);
    Document respDoc4j = messageRecive(textMessage);
    return respDoc4j;
}

From source file:cn.com.xdays.xshop.action.admin.InstallAction.java

private boolean isInstalled() {
    try {//  w w w .  j  a  v  a 2s  . c  om
        String systemConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
                .getPath() + SystemConfigUtil.CONFIG_FILE_NAME;
        File systemConfigFile = new File(systemConfigFilePath);
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(systemConfigFile);
        Node isInstalledNode = document.selectSingleNode("/shopxx/systemConfig/isInstalled");
        if (isInstalledNode != null && StringUtils.equalsIgnoreCase(isInstalledNode.getText(), "false")) {
            return false;
        } else {
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return true;
    }
}

From source file:cn.mario256.blog.service.impl.ThemeServiceImpl.java

License:Open Source License

/**
 * ?/*from   ww w  .  j  av a  2 s.co  m*/
 * 
 * @param themeXmlFile
 *            ?
 * @return 
 */
private Theme get(File themeXmlFile) {
    try {
        Document document = new SAXReader().read(themeXmlFile);
        Node idNode = document.selectSingleNode("/theme/id");
        Node nameNode = document.selectSingleNode("/theme/name");
        Node versionNode = document.selectSingleNode("/theme/version");
        Node authorNode = document.selectSingleNode("/theme/author");
        Node siteUrlNode = document.selectSingleNode("/theme/siteUrl");
        Node previewNode = document.selectSingleNode("/theme/preview");

        Theme theme = new Theme();
        theme.setId(idNode != null ? idNode.getText().trim() : null);
        theme.setName(nameNode != null ? nameNode.getText().trim() : null);
        theme.setVersion(versionNode != null ? versionNode.getText().trim() : null);
        theme.setAuthor(authorNode != null ? authorNode.getText().trim() : null);
        theme.setSiteUrl(siteUrlNode != null ? siteUrlNode.getText().trim() : null);
        theme.setPreview(previewNode != null ? previewNode.getText().trim() : null);
        return theme;
    } catch (DocumentException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.alefissak.parsers.PlanningParserImpl.java

License:Apache License

/**
 * Parse nodes of receivers, get all informations from these nodes, then
 * add them into planning receivers list
 * /* w  w  w.  j  a va  2s  .co  m*/
 * @param planning the planning to be fill
 * @param planningNode node containing informations on receivers
 * @throws AlefissakParsingException
 */
private void parseReceivers(Planning planning, Node planningNode) throws AlefissakParsingException {

    @SuppressWarnings("unchecked")
    List<Node> receiverNodes = planningNode
            .selectNodes(Constants.CFG_RECEIVERS_TAG_NAME + "/" + Constants.CFG_RECEIVER_TAG_NAME);

    if (receiverNodes.isEmpty()) {
        throw new AlefissakParsingException("You have to specify at least one receiver");
    }

    Node workingNode;

    for (Iterator<Node> iter = receiverNodes.iterator(); iter.hasNext();) {
        Node receiverNode = iter.next();

        workingNode = receiverNode.selectSingleNode(Constants.CFG_NAME_TAG_NAME);

        if (workingNode == null) {
            throw new AlefissakParsingException("Please define all receiver's name");
        }

        AlefissakReceiver receiver = new AlefissakReceiver();
        receiver.setName(workingNode.getText().toString());

        workingNode = receiverNode.selectSingleNode(Constants.CFG_MAIL_TAG_NAME);
        if (workingNode == null) {
            throw new AlefissakParsingException("Please define all receiver's mail");
        }

        receiver.setMail(workingNode.getText().toString());

        workingNode = receiverNode.selectSingleNode(Constants.CFG_VARS_TAG_NAME);

        if (workingNode != null) {
            setVars(receiver, workingNode.getText().toString());
        }

        planning.addReceiver(receiver);
    }
}

From source file:com.alibaba.antx.config.resource.util.ApacheIndexPageParser.java

License:Open Source License

public List parse(Resource resource) {
    Document doc = getHtmlDocument(resource);

    if (doc != null) {
        Node title = doc.selectSingleNode("//head/title");

        if (title != null && title.getText() != null && title.getText().startsWith("Index of")) {
            List nodes = doc//from  w  w w. j a  va 2 s.  co  m
                    .selectNodes("//pre/img[starts-with(@alt,'[') and ends-with(@alt,']')]/following::a/@href");
            List items = new ArrayList(nodes.size());

            for (Iterator i = nodes.iterator(); i.hasNext();) {
                Node node = (Node) i.next();
                String name = node.getText();

                try {
                    name = URLDecoder.decode(name, getCharset(resource));
                } catch (UnsupportedEncodingException e) {
                }

                Item item = getItem(name);

                if (item != null) {
                    items.add(item);
                }
            }

            return items;
        }
    }

    return null;
}

From source file:com.alibaba.antx.config.resource.util.SvnIndexPageParser.java

License:Open Source License

public List parse(Resource resource) {
    Document doc;/*from www  . ja  va2s .  co m*/
    boolean xml = true;

    doc = getXmlDocument(resource);

    if (doc == null) {
        doc = getHtmlDocument(resource);
        xml = false;
    }

    List items = null;

    if (doc != null && xml) {
        DocumentType docType = doc.getDocType();

        if (docType != null && "svn".equalsIgnoreCase(docType.getName())) {
            items = new ArrayList();

            addNodes(items, doc.selectNodes("//dir/@name"), true);
            addNodes(items, doc.selectNodes("//file/@name"), false);
        }
    } else if (doc != null && !xml) {
        Node title = doc.selectSingleNode("//head/title");

        if (title != null && title.getText() != null && title.getText().indexOf("Revision") > 0) {
            List nodes = doc.selectNodes("//ul/li/a/@href");

            items = new ArrayList();

            for (Iterator i = nodes.iterator(); i.hasNext();) {
                Node node = (Node) i.next();
                String name = node.getText();

                try {
                    name = URLDecoder.decode(name, getCharset(resource));
                } catch (UnsupportedEncodingException e) {
                }

                Item item = getItem(name);

                if (item != null) {
                    items.add(item);
                }
            }
        }
    }

    return items;
}

From source file:com.alibaba.antx.config.resource.util.SvnIndexPageParser.java

License:Open Source License

private void addNodes(List items, List listOfNodes, boolean directory) {
    for (Iterator i = listOfNodes.iterator(); i.hasNext();) {
        Node node = (Node) i.next();

        items.add(new Item(node.getText(), directory));
    }//  w w  w.  j a v a2 s.c o m
}

From source file:com.alibaba.intl.bcds.goldroom.remote.DoubanBookInfoFetcher.java

License:Open Source License

private String queryByXpath(String xpathExpression, Document document) {
    try {//from  www  . j a v  a2s.co  m
        XPath xPath = createXpath(xpathExpression);
        Node node = xPath.selectSingleNode(document);
        if (node != null) {
            return node.getText();
        }
        return null;
    } catch (RuntimeException e) {
        return null;
    }
}

From source file:com.amalto.workbench.widgets.xmleditor.pagecontent.ExtensibleXMLEditorPageContent.java

License:Open Source License

protected String getSingleValueByPath(Node parent, String relativePath, String valueForNull) {

    if (parent == null) {
        return valueForNull;
    }// www. j av a  2  s  .c  om

    Node node = parent.selectSingleNode("./" + relativePath);//$NON-NLS-1$

    if (node == null) {
        return valueForNull;
    }

    return node.getText();
}