/**
   * @return String - returns a String XML representation of the packet Builds an XLM-style string
   *     representation of the packet
   */
  public String toXML() {
    StringBuilder buf = new StringBuilder();
    buf.append("<ConferencePacket ");
    if (packetIDSet) { // includes only a set Id - not a default
      buf.append("id=\"" + getPacketID() + "\"");
    }
    if (getTo() != null) {
      buf.append(" to=\"").append(StringUtils.escapeForXML(getTo())).append("\"");
    }
    if (getFrom() != null) {
      buf.append(" from=\"").append(StringUtils.escapeForXML(getFrom())).append("\"");
    }
    buf.append(">");
    Collection<String> propertyNames = this.getPropertyNames();

    // write every property and its value to the xml
    for (String propName : propertyNames) {

      if (propName.length() >= 12 && propName.substring(0, 11).equals("participant")) {

        buf.append("\n\t<participant>" + getProperty(propName) + "</participant>");
      } else {
        buf.append("\n\t<" + propName + ">" + getProperty(propName) + "</" + propName + ">");
      }
    }

    buf.append("\n</ConferencePacket>");
    return buf.toString();
  }
Beispiel #2
0
 public String toXML() {
   StringBuilder buf = new StringBuilder();
   buf.append("<iq ");
   if (getPacketID() != null) {
     buf.append("id=\"" + getPacketID() + "\" ");
   }
   if (getTo() != null) {
     buf.append("to=\"").append(StringUtils.escapeForXML(getTo())).append("\" ");
   }
   if (getFrom() != null) {
     buf.append("from=\"").append(StringUtils.escapeForXML(getFrom())).append("\" ");
   }
   if (type == null) {
     buf.append("type=\"get\">");
   } else {
     buf.append("type=\"").append(getType()).append("\">");
   }
   // Add the query section if there is one.
   String queryXML = getChildElementXML();
   if (queryXML != null) {
     buf.append(queryXML);
   }
   // Add the error sub-packet, if there is one.
   XMPPError error = getError();
   if (error != null) {
     buf.append(error.toXML());
   }
   buf.append("</iq>");
   return buf.toString();
 }
Beispiel #3
0
 @Override
 protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(
     IQChildElementXmlStringBuilder builder) {
   builder.append(" ");
   builder.append("version='").append(StringUtils.escapeForXML(version)).append("'");
   builder.append(" ");
   builder.append("statusCode='").append(Integer.toString(statusCode)).append("'");
   if (statusMessage != null) {
     builder.append(" ");
     builder.append("statusMessage='").append(StringUtils.escapeForXML(statusMessage)).append("'");
   }
   builder.append(">");
   return builder;
 }
Beispiel #4
0
  /**
   * Represents this <tt>FileElement</tt> in an XML.
   *
   * @see File#toXML()
   */
  @Override
  public String toXML() {
    StringBuilder buffer = new StringBuilder();

    buffer
        .append("<")
        .append(getElementName())
        .append(" xmlns=\"")
        .append(getNamespace())
        .append("\" ");

    if (getName() != null) {
      buffer.append("name=\"").append(StringUtils.escapeForXML(getName())).append("\" ");
    }

    if (getSize() > 0) {
      buffer.append("size=\"").append(getSize()).append("\" ");
    }

    if (getDate() != null) {
      buffer.append("date=\"").append(StringUtils.formatXEP0082Date(this.getDate())).append("\" ");
    }

    if (getHash() != null) {
      buffer.append("hash=\"").append(getHash()).append("\" ");
    }

    if ((this.getDesc() != null && getDesc().length() > 0) || isRanged() || thumbnail != null) {
      buffer.append(">");

      if (getDesc() != null && getDesc().length() > 0) {
        buffer.append("<desc>").append(StringUtils.escapeForXML(getDesc())).append("</desc>");
      }

      if (isRanged()) {
        buffer.append("<range/>");
      }

      if (thumbnail != null) {
        buffer.append(thumbnail.toXML());
      }

      buffer.append("</").append(getElementName()).append(">");
    } else {
      buffer.append("/>");
    }

    return buffer.toString();
  }
 public String getChildElementXML() {
   StringBuilder buf = new StringBuilder();
   buf.append("<query xmlns=\"jabber:iq:auth\">");
   if (username != null) {
     if (username.equals("")) {
       buf.append("<username/>");
     } else {
       buf.append("<username>").append(username).append("</username>");
     }
   }
   if (digest != null) {
     if (digest.equals("")) {
       buf.append("<digest/>");
     } else {
       buf.append("<digest>").append(digest).append("</digest>");
     }
   }
   if (password != null && digest == null) {
     if (password.equals("")) {
       buf.append("<password/>");
     } else {
       buf.append("<password>").append(StringUtils.escapeForXML(password)).append("</password>");
     }
   }
   if (resource != null) {
     if (resource.equals("")) {
       buf.append("<resource/>");
     } else {
       buf.append("<resource>").append(resource).append("</resource>");
     }
   }
   buf.append("</query>");
   return buf.toString();
 }
