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.ext.weixin.msg.InMsgParaser.java

License:Apache License

private static InMsg parseInTextMsg(Element root, String toUserName, String fromUserName, Integer createTime,
        String msgType) {/*w w  w. j  ava2s .c  o  m*/
    InTextMsg msg = new InTextMsg(toUserName, fromUserName, createTime, msgType);
    msg.setContent(root.elementText("Content"));
    msg.setMsgId(root.elementText("MsgId"));
    return msg;
}

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

License:Apache License

private static InMsg parseInImageMsg(Element root, String toUserName, String fromUserName, Integer createTime,
        String msgType) {//from   w w w .  j a va2s.  c  o  m
    InImageMsg msg = new InImageMsg(toUserName, fromUserName, createTime, msgType);
    msg.setPicUrl(root.elementText("PicUrl"));
    msg.setMediaId(root.elementText("MediaId"));
    msg.setMsgId(root.elementText("MsgId"));
    return msg;
}

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

License:Apache License

private static InMsg parseInVoiceMsg(Element root, String toUserName, String fromUserName, Integer createTime,
        String msgType) {//from   w w w  .  ja  va2  s  . c  om
    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;
}

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

License:Apache License

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

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

License:Apache License

private static InMsg parseInLocationMsg(Element root, String toUserName, String fromUserName,
        Integer createTime, String msgType) {
    InLocationMsg msg = new InLocationMsg(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;/*from   w w w .j a v  a2 s . c  o  m*/
}

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

License:Apache License

private static InMsg parseInLinkMsg(Element root, String toUserName, String fromUserName, Integer createTime,
        String msgType) {/*w  w w.j av  a 2s .c o m*/
    InLinkMsg msg = new InLinkMsg(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;
}

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

License:Apache License

private static InMsg parseInEvent(Element root, String toUserName, String fromUserName, Integer createTime,
        String msgType) {//w  w w  .  j a  v  a2 s . c om
    String event = root.elementText("Event");
    String eventKey = root.elementText("EventKey");

    // /???????????
    if (("subscribe".equals(event) || "unsubscribe".equals(event)) && StrKit.isBlank(eventKey)) {
        InFollowEvent e = new InFollowEvent(toUserName, fromUserName, createTime, msgType);
        e.setEvent(event);
        return e;
    }

    // ????      1: ??
    String ticket = root.elementText("Ticket");
    if ("subscribe".equals(event) && StrKit.notBlank(eventKey) && eventKey.startsWith("qrscene_")) {
        InQrCodeEvent e = new InQrCodeEvent(toUserName, fromUserName, createTime, msgType);
        e.setEvent(event);
        e.setEventKey(eventKey);
        e.setTicket(ticket);
        return e;
    }
    // ????      2: ?
    if ("SCAN".equals(event)) {
        InQrCodeEvent e = new InQrCodeEvent(toUserName, fromUserName, createTime, msgType);
        e.setEvent(event);
        e.setEventKey(eventKey);
        e.setTicket(ticket);
        return e;
    }

    // ??
    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;
    }

    // ??         1?????
    if ("CLICK".equals(event)) {
        InMenuEvent e = new InMenuEvent(toUserName, fromUserName, createTime, msgType);
        e.setEvent(event);
        e.setEventKey(eventKey);
        return e;
    }
    // ??         2???
    if ("VIEW".equals(event)) {
        InMenuEvent e = new InMenuEvent(toUserName, fromUserName, createTime, msgType);
        e.setEvent(event);
        e.setEventKey(eventKey);
        return e;
    }

    throw new RuntimeException("??");
}

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

License:Apache License

@SuppressWarnings("unused")
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>";

    //      InTextMsg msg = (InTextMsg)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);/*w  w w  .  j  a  v  a  2s  .  co m*/
}

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

License:Apache License

/**
 * ?/*from   ww w  .ja  v  a  2s . c o m*/
 * 1text ?
 * 2image ?
 * 3voice ?
 * 4video ?
 * 5location ???
 * 6link ?
 * 7event 
 */
private static InMessage 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 parseInTextMessage(root, toUserName, fromUserName, createTime, msgType);
    if ("image".equals(msgType))
        return parseInImageMessage(root, toUserName, fromUserName, createTime, msgType);
    if ("voice".equals(msgType))
        return parseInVoiceMessage(root, toUserName, fromUserName, createTime, msgType);
    if ("video".equals(msgType))
        return parseInVideoMessage(root, toUserName, fromUserName, createTime, msgType);
    if ("location".equals(msgType))
        return parseInLocationMessage(root, toUserName, fromUserName, createTime, msgType);
    if ("link".equals(msgType))
        return parseInLinkMessage(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.message.InMessageParaser.java

License:Apache License

private static InMessage parseInTextMessage(Element root, String toUserName, String fromUserName,
        Integer createTime, String msgType) {
    InTextMessage msg = new InTextMessage(toUserName, fromUserName, createTime, msgType);
    msg.setContent(root.elementText("Content"));
    msg.setMsgId(root.elementText("MsgId"));
    return msg;// w  w w. j av a2s. com
}