/**
     * Appends the XML <tt>String</tt> representation of this <tt>Content</tt> to a specific
     * <tt>StringBuilder</tt>.
     *
     * @param xml the <tt>StringBuilder</tt> to which the XML <tt>String</tt> representation of this
     *     <tt>Content</tt> is to be appended
     */
    public void toXML(StringBuilder xml) {
      xml.append('<').append(ELEMENT_NAME);
      xml.append(' ').append(NAME_ATTR_NAME).append("='").append(getName()).append('\'');

      List<Channel> channels = getChannels();
      List<SctpConnection> connections = getSctpConnections();

      if (channels.size() == 0 && connections.size() == 0) {
        xml.append(" />");
      } else {
        xml.append('>');
        for (Channel channel : channels) channel.toXML(xml);
        for (SctpConnection conn : connections) conn.toXML(xml);
        xml.append("</").append(ELEMENT_NAME).append('>');
      }
    }
示例#2
0
  /**
   * Converts the form field values in the <tt>ffValuesIter</tt> into a caps string.
   *
   * @param ffValuesIter the {@link Iterator} containing the form field values.
   * @param capsBldr a <tt>StringBuilder</tt> to which the caps string representing the form field
   *     values is to be appended
   */
  private static void formFieldValuesToCaps(Iterator<String> ffValuesIter, StringBuilder capsBldr) {
    SortedSet<String> fvs = new TreeSet<String>();

    while (ffValuesIter.hasNext()) fvs.add(ffValuesIter.next());

    for (String fv : fvs) capsBldr.append(fv).append('<');
  }
    @Override
    protected void printAttributes(StringBuilder xml) {
      // direction
      MediaDirection direction = getDirection();

      if ((direction != null) && (direction != MediaDirection.SENDRECV)) {
        xml.append(' ')
            .append(DIRECTION_ATTR_NAME)
            .append("='")
            .append(direction.toString())
            .append('\'');
      }

      // host
      String host = getHost();

      if (host != null) {
        xml.append(' ').append(HOST_ATTR_NAME).append("='").append(host).append('\'');
      }

      // id
      String id = getID();

      if (id != null) {
        xml.append(' ').append(ID_ATTR_NAME).append("='").append(id).append('\'');
      }

      // lastN
      Integer lastN = getLastN();

      if (lastN != null) {
        xml.append(' ').append(LAST_N_ATTR_NAME).append("='").append(lastN).append('\'');
      }

      // rtcpPort
      int rtcpPort = getRTCPPort();

      if (rtcpPort > 0) {
        xml.append(' ').append(RTCP_PORT_ATTR_NAME).append("='").append(rtcpPort).append('\'');
      }

      // rtpLevelRelayType
      RTPLevelRelayType rtpLevelRelayType = getRTPLevelRelayType();

      if (rtpLevelRelayType != null) {
        xml.append(' ')
            .append(RTP_LEVEL_RELAY_TYPE_ATTR_NAME)
            .append("='")
            .append(rtpLevelRelayType)
            .append('\'');
      }

      // rtpPort
      int rtpPort = getRTPPort();

      if (rtpPort > 0) {
        xml.append(' ').append(RTP_PORT_ATTR_NAME).append("='").append(rtpPort).append('\'');
      }
    }
    @Override
    protected void printContent(StringBuilder xml) {
      List<PayloadTypePacketExtension> payloadTypes = getPayloadTypes();
      List<SourcePacketExtension> sources = getSources();
      int[] ssrcs = getSSRCs();

      for (PayloadTypePacketExtension payloadType : payloadTypes) xml.append(payloadType.toXML());

      for (SourcePacketExtension source : sources) xml.append(source.toXML());

      for (int i = 0; i < ssrcs.length; i++) {
        xml.append('<')
            .append(SSRC_ELEMENT_NAME)
            .append('>')
            .append(Long.toString(ssrcs[i] & 0xFFFFFFFFL))
            .append("</")
            .append(SSRC_ELEMENT_NAME)
            .append('>');
      }
    }
