package org.greenstone.gsdl3.gs3build.util; public class HTMLCText implements HTMLObject { String text; int start; int end; public static final String HTML_TEXT_TYPE = "Text"; public HTMLCText(String text, int start, int end) { this.text = text; this.start = start; this.end = end; } public String getHTMLType() { return HTML_TEXT_TYPE; } public int startPos() { return this.start; } public int endPos() { return this.end; } public boolean isEmpty() { return emptyString(this.text); } public static boolean emptyString(String s) { int c; for (c = 0; c < s.length(); c ++) { if (s.charAt(c) > 32) { return false; } } return true; } public static StringBuffer cleanString(StringBuffer buffer) { int c; int w; w = 0; for (c = 0; c < buffer.length(); c ++) { if (buffer.charAt(c) >= 32) { if (buffer.charAt(c) == 32) { if (w > 0 && buffer.charAt(w-1) > 32) { buffer.setCharAt(w, buffer.charAt(c)); w ++; } } else { if (c != w) { buffer.setCharAt(w, buffer.charAt(c)); } w ++; } } else { if (w > 0 && buffer.charAt(w-1) > 32) { buffer.setCharAt(w,' '); w ++; } } } buffer.setLength(w); return buffer; } /** * nullString; used by initialisation for checking for * non-blank content (ie. text other than just spaces/returns) * see constructor (ie HTMLBlockList) methods below for role of * this in the larger plan of things */ public boolean nullString() { int ch; if (text != null) { for (ch = 0; ch < text.length(); ch ++) { if (text.charAt(ch) > ' ') { return false; } } } return true; } public String toString() { return this.text; } public String toString(boolean cleaned) { if (cleaned == false) { return toString(); } else { return HTMLEntity.decodeText(this.text); } } }