HttpOverXmppReq.java

  1. /**
  2.  *
  3.  * Copyright 2014 Andriy Tsykholyas
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.hoxt.packet;

  18. import org.jivesoftware.smack.util.StringUtils;

  19. /**
  20.  * Represents Req IQ packet.
  21.  *
  22.  * @author Andriy Tsykholyas
  23.  * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
  24.  */
  25. public class HttpOverXmppReq extends AbstractHttpOverXmpp {

  26.     public static final String ELEMENT = "req";


  27.     public HttpOverXmppReq(HttpMethod method, String resource) {
  28.         super(ELEMENT);
  29.         this.method = method;
  30.         this.resource = resource;
  31.         setType(Type.set);
  32.     }

  33.     private HttpMethod method;
  34.     private String resource;

  35.     // TODO: validate: xs:minInclusive value='256' xs:maxInclusive value='65536'
  36.     private int maxChunkSize = 0; // 0 means not set

  37.     private boolean sipub = true;

  38.     private boolean ibb = true;
  39.     private boolean jingle = true;

  40.     @Override
  41.     protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder builder) {
  42.         builder.append(" ");
  43.         builder.append("method='").append(method.toString()).append("'");
  44.         builder.append(" ");
  45.         builder.append("resource='").append(StringUtils.escapeForXML(resource)).append("'");
  46.         builder.append(" ");
  47.         builder.append("version='").append(StringUtils.escapeForXML(version)).append("'");
  48.         if (maxChunkSize != 0) {
  49.             builder.append(" ");
  50.             builder.append("maxChunkSize='").append(Integer.toString(maxChunkSize)).append("'");
  51.         }
  52.         builder.append(" ");
  53.         builder.append("sipub='").append(Boolean.toString(sipub)).append("'");
  54.         builder.append(" ");
  55.         builder.append("ibb='").append(Boolean.toString(ibb)).append("'");
  56.         builder.append(" ");
  57.         builder.append("jingle='").append(Boolean.toString(jingle)).append("'");
  58.         builder.append(">");
  59.         return builder;
  60.     }

  61.     /**
  62.      * Returns method attribute.
  63.      *
  64.      * @return method attribute
  65.      */
  66.     public HttpMethod getMethod() {
  67.         return method;
  68.     }

  69.     /**
  70.      * Returns resource attribute.
  71.      *
  72.      * @return resource attribute
  73.      */
  74.     public String getResource() {
  75.         return resource;
  76.     }

  77.     /**
  78.      * Returns maxChunkSize attribute.
  79.      *
  80.      * @return maxChunkSize attribute
  81.      */
  82.     public int getMaxChunkSize() {
  83.         return maxChunkSize;
  84.     }

  85.     /**
  86.      * Sets maxChunkSize attribute.
  87.      *
  88.      * @param maxChunkSize maxChunkSize attribute
  89.      */
  90.     public void setMaxChunkSize(int maxChunkSize) {
  91.         this.maxChunkSize = maxChunkSize;
  92.     }

  93.     /**
  94.      * Returns sipub attribute.
  95.      *
  96.      * @return sipub attribute
  97.      */
  98.     public boolean isSipub() {
  99.         return sipub;
  100.     }

  101.     /**
  102.      * Sets sipub attribute.
  103.      *
  104.      * @param sipub sipub attribute
  105.      */
  106.     public void setSipub(boolean sipub) {
  107.         this.sipub = sipub;
  108.     }

  109.     /**
  110.      * Returns ibb attribute.
  111.      *
  112.      * @return ibb attribute
  113.      */
  114.     public boolean isIbb() {
  115.         return ibb;
  116.     }

  117.     /**
  118.      * Sets ibb attribute.
  119.      *
  120.      * @param ibb ibb attribute
  121.      */
  122.     public void setIbb(boolean ibb) {
  123.         this.ibb = ibb;
  124.     }

  125.     /**
  126.      * Returns jingle attribute.
  127.      *
  128.      * @return jingle attribute
  129.      */
  130.     public boolean isJingle() {
  131.         return jingle;
  132.     }

  133.     /**
  134.      * Sets jingle attribute.
  135.      *
  136.      * @param jingle jingle attribute
  137.      */
  138.     public void setJingle(boolean jingle) {
  139.         this.jingle = jingle;
  140.     }
  141. }