Beispiel #6
0
 protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(
     IQChildElementXmlStringBuilder iQChildElementXmlStringBuilder) {
   iQChildElementXmlStringBuilder.append((CharSequence) " ");
   iQChildElementXmlStringBuilder
       .append((CharSequence) "method='")
       .append(this.method.toString())
       .append((CharSequence) "'");
   iQChildElementXmlStringBuilder.append((CharSequence) " ");
   iQChildElementXmlStringBuilder
       .append((CharSequence) "resource='")
       .append(StringUtils.escapeForXML(this.resource))
       .append((CharSequence) "'");
   iQChildElementXmlStringBuilder.append((CharSequence) " ");
   iQChildElementXmlStringBuilder
       .append((CharSequence) "version='")
       .append(StringUtils.escapeForXML(this.version))
       .append((CharSequence) "'");
   if (this.maxChunkSize != 0) {
     iQChildElementXmlStringBuilder.append((CharSequence) " ");
     iQChildElementXmlStringBuilder
         .append((CharSequence) "maxChunkSize='")
         .append(Integer.toString(this.maxChunkSize))
         .append((CharSequence) "'");
   }
   iQChildElementXmlStringBuilder.append((CharSequence) " ");
   iQChildElementXmlStringBuilder
       .append((CharSequence) "sipub='")
       .append(Boolean.toString(this.sipub))
       .append((CharSequence) "'");
   iQChildElementXmlStringBuilder.append((CharSequence) " ");
   iQChildElementXmlStringBuilder
       .append((CharSequence) "ibb='")
       .append(Boolean.toString(this.ibb))
       .append((CharSequence) "'");
   iQChildElementXmlStringBuilder.append((CharSequence) " ");
   iQChildElementXmlStringBuilder
       .append((CharSequence) "jingle='")
       .append(Boolean.toString(this.jingle))
       .append((CharSequence) "'");
   iQChildElementXmlStringBuilder.append((CharSequence) ">");
   return iQChildElementXmlStringBuilder;
 }
Beispiel #7
0
  /**
   * Joins the workgroup queue to wait to be routed to an agent. After joining the queue, queue
   * status events will be sent to indicate the user's position and estimated time left in the
   * queue. Once joining the queue, there are three ways the user can leave the queue:
   *
   * <ul>
   *   <p>
   *   <li>The user is routed to an agent, which triggers a GroupChat invitation.
   *   <li>The user asks to leave the queue by calling the {@link #departQueue} method.
   *   <li>A server error occurs, or an administrator explicitly removes the user from the queue.
   * </ul>
   *
   * <p>A user cannot request to join the queue again if already in the queue. Therefore, this
   * method will throw an IllegalStateException if the user is already in the queue.
   *
   * <p>
   *
   * <p>Some servers may be configured to require certain meta-data in order to join the queue.
   *
   * <p>
   *
   * <p>The server tracks the conversations that a user has with agents over time. By default, that
   * tracking is done using the user's JID. However, this is not always possible. For example, when
   * the user is logged in anonymously using a web client. In that case the user ID might be a
   * randomly generated value put into a persistent cookie or a username obtained via the session.
   * When specified, that userID will be used instead of the user's JID to track conversations. The
   * server will ignore a manually specified userID if the user's connection to the server is not
   * anonymous.
   *
   * @param metadata metadata to create a dataform from.
   * @param userID String that represents the ID of the user when using anonymous sessions or
   *     <tt>null</tt> if a userID should not be used.
   * @throws XMPPException if an error occured joining the queue. An error may indicate that a
   *     connection failure occured or that the server explicitly rejected the request to join the
   *     queue.
   */
  public void joinQueue(Map<String, Object> metadata, String userID) throws XMPPException {
    // If already in the queue ignore the join request.
    if (inQueue) {
      throw new IllegalStateException("Already in queue " + workgroupJID);
    }

    // Build dataform from metadata
    Form form = new Form(Form.TYPE_SUBMIT);
    Iterator<String> iter = metadata.keySet().iterator();
    while (iter.hasNext()) {
      String name = iter.next();
      String value = metadata.get(name).toString();

      String escapedName = StringUtils.escapeForXML(name);
      String escapedValue = StringUtils.escapeForXML(value);

      FormField field = new FormField(escapedName);
      field.setType(FormField.TYPE_TEXT_SINGLE);
      form.addField(field);
      form.setAnswer(escapedName, escapedValue);
    }
    joinQueue(form, userID);
  }
 public String toXML() {
   StringBuilder stringBuilder = new StringBuilder();
   stringBuilder
       .append("<")
       .append(getElementName())
       .append(" xmlns=\"")
       .append(getNamespace())
       .append("\" ");
   if (getName() != null) {
     stringBuilder.append("name=\"").append(StringUtils.escapeForXML(getName())).append("\" ");
   }
   if (getSize() > 0) {
     stringBuilder.append("size=\"").append(getSize()).append("\" ");
   }
   if (getDate() != null) {
     stringBuilder.append("date=\"").append(XmppDateTime.m13428a(this.date)).append("\" ");
   }
   if (getHash() != null) {
     stringBuilder.append("hash=\"").append(getHash()).append("\" ");
   }
   if ((this.desc == null || this.desc.length() <= 0) && !this.isRanged) {
     stringBuilder.append("/>");
   } else {
     stringBuilder.append(">");
     if (getDesc() != null && this.desc.length() > 0) {
       stringBuilder
           .append("<desc>")
           .append(StringUtils.escapeForXML(getDesc()))
           .append("</desc>");
     }
     if (isRanged()) {
       stringBuilder.append("<range/>");
     }
     stringBuilder.append("</").append(getElementName()).append(">");
   }
   return stringBuilder.toString();
 }
Beispiel #9
0
 public XmlStringBuilder escape(String text) {
   assert text != null;
   sb.append(StringUtils.escapeForXML(text));
   return this;
 }
Beispiel #10
0
 /**
  * Appends a given text to the XHTMLText.
  *
  * @param textToAppend the text to append
  */
 public void append(String textToAppend) {
   text.append(StringUtils.escapeForXML(textToAppend));
 }
Beispiel #11
0
 @Override
 public String toXML() {
   return String.format(
       "<%s xmlns=\"%s\">%s</%s>",
       GCM_ELEMENT_NAME, GCM_NAMESPACE, StringUtils.escapeForXML(json), GCM_ELEMENT_NAME);
 }