Search in sources :

Example 1 with Checksum

use of org.jivesoftware.smackx.jingle_filetransfer.element.Checksum in project Smack by igniterealtime.

the class ChecksumProvider method parse.

@Override
public Checksum parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    JingleContent.Creator creator = null;
    String creatorString = parser.getAttributeValue(null, Checksum.ATTR_CREATOR);
    if (creatorString != null) {
        creator = JingleContent.Creator.valueOf(creatorString);
    }
    String name = parser.getAttributeValue(null, Checksum.ATTR_NAME);
    JingleFileTransferChild.Builder cb = JingleFileTransferChild.getBuilder();
    HashElement hashElement = null;
    Range range = null;
    boolean go = true;
    while (go) {
        XmlPullParser.TagEvent tag = parser.nextTag();
        String n = parser.getText();
        switch(tag) {
            case START_ELEMENT:
                switch(n) {
                    case HashElement.ELEMENT:
                        hashElement = new HashElementProvider().parse(parser);
                        break;
                    case Range.ELEMENT:
                        String offset = parser.getAttributeValue(null, Range.ATTR_OFFSET);
                        String length = parser.getAttributeValue(null, Range.ATTR_LENGTH);
                        int o = offset == null ? 0 : Integer.parseInt(offset);
                        int l = length == null ? -1 : Integer.parseInt(length);
                        range = new Range(o, l);
                }
                break;
            case END_ELEMENT:
                switch(n) {
                    case Range.ELEMENT:
                        if (hashElement != null && range != null) {
                            range = new Range(range.getOffset(), range.getLength(), hashElement);
                            hashElement = null;
                        }
                        break;
                    case JingleFileTransferChild.ELEMENT:
                        if (hashElement != null) {
                            cb.setHash(hashElement);
                        }
                        if (range != null) {
                            cb.setRange(range);
                        }
                        go = false;
                }
                break;
        }
    }
    return new Checksum(creator, name, cb.build());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) HashElementProvider(org.jivesoftware.smackx.hashes.provider.HashElementProvider) Range(org.jivesoftware.smackx.jingle_filetransfer.element.Range) JingleFileTransferChild(org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild) Checksum(org.jivesoftware.smackx.jingle_filetransfer.element.Checksum) HashElement(org.jivesoftware.smackx.hashes.element.HashElement) JingleContent(org.jivesoftware.smackx.jingle.element.JingleContent)

Aggregations

XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 HashElement (org.jivesoftware.smackx.hashes.element.HashElement)1 HashElementProvider (org.jivesoftware.smackx.hashes.provider.HashElementProvider)1 JingleContent (org.jivesoftware.smackx.jingle.element.JingleContent)1 Checksum (org.jivesoftware.smackx.jingle_filetransfer.element.Checksum)1 JingleFileTransferChild (org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild)1 Range (org.jivesoftware.smackx.jingle_filetransfer.element.Range)1