From 3d9fd91ed5113c7db12b8be97c864522cee88b27 Mon Sep 17 00:00:00 2001 From: Sylvain Jermini Date: Sat, 13 Jun 2020 16:57:24 +0200 Subject: [PATCH] cleanup: remove unused class, remove unused imports --- .../openhtmltopdf/render/BorderPainter.java | 4 - .../simple/extend/form/ImageField.java | 1 - .../simple/extend/form/TextAreaField.java | 2 +- .../openhtmltopdf/simple/xhtml/XhtmlForm.java | 5 +- .../swing/DeferredImageReplacedElement.java | 1 - .../openhtmltopdf/swing/MutableFSImage.java | 2 - .../openhtmltopdf/test/ElementReplacer.java | 30 --- .../test/SwingImageReplacer.java | 155 ----------- .../java/com/openhtmltopdf/test/XLayout.java | 105 -------- .../com/openhtmltopdf/util/FSImageWriter.java | 243 ------------------ .../java/com/openhtmltopdf/util/IOUtil.java | 96 ------- .../com/openhtmltopdf/util/JDKXRLogger.java | 4 - .../util/SystemPropertiesUtil.java | 44 ---- .../java/com/openhtmltopdf/util/XMLUtil.java | 85 ------ .../java/com/openhtmltopdf/util/Zipper.java | 105 -------- 15 files changed, 3 insertions(+), 879 deletions(-) delete mode 100644 openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/ElementReplacer.java delete mode 100644 openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/SwingImageReplacer.java delete mode 100755 openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/XLayout.java delete mode 100644 openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/FSImageWriter.java delete mode 100644 openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/IOUtil.java delete mode 100644 openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/SystemPropertiesUtil.java delete mode 100644 openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/XMLUtil.java delete mode 100644 openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Zipper.java diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BorderPainter.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BorderPainter.java index 4b976d56b..2cca61849 100755 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BorderPainter.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BorderPainter.java @@ -20,19 +20,15 @@ package com.openhtmltopdf.render; import java.awt.BasicStroke; -import java.awt.Polygon; import java.awt.Rectangle; -import java.awt.RenderingHints; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.AffineTransform; import java.awt.geom.Arc2D; import java.awt.geom.Area; import java.awt.geom.Path2D; -import java.awt.geom.Point2D; import com.openhtmltopdf.css.constants.IdentValue; -import com.openhtmltopdf.css.parser.FSColor; import com.openhtmltopdf.css.parser.FSRGBColor; import com.openhtmltopdf.css.style.BorderRadiusCorner; import com.openhtmltopdf.css.style.derived.BorderPropertySet; diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/extend/form/ImageField.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/extend/form/ImageField.java index d8db3ac90..cdc0a0405 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/extend/form/ImageField.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/extend/form/ImageField.java @@ -23,7 +23,6 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComponent; diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/extend/form/TextAreaField.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/extend/form/TextAreaField.java index 7529ac732..b2bf50c6c 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/extend/form/TextAreaField.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/extend/form/TextAreaField.java @@ -146,7 +146,7 @@ protected String[] getFieldValues() { } - private class TextAreaFieldJTextArea extends JTextArea { + private static class TextAreaFieldJTextArea extends JTextArea { int columnWidth = 0; public TextAreaFieldJTextArea(int rows, int columns) { diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/xhtml/XhtmlForm.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/xhtml/XhtmlForm.java index 8d805063e..8913bfb1e 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/xhtml/XhtmlForm.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/simple/xhtml/XhtmlForm.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import org.w3c.dom.Element; @@ -42,9 +41,9 @@ public XhtmlForm(String action, String method) { _method = method; } - protected List _controls = new ArrayList(); + protected List _controls = new ArrayList<>(); - private List _listeners = new ArrayList(); + private List _listeners = new ArrayList<>(); public void addFormListener(FormListener listener) { _listeners.add(listener); diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/swing/DeferredImageReplacedElement.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/swing/DeferredImageReplacedElement.java index 5fce785bc..a5f706507 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/swing/DeferredImageReplacedElement.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/swing/DeferredImageReplacedElement.java @@ -23,7 +23,6 @@ import java.awt.image.BufferedImage; import java.util.logging.Level; -import com.openhtmltopdf.extend.ReplacedElement; import com.openhtmltopdf.layout.LayoutContext; import com.openhtmltopdf.resource.ImageResource; import com.openhtmltopdf.util.Configuration; diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/swing/MutableFSImage.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/swing/MutableFSImage.java index fe5ee4adc..3d3f907ce 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/swing/MutableFSImage.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/swing/MutableFSImage.java @@ -22,8 +22,6 @@ import com.openhtmltopdf.util.ImageUtil; import com.openhtmltopdf.util.XRLog; -import javax.swing.*; - import java.awt.*; import java.awt.image.BufferedImage; import java.util.logging.Level; diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/ElementReplacer.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/ElementReplacer.java deleted file mode 100644 index bf6070d1e..000000000 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/ElementReplacer.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.openhtmltopdf.test; - -import org.w3c.dom.Element; - -import com.openhtmltopdf.extend.ReplacedElement; -import com.openhtmltopdf.extend.UserAgentCallback; -import com.openhtmltopdf.layout.LayoutContext; -import com.openhtmltopdf.render.BlockBox; - -/** - * @author patrick -*/ -public abstract class ElementReplacer { - public abstract boolean isElementNameMatch(); - - public abstract String getElementNameMatch(); - - public abstract boolean accept(LayoutContext context, Element element); - - public abstract ReplacedElement replace(final LayoutContext context, - final BlockBox box, - final UserAgentCallback uac, - final int cssWidth, - final int cssHeight - ); - - public abstract void clear(final Element element); - - public abstract void reset(); -} diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/SwingImageReplacer.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/SwingImageReplacer.java deleted file mode 100644 index 5ab5563cf..000000000 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/SwingImageReplacer.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.openhtmltopdf.test; - -import org.w3c.dom.Element; - -import com.openhtmltopdf.extend.FSImage; -import com.openhtmltopdf.extend.ReplacedElement; -import com.openhtmltopdf.extend.UserAgentCallback; -import com.openhtmltopdf.layout.LayoutContext; -import com.openhtmltopdf.render.BlockBox; -import com.openhtmltopdf.swing.AWTFSImage; -import com.openhtmltopdf.swing.EmptyReplacedElement; -import com.openhtmltopdf.swing.ImageReplacedElement; -import com.openhtmltopdf.util.ImageUtil; -import com.openhtmltopdf.util.XRLog; - -import java.awt.*; -import java.awt.image.BufferedImage; -import java.util.logging.Level; -import java.util.*; -import java.util.List; - -/** - * @author patrick - */ -public class SwingImageReplacer extends ElementReplacer { - private final Map imageComponents; - - public SwingImageReplacer() { - imageComponents = new HashMap(); - } - - public boolean isElementNameMatch() { - return true; - } - - public String getElementNameMatch() { - return "img"; - } - - public boolean accept(final LayoutContext context, final Element element) { - return context.getNamespaceHandler().isImageElement(element); - } - - public ReplacedElement replace(LayoutContext context, BlockBox box, UserAgentCallback uac, int cssWidth, int cssHeight) { - return replaceImage(uac, context, box.getElement(), cssWidth, cssHeight); - } - - public void clear(Element element) { - System.out.println("*** cleared image components for element " + element); - imageComponents.remove(element); - } - - public void reset() { - System.out.println("*** cleared image componentes"); - imageComponents.clear(); - } - - /** - * Handles replacement of image elements in the document. May return the same ReplacedElement for a given image - * on multiple calls. Image will be automatically scaled to cssWidth and cssHeight assuming these are non-zero - * positive values. The element is assume to have a src attribute (e.g. it's an <img> element) - * - * @param uac Used to retrieve images on demand from some source. - * @param context - * @param elem The element with the image reference - * @param cssWidth Target width of the image - * @param cssHeight Target height of the image @return A ReplacedElement for the image; will not be null. - */ - protected ReplacedElement replaceImage(UserAgentCallback uac, LayoutContext context, Element elem, int cssWidth, int cssHeight) { - ReplacedElement re = null; - - // lookup in cache, or instantiate - re = lookupImageReplacedElement(elem); - if (re == null) { - Image im = null; - String imageSrc = context.getNamespaceHandler().getImageSourceURI(elem); - if (imageSrc == null || imageSrc.length() == 0) { - XRLog.layout(Level.WARNING, "No source provided for img element."); - re = newIrreplaceableImageElement(cssWidth, cssHeight); - } else { - //FSImage is here since we need to capture a target H/W - //for the image (as opposed to what the actual image size is). - FSImage fsImage = uac.getImageResource(imageSrc).getImage(); - if (fsImage != null) { - im = ((AWTFSImage) fsImage).getImage(); - } - - if (im != null) { - re = new ImageReplacedElement(im, cssWidth, cssHeight); - } else { - // TODO: Should return "broken" image icon, e.g. "not found" - re = newIrreplaceableImageElement(cssWidth, cssHeight); - } - } - storeImageReplacedElement(elem, re); - } - return re; - } - - /** - * Adds a ReplacedElement containing an image to a cache of images for quick lookup. - * - * @param e The element under which the image is keyed. - * @param cc The replaced element containing the image, or another ReplacedElement to be used in its place - * (like a placeholder if the image can't be loaded). - */ - protected void storeImageReplacedElement(Element e, ReplacedElement cc) { - System.out.println("\n*** Cached image for element"); - imageComponents.put(e, cc); - } - - /** - * Retrieves a ReplacedElement for an image from cache, or null if not found. - * - * @param e The element by which the image is keyed - * @return The ReplacedElement for the image, or null if there is none. - */ - protected ReplacedElement lookupImageReplacedElement(Element e) { - if (imageComponents.size() == 0) { - return null; - } - ReplacedElement replacedElement = (ReplacedElement) imageComponents.get(e); - return replacedElement; - } - - /** - * Returns a ReplacedElement for some element in the stream which should be replaceable, but is not. This might - * be the case for an element like img, where the source isn't provided. - * - * @param cssWidth Target width for the element. - * @param cssHeight Target height for the element - * @return A ReplacedElement to substitute for one that can't be generated. - */ - protected ReplacedElement newIrreplaceableImageElement(int cssWidth, int cssHeight) { - BufferedImage missingImage = null; - ReplacedElement mre; - try { - // TODO: we can come up with something better; not sure if we should use Alt text, how text should size, etc. - missingImage = ImageUtil.createCompatibleBufferedImage(cssWidth, cssHeight, BufferedImage.TYPE_INT_RGB); - Graphics2D g = missingImage.createGraphics(); - g.setColor(Color.BLACK); - g.setBackground(Color.WHITE); - g.setFont(new Font("Serif", Font.PLAIN, 12)); - g.drawString("Missing", 0, 12); - g.dispose(); - mre = new ImageReplacedElement(missingImage, cssWidth, cssHeight); - } catch (Exception e) { - mre = new EmptyReplacedElement( - cssWidth < 0 ? 0 : cssWidth, - cssHeight < 0 ? 0 : cssHeight); - } - return mre; - } - -} diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/XLayout.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/XLayout.java deleted file mode 100755 index 464317f1f..000000000 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/test/XLayout.java +++ /dev/null @@ -1,105 +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.test; - -import org.w3c.dom.Element; - -import com.openhtmltopdf.layout.LayoutContext; - -import java.awt.Dimension; - - -/** - * Description of the Class - * - * @author empty - */ -public class XLayout /*extends CustomBlockLayout*/ { - - /** - * Description of the Method - * - * @param c PARAM - * @param box PARAM - */ - /* not used public void paintComponent(Context c, Box box) { - int w = box.getWidth() - box.totalHorizontalPadding(c.getCurrentStyle(), c); - int h = box.getHeight() - box.totalVerticalPadding(c.getCurrentStyle(), c); - Dimension dim = new Dimension(w, h); - Uu.p("dim = " + dim); - c.getGraphics().drawLine(box.x, - box.y, - box.x + (int) dim.getWidth(), - box.y + (int) dim.getHeight()); - c.getGraphics().drawLine(box.x, - box.y + (int) dim.getHeight(), - box.x + (int) dim.getWidth(), - box.y); - }*/ - - /** - * Gets the intrinsicDimensions attribute of the XLayout object - * - * @param c PARAM - * @param elem PARAM - * @return The intrinsicDimensions value - */ - public Dimension getIntrinsicDimensions(LayoutContext c, Element elem) { - return new Dimension(50, 50); - } - -} - -/* - * $Id$ - * - * $Log$ - * Revision 1.11 2005/10/27 00:09:10 tobega - * Sorted out Context into RenderingContext and LayoutContext - * - * Revision 1.10 2005/05/13 15:23:57 tobega - * Done refactoring box borders, margin and padding. Hover is working again. - * - * Revision 1.9 2005/05/08 14:36:59 tobega - * Refactored away the need for having a context in a CalculatedStyle - * - * Revision 1.8 2005/01/29 20:18:39 pdoubleya - * Clean/reformat code. Removed commented blocks, checked copyright. - * - * Revision 1.7 2005/01/02 12:22:23 tobega - * Cleaned out old layout code - * - * Revision 1.6 2004/12/29 10:39:37 tobega - * Separated current state Context into LayoutContext and the rest into SharedContext. - * - * Revision 1.5 2004/12/27 07:43:34 tobega - * Cleaned out border from box, it can be gotten from current style. Is it maybe needed for dynamic stuff? - * - * Revision 1.4 2004/12/12 03:33:04 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:01:42 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/FSImageWriter.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/FSImageWriter.java deleted file mode 100644 index 0f7c22e54..000000000 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/FSImageWriter.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * {{{ header & license - * Copyright (c) 2007 Patrick Wright - * - * 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 P.ublic 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.imageio.IIOImage; -import javax.imageio.ImageIO; -import javax.imageio.ImageWriteParam; -import javax.imageio.ImageWriter; -import javax.imageio.stream.ImageOutputStream; -import java.awt.image.BufferedImage; -import java.io.*; -import java.util.Iterator; - -/** - *

Writes out BufferedImages to some outputstream, like a file. Allows image writer parameters to be specified and - * thus controlled. Uses the java ImageIO libraries--see {@link javax.imageio.ImageIO} and related classes, - * especially {@link javax.imageio.ImageWriter}.

- *
- * By default, FSImageWriter writes BufferedImages out in PNG format. The simplest possible usage is - *
- * FSImageWriter writer = new FSImageWriter();
- * writer.write(img, new File("image.png"));
- * 
- *
- *

You can set the image format in the constructore ({@link com.openhtmltopdf.util.FSImageWriter#FSImageWriter(String)}, - * and can set compression settings using various setters; this lets you create writer to reuse across a number - * of images, all output at the same compression level. Note that not all image formats support compression. For - * those that do, you may need to set more than one compression setting, in combination, for it to work. For JPG, - * it might look like this

- *
- *      writer = new FSImageWriter("jpg");
- * 		writer.setWriteCompressionMode(ImageWriteParam.MODE_EXPLICIT);
- * 		writer.setWriteCompressionType("JPEG");
- * 		writer.setWriteCompressionQuality(.75f);
- * 
- *

The method {@link #newJpegWriter(float)} creates a writer for JPG images; you just need to specify the - * output quality. Note that for the JPG format, your image or BufferedImage shouldn't be ARGB.

- */ -public class FSImageWriter { - private String imageFormat; - private float writeCompressionQuality; - private int writeCompressionMode; - private String writeCompressionType; - public static final String DEFAULT_IMAGE_FORMAT = "png"; - - - /** - * New image writer for the PNG image format - */ - public FSImageWriter() { - this("png"); - } - - /** - * New writer for a given image format, using the informal format name. - * - * @param imageFormat Informal image format name, e.g. "jpg", "png", "bmp"; usually the part that appears - * as the file extension. - */ - public FSImageWriter(String imageFormat) { - this.imageFormat = imageFormat; - this.writeCompressionMode = ImageWriteParam.MODE_COPY_FROM_METADATA; - this.writeCompressionType = null; - this.writeCompressionQuality = 1.0f; - } - - /** - * Convenience method for initializing a writer for the JPEG image format. - * - * @param quality level of compression, between 0 and 1; 0 is lowest, 1 is highest quality. - * @return a writer for JPEG images - */ - public static FSImageWriter newJpegWriter(float quality) { - FSImageWriter writer = new FSImageWriter("jpg"); - writer.setWriteCompressionMode(ImageWriteParam.MODE_EXPLICIT); - writer.setWriteCompressionType("JPEG"); - writer.setWriteCompressionQuality(quality); - return writer; - } - - /** - * Writes the image out to the target file, creating the file if necessary, or overwriting if it already - * exists. - * - * @param bimg Image to write. - * @param filePath Path for file to write. The extension for the file name is not changed; it is up to the - * caller to make sure this corresponds to the image format. - * @throws IOException If the file could not be written. - */ - public void write(BufferedImage bimg, String filePath) throws IOException { - File file = new File(filePath); - if (file.exists()) { - if (!file.delete()) { - throw new IOException("File " + filePath + " exists already, and call to .delete() failed " + - "unexpectedly"); - } - } else { - if (!file.createNewFile()) { - throw new IOException("Unable to create file at path " + filePath + ", call to .createNewFile() " + - "failed unexpectedly."); - } - } - - OutputStream fos = new BufferedOutputStream(new FileOutputStream(file)); - try { - write(bimg, fos); - } finally { - try { - fos.close(); - } catch (IOException e) { - // ignore - } - } - } - - /** - * Writes the image out to the target file, creating the file if necessary, or overwriting if it already - * exists. - * - * @param bimg Image to write. - * @param os outputstream to write to - * @throws IOException If the file could not be written. - */ - public void write(BufferedImage bimg, OutputStream os) throws IOException { - ImageWriter writer = null; - ImageOutputStream ios = null; - try { - writer = lookupImageWriterForFormat(imageFormat); - ios = ImageIO.createImageOutputStream(os); - writer.setOutput(ios); - ImageWriteParam iwparam = getImageWriteParameters(writer); - - writer.write(null, new IIOImage(bimg, null, null), iwparam); - } finally { - if (ios != null) { - try { - ios.flush(); - } catch (IOException e) { - // ignore - } - try { - ios.close(); - } catch (IOException e) { - // ignore - } - } - if (writer != null) { - writer.dispose(); - } - } - } - - /** - * Returns the image output parameters to control the output image quality, compression, etc. By default - * this uses the compression values set in this class. Override this method to get full control over the - * ImageWriteParam used in image output. - * - * @param writer The ImageWriter we are going to use for image output. - * @return ImageWriteParam configured for image output. - */ - protected ImageWriteParam getImageWriteParameters(ImageWriter writer) { - ImageWriteParam param = writer.getDefaultWriteParam(); - if (param.canWriteCompressed()) { - if (writeCompressionMode != ImageWriteParam.MODE_COPY_FROM_METADATA) { - param.setCompressionMode(writeCompressionMode); - - // see docs for IWP--only allowed to set type and quality if mode is EXPLICIT - if (writeCompressionMode == ImageWriteParam.MODE_EXPLICIT) { - param.setCompressionType(writeCompressionType); - param.setCompressionQuality(writeCompressionQuality); - } - - } - } - - return param; - } - - /** - * Compression quality for images to be generated from this writer. See - * {@link javax.imageio.ImageWriteParam#setCompressionQuality(float)} for a description of what this means - * and valid range of values. - * - * @param q Compression quality for image output. - */ - public void setWriteCompressionQuality(float q) { - writeCompressionQuality = q; - } - - /** - * Compression mode for images to be generated from this writer. See - * {@link javax.imageio.ImageWriteParam#setCompressionMode(int)} for a description of what this means - * and valid range of values. - * - * @param mode Compression mode for image output. - */ - public void setWriteCompressionMode(int mode) { - this.writeCompressionMode = mode; - } - - /** - * Compression type for images to be generated from this writer. See - * {@link javax.imageio.ImageWriteParam#setCompressionType(String)} for a description of what this means - * and valid range of values. - * - * @param type Type of compression for image output. - */ - public void setWriteCompressionType(String type) { - this.writeCompressionType = type; - } - - /** - * Utility method to find an imagewriter. - * - * @param imageFormat String informal format name, "jpg" - * @return ImageWriter corresponding to that format, null if not found. - */ - private ImageWriter lookupImageWriterForFormat(String imageFormat) { - ImageWriter writer = null; - Iterator iter = ImageIO.getImageWritersByFormatName(imageFormat); - if (iter.hasNext()) { - writer = (ImageWriter) iter.next(); - } - return writer; - } -} diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/IOUtil.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/IOUtil.java deleted file mode 100644 index 1839c0de7..000000000 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/IOUtil.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.openhtmltopdf.util; - -import java.io.*; -import java.net.URL; -import java.net.URLConnection; - -/** - * @author patrick - */ -public class IOUtil { - public static File copyFile(File page, File outputDir) throws IOException { - InputStream in = null; - OutputStream out = null; - try { - in = new BufferedInputStream(new FileInputStream(page)); - File outputFile; - outputFile = new File(outputDir, page.getName()); - out = new BufferedOutputStream(new FileOutputStream(outputFile)); - - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - in.close(); - out.flush(); - out.close(); - return outputFile; - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - // swallow - } - } - if (out != null) { - try { - out.close(); - } catch (IOException e) { - // swallow - } - } - } - } - - public static void deleteAllFiles(final File dir) throws IOException { - File[] files = dir.listFiles(); - for (int i = 0; i < files.length; i++) { - File file = files[i]; - if (!file.delete()) { - throw new IOException("Cleanup directory " + dir + ", can't delete file " + file); - } - } - } - - /** - * Attempts to open a connection, and a stream, to the URI provided. timeouts will be set for opening the connection - * and reading from it. will return the stream, or null if unable to open or read or a timeout occurred. Does not - * buffer the stream. - */ - @Deprecated - public static InputStream openStreamAtUrl(String uri) { - InputStream is = null; - try { - final URLConnection uc = new URL(uri).openConnection(); - - // If using Java 5+ you can set timeouts for the URL connection--useful if the remote - // server is down etc.; the default timeout is pretty long - // - //uc.setConnectTimeout(10 * 1000); - //uc.setReadTimeout(30 * 1000); - // - // TODO:CLEAN-JDK1.4 - // Since we target 1.4, we use a couple of system properties--note these are only supported - // in the Sun JDK implementation--see the Net properties guide in the JDK - // e.g. file:///usr/java/j2sdk1.4.2_17/docs/guide/net/properties.html - System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(10 * 1000)); - System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(30 * 1000)); - - uc.connect(); - - is = uc.getInputStream(); - } catch (java.net.MalformedURLException e) { - XRLog.exception("bad URL given: " + uri, e); - } catch (FileNotFoundException e) { - XRLog.exception("item at URI " + uri + " not found"); - } catch (IOException e) { - XRLog.exception("IO problem for " + uri, e); - } - - return is; - - } -} diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/JDKXRLogger.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/JDKXRLogger.java index e0d6c2eb4..760d1f774 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/JDKXRLogger.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/JDKXRLogger.java @@ -21,13 +21,9 @@ */ package com.openhtmltopdf.util; -import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.util.logging.Level; -import java.util.logging.LogManager; import java.util.logging.Logger; import java.util.logging.Handler; import java.util.logging.Formatter; diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/SystemPropertiesUtil.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/SystemPropertiesUtil.java deleted file mode 100644 index a0bd2c2bc..000000000 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/SystemPropertiesUtil.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * {{{ header & license - * Copyright (c) 2008 Patrick Wright - * - * 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; - -/** - * Utility methods for working with System properties. - */ -public class SystemPropertiesUtil { - /** - * Attempts to retrieve a system property; if the property is not found, or if a SecurityException is thrown (for - * example, in a sandbox environment) will return the default value. Will swallow stack traces and any - * SecurityExceptions, and will not log any output to the console. - * - * @param propertyName property to retrieve - * @param defaultVal value to use if not found, or not allowed to use the property - * @return - */ - public static String getPropertyOrDefaultSandbox(String propertyName, String defaultVal) { - String val = defaultVal; - try { - val = System.getProperty(propertyName); - } catch (SecurityException e) { - // can happen in sandbox - } - return val; - } -} diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/XMLUtil.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/XMLUtil.java deleted file mode 100644 index 21ca4a1ff..000000000 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/XMLUtil.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * {{{ header & license - * XMLUtil.java - * Copyright (c) 2004, 2005 Patrick Wright - * - * 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.File; -import java.io.StringReader; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.w3c.dom.Document; -import org.xml.sax.InputSource; - -/** - * Booch utility class for XML processing using DOM - */ -public class XMLUtil { - - public static Document documentFromString(final String documentContents) - throws Exception { - - return createDocumentBuilder().parse(new InputSource(new StringReader(documentContents))); - } - - public static Document documentFromFile(final String filename) - throws Exception { - - return createDocumentBuilder().parse(new File(filename).toURI().toURL().openStream()); - } - - private static DocumentBuilder createDocumentBuilder() - throws ParserConfigurationException { - - DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = fact.newDocumentBuilder(); - - builder.setErrorHandler( null ); - - return builder; - } -} - -/* - * $Id$ - * - * $Log$ - * Revision 1.7 2007/05/23 00:12:18 peterbrant - * Code cleanup (patch from Sean Bright) - * - * Revision 1.6 2006/07/26 18:18:16 pdoubleya - * TODOs - * - * Revision 1.5 2006/05/08 20:55:08 pdoubleya - * Parse input source from string using a reader, to handle encoding. - * - * Revision 1.4 2005/01/29 20:18:38 pdoubleya - * Clean/reformat code. Removed commented blocks, checked copyright. - * - * 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/Zipper.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Zipper.java deleted file mode 100644 index 7078bf19e..000000000 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/Zipper.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * {{{ header & license - * Copyright (c) 2006 Patrick Wright - * - * 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.*; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -/** - * Create a ZIP-format file from the contents of some directory. All files - * in the directory are included. To use, instantiate with a reference to - * the directory to ZIP, and to the output file to create, then call - * {@link #zipDirectory()} to create the output file. - *
- * Note that this is ZIP-compatible, not GZIP-compatible (ZIP is both an archive format - * and a compression format, GZIP is just a compression format). - */ -public class Zipper { - private final File sourceDir; - private final File outputFile; - - public Zipper(File sourceDir, File outputFile) { - this.sourceDir = sourceDir; - this.outputFile = outputFile; - if (!this.outputFile.delete()) { - throw new IllegalArgumentException("Can't delete outputfile " + outputFile.getAbsolutePath()); - } - } - - public static void main(String[] args) { - File sourceDir = getSourceDir(args); - File outputFile = new File(System.getProperty("user.home") + File.separator + sourceDir.getName() + ".zip"); - try { - new Zipper(sourceDir, outputFile).zipDirectory(); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println("Created zip file " + outputFile.getPath()); - } - - public File zipDirectory() throws IOException { - ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outputFile)); - recurseAndZip(sourceDir, zos); - zos.close(); - return outputFile; - } - - private static void recurseAndZip(File file, ZipOutputStream zos) throws IOException { - if (file.isDirectory()) { - File[] files = file.listFiles(); - if (files != null) { - for (int i = 0; i < files.length; i++) { - File file1 = files[i]; - recurseAndZip(file1, zos); - } - } - } else { - byte[] buf = new byte[1024]; - int len; - ZipEntry entry = new ZipEntry(file.getName()); - FileInputStream fis = new FileInputStream(file); - BufferedInputStream bis = new BufferedInputStream(fis); - zos.putNextEntry(entry); - while ((len = bis.read(buf)) >= 0) { - zos.write(buf, 0, len); - } - bis.close(); - zos.closeEntry(); - } - } - - private static File getSourceDir(String[] args) { - if (args.length != 1) { - usageAndExit("Need directory name containing input files to render."); - } - String sourceDirPath = args[0]; - File sourceDir = new File(sourceDirPath); - if (!sourceDir.exists()) { - usageAndExit(sourceDirPath); - } - return sourceDir; - } - - private static void usageAndExit(String msg) { - System.err.println("Source directory not found: " + msg); - System.exit(-1); - } -}