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.packet; 018 019import org.jivesoftware.smack.util.StringUtils; 020import org.jivesoftware.smackx.hoxt.HOXTManager; 021 022/** 023 * Represents Resp IQ packet. 024 * 025 * @author Andriy Tsykholyas 026 * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> 027 */ 028public class HttpOverXmppResp extends AbstractHttpOverXmpp { 029 030 private Resp resp; 031 032 @Override 033 public String getChildElementXML() { 034 return resp.toXML(); 035 } 036 037 /** 038 * Returns Resp element. 039 * 040 * @return Resp element 041 */ 042 public Resp getResp() { 043 return resp; 044 } 045 046 /** 047 * Sets Resp element. 048 * 049 * @param resp Resp element 050 */ 051 public void setResp(Resp resp) { 052 this.resp = resp; 053 } 054 055 /** 056 * Represents Resp element. 057 */ 058 public static class Resp extends AbstractBody { 059 060 private int statusCode; 061 private String statusMessage = null; 062 063 @Override 064 protected String getStartTag() { 065 StringBuilder builder = new StringBuilder(); 066 builder.append("<resp"); 067 builder.append(" "); 068 builder.append("xmlns='").append(HOXTManager.NAMESPACE).append("'"); 069 builder.append(" "); 070 builder.append("version='").append(StringUtils.escapeForXML(version)).append("'"); 071 builder.append(" "); 072 builder.append("statusCode='").append(Integer.toString(statusCode)).append("'"); 073 if (statusMessage != null) { 074 builder.append(" "); 075 builder.append("statusMessage='").append(StringUtils.escapeForXML(statusMessage)).append("'"); 076 } 077 builder.append(">"); 078 return builder.toString(); 079 } 080 081 @Override 082 protected String getEndTag() { 083 return "</resp>"; 084 } 085 086 /** 087 * Returns statusCode attribute. 088 * 089 * @return statusCode attribute 090 */ 091 public int getStatusCode() { 092 return statusCode; 093 } 094 095 /** 096 * Sets statusCode attribute. 097 * 098 * @param statusCode statusCode attribute 099 */ 100 public void setStatusCode(int statusCode) { 101 this.statusCode = statusCode; 102 } 103 104 /** 105 * Returns statusMessage attribute. 106 * 107 * @return statusMessage attribute 108 */ 109 public String getStatusMessage() { 110 return statusMessage; 111 } 112 113 /** 114 * Sets statusMessage attribute. 115 * 116 * @param statusMessage statusMessage attribute 117 */ 118 public void setStatusMessage(String statusMessage) { 119 this.statusMessage = statusMessage; 120 } 121 } 122}