示例#5
0
    public String getChildElementXML() {
      StringBuilder buf = new StringBuilder();

      buf.append("<join-queue xmlns=\"http://jabber.org/protocol/workgroup\">");
      buf.append("<queue-notifications/>");
      // Add the user unique identification if the session is anonymous
      if (connection.isAnonymous()) {
        buf.append(new UserID(userID).toXML());
      }

      // Append data form text
      buf.append(form.toXML());

      buf.append("</join-queue>");

      return buf.toString();
    }
  /**
   * Returns an XML <tt>String</tt> representation of this <tt>IQ</tt>.
   *
   * @return an XML <tt>String</tt> representation of this <tt>IQ</tt>
   */
  @Override
  public String getChildElementXML() {
    StringBuilder xml = new StringBuilder();

    xml.append('<').append(ELEMENT_NAME);
    xml.append(" xmlns='").append(NAMESPACE).append('\'');

    String id = getID();

    if (id != null) xml.append(' ').append(ID_ATTR_NAME).append("='").append(id).append('\'');

    List<Content> contents = getContents();

    if (contents.size() == 0) {
      xml.append(" />");
    } else {
      xml.append('>');
      for (Content content : contents) content.toXML(xml);
      xml.append("</").append(ELEMENT_NAME).append('>');
    }
    return xml.toString();
  }
    /**
     * Appends the XML <tt>String</tt> representation of this <tt>Channel</tt> to a specific
     * <tt>StringBuilder</tt>.
     *
     * @param xml the <tt>StringBuilder</tt> to which the XML <tt>String</tt> representation of this
     *     <tt>Channel</tt> is to be appended
     */
    public void toXML(StringBuilder xml) {
      xml.append('<').append(elementName);

      // endpoint
      String endpoint = getEndpoint();

      if (endpoint != null) {
        xml.append(' ').append(ENDPOINT_ATTR_NAME).append("='").append(endpoint).append('\'');
      }

      // expire
      int expire = getExpire();

      if (expire >= 0) {
        xml.append(' ').append(EXPIRE_ATTR_NAME).append("='").append(expire).append('\'');
      }

      // initiator
      Boolean initiator = isInitiator();

      if (initiator != null) {
        xml.append(' ').append(INITIATOR_ATTR_NAME).append("='").append(initiator).append('\'');
      }

      // Print derived class attributes
      printAttributes(xml);

      IceUdpTransportPacketExtension transport = getTransport();
      boolean hasTransport = (transport != null);
      if (hasTransport || hasContent()) {
        xml.append('>');
        if (hasContent()) printContent(xml);
        if (hasTransport) xml.append(transport.toXML());
        xml.append("</").append(elementName).append('>');
      } else {
        xml.append(" />");
      }
    }
  /**
   * Returns the XML representation of the PacketExtension.
   *
   * @return the packet extension as XML.
   */
  public String toXML() {
    StringBuilder bldr = new StringBuilder("<" + getElementName() + ">");

    bldr.append("<" + getReason().toString() + "/>");

    // add reason "text" if we have it
    if (getText() != null) {
      bldr.append("<text>");
      bldr.append(getText());
      bldr.append("</text>");
    }

    // add the extra element if it has been specified.
    if (getOtherExtension() != null) {
      bldr.append(getOtherExtension().toXML());
    }

    bldr.append("</" + getElementName() + ">");
    return bldr.toString();
  }
示例#9
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();
  }
  /**
   * Creates an html description of the specified mailbox.
   *
   * @param mailboxIQ the mailboxIQ that we are to describe.
   * @return an html description of <tt>mailboxIQ</tt>
   */
  private String createMailboxDescription(MailboxIQ mailboxIQ) {
    int threadCount = mailboxIQ.getThreadCount();

    String resourceHeaderKey =
        threadCount > 1 ? "service.gui.NEW_GMAIL_MANY_HEADER" : "service.gui.NEW_GMAIL_HEADER";

    String resourceFooterKey =
        threadCount > 1 ? "service.gui.NEW_GMAIL_MANY_FOOTER" : "service.gui.NEW_GMAIL_FOOTER";

    // FIXME Escape HTML!
    String newMailHeader =
        JabberActivator.getResources()
            .getI18NString(
                resourceHeaderKey,
                new String[] {
                  jabberProvider.getAccountID().getService(), // {0} - service name
                  mailboxIQ.getUrl(), // {1} - inbox URI
                  Integer.toString(threadCount) // {2} - thread count
                });

    StringBuilder message = new StringBuilder(newMailHeader);

    // we now start an html table for the threads.
    message.append("<table width=100% cellpadding=2 cellspacing=0 ");
    message.append("border=0 bgcolor=#e8eef7>");

    Iterator<MailThreadInfo> threads = mailboxIQ.threads();

    String maxThreadsStr =
        (String)
            JabberActivator.getConfigurationService()
                .getProperty(PNAME_MAX_GMAIL_THREADS_PER_NOTIFICATION);

    int maxThreads = 5;

    try {
      if (maxThreadsStr != null) maxThreads = Integer.parseInt(maxThreadsStr);
    } catch (NumberFormatException e) {
      if (logger.isDebugEnabled())
        logger.debug("Failed to parse max threads count: " + maxThreads + ". Going for default.");
    }

    // print a maximum of MAX_THREADS
    for (int i = 0; i < maxThreads && threads.hasNext(); i++) {
      message.append(threads.next().createHtmlDescription());
    }
    message.append("</table><br/>");

    if (threadCount > maxThreads) {
      String messageFooter =
          JabberActivator.getResources()
              .getI18NString(
                  resourceFooterKey,
                  new String[] {
                    mailboxIQ.getUrl(), // {0} - inbox URI
                    Integer.toString(threadCount - maxThreads) // {1} - thread count
                  });
      message.append(messageFooter);
    }

    return message.toString();
  }
 /** {@inheritDoc} */
 @Override
 protected void printAttributes(StringBuilder xml) {
   xml.append(' ').append(PORT_ATTR_NAME).append("='").append(getPort()).append('\'');
 }
