01: /**
02: * $Revision: $
03: * $Date: $
04: *
05: * Copyright (C) 2007 Jive Software. All rights reserved.
06: *
07: * This software is published under the terms of the GNU Public License (GPL),
08: * a copy of which is included in this distribution.
09: */package org.jivesoftware.openfire.nio;
10:
11: import org.apache.mina.common.ByteBuffer;
12: import org.apache.mina.common.IoSession;
13: import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
14: import org.apache.mina.filter.codec.ProtocolDecoderOutput;
15:
16: /**
17: * Decoder class that parses ByteBuffers and generates XML stanzas. Generated
18: * stanzas are then passed to the next filters.
19: *
20: * @author Gaston Dombiak
21: */
22: public class XMPPDecoder extends CumulativeProtocolDecoder {
23:
24: protected boolean doDecode(IoSession session, ByteBuffer in,
25: ProtocolDecoderOutput out) throws Exception {
26: // Get the XML light parser from the IoSession
27: XMLLightweightParser parser = (XMLLightweightParser) session
28: .getAttribute(ConnectionHandler.XML_PARSER);
29: // Parse as many stanzas as possible from the received data
30: parser.read(in);
31:
32: if (parser.areThereMsgs()) {
33: for (String stanza : parser.getMsgs()) {
34: out.write(stanza);
35: }
36: }
37: return true;
38: }
39: }
|