001/** 002 * 003 * Copyright 2014 Andriy Tsykholyas 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.hoxt.provider; 018 019import java.io.IOException; 020 021import org.jivesoftware.smack.SmackException; 022import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp; 023import org.xmlpull.v1.XmlPullParser; 024import org.xmlpull.v1.XmlPullParserException; 025 026/** 027 * Resp stanza(/packet) provider. 028 * 029 * @author Andriy Tsykholyas 030 * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> 031 */ 032public class HttpOverXmppRespProvider extends AbstractHttpOverXmppProvider<HttpOverXmppResp> { 033 034 private static final String ATTRIBUTE_STATUS_MESSAGE = "statusMessage"; 035 private static final String ATTRIBUTE_STATUS_CODE = "statusCode"; 036 037 @Override 038 public HttpOverXmppResp parse(XmlPullParser parser, int initialDepth) 039 throws XmlPullParserException, IOException, SmackException { 040 String version = parser.getAttributeValue("", ATTRIBUTE_VERSION); 041 String statusMessage = parser.getAttributeValue("", ATTRIBUTE_STATUS_MESSAGE); 042 String statusCodeString = parser.getAttributeValue("", ATTRIBUTE_STATUS_CODE); 043 int statusCode = Integer.parseInt(statusCodeString); 044 045 HttpOverXmppResp resp = new HttpOverXmppResp(); 046 047 resp.setVersion(version); 048 resp.setStatusMessage(statusMessage); 049 resp.setStatusCode(statusCode); 050 parseHeadersAndData(parser, HttpOverXmppResp.ELEMENT, resp); 051 return resp; 052 } 053}