/** * 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(); }
/** * Converts the byte array to hex string. * * @param raw the data. * @return the hex string. */ private String getHex(byte[] raw) { if (raw == null) return null; StringBuilder hex = new StringBuilder(2 * raw.length); Formatter f = new Formatter(hex); try { for (byte b : raw) f.format("%02x", b); } finally { f.close(); } return hex.toString(); }
@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; }
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; }
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(); }
/** * Calculates the hash of the certificate known as the "thumbprint" and returns it as a string * representation. * * @param cert The certificate to hash. * @param algorithm The hash algorithm to use. * @return The SHA-1 hash of the certificate. * @throws CertificateException */ private static String getThumbprint(X509Certificate cert, String algorithm) throws CertificateException { MessageDigest digest; try { digest = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new CertificateException(e); } byte[] encodedCert = cert.getEncoded(); StringBuilder sb = new StringBuilder(encodedCert.length * 2); Formatter f = new Formatter(sb); try { for (byte b : digest.digest(encodedCert)) f.format("%02x", b); } finally { f.close(); } return sb.toString(); }
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"); }
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(); }
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(); }
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"); }