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; 020 021/** 022 * Represents Req IQ packet. 023 * 024 * @author Andriy Tsykholyas 025 * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a> 026 */ 027public class HttpOverXmppReq extends AbstractHttpOverXmpp { 028 029 public static final String ELEMENT = "req"; 030 031 032 public HttpOverXmppReq(HttpMethod method, String resource) { 033 super(ELEMENT); 034 this.method = method; 035 this.resource = resource; 036 setType(Type.set); 037 } 038 039 private HttpMethod method; 040 private String resource; 041 042 // TODO: validate: xs:minInclusive value='256' xs:maxInclusive value='65536' 043 private int maxChunkSize = 0; // 0 means not set 044 045 private boolean sipub = true; 046 047 private boolean ibb = true; 048 private boolean jingle = true; 049 050 @Override 051 protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder builder) { 052 builder.append(" "); 053 builder.append("method='").append(method.toString()).append("'"); 054 builder.append(" "); 055 builder.append("resource='").append(StringUtils.escapeForXML(resource)).append("'"); 056 builder.append(" "); 057 builder.append("version='").append(StringUtils.escapeForXML(version)).append("'"); 058 if (maxChunkSize != 0) { 059 builder.append(" "); 060 builder.append("maxChunkSize='").append(Integer.toString(maxChunkSize)).append("'"); 061 } 062 builder.append(" "); 063 builder.append("sipub='").append(Boolean.toString(sipub)).append("'"); 064 builder.append(" "); 065 builder.append("ibb='").append(Boolean.toString(ibb)).append("'"); 066 builder.append(" "); 067 builder.append("jingle='").append(Boolean.toString(jingle)).append("'"); 068 builder.append(">"); 069 return builder; 070 } 071 072 /** 073 * Returns method attribute. 074 * 075 * @return method attribute 076 */ 077 public HttpMethod getMethod() { 078 return method; 079 } 080 081 /** 082 * Returns resource attribute. 083 * 084 * @return resource attribute 085 */ 086 public String getResource() { 087 return resource; 088 } 089 090 /** 091 * Returns maxChunkSize attribute. 092 * 093 * @return maxChunkSize attribute 094 */ 095 public int getMaxChunkSize() { 096 return maxChunkSize; 097 } 098 099 /** 100 * Sets maxChunkSize attribute. 101 * 102 * @param maxChunkSize maxChunkSize attribute 103 */ 104 public void setMaxChunkSize(int maxChunkSize) { 105 this.maxChunkSize = maxChunkSize; 106 } 107 108 /** 109 * Returns sipub attribute. 110 * 111 * @return sipub attribute 112 */ 113 public boolean isSipub() { 114 return sipub; 115 } 116 117 /** 118 * Sets sipub attribute. 119 * 120 * @param sipub sipub attribute 121 */ 122 public void setSipub(boolean sipub) { 123 this.sipub = sipub; 124 } 125 126 /** 127 * Returns ibb attribute. 128 * 129 * @return ibb attribute 130 */ 131 public boolean isIbb() { 132 return ibb; 133 } 134 135 /** 136 * Sets ibb attribute. 137 * 138 * @param ibb ibb attribute 139 */ 140 public void setIbb(boolean ibb) { 141 this.ibb = ibb; 142 } 143 144 /** 145 * Returns jingle attribute. 146 * 147 * @return jingle attribute 148 */ 149 public boolean isJingle() { 150 return jingle; 151 } 152 153 /** 154 * Sets jingle attribute. 155 * 156 * @param jingle jingle attribute 157 */ 158 public void setJingle(boolean jingle) { 159 this.jingle = jingle; 160 } 161}