示例#12
0
  /**
   * Get an XML string representation.
   *
   * @return XML string representation
   */
  @Override
  public String toXML() {
    StringBuilder bldr = new StringBuilder();

    bldr.append("<").append(getElementName()).append(" ");

    if (getNamespace() != null) bldr.append("xmlns='").append(getNamespace()).append("'");

    // add the rest of the attributes if any
    for (Map.Entry<String, String> entry : attributes.entrySet()) {
      bldr.append(" ").append(entry.getKey()).append("='").append(entry.getValue()).append("'");
    }

    bldr.append(">");

    if (userCount != 0)
      bldr.append("<")
          .append(ELEMENT_USER_COUNT)
          .append(">")
          .append(userCount)
          .append("</")
          .append(ELEMENT_USER_COUNT)
          .append(">");

    if (active != -1)
      bldr.append("<")
          .append(ELEMENT_ACTIVE)
          .append(">")
          .append((active > 0))
          .append("</")
          .append(ELEMENT_ACTIVE)
          .append(">");

    if (locked != -1)
      bldr.append("<")
          .append(ELEMENT_LOCKED)
          .append(">")
          .append((active > 0))
          .append("</")
          .append(ELEMENT_LOCKED)
          .append(">");

    for (PacketExtension ext : getChildExtensions()) {
      bldr.append(ext.toXML());
    }

    bldr.append("</").append(getElementName()).append(">");
    return bldr.toString();
  }
示例#13
0
  /**
   * Calculates the <tt>String</tt> for a specific <tt>DiscoverInfo</tt> which is to be hashed in
   * order to compute the ver string for that <tt>DiscoverInfo</tt>.
   *
   * @param discoverInfo the <tt>DiscoverInfo</tt> for which the <tt>String</tt> to be hashed in
   *     order to compute its ver string is to be calculated
   * @return the <tt>String</tt> for <tt>discoverInfo</tt> which is to be hashed in order to compute
   *     its ver string
   */
  private static String calculateEntityCapsString(DiscoverInfo discoverInfo) {
    StringBuilder bldr = new StringBuilder();

    // Add identities
    {
      Iterator<DiscoverInfo.Identity> identities = discoverInfo.getIdentities();
      SortedSet<DiscoverInfo.Identity> is =
          new TreeSet<DiscoverInfo.Identity>(
              new Comparator<DiscoverInfo.Identity>() {
                public int compare(DiscoverInfo.Identity i1, DiscoverInfo.Identity i2) {
                  int category = i1.getCategory().compareTo(i2.getCategory());

                  if (category != 0) return category;

                  int type = i1.getType().compareTo(i2.getType());

                  if (type != 0) return type;

                  /*
                   * TODO Sort by xml:lang.
                   *
                   * Since sort by xml:lang is currently missing,
                   * use the last supported sort criterion i.e.
                   * type.
                   */
                  return type;
                }
              });

      if (identities != null) while (identities.hasNext()) is.add(identities.next());

      for (DiscoverInfo.Identity i : is) {
        bldr.append(i.getCategory())
            .append('/')
            .append(i.getType())
            .append("//")
            .append(i.getName())
            .append('<');
      }
    }

    // Add features
    {
      Iterator<DiscoverInfo.Feature> features = getDiscoverInfoFeatures(discoverInfo);
      SortedSet<String> fs = new TreeSet<String>();

      if (features != null) while (features.hasNext()) fs.add(features.next().getVar());

      for (String f : fs) bldr.append(f).append('<');
    }

    DataForm extendedInfo = (DataForm) discoverInfo.getExtension("x", "jabber:x:data");

    if (extendedInfo != null) {
      synchronized (extendedInfo) {
        SortedSet<FormField> fs =
            new TreeSet<FormField>(
                new Comparator<FormField>() {
                  public int compare(FormField f1, FormField f2) {
                    return f1.getVariable().compareTo(f2.getVariable());
                  }
                });

        FormField formType = null;

        for (Iterator<FormField> fieldsIter = extendedInfo.getFields(); fieldsIter.hasNext(); ) {
          FormField f = fieldsIter.next();
          if (!f.getVariable().equals("FORM_TYPE")) fs.add(f);
          else formType = f;
        }

        // Add FORM_TYPE values
        if (formType != null) formFieldValuesToCaps(formType.getValues(), bldr);

        // Add the other values
        for (FormField f : fs) {
          bldr.append(f.getVariable()).append('<');
          formFieldValuesToCaps(f.getValues(), bldr);
        }
      }
    }

    return bldr.toString();
  }