1 11 package org.eclipse.ant.internal.ui.editor.derived; 12 13 14 import java.io.IOException ; 15 import java.io.Reader ; 16 17 18 23 public class HTMLPrinter { 24 25 private HTMLPrinter() { 26 } 27 28 private static String replace(String text, char c, String s) { 29 30 int previous= 0; 31 int current= text.indexOf(c, previous); 32 33 if (current == -1) 34 return text; 35 36 StringBuffer buffer= new StringBuffer (); 37 while (current > -1) { 38 buffer.append(text.substring(previous, current)); 39 buffer.append(s); 40 previous= current + 1; 41 current= text.indexOf(c, previous); 42 } 43 buffer.append(text.substring(previous)); 44 45 return buffer.toString(); 46 } 47 48 public static String convertToHTMLContent(String content) { 49 content= replace(content, '<', "<"); return replace(content, '>', ">"); } 52 53 public static String read(Reader rd) { 54 55 StringBuffer buffer= new StringBuffer (); 56 char[] readBuffer= new char[2048]; 57 58 try { 59 int n= rd.read(readBuffer); 60 while (n > 0) { 61 buffer.append(readBuffer, 0, n); 62 n= rd.read(readBuffer); 63 } 64 return buffer.toString(); 65 } catch (IOException x) { 66 } 67 68 return null; 69 } 70 71 public static void insertPageProlog(StringBuffer buffer, int position) { 72 buffer.insert(position, "<html><body text=\"#000000\" bgcolor=\"#FFFF88\"><font size=-1>"); } 74 75 public static void addPageProlog(StringBuffer buffer) { 76 insertPageProlog(buffer, buffer.length()); 77 } 78 79 public static void addPageEpilog(StringBuffer buffer) { 80 buffer.append("</font></body></html>"); } 82 83 public static void startBulletList(StringBuffer buffer) { 84 buffer.append("<ul>"); } 86 87 public static void endBulletList(StringBuffer buffer) { 88 buffer.append("</ul>"); } 90 91 public static void addBullet(StringBuffer buffer, String bullet) { 92 if (bullet != null) { 93 buffer.append("<li>"); buffer.append(bullet); 95 buffer.append("</li>"); } 97 } 98 99 public static void addSmallHeader(StringBuffer buffer, String header) { 100 if (header != null) { 101 buffer.append("<h5>"); buffer.append(header); 103 buffer.append("</h5>"); } 105 } 106 107 public static void addParagraph(StringBuffer buffer, String paragraph) { 108 if (paragraph != null) { 109 buffer.append("<p>"); buffer.append(paragraph); 111 } 112 } 113 114 public static void addParagraph(StringBuffer buffer, Reader paragraphReader) { 115 if (paragraphReader != null) 116 addParagraph(buffer, read(paragraphReader)); 117 } 118 } 119 | Popular Tags |