Bug 530240 - Restore StringBuffer based methods in internal HTMLPrinter
API
This reverts commit 432db08619cda4364032721bf730f48194237ce6.
Change-Id: Idf51acb5bb4324a150d432426629c6884b238f62
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java
index a138194..0e9b4c8 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/html/HTMLPrinter.java
@@ -160,6 +160,34 @@
/**
*
+ * @deprecated migrate to new StringBuilder API
+ *
+ * @param buffer the output StringBuilder
+ * @param position offset where the prolog is placed
+ * @param fgRGB Foreground-Color
+ * @param bgRGB Background-Color
+ * @param styleSheet Stylesheet
+ */
+ @Deprecated
+ public static void insertPageProlog(StringBuffer buffer, int position, RGB fgRGB, RGB bgRGB, String styleSheet) {
+ if (fgRGB == null)
+ fgRGB= FG_COLOR_RGB;
+ if (bgRGB == null)
+ bgRGB= BG_COLOR_RGB;
+
+ StringBuffer pageProlog= new StringBuffer(300);
+
+ pageProlog.append("<html>"); //$NON-NLS-1$
+
+ appendStyleSheet(pageProlog, styleSheet, fgRGB, bgRGB);
+
+ appendColors(pageProlog, fgRGB, bgRGB);
+
+ buffer.insert(position, pageProlog.toString());
+ }
+
+ /**
+ *
* @param buffer the output StringBuilder
* @param position offset where the prolog is placed
* @param fgRGB Foreground-Color
@@ -202,6 +230,24 @@
/**
*
*
+ * @param pageProlog The Pageprolog where the color has to be set
+ * @param fgRGB Foreground-Color
+ * @param bgRGB Background-Color
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ private static void appendColors(StringBuffer pageProlog, RGB fgRGB, RGB bgRGB) {
+ pageProlog.append("<body text=\""); //$NON-NLS-1$
+ appendColor(pageProlog, fgRGB);
+ pageProlog.append("\" bgcolor=\""); //$NON-NLS-1$
+ appendColor(pageProlog, bgRGB);
+ pageProlog.append("\">"); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ *
* @param buffer The Output buffer
* @param rgb RGB-Value
*
@@ -215,6 +261,22 @@
/**
*
+ *
+ * @param buffer The Output buffer
+ * @param rgb RGB-Value
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ private static void appendColor(StringBuffer buffer, RGB rgb) {
+ buffer.append('#');
+ appendAsHexString(buffer, rgb.red);
+ appendAsHexString(buffer, rgb.green);
+ appendAsHexString(buffer, rgb.blue);
+ }
+
+ /**
+ *
* @param buffer the output buffer
* @param intValue the intValue will be converted to hex and appended
*
@@ -229,6 +291,21 @@
/**
*
* @param buffer the output buffer
+ * @param intValue the intValue will be converted to hex and appended
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ private static void appendAsHexString(StringBuffer buffer, int intValue) {
+ String hexValue= Integer.toHexString(intValue);
+ if (hexValue.length() == 1)
+ buffer.append('0');
+ buffer.append(hexValue);
+ }
+
+ /**
+ *
+ * @param buffer the output buffer
* @param styles array with styles to be appended
*
*/
@@ -264,6 +341,42 @@
/**
*
* @param buffer the output buffer
+ * @param styles array with styles to be appended
+ *
+ * @deprecated As of 3.13, replaced by {@link #insertStyles(StringBuilder, String[])}
+ */
+ @Deprecated
+ public static void insertStyles(StringBuffer buffer, String[] styles) {
+ if (styles == null || styles.length == 0)
+ return;
+
+ StringBuffer styleBuf= new StringBuffer(10 * styles.length);
+ for (String style : styles) {
+ styleBuf.append(" style=\""); //$NON-NLS-1$
+ styleBuf.append(style);
+ styleBuf.append('"');
+ }
+
+ // Find insertion index
+ // a) within existing body tag with trailing space
+ int index= buffer.indexOf("<body "); //$NON-NLS-1$
+ if (index != -1) {
+ buffer.insert(index+5, styleBuf);
+ return;
+ }
+
+ // b) within existing body tag without attributes
+ index= buffer.indexOf("<body>"); //$NON-NLS-1$
+ if (index != -1) {
+ buffer.insert(index+5, ' ');
+ buffer.insert(index+6, styleBuf);
+ return;
+ }
+ }
+
+ /**
+ *
+ * @param buffer the output buffer
* @param styleSheet the stylesheet
* @param fgRGB Foreground-Color
* @param bgRGB Background-Color
@@ -289,6 +402,33 @@
/**
*
* @param buffer the output buffer
+ * @param styleSheet the stylesheet
+ * @param fgRGB Foreground-Color
+ * @param bgRGB Background-Color
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ private static void appendStyleSheet(StringBuffer buffer, String styleSheet, RGB fgRGB, RGB bgRGB) {
+ if (styleSheet == null)
+ return;
+
+ // workaround for https://bugs.eclipse.org/318243
+ StringBuffer fg= new StringBuffer();
+ appendColor(fg, fgRGB);
+ styleSheet= styleSheet.replaceAll("InfoText", fg.toString()); //$NON-NLS-1$
+ StringBuilder bg= new StringBuilder();
+ appendColor(bg, bgRGB);
+ styleSheet= styleSheet.replaceAll("InfoBackground", bg.toString()); //$NON-NLS-1$
+
+ buffer.append("<head><style CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"); //$NON-NLS-1$
+ buffer.append(styleSheet);
+ buffer.append("</style></head>"); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @param buffer the output buffer
* @param styleSheetURL the URL to the Stylesheet
*
*/
@@ -308,6 +448,28 @@
/**
*
* @param buffer the output buffer
+ * @param styleSheetURL the URL to the Stylesheet
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ private static void appendStyleSheetURL(StringBuffer buffer, URL styleSheetURL) {
+ if (styleSheetURL == null)
+ return;
+
+ buffer.append("<head>"); //$NON-NLS-1$
+
+ buffer.append("<LINK REL=\"stylesheet\" HREF= \""); //$NON-NLS-1$
+ buffer.append(styleSheetURL);
+ buffer.append("\" CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"); //$NON-NLS-1$
+
+ buffer.append("</head>"); //$NON-NLS-1$
+ }
+
+
+ /**
+ *
+ * @param buffer the output buffer
* @param position the offset
*
*/
@@ -322,6 +484,38 @@
*
* @param buffer the output buffer
* @param position the offset
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void insertPageProlog(StringBuffer buffer, int position) {
+ StringBuffer pageProlog= new StringBuffer(60);
+ pageProlog.append("<html>"); //$NON-NLS-1$
+ appendColors(pageProlog, FG_COLOR_RGB, BG_COLOR_RGB);
+ buffer.insert(position, pageProlog.toString());
+ }
+
+ /**
+ *
+ * @param buffer the output buffer
+ * @param position the offset
+ * @param styleSheetURL URL to the Stylesheet
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void insertPageProlog(StringBuffer buffer, int position, URL styleSheetURL) {
+ StringBuffer pageProlog= new StringBuffer(300);
+ pageProlog.append("<html>"); //$NON-NLS-1$
+ appendStyleSheetURL(pageProlog, styleSheetURL);
+ appendColors(pageProlog, FG_COLOR_RGB, BG_COLOR_RGB);
+ buffer.insert(position, pageProlog.toString());
+ }
+
+ /**
+ *
+ * @param buffer the output buffer
+ * @param position the offset
* @param styleSheetURL URL to the Stylesheet
*
*/
@@ -347,12 +541,36 @@
/**
*
* @param buffer the output buffer
+ * @param position the offset
+ * @param styleSheet Stylesheet
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void insertPageProlog(StringBuffer buffer, int position, String styleSheet) {
+ insertPageProlog(buffer, position, null, null, styleSheet);
+ }
+
+ /**
+ *
+ * @param buffer the output buffer
*
*/
public static void addPageProlog(StringBuilder buffer) {
insertPageProlog(buffer, buffer.length());
}
+ /**
+ *
+ * @param buffer the output buffer
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void addPageProlog(StringBuffer buffer) {
+ insertPageProlog(buffer, buffer.length());
+ }
+
public static void addPageEpilog(StringBuilder buffer) {
buffer.append("</body></html>"); //$NON-NLS-1$
}
@@ -361,12 +579,34 @@
*
* @param buffer the output buffer
*
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void addPageEpilog(StringBuffer buffer) {
+ buffer.append("</body></html>"); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @param buffer the output buffer
+ *
*/
public static void startBulletList(StringBuilder buffer) {
buffer.append("<ul>"); //$NON-NLS-1$
}
/**
+ *
+ * @param buffer the output buffer
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void startBulletList(StringBuffer buffer) {
+ buffer.append("<ul>"); //$NON-NLS-1$
+ }
+
+ /**
* ends the bulletpointlist
*
* @param buffer the output buffer
@@ -377,6 +617,18 @@
}
/**
+ * ends the bulletpointlist
+ *
+ * @param buffer the output buffer
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void endBulletList(StringBuffer buffer) {
+ buffer.append("</ul>"); //$NON-NLS-1$
+ }
+
+ /**
* Adds bulletpoint
*
* @param buffer the output buffer
@@ -392,6 +644,23 @@
}
/**
+ * Adds bulletpoint
+ *
+ * @param buffer the output buffer
+ * @param bullet the bulletpoint
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void addBullet(StringBuffer buffer, String bullet) {
+ if (bullet != null) {
+ buffer.append("<li>"); //$NON-NLS-1$
+ buffer.append(bullet);
+ buffer.append("</li>"); //$NON-NLS-1$
+ }
+ }
+
+ /**
*
* Adds h5 headline
*
@@ -409,6 +678,24 @@
/**
*
+ * Adds h5 headline
+ *
+ * @param buffer the output buffer
+ * @param header of h5 headline
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void addSmallHeader(StringBuffer buffer, String header) {
+ if (header != null) {
+ buffer.append("<h5>"); //$NON-NLS-1$
+ buffer.append(header);
+ buffer.append("</h5>"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ *
* @param buffer the output buffer
* @param paragraph the content of the paragraph
*
@@ -421,6 +708,21 @@
}
/**
+ *
+ * @param buffer the output buffer
+ * @param paragraph the content of the paragraph
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void addParagraph(StringBuffer buffer, String paragraph) {
+ if (paragraph != null) {
+ buffer.append("<p>"); //$NON-NLS-1$
+ buffer.append(paragraph);
+ }
+ }
+
+ /**
* Appends a string and keeps its whitespace and newlines.
* <p>
* <b>Warning:</b> This starts a new paragraph when rendered in a browser, but
@@ -443,6 +745,31 @@
}
/**
+ * Appends a string and keeps its whitespace and newlines.
+ * <p>
+ * <b>Warning:</b> This starts a new paragraph when rendered in a browser, but
+ * it doesn't starts a new paragraph when rendered with a {@link HTML2TextReader}
+ * (e.g. in a {@link DefaultInformationControl} that renders simple HTML).
+ *
+ * @param buffer the output buffer
+ * @param preFormatted the string that should be rendered with whitespace preserved
+ *
+ * @deprecated migrate to new StringBuilder API
+ *
+ * @see #convertToHTMLContent(String)
+ * @see #convertToHTMLContentWithWhitespace(String)
+ * @since 3.7
+ */
+ @Deprecated
+ public static void addPreFormatted(StringBuffer buffer, String preFormatted) {
+ if (preFormatted != null) {
+ buffer.append("<pre>"); //$NON-NLS-1$
+ buffer.append(preFormatted);
+ buffer.append("</pre>"); //$NON-NLS-1$
+ }
+ }
+
+ /**
*
* @param buffer the output buffer
* @param paragraphReader The content of the Read will be added to output buffer
@@ -454,6 +781,19 @@
}
/**
+ *
+ * @param buffer the output buffer
+ * @param paragraphReader The content of the Read will be added to output buffer
+ *
+ * @deprecated migrate to new StringBuilder API
+ */
+ @Deprecated
+ public static void addParagraph(StringBuffer buffer, Reader paragraphReader) {
+ if (paragraphReader != null)
+ addParagraph(buffer, read(paragraphReader));
+ }
+
+ /**
* Replaces the following style attributes of the font definition of the <code>html</code>
* element:
* <ul>