/**
   * Creates a String representation of the given object.
   *
   * @param certificate to print
   * @return the String representation
   */
  private String toString(Object certificate) {
    final StringBuilder sb = new StringBuilder();
    sb.append("<html><body>\n");

    if (certificate instanceof X509Certificate) {
      renderX509(sb, (X509Certificate) certificate);
    } else {
      sb.append("<pre>\n");
      sb.append(certificate.toString());
      sb.append("</pre>\n");
    }

    sb.append("</body></html>");
    return sb.toString();
  }
 public String toString() {
   StringBuilder buf = new StringBuilder();
   buf.append(idToString(getId()));
   buf.append(' ');
   buf.append(getLength());
   if (data == null) {
     buf.append(' ');
     buf.append(idToString(getType()));
   }
   return buf.toString();
 }
Ejemplo n.º 3
0
 @Override
 public boolean processNode(DefaultMutableTreeNode node) {
   Object userObject = node.getUserObject();
   if (userObject instanceof HyperSearchFileNode)
     nodesString.append(((HyperSearchFileNode) userObject).path);
   else if (userObject instanceof HyperSearchResult) {
     HyperSearchResult hsr = (HyperSearchResult) userObject;
     // Copy the ORIGINAL line from the buffer!
     nodesString.append(hsr.buffer == null ? hsr.toString() : hsr.buffer.getLineText(hsr.line));
   } else nodesString.append(userObject.toString());
   nodesString.append('\n');
   return true;
 }
Ejemplo n.º 4
0
      String print(int indent) {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < indent; i++) sb.append(' ');
        if (!isRoot()) {
          if (name == null) sb.append("/<unnamed>");
          else {
            sb.append(ReplicatedTreeView.SEP + name);
          }
        }
        sb.append('\n');
        if (getChildCount() > 0) {
          if (isRoot()) indent = 0;
          else indent += 4;
          for (int i = 0; i < getChildCount(); i++)
            sb.append(((MyNode) getChildAt(i)).print(indent));
        }
        return sb.toString();
      }
Ejemplo n.º 5
0
  private static String getNodePathString(final MyNode node) {
    StringBuilder path = new StringBuilder();
    MyNode current = node;
    while (current != null) {
      final Object userObject = current.getUserObject();
      if (!(userObject instanceof NamedConfigurable)) break;
      final String displayName = current.getDisplayName();
      if (StringUtil.isEmptyOrSpaces(displayName)) break;
      if (path.length() > 0) {
        path.append('|');
      }
      path.append(displayName);

      final TreeNode parent = current.getParent();
      if (!(parent instanceof MyNode)) break;
      current = (MyNode) parent;
    }
    return path.toString();
  }
 // ===========================================================
 private PoolThreadsInfo(TangoServer server) throws DevFailed {
   DbDatum[] data = server.get_property(propertyNames);
   String[] config = new String[0];
   int threadsNumber = 1;
   if (data[NB_THREADS].is_empty() && data[THREADS_CONFIG].is_empty()) {
     //	If no property --> get device list from db
     String[] s = server.queryDeviceFromDb();
     //	and set all for on thread
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < s.length; i++) {
       sb.append(s[i]);
       if (i < s.length - 1) sb.append(',');
     }
     config = new String[] {sb.toString()};
   }
   if (!data[NB_THREADS].is_empty()) threadsNumber = data[NB_THREADS].extractLong();
   if (!data[THREADS_CONFIG].is_empty()) config = data[THREADS_CONFIG].extractStringArray();
   buildConfig(config, threadsNumber);
 }
 /**
  * Add a field.
  *
  * @param sb StringBuilder to append to
  * @param field name of the certificate field
  * @param value to print
  */
 private void addField(StringBuilder sb, String field, String value) {
   sb.append("<tr>")
       .append("<td style='margin-left: 5pt; margin-right: 25pt;")
       .append(" white-space: nowrap'>")
       .append(field)
       .append("</td>")
       .append("<td>")
       .append(value)
       .append("</td>")
       .append("</tr>\n");
 }
Ejemplo n.º 8
0
    String makeFQN(Object[] path) {
      StringBuilder sb = new StringBuilder("");
      String tmp_name;

      if (path == null) return null;
      for (int i = 0; i < path.length; i++) {
        tmp_name = ((MyNode) path[i]).name;
        if (tmp_name.equals(SEP)) continue;
        else sb.append(SEP + tmp_name);
      }
      tmp_name = sb.toString();
      if (tmp_name.length() == 0) return SEP;
      else return tmp_name;
    }
Ejemplo n.º 9
0
 private String tameTooltipText(String text) {
   List<String> lines = new ArrayList<String>();
   while (text.length() > MAX_LENGTH) {
     int pos = text.indexOf(' ', MAX_LENGTH - 10);
     if (pos < 0) break;
     if (pos > MAX_LENGTH + 5) pos = MAX_LENGTH;
     lines.add(text.substring(0, pos).trim());
     text = text.substring(pos).trim();
   }
   if (!text.trim().isEmpty()) lines.add(text);
   StringBuilder html = new StringBuilder("<html>");
   for (String line : lines) html.append(line).append("<br/>\n");
   return html.toString();
 }
 public String dump(int depth) {
   StringBuilder buf = new StringBuilder();
   for (int i = 0; i < depth; i++) {
     buf.append('.');
   }
   buf.append(idToString(getId()));
   buf.append(' ');
   buf.append(getLength());
   if (getChildCount() > 0) {
     buf.append(' ');
     buf.append(idToString(getType()));
     for (MutableIFFChunk child : childChunks()) {
       buf.append('\n');
       buf.append(child.dump(depth + 1));
     }
   }
   return buf.toString();
 }
Ejemplo n.º 11
0
 public void addJavacMessage(AntMessage message, String url) {
   final StringBuilder builder = StringBuilderSpinAllocator.alloc();
   try {
     final VirtualFile file = message.getFile();
     if (message.getLine() > 0) {
       if (file != null) {
         ApplicationManager.getApplication()
             .runReadAction(
                 new Runnable() {
                   public void run() {
                     String presentableUrl = file.getPresentableUrl();
                     builder.append(presentableUrl);
                     builder.append(' ');
                   }
                 });
       } else if (url != null) {
         builder.append(url);
         builder.append(' ');
       }
       builder.append('(');
       builder.append(message.getLine());
       builder.append(':');
       builder.append(message.getColumn());
       builder.append(") ");
     }
     addJavacMessageImpl(
         new AntMessage(
             message.getType(),
             message.getPriority(),
             builder.toString() + message.getText(),
             message.getFile(),
             message.getLine(),
             message.getColumn()));
   } finally {
     StringBuilderSpinAllocator.dispose(builder);
   }
 }
 /**
  * Add a title.
  *
  * @param sb StringBuilder to append to
  * @param title to print
  */
 private void addTitle(StringBuilder sb, String title) {
   sb.append("<tr><td colspan='2'")
       .append(" style='margin-top: 5pt; white-space: nowrap'><p><b>")
       .append(title)
       .append("</b></p></td></tr>\n");
 }
  /**
   * Appends an HTML representation of the given X509Certificate.
   *
   * @param sb StringBuilder to append to
   * @param certificate to print
   */
  private void renderX509(StringBuilder sb, X509Certificate certificate) {
    X500Principal issuer = certificate.getIssuerX500Principal();
    X500Principal subject = certificate.getSubjectX500Principal();

    sb.append("<table cellspacing='1' cellpadding='1'>\n");

    // subject
    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_TO"));
    try {
      for (Rdn name : new LdapName(subject.getName()).getRdns()) {
        String nameType = name.getType();
        String lblKey = "service.gui.CERT_INFO_" + nameType;
        String lbl = R.getI18NString(lblKey);

        if ((lbl == null) || ("!" + lblKey + "!").equals(lbl)) lbl = nameType;

        final String value;
        Object nameValue = name.getValue();

        if (nameValue instanceof byte[]) {
          byte[] nameValueAsByteArray = (byte[]) nameValue;

          value = getHex(nameValueAsByteArray) + " (" + new String(nameValueAsByteArray) + ")";
        } else value = nameValue.toString();

        addField(sb, lbl, value);
      }
    } catch (InvalidNameException ine) {
      addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"), subject.getName());
    }

    // issuer
    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_BY"));
    try {
      for (Rdn name : new LdapName(issuer.getName()).getRdns()) {
        String nameType = name.getType();
        String lblKey = "service.gui.CERT_INFO_" + nameType;
        String lbl = R.getI18NString(lblKey);

        if ((lbl == null) || ("!" + lblKey + "!").equals(lbl)) lbl = nameType;

        final String value;
        Object nameValue = name.getValue();

        if (nameValue instanceof byte[]) {
          byte[] nameValueAsByteArray = (byte[]) nameValue;

          value = getHex(nameValueAsByteArray) + " (" + new String(nameValueAsByteArray) + ")";
        } else value = nameValue.toString();

        addField(sb, lbl, value);
      }
    } catch (InvalidNameException ine) {
      addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"), issuer.getName());
    }

    // validity
    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_VALIDITY"));
    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_ISSUED_ON"),
        certificate.getNotBefore().toString());
    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_EXPIRES_ON"),
        certificate.getNotAfter().toString());

    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_FINGERPRINTS"));
    try {
      String sha1String = getThumbprint(certificate, "SHA1");
      String md5String = getThumbprint(certificate, "MD5");

      addField(sb, "SHA1:", sha1String);
      addField(sb, "MD5:", md5String);
    } catch (CertificateException e) {
      // do nothing as we cannot show this value
    }

    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_CERT_DETAILS"));

    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_SER_NUM"),
        certificate.getSerialNumber().toString());

    addField(
        sb, R.getI18NString("service.gui.CERT_INFO_VER"), String.valueOf(certificate.getVersion()));

    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_SIGN_ALG"),
        String.valueOf(certificate.getSigAlgName()));

    addTitle(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY_INFO"));

    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_ALG"),
        certificate.getPublicKey().getAlgorithm());

    if (certificate.getPublicKey().getAlgorithm().equals("RSA")) {
      RSAPublicKey key = (RSAPublicKey) certificate.getPublicKey();

      addField(
          sb,
          R.getI18NString("service.gui.CERT_INFO_PUB_KEY"),
          R.getI18NString(
              "service.gui.CERT_INFO_KEY_BYTES_PRINT",
              new String[] {
                String.valueOf(key.getModulus().toByteArray().length - 1),
                key.getModulus().toString(16)
              }));

      addField(
          sb, R.getI18NString("service.gui.CERT_INFO_EXP"), key.getPublicExponent().toString());

      addField(
          sb,
          R.getI18NString("service.gui.CERT_INFO_KEY_SIZE"),
          R.getI18NString(
              "service.gui.CERT_INFO_KEY_BITS_PRINT",
              new String[] {String.valueOf(key.getModulus().bitLength())}));
    } else if (certificate.getPublicKey().getAlgorithm().equals("DSA")) {
      DSAPublicKey key = (DSAPublicKey) certificate.getPublicKey();

      addField(sb, "Y:", key.getY().toString(16));
    }

    addField(
        sb,
        R.getI18NString("service.gui.CERT_INFO_SIGN"),
        R.getI18NString(
            "service.gui.CERT_INFO_KEY_BYTES_PRINT",
            new String[] {
              String.valueOf(certificate.getSignature().length), getHex(certificate.getSignature())
            }));

    sb.append("</table>\n");
  }