/** * Given a string, replace all occurraces of 'newStr' with 'oldStr'. * * @param originalStr the string to modify. * @param oldStr the string to replace. * @param newStr the string to insert in place of the old string. */ public static String replaceText(String originalStr, String oldStr, String newStr) { if (oldStr == null || newStr == null || oldStr.equals(newStr)) { return originalStr; } StringBuffer result = new StringBuffer(originalStr); int startIndex = 0; while ((startIndex = result.indexOf(oldStr, startIndex)) != -1) { result = result.replace(startIndex, startIndex + oldStr.length(), newStr); startIndex += newStr.length(); } return result.toString(); }
/** * Given a string, replace all tabs with the appropriate number of spaces. * * @param tabLength the length of each tab. * @param s the String to scan. */ public static void replaceTabs(int tabLength, StringBuffer s) { int index, col; StringBuffer whitespace; while ((index = s.indexOf("\t")) != -1) { whitespace = new StringBuffer(); col = index; do { whitespace.append(" "); col++; } while ((col % tabLength) != 0); s.replace(index, index + 1, whitespace.toString()); } }
/** * Build the signature of the current annotation type. * * @param node the XML element that specifies which components to document * @param annotationInfoTree the content tree to which the documentation will be added */ public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) { StringBuffer modifiers = new StringBuffer(annotationTypeDoc.modifiers() + " "); writer.addAnnotationTypeSignature( Util.replaceText(modifiers.toString(), "interface", "@interface"), annotationInfoTree); }
/** * Get Html Hyper Link string. * * @param link String name of the file. * @param where Position of the link in the file. Character '#' is not needed. * @param label Tag for the link. * @param bold Boolean that sets label to bold. * @param stylename String style of text defined in style sheet. * @param title String that describes the link's content for accessibility. * @param target Target frame. * @return String Hyper Link. */ public String getHyperLink( String link, String where, String label, boolean bold, String stylename, String title, String target) { StringBuffer retlink = new StringBuffer(); retlink.append("<A HREF=\""); retlink.append(link); if (where != null && where.length() != 0) { retlink.append("#"); retlink.append(where); } retlink.append("\""); if (title != null && title.length() != 0) { retlink.append(" title=\"" + title + "\""); } if (target != null && target.length() != 0) { retlink.append(" target=\"" + target + "\""); } retlink.append(">"); if (stylename != null && stylename.length() != 0) { retlink.append("<FONT CLASS=\""); retlink.append(stylename); retlink.append("\">"); } if (bold) { retlink.append("<B>"); } retlink.append(label); if (bold) { retlink.append("</B>"); } if (stylename != null && stylename.length() != 0) { retlink.append("</FONT>"); } retlink.append("</A>"); return retlink.toString(); }