예제 #1
0
파일: FileElement.java 프로젝트: 0xbb/jitsi
  /**
   * 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();
  }