iter = _listeners.iterator(); iter.hasNext();) {
+ if(!(iter.next()).pressed(this))
return false;
}
return true;
diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/ArrayUtil.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/ArrayUtil.java
index 5f25bd36d..4a6598399 100644
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/ArrayUtil.java
+++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/ArrayUtil.java
@@ -26,9 +26,6 @@ public class ArrayUtil {
public static String[] cloneOrEmpty(String[] source){
return source == null ? Constants.EMPTY_STR_ARR : (String[]) source.clone();
}
- public static byte[] cloneOrEmpty(byte[] source){
- return source == null ? Constants.EMPTY_BYTE_ARR : (byte[]) source.clone();
- }
public static int[] cloneOrEmpty(int[] source) {
return source == null ? Constants.EMPTY_INT_ARR : (int[]) source.clone();
diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/GeneralUtil.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/GeneralUtil.java
index 909041705..ed085e5dc 100644
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/GeneralUtil.java
+++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/GeneralUtil.java
@@ -32,12 +32,6 @@
*/
public class GeneralUtil {
- /**
- * Used to format an Object's hashcode into a 0-padded 10 char String, e.g.
- * for 24993066 returns "0024993066"
- */
- public final static java.text.DecimalFormat PADDED_HASH_FORMAT = new java.text.DecimalFormat("0000000000");
-
/**
* Dumps an exception to the console, only the last 5 lines of the stack
* trace.
@@ -57,187 +51,6 @@ public static void dumpShortException(Exception ex) {
}
}
- /**
- * Returns a String tracking the last n method calls, from oldest to most
- * recent. You can use this as a simple tracing mechanism to find out the
- * calls that got to where you execute the trackBack() call
- * from. Example:
- *
- * // called from Box.calcBorders(), line 639
- * String tback = GeneralUtil.trackBack(6);
- * System.out.println(tback);
- *
produces
- *
- * Boxing.layoutChildren(ln 204)
- * BlockBoxing.layoutContent(ln 81)
- * Boxing.layout(ln 72)
- * Boxing.layout(ln 133)
- * Box.totalLeftPadding(ln 306)
- * Box.calcBorders(ln 639)
- *
- * The trackBack() method itself is always excluded from the dump.
- * Note the output may not be useful if HotSpot has been optimizing the
- * code.
- *
- * @param cnt How far back in the call tree to go; if call tree is smaller, will
- * be limited to call tree.
- * @return see desc
- */
- public static String trackBack(int cnt) {
- Exception ex = new Exception();
- StringBuilder sb = new StringBuilder();
- List list = new ArrayList(cnt);
- StackTraceElement[] stes = ex.getStackTrace();
- if (cnt >= stes.length) {
- cnt = stes.length - 1;
- }
-
- // >= 1 to not include this method
- for (int i = cnt; i >= 1; i--) {
- StackTraceElement ste = stes[i];
- sb.append(GeneralUtil.classNameOnly(ste.getClassName()));
- sb.append(".");
- sb.append(ste.getMethodName());
- sb.append("(ln ").append(ste.getLineNumber()).append(")");
- list.add(sb.toString());
- sb = new StringBuilder();
- }
-
- Iterator iter = list.iterator();
- StringBuilder padding = new StringBuilder();
- StringBuilder trackback = new StringBuilder();
- while (iter.hasNext()) {
- String s = (String) iter.next();
- trackback.append(padding).append(s).append("\n");
- padding.append(" ");
- }
- return trackback.toString();
- }
-
-
- /**
- * Given an Object instance, returns just the classname with no package
- *
- * @param o PARAM
- * @return Returns
- */
- public static String classNameOnly(Object o) {
- String s = "[null object ref]";
- if (o != null) {
- s = classNameOnly(o.getClass().getName());
- }
- return s;
- }
-
- /**
- * Given a String classname, returns just the classname with no package
- *
- * @param cname PARAM
- * @return Returns
- */
- public static String classNameOnly(String cname) {
- String s = "[null object ref]";
- if (cname != null) {
- s = cname.substring(cname.lastIndexOf('.') + 1);
- }
- return s;
- }
-
- /**
- * Description of the Method
- *
- * @param o PARAM
- * @return Returns
- */
- public static String paddedHashCode(Object o) {
- String s = "0000000000";
- if (o != null) {
- s = PADDED_HASH_FORMAT.format(o.hashCode());
- }
- return s;
- }
-
- public static boolean isMacOSX() {
- try {
- if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
- return true;
- }
- } catch (SecurityException e) {
- System.err.println(e.getLocalizedMessage());
- }
- return false;
- }
-
- public static StringBuilder htmlEscapeSpace(String uri) {
- StringBuilder sbURI = new StringBuilder((int) (uri.length() * 1.5));
- char ch;
- for (int i = 0; i < uri.length(); ++i) {
- ch = uri.charAt(i);
- if (ch == ' ') {
- sbURI.append("%20");
- } else if (ch == '\\') {
- sbURI.append('/');
- } else {
- sbURI.append(ch);
- }
- }
- return sbURI;
- }
-
- /**
- * Reads all content from a given InputStream into a String using the default platform encoding.
- *
- * @param is the InputStream to read from. Must already be open, and will NOT be closed by this function. Failing to
- * close this stream after the call will result in a resource leak.
- *
- * @return String containing contents read from the stream
- * @throws IOException if the stream could not be read
- */
- public static String inputStreamToString(InputStream is) throws IOException {
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- StringWriter sw = new StringWriter();
- char c[] = new char[1024];
- while (true) {
- int n = br.read(c, 0, c.length);
- if (n < 0) break;
- sw.write(c, 0, n);
- }
- isr.close();
- return sw.toString();
- }
-
- public static void writeStringToFile(String content, String encoding, String fileName)
- throws IOException {
- File f = new File(fileName);
- FileOutputStream fos = new FileOutputStream(f);
- try {
- OutputStreamWriter osw = new OutputStreamWriter(fos, encoding);
- BufferedWriter bw = new BufferedWriter(osw);
- PrintWriter pw = new PrintWriter(bw);
- try {
- pw.print(content);
- pw.flush();
- bw.flush();
- } finally {
- try {
- pw.close();
- } catch (Exception e) {
- // ignore
- }
- }
- } catch (IOException e) {
- throw e;
- } finally {
- try {
- fos.close();
- } catch (Exception e) {
- // ignore
- }
- }
- System.out.println("Wrote file: " + f.getAbsolutePath());
- }
-
/**
* Parses an integer from a string using less restrictive rules about which
* characters we won't accept. This scavenges the supplied string for any
@@ -281,91 +94,6 @@ public static int parseIntRelaxed(String s) {
return Integer.MAX_VALUE;
}
}
-
- /**
- * Converts any special characters into their corresponding HTML entities, for example < to <. This is done using a character
- * by character test, so you may consider other approaches for large documents. Make sure you declare the
- * entities that might appear in this replacement, e.g. the latin-1 entities
- * This method was taken from a code-samples website, written and hosted by Real Gagnon, at
- * http://www.rgagnon.com/javadetails/java-0306.html.
- *
- * @param s The String which may contain characters to escape.
- * @return The string with the characters as HTML entities.
- */
- public static String escapeHTML(String s){
- if (s == null) {
- return "";
- }
- StringBuilder sb = new StringBuilder();
- int n = s.length();
- for (int i = 0; i < n; i++) {
- char c = s.charAt(i);
- switch (c) {
- case '<':
- sb.append("<");
- break;
- case '>':
- sb.append(">");
- break;
- case '&':
- sb.append("&");
- break;
- case '"':
- sb.append(""");
- break;
- /*
- case 'ÔøΩ': sb.append("à");break;
- case 'ÔøΩ': sb.append("À");break;
- case 'ÔøΩ': sb.append("â");break;
- case 'ÔøΩ': sb.append("Â");break;
- case 'ÔøΩ': sb.append("ä");break;
- case 'ÔøΩ': sb.append("Ä");break;
- case 'ÔøΩ': sb.append("å");break;
- case 'ÔøΩ': sb.append("Å");break;
- case 'ÔøΩ': sb.append("æ");break;
- case 'ÔøΩ': sb.append("Æ");break;
- case 'ÔøΩ': sb.append("ç");break;
- case 'ÔøΩ': sb.append("Ç");break;
- case 'ÔøΩ': sb.append("é");break;
- case 'ÔøΩ': sb.append("É");break;
- case 'ÔøΩ': sb.append("è");break;
- case 'ÔøΩ': sb.append("È");break;
- case 'ÔøΩ': sb.append("ê");break;
- case 'ÔøΩ': sb.append("Ê");break;
- case 'ÔøΩ': sb.append("ë");break;
- case 'ÔøΩ': sb.append("Ë");break;
- case 'ÔøΩ': sb.append("ï");break;
- case 'ÔøΩ': sb.append("Ï");break;
- case 'ÔøΩ': sb.append("ô");break;
- case 'ÔøΩ': sb.append("Ô");break;
- case 'ÔøΩ': sb.append("ö");break;
- case 'ÔøΩ': sb.append("Ö");break;
- case 'ÔøΩ': sb.append("ø");break;
- case 'ÔøΩ': sb.append("Ø");break;
- case 'ÔøΩ': sb.append("ß");break;
- case 'ÔøΩ': sb.append("ù");break;
- case 'ÔøΩ': sb.append("Ù");break;
- case 'ÔøΩ': sb.append("û");break;
- case 'ÔøΩ': sb.append("Û");break;
- case 'ÔøΩ': sb.append("ü");break;
- case 'ÔøΩ': sb.append("Ü");break;
- case 'ÔøΩ': sb.append("®");break;
- case 'ÔøΩ': sb.append("©");break;
- case 'ÔøΩ': sb.append("€"); break;
- */
- // be carefull with this one (non-breaking whitee space)
- case ' ':
- sb.append(" ");
- break;
-
- default:
- sb.append(c);
- break;
- }
- }
- return sb.toString();
- }
-
}
/*
diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/PermutationGenerator.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/PermutationGenerator.java
deleted file mode 100644
index 33ec501a8..000000000
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/PermutationGenerator.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package com.openhtmltopdf.util;
-
-
-import java.math.BigInteger;
-
-/**
- * The PermutationGenerator Java class systematically generates permutations. It relies on the fact that any set with n
- * elements can be placed in one-to-one correspondence with the set {1, 2, 3, ..., n}. The algorithm is described by
- * Kenneth H. Rosen, Discrete Mathematics and Its Applications, 2nd edition (NY: McGraw-Hill, 1991), pp. 282-284.
- *
- * The class is very easy to use. Suppose that you wish to generate all permutations of the strings "a", "b", "c", and
- * "d". Put them into an array. Keep calling the permutation generator's {@link #getNext ()} method until there are no
- * more permutations left. The {@link #getNext ()} method returns an array of integers, which tell you the order in
- * which to arrange your original array of strings. Here is a snippet of code which illustrates how to use the
- * PermutationGenerator class.
- *
- * int[] indices;
- * String[] elements = {"a", "b", "c", "d"};
- * PermutationGenerator x = new PermutationGenerator (elements.length);
- * StringBuffer permutation;
- * while (x.hasMore ()) {
- * permutation = new StringBuffer ();
- * indices = x.getNext ();
- * for (int i = 0; i < indices.length; i++) {
- * permutation.append (elements[indices[i]]);
- * }
- * System.out.println (permutation.toString ());
- * }
- *
- * One caveat. Don't use this class on large sets. Recall that the number of permutations of a set containing n elements
- * is n factorial, which is a very large number even when n is as small as 20. 20! is 2,432,902,008,176,640,000.
- *
- * NOTE: This class was taken from the internet, as posted by Michael Gilleland on this website. The code was posted with the following comment: "The
- * source code is free for you to use in whatever way you wish."
- *
- * @author Michael Gilleland, Merriam Park Software (http://www.merriampark.com/index.htm)
- */
-public class PermutationGenerator {
-
- private int[] a;
- private BigInteger numLeft;
- private BigInteger total;
-
- //-----------------------------------------------------------
- // Constructor. WARNING: Don't make n too large.
- // Recall that the number of permutations is n!
- // which can be very large, even when n is as small as 20 --
- // 20! = 2,432,902,008,176,640,000 and
- // 21! is too big to fit into a Java long, which is
- // why we use BigInteger instead.
- //----------------------------------------------------------
-
- public PermutationGenerator(int n) {
- if (n < 1) {
- throw new IllegalArgumentException("Min 1");
- }
- a = new int[n];
- total = getFactorial(n);
- reset();
- }
-
- //------
- // Reset
- //------
-
- public void reset() {
- for (int i = 0; i < a.length; i++) {
- a[i] = i;
- }
- numLeft = new BigInteger(total.toString());
- }
-
- //------------------------------------------------
- // Return number of permutations not yet generated
- //------------------------------------------------
-
- public BigInteger getNumLeft() {
- return numLeft;
- }
-
- //------------------------------------
- // Return total number of permutations
- //------------------------------------
-
- public BigInteger getTotal() {
- return total;
- }
-
- //-----------------------------
- // Are there more permutations?
- //-----------------------------
-
- public boolean hasMore() {
- return numLeft.compareTo(BigInteger.ZERO) == 1;
- }
-
- //------------------
- // Compute factorial
- //------------------
-
- private static BigInteger getFactorial(int n) {
- BigInteger fact = BigInteger.ONE;
- for (int i = n; i > 1; i--) {
- fact = fact.multiply(new BigInteger(Integer.toString(i)));
- }
- return fact;
- }
-
- //--------------------------------------------------------
- // Generate next permutation (algorithm from Rosen p. 284)
- //--------------------------------------------------------
-
- public int[] getNext() {
-
- if (numLeft.equals(total)) {
- numLeft = numLeft.subtract(BigInteger.ONE);
- return ArrayUtil.cloneOrEmpty(a);
- }
-
- int temp;
-
- // Find largest index j with a[j] < a[j+1]
-
- int j = a.length - 2;
- while (a[j] > a[j + 1]) {
- j--;
- }
-
- // Find index k such that a[k] is smallest integer
- // greater than a[j] to the right of a[j]
-
- int k = a.length - 1;
- while (a[j] > a[k]) {
- k--;
- }
-
- // Interchange a[j] and a[k]
-
- temp = a[k];
- a[k] = a[j];
- a[j] = temp;
-
- // Put tail end of permutation after jth position in increasing order
-
- int r = a.length - 1;
- int s = j + 1;
-
- while (r > s) {
- temp = a[s];
- a[s] = a[r];
- a[r] = temp;
- r--;
- s++;
- }
-
- numLeft = numLeft.subtract(BigInteger.ONE);
- return ArrayUtil.cloneOrEmpty(a);
- }
-} // end class
diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Util.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Util.java
deleted file mode 100755
index 9fd61ec0c..000000000
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Util.java
+++ /dev/null
@@ -1,635 +0,0 @@
-/*
- * {{{ header & license
- * Copyright (c) 2004, 2005 Joshua Marinacci
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * }}}
- */
-package com.openhtmltopdf.util;
-
-import javax.swing.*;
-import java.awt.Dimension;
-import java.awt.Toolkit;
-import java.io.*;
-import java.text.DateFormat;
-import java.util.*;
-
-
-/**
- * Description of the Class
- *
- * @author empty
- */
-public class Util {
- /**
- * Description of the Field
- */
- private PrintWriter pw = null;
- /**
- * Description of the Field
- */
- private boolean on = true;
-
- /**
- * Constructor for the Util object
- *
- * @param writer PARAM
- */
- public Util(PrintWriter writer) {
- this.pw = writer;
- }
-
- /**
- * Constructor for the Util object
- *
- * @param out PARAM
- */
- public Util(OutputStream out) {
- this.pw = new PrintWriter(out);
- }
-
- /*
- * ------------ static stuff -------------
- */
- /*
- * ---- general print functions -----
- */
- /**
- * Description of the Method
- *
- * @param o PARAM
- */
- public void print(Object o) {
- println(o, false);
- }
-
- /**
- * Description of the Method
- *
- * @param o PARAM
- */
- public void println(Object o) {
- println(o, true);
- }
-
- /**
- * Description of the Method
- *
- * @param o PARAM
- * @param line PARAM
- */
- public void println(Object o, boolean line) {
- if (o == null) {
- ps("null");
- return;
- }
- //ps("in p: " + o.getClass());
- if (o instanceof Object[]) {
- print_array((Object[]) o);
- return;
- }
- if (o instanceof int[]) {
- print_array((int[]) o);
- }
- if (o instanceof String) {
- ps((String) o, line);
- return;
- }
- if (o instanceof Exception) {
- ps(stack_to_string((Exception) o));
- return;
- }
- if (o instanceof Vector) {
- print_vector((Vector) o);
- return;
- }
- if (o instanceof Hashtable) {
- print_hashtable((Hashtable) o);
- return;
- }
- if (o instanceof Date) {
- print_date((Date) o);
- return;
- }
- if (o instanceof Calendar) {
- print_calendar((Calendar) o);
- return;
- }
-
- ps(o.toString(), line);
- }
-
-
- /*
- * --- data type specific print functions ----
- */
- /**
- * Description of the Method
- *
- * @param v PARAM
- */
- public void print_vector(Vector v) {
- ps("vector: size=" + v.size());
- for (int i = 0; i < v.size(); i++) {
- ps(v.elementAt(i).toString());
- }
- }
-
- /**
- * Description of the Method
- *
- * @param array PARAM
- */
- public void print_array(int[][] array) {
- print("array: size=" + array.length + " by " + array[0].length);
- for (int i = 0; i < array.length; i++) {
- for (int j = 0; j < array[i].length; j++) {
- //pr("i = " + i + " j = " + j);
- ps(array[i][j] + " ", false);
- }
- print("");
- }
- }
-
- /**
- * Description of the Method
- *
- * @param array PARAM
- */
- public void print_array(Object[] array) {
- print("array: size=" + array.length);
- for (int i = 0; i < array.length; i++) {
- ps(" " + array[i].toString(), false);
- }
- }
-
- /**
- * Description of the Method
- *
- * @param array PARAM
- */
- public void print_array(int[] array) {
- print("array: size=" + array.length);
- for (int i = 0; i < array.length; i++) {
- ps(" " + array[i], false);
- }
- }
-
- /**
- * Description of the Method
- *
- * @param h PARAM
- */
- public void print_hashtable(Hashtable h) {
- print("hashtable size=" + h.size());
- Enumeration keys = h.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- print(key + " = ");
- print(h.get(key).toString());
- }
- }
-
- /**
- * Description of the Method
- *
- * @param array PARAM
- */
- public void print_array(byte[] array) {
- print("byte array: size = " + array.length);
- for (int i = 0; i < array.length; i++) {
- print("" + array[i]);
- }
- }
-
- /**
- * Description of the Method
- *
- * @param date PARAM
- */
- public void print_date(Date date) {
- DateFormat date_format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
- print(date_format.format(date));
- }
-
- /**
- * Description of the Method
- *
- * @param cal PARAM
- */
- public void print_calendar(Calendar cal) {
- print(cal.getTime());
- }
-
- /**
- * Description of the Method
- *
- * @param sec PARAM
- */
- public void printUnixtime(long sec) {
- print(new Date(sec * 1000));
- }
-
- /**
- * Sets the on attribute of the Util object
- *
- * @param on The new on value
- */
- public void setOn(boolean on) {
- this.on = on;
- }
-
-
- /**
- * Sets the printWriter attribute of the Util object
- *
- * @param writer The new printWriter value
- */
- public void setPrintWriter(PrintWriter writer) {
- this.pw = writer;
- }
-
- /**
- * Description of the Method
- *
- * @param s PARAM
- */
- private void ps(String s) {
- ps(s, true);
- }
-
- /**
- * Description of the Method
- *
- * @param s PARAM
- * @param line PARAM
- */
- private void ps(String s, boolean line) {
- if (!on) {
- return;
- }
- if (line) {
- if (pw == null) {
- System.out.println(s);
- } else {
- //System.out.println(s);
- pw.println(s);
- //pw.println("
");
- }
- } else {
- if (pw == null) {
- System.out.print(s);
- } else {
- //System.out.print(s);
- pw.print(s);
- //pw.print("
");
- }
- }
- }
-
-
- /*
- * ----- other stuff ----
- */
- /**
- * Description of the Method
- *
- * @param filename PARAM
- * @return Returns
- * @throws FileNotFoundException Throws
- * @throws IOException Throws
- */
- public static String file_to_string(String filename)
- throws FileNotFoundException, IOException {
- File file = new File(filename);
- return file_to_string(file);
- }
-
- /**
- * Description of the Method
- *
- * @param text PARAM
- * @param file PARAM
- * @throws IOException Throws
- */
- public static void string_to_file(String text, File file)
- throws IOException {
- FileWriter writer = null;
- writer = new FileWriter(file);
- try {
- StringReader reader = new StringReader(text);
- char[] buf = new char[1000];
- while (true) {
- int n = reader.read(buf, 0, 1000);
- if (n == -1) {
- break;
- }
- writer.write(buf, 0, n);
- }
- writer.flush();
- } finally {
- if (writer != null) {
- writer.close();
- }
- }
- }
-
- /**
- * Description of the Method
- *
- * @param str PARAM
- * @return Returns
- */
- public static int string_to_int(String str) {
- return Integer.parseInt(str);
- }
-
- /**
- * Description of the Method
- *
- * @param e PARAM
- * @return Returns
- */
- public static String stack_to_string(Exception e) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- pw.close();
- return sw.toString();
- }
-
- /**
- * Description of the Method
- *
- * @param e PARAM
- * @return Returns
- */
- public static String stack_to_string(Throwable e) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- pw.close();
- return sw.toString();
- }
-
- /**
- * Description of the Method
- *
- * @param in PARAM
- * @return Returns
- * @throws IOException Throws
- */
- public static String inputstream_to_string(InputStream in)
- throws IOException {
- Reader reader = new InputStreamReader(in);
- StringWriter writer = new StringWriter();
- char[] buf = new char[1000];
- while (true) {
- int n = reader.read(buf, 0, 1000);
- if (n == -1) {
- break;
- }
- writer.write(buf, 0, n);
- }
- return writer.toString();
- }
-
- /**
- * Description of the Method
- *
- * @param file PARAM
- * @return Returns
- * @throws FileNotFoundException Throws
- * @throws IOException Throws
- */
- public static String file_to_string(File file)
- throws IOException {
- FileReader reader = null;
- StringWriter writer = null;
- String str;
- try {
- reader = new FileReader(file);
- writer = new StringWriter();
- char[] buf = new char[1000];
- while (true) {
- int n = reader.read(buf, 0, 1000);
- if (n == -1) {
- break;
- }
- writer.write(buf, 0, n);
- }
- str = writer.toString();
- } finally {
- if (reader != null) {
- reader.close();
- }
- if (writer != null) {
- writer.close();
- }
- }
- return str;
- }
-
- /**
- * Description of the Method
- *
- * @param source PARAM
- * @param target PARAM
- * @param replacement PARAM
- * @return Returns
- */
- public static String replace(String source, String target, String replacement) {
- StringBuilder output = new StringBuilder();
- int n = 0;
- while (true) {
- //print("n = " + n);
- int off = source.indexOf(target, n);
- if (off == -1) {
- output.append(source.substring(n));
- break;
- }
- output.append(source, n, off);
- output.append(replacement);
- n = off + target.length();
- }
-// output.append(source.substring(off+target.length()));
- return output.toString();
- }
-
- /**
- * Description of the Method
- *
- * @param v PARAM
- * @return Returns
- */
- public static String[] vector_to_strings(Vector v) {
- int len = v.size();
- String[] ret = new String[len];
- for (int i = 0; i < len; i++) {
- ret[i] = v.elementAt(i).toString();
- }
- return ret;
- }
-
- /**
- * Description of the Method
- *
- * @param l PARAM
- * @return Returns
- */
- public static String[] list_to_strings(List l) {
- int len = l.size();
- String[] ret = new String[len];
- for (int i = 0; i < len; i++) {
- ret[i] = l.get(i).toString();
- }
- return ret;
- }
-
- /**
- * Description of the Method
- *
- * @param array PARAM
- * @return Returns
- */
- public static List toList(Object[] array) {
- return to_list(array);
- }
-
- /**
- * Description of the Method
- *
- * @param array PARAM
- * @return Returns
- */
- public static List to_list(Object[] array) {
- List list = new ArrayList();
- for (int i = 0; i < array.length; i++) {
- list.add(array[i]);
- }
- return list;
- }
-
- /*
- * public void pr(Date date) {
- * DateFormat date_format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
- * pr(date_format.format(date));
- * }
- */
- /*
- * public void pr(Calendar cal) {
- * pr(cal.getTime());
- * }
- */
-
- /**
- * Description of the Method
- *
- * @param msec PARAM
- */
- public static void sleep(long msec) {
- try {
- Thread.sleep(msec);
- } catch (InterruptedException ex) {
- com.openhtmltopdf.util.Uu.p(stack_to_string(ex));
- }
- }
-
- /**
- * Description of the Method
- *
- * @param frame PARAM
- */
- public static void center(JFrame frame) {
- //p("centering");
- Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
- frame.setLocation((int) ((screen_size.getWidth() - frame.getWidth()) / 2),
- (int) ((screen_size.getHeight() - frame.getHeight()) / 2));
- }
-
- /**
- * Description of the Method
- *
- * @param frame PARAM
- */
- public static void center(JDialog frame) {
- //p("centering");
- Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
- frame.setLocation((int) ((screen_size.getWidth() - frame.getWidth()) / 2),
- (int) ((screen_size.getHeight() - frame.getHeight()) / 2));
- }
-
-
- /**
- * Gets the number attribute of the Util class
- *
- * @param str PARAM
- * @return The number value
- */
- public static boolean isNumber(String str) {
- try {
- Integer.parseInt(str);
- return true;
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
- public static boolean isNullOrEmpty(String str) {
- return str == null || str.length() == 0;
- }
-
- public static boolean isNullOrEmpty(String str, boolean trim) {
- return str == null || str.length() == 0 || (trim && str.trim().length() == 0);
- }
-
- public static boolean isEqual(String str1, String str2) {
- return str1 == str2 || (str1 != null && str1.equals(str2));
- }
-
- public static boolean isEqual(String str1, String str2, boolean ignoreCase) {
- return str1 == str2 || (str1 != null && (ignoreCase ? str1.equalsIgnoreCase(str2) : str1.equals(str2)));
- }
-}
-
-/*
- * $Id$
- *
- * $Log$
- * Revision 1.8 2009/05/09 15:16:43 pdoubleya
- * FindBugs: proper disposal of IO resources
- *
- * Revision 1.7 2009/04/25 11:19:07 pdoubleya
- * Add utility methods to compare strings, patch from Peter Fassev in issue #263.
- *
- * Revision 1.6 2007/05/20 23:25:31 peterbrant
- * Various code cleanups (e.g. remove unused imports)
- *
- * Patch from Sean Bright
- *
- * Revision 1.5 2005/01/29 20:18:38 pdoubleya
- * Clean/reformat code. Removed commented blocks, checked copyright.
- *
- * Revision 1.4 2004/12/12 03:33:05 tobega
- * Renamed x and u to avoid confusing IDE. But that got cvs in a twist. See if this does it
- *
- * Revision 1.3 2004/10/23 14:06:57 pdoubleya
- * Re-formatted using JavaStyle tool.
- * Cleaned imports to resolve wildcards except for common packages (java.io, java.util, etc).
- * Added CVS log comments at bottom.
- *
- *
- */
-
diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Uu.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Uu.java
deleted file mode 100644
index 6497b52fa..000000000
--- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Uu.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * {{{ header & license
- * Copyright (c) 2004, 2005 Joshua Marinacci
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * }}}
- */
-package com.openhtmltopdf.util;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-
-/**
- * Description of the Class
- *
- * @author empty
- */
-public class Uu extends Util {
- /**
- * Description of the Field
- */
- private static Util util;
- /**
- * Description of the Field
- */
- private static Util utilAsString;
-
- /**
- * Constructor for the Uu object
- */
- private Uu() {
- super(System.out);
- }
-
- /**
- * Description of the Method
- */
- public static void on() {
- init();
- util.setOn(true);
- }
-
- /**
- * Description of the Method
- */
- public static void off() {
- init();
- util.setOn(false);
- }
-
- /**
- * Description of the Method
- *
- * @param object PARAM
- */
- public static void p(Object object) {
- init();
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- utilAsString.setPrintWriter(pw);
- utilAsString.print(object);// our log adds a newline
- pw.flush();
- if (XRLog.isLoggingEnabled()) {
- XRLog.general(sw.getBuffer().toString());
- }
- }
-
- /**
- * Description of the Method
- *
- * @param object PARAM
- */
- public static void pr(Object object) {
- init();
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- utilAsString.setPrintWriter(pw);
- utilAsString.print(object);// our log adds a newline
- pw.flush();
- if (XRLog.isLoggingEnabled()) {
- XRLog.general(sw.getBuffer().toString());
- }
- //util.print( object );
- }
-
- /**
- * Description of the Method
- *
- * @param msec PARAM
- */
- public static void sleep(int msec) throws InterruptedException {
- Thread.sleep(msec);
- }
-
- /**
- * Description of the Method
- */
- public static void dump_stack() {
- p(stack_to_string(new Exception()));
- }
-
- /**
- * Description of the Method
- *
- * @param args PARAM
- */
- public static void main(String args[]) {
- try {
- Uu.p(new Object());
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- /**
- * Description of the Method
- */
- private static void init() {
- if (util == null) {
- util = new Util(System.out);
- }
- if (utilAsString == null) {
- utilAsString = new Util(System.out);
- }
- }// end main()
-}
-
-/*
- * $Id$
- *
- * $Log$
- * Revision 1.4 2009/04/25 11:57:05 pdoubleya
- * Small opt, avoid log calls where logging is disabled, patch from Peter Fassev issue #263
- *
- * Revision 1.3 2005/09/29 06:15:07 tobega
- * Patch from Peter Brant:
- * List of changes:
- * - Fix extents height calculation
- * - Small refactoring to Boxing to combine a method
- * - Make render and layout threads interruptible and add
- * RootPanel.shutdown() method to shut them down in an orderly manner
- * - Fix NPE in Graphics2DRenderer. It looks like
- * BasicPanel.intrinsic_size will always be null anyway?
- * - Fix NPE in RootPanel when enclosingScrollPane is null.
- * - Both RenderLoop.collapseRepaintEvents and
- * LayoutLoop.collapseLayoutEvents will go into an infinite loop if the
- * next event isn't collapsible. I added a common implementation to
- * RenderQueue which doesn't have this problem.
- *
- * Revision 1.2 2005/01/29 20:18:38 pdoubleya
- * Clean/reformat code. Removed commented blocks, checked copyright.
- *
- * Revision 1.1 2004/12/12 03:33:05 tobega
- * Renamed x and u to avoid confusing IDE. But that got cvs in a twist. See if this does it
- *
- * Revision 1.4 2004/11/22 21:34:05 joshy
- * created new whitespace handler.
- * new whitespace routines only work if you set a special property. it's
- * off by default.
- *
- * turned off fractional font metrics
- *
- * fixed some bugs in Uu and Xx
- *
- * - j
- *
- * Issue number:
- * Obtained from:
- * Submitted by:
- * Reviewed by:
- *
- * Revision 1.3 2004/10/23 14:06:57 pdoubleya
- * Re-formatted using JavaStyle tool.
- * Cleaned imports to resolve wildcards except for common packages (java.io, java.util, etc).
- * Added CVS log comments at bottom.
- *
- *
- */
-