Search in sources :

Example 1 with JingleContentDescriptionChildElement

use of org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement in project Smack by igniterealtime.

the class JingleFileTransferProvider method parse.

@Override
public JingleFileTransfer parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException, ParseException {
    ArrayList<JingleContentDescriptionChildElement> payloads = new ArrayList<>();
    JingleFileTransferChild.Builder builder = JingleFileTransferChild.getBuilder();
    String elementName;
    while (true) {
        XmlPullParser.TagEvent tag = parser.nextTag();
        switch(tag) {
            case START_ELEMENT:
                elementName = parser.getName();
                switch(elementName) {
                    case JingleFileTransferChild.ELEM_DATE:
                        builder.setDate(XmppDateTime.parseXEP0082Date(parser.nextText()));
                        break;
                    case JingleFileTransferChild.ELEM_DESC:
                        builder.setDescription(parser.nextText());
                        break;
                    case JingleFileTransferChild.ELEM_MEDIA_TYPE:
                        builder.setMediaType(parser.nextText());
                        break;
                    case JingleFileTransferChild.ELEM_NAME:
                        builder.setName(parser.nextText());
                        break;
                    case JingleFileTransferChild.ELEM_SIZE:
                        builder.setSize(Integer.parseInt(parser.nextText()));
                        break;
                    case Range.ELEMENT:
                        Range range = parseRangeElement(parser);
                        builder.setRange(range);
                        break;
                    case HashElement.ELEMENT:
                        HashElement hashElement = HashElementProvider.INSTANCE.parse(parser);
                        builder.setHash(hashElement);
                        break;
                }
                break;
            case END_ELEMENT:
                elementName = parser.getName();
                switch(elementName) {
                    case JingleFileTransferChild.ELEMENT:
                        payloads.add(builder.build());
                        builder = JingleFileTransferChild.getBuilder();
                        break;
                    case JingleContentDescription.ELEMENT:
                        return new JingleFileTransfer(payloads);
                }
                break;
        }
    }
}
Also used : JingleFileTransferChild(org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild) JingleFileTransfer(org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer) HashElement(org.jivesoftware.smackx.hashes.element.HashElement) ArrayList(java.util.ArrayList) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) JingleContentDescriptionChildElement(org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement) Range(org.jivesoftware.smackx.jingle_filetransfer.element.Range)

Aggregations

ArrayList (java.util.ArrayList)1 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 HashElement (org.jivesoftware.smackx.hashes.element.HashElement)1 JingleContentDescriptionChildElement (org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement)1 JingleFileTransfer (org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer)1 JingleFileTransferChild (org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild)1 Range (org.jivesoftware.smackx.jingle_filetransfer.element.Range)1