Package org.jivesoftware.smackx.packet

Examples of org.jivesoftware.smackx.packet.XHTMLExtension


     *
     * @param message the message that will receive the XHTML body
     * @param body the string to add as an XHTML body to the message
     */
    public static void addBody(Message message, String body) {
        XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension("html", namespace);
        if (xhtmlExtension == null) {
            // Create an XHTMLExtension and add it to the message
            xhtmlExtension = new XHTMLExtension();
            message.addExtension(xhtmlExtension);
        }
        // Add the required bodies to the message
        xhtmlExtension.addBody(body);
    }
View Full Code Here


     * @return a PacketExtension.
     * @throws Exception if a parsing error occurs.
     */
    public PacketExtension parseExtension(XmlPullParser parser)
        throws Exception {
        XHTMLExtension xhtmlExtension = new XHTMLExtension();
        boolean done = false;
        StringBuilder buffer = new StringBuilder();
        int startDepth = parser.getDepth();
        int depth = parser.getDepth();
        String lastTag = "";
        while (!done) {
            int eventType = parser.next();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("body")) {
                    buffer = new StringBuilder();
                    depth = parser.getDepth();
                }
                lastTag = parser.getText();
                buffer.append(parser.getText());
            } else if (eventType == XmlPullParser.TEXT) {
                if (buffer != null) {
                    // We need to return valid XML so any inner text needs to be re-escaped
                    buffer.append(StringUtils.escapeForXML(parser.getText()));
                }
            } else if (eventType == XmlPullParser.END_TAG) {
                if (parser.getName().equals("body") && parser.getDepth() <= depth) {
                    buffer.append(parser.getText());
                    xhtmlExtension.addBody(buffer.toString());
                }
                else if (parser.getName().equals(xhtmlExtension.getElementName())
                        && parser.getDepth() <= startDepth) {
                    done = true;
                }
                else {
                    // This is a check for tags that are both a start and end tag like <br/>
View Full Code Here

  protected boolean handleAsExtension(Packet packet) {
    final Iterator i = packet.getExtensions().iterator();
    for (; i.hasNext();) {
      final Object extension = i.next();
      if (extension instanceof XHTMLExtension) {
        final XHTMLExtension xhtmlExtension = (XHTMLExtension) extension;
        deliverEvent(new MessageEvent((Message) packet,
            xhtmlExtension.getBodies()));
        return true;
      }
      if (packet instanceof Presence && extension instanceof MUCUser) {
        return true;
      }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.packet.XHTMLExtension

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.