Example usage for org.dom4j Element elementText

List of usage examples for org.dom4j Element elementText

Introduction

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

Prototype

String elementText(QName qname);

Source Link

Usage

From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java

License:Apache License

private static InMessage parseInImageMessage(Element root, String toUserName, String fromUserName,
        Integer createTime, String msgType) {
    InImageMessage msg = new InImageMessage(toUserName, fromUserName, createTime, msgType);
    msg.setPicUrl(root.elementText("PicUrl"));
    msg.setMediaId(root.elementText("MediaId"));
    msg.setMsgId(root.elementText("MsgId"));
    return msg;/* w  ww  .  j ava 2  s  .c o m*/
}

From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java

License:Apache License

private static InMessage parseInVoiceMessage(Element root, String toUserName, String fromUserName,
        Integer createTime, String msgType) {
    InVoiceMessage msg = new InVoiceMessage(toUserName, fromUserName, createTime, msgType);
    msg.setMediaId(root.elementText("MediaId"));
    msg.setFormat(root.elementText("Format"));
    msg.setMsgId(root.elementText("MsgId"));
    return msg;//from  w w  w. j  a va 2 s.  c  om
}

From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java

License:Apache License

private static InMessage parseInVideoMessage(Element root, String toUserName, String fromUserName,
        Integer createTime, String msgType) {
    InVideoMessage msg = new InVideoMessage(toUserName, fromUserName, createTime, msgType);
    msg.setMediaId(root.elementText("MediaId"));
    msg.setThumbMediaId(root.elementText("ThumbMediaId"));
    msg.setMsgId(root.elementText("MsgId"));
    return msg;//from www . jav a  2  s.c  o m
}

From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java

License:Apache License

private static InMessage parseInLocationMessage(Element root, String toUserName, String fromUserName,
        Integer createTime, String msgType) {
    InLocationMessage msg = new InLocationMessage(toUserName, fromUserName, createTime, msgType);
    msg.setLocation_X(root.elementText("Location_X"));
    msg.setLocation_Y(root.elementText("Location_Y"));
    msg.setScale(root.elementText("Scale"));
    msg.setLabel(root.elementText("Label"));
    msg.setMsgId(root.elementText("MsgId"));
    return msg;// w w w  .j av a  2s  .  c  o m
}

From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java

License:Apache License

private static InMessage parseInLinkMessage(Element root, String toUserName, String fromUserName,
        Integer createTime, String msgType) {
    InLinkMessage msg = new InLinkMessage(toUserName, fromUserName, createTime, msgType);
    msg.setTitle(root.elementText("Title"));
    msg.setDescription(root.elementText("Description"));
    msg.setUrl(root.elementText("Url"));
    msg.setMsgId(root.elementText("MsgId"));
    return msg;/* w  w w. j  av a 2  s  .c  o  m*/
}

From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java

License:Apache License

private static InMessage parseInEvent(Element root, String toUserName, String fromUserName, Integer createTime,
        String msgType) {/*from w w  w  . j av  a2s  .com*/
    String event = root.elementText("Event");
    if ("LOCATION".equals(event)) {
        InLocationEvent e = new InLocationEvent(toUserName, fromUserName, createTime, msgType);
        e.setEvent(event);
        e.setLatitude(root.elementText("Latitude"));
        e.setLongitude(root.elementText("Longitude"));
        e.setPrecision(root.elementText("Precision"));
        return e;
    }

    if ("CLICK".equals(event) || "VIEW".equals(event)) {
        InMenuEvent e = new InMenuEvent(toUserName, fromUserName, createTime, msgType);
        e.setEvent(event);
        e.setEventKey(root.elementText("EventKey"));
        return e;
    }

    String eventKey = root.elementText("EventKey");
    if ("subscribe".equals(event) && eventKey == null) {
        InFollowEvent e = new InFollowEvent(toUserName, fromUserName, createTime, msgType);
        e.setEvent(event);
        return e;
    }

    String ticket = root.elementText("Ticket");
    if ("subscribe".equals(event) || "SCAN".equals(event)) {
        if (eventKey != null && ticket != null) {
            InQrCodeEvent e = new InQrCodeEvent(toUserName, fromUserName, createTime, msgType);
            e.setEvent(event);
            e.setEventKey(eventKey);
            e.setTicket(ticket);
            return e;
        }
    }

    throw new RuntimeException("??");
}

From source file:com.jfinal.weixin.sdk.message.InMessageParaser.java

License:Apache License

public static void main(String[] args) throws DocumentException {
    String xml = "<xml>\n" + "<ToUserName><![CDATA[James]]></ToUserName>\n"
            + "<FromUserName><![CDATA[JFinal]]></FromUserName>\n" + "<CreateTime>1348831860</CreateTime>\n"
            + "<MsgType><![CDATA[text]]></MsgType>\n" + "<Content><![CDATA[this is a test]]></Content>\n"
            + "<MsgId>1234567890123456</MsgId>\n" + "</xml>";

    //      InTextMessage msg = (InTextMessage)parse(xml);
    //      System.out.println(msg.getToUserName());
    //      System.out.println(msg.getFromUserName());
    //      System.out.println(msg.getContent());

    String xml_2 = "<xml>\n" + "<ToUserName><![CDATA[James]]></ToUserName>\n"
            + "<FromUserName><![CDATA[JFinal]]></FromUserName>\n" + "<CreateTime>1348831860</CreateTime>\n"
            + "<MsgType><![CDATA[text]]></MsgType>\n" + "<Content><![CDATA[this is a test]]></Content>\n"
            + "<MsgId>1234567890123456</MsgId>\n" + "</xml>";

    Document doc = DocumentHelper.parseText(xml_2);
    Element root = doc.getRootElement();
    String value = root.elementText("abc");
    System.out.println(value);/*from   w  w w. j  ava2  s. com*/
}

From source file:com.jfinal.weixin.sdk.msg.InMsgParaser.java

License:Apache License

/**
 * ?//from   w  w  w  .  j a v a  2 s . com
 * 1text ?
 * 2image ?
 * 3voice ?
 * 4video ?
 * 5location ???
 * 6link ?
 * 7event 
 */
private static InMsg doParse(String xml) throws DocumentException {
    Document doc = DocumentHelper.parseText(xml);
    Element root = doc.getRootElement();
    String toUserName = root.elementText("ToUserName");
    String fromUserName = root.elementText("FromUserName");
    Integer createTime = Integer.parseInt(root.elementText("CreateTime"));
    String msgType = root.elementText("MsgType");
    if ("text".equals(msgType))
        return parseInTextMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("image".equals(msgType))
        return parseInImageMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("voice".equals(msgType))
        return parseInVoiceMsgAndInSpeechRecognitionResults(root, toUserName, fromUserName, createTime,
                msgType);
    if ("video".equals(msgType))
        return parseInVideoMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("location".equals(msgType))
        return parseInLocationMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("link".equals(msgType))
        return parseInLinkMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("event".equals(msgType))
        return parseInEvent(root, toUserName, fromUserName, createTime, msgType);
    throw new RuntimeException("???");
}

From source file:com.jfinal.weixin.sdk.msg.InMsgParaser.java

License:Apache License

private static InMsg parseInVoiceMsgAndInSpeechRecognitionResults(Element root, String toUserName,
        String fromUserName, Integer createTime, String msgType) {
    String recognition = root.elementText("Recognition");
    if (StrKit.isBlank(recognition)) {
        InVoiceMsg msg = new InVoiceMsg(toUserName, fromUserName, createTime, msgType);
        msg.setMediaId(root.elementText("MediaId"));
        msg.setFormat(root.elementText("Format"));
        msg.setMsgId(root.elementText("MsgId"));
        return msg;
    } else {//from w ww  .  j a va 2 s .c o  m
        InSpeechRecognitionResults msg = new InSpeechRecognitionResults(toUserName, fromUserName, createTime,
                msgType);
        msg.setMediaId(root.elementText("MediaId"));
        msg.setFormat(root.elementText("Format"));
        msg.setMsgId(root.elementText("MsgId"));
        msg.setRecognition(recognition); //  InVoiceMsg ??
        return msg;
    }
}

From source file:com.jfinal.weixin.sdk.msg.InMsgParser.java

License:Apache License

/**
 * ?/*from ww w .ja v  a 2 s. c o  m*/
 * 1text ?
 * 2image ?
 * 3voice ?
 * 4video ?
 *    shortvideo ??
 * 5location ???
 * 6link ?
 * 7event 
 */
private static InMsg doParse(String xml) throws DocumentException {
    Document doc = DocumentHelper.parseText(xml);
    Element root = doc.getRootElement();
    String toUserName = root.elementText("ToUserName");
    String fromUserName = root.elementText("FromUserName");
    Integer createTime = Integer.parseInt(root.elementText("CreateTime"));
    String msgType = root.elementText("MsgType");
    if ("text".equals(msgType))
        return parseInTextMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("image".equals(msgType))
        return parseInImageMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("voice".equals(msgType))
        return parseInVoiceMsgAndInSpeechRecognitionResults(root, toUserName, fromUserName, createTime,
                msgType);
    if ("video".equals(msgType))
        return parseInVideoMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("shortvideo".equals(msgType)) //??
        return parseInShortVideoMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("location".equals(msgType))
        return parseInLocationMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("link".equals(msgType))
        return parseInLinkMsg(root, toUserName, fromUserName, createTime, msgType);
    if ("event".equals(msgType))
        return parseInEvent(root, toUserName, fromUserName, createTime, msgType);
    throw new RuntimeException(
            "? " + msgType + "??");
}