From 26425b977d194dca2382e82bcf6dbed471c21fe5 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Tue, 26 Dec 2023 21:08:07 +0100 Subject: [PATCH] Minify example application This reproduces https://github.com/apache/logging-log4j2/issues/2129 --- poishadow/build.gradle | 64 -- .../java/org/apache/poi/java/awt/Color.java | 959 ------------------ .../org/apache/poi/java/awt/Dimension.java | 202 ---- .../apache/poi/java/awt/geom/Dimension2D.java | 90 -- .../poi/java/awt/image/BufferedImage.java | 47 - .../org/apache/poi/javax/imageio/ImageIO.java | 71 -- .../apache/poi/javax/imageio/ImageReader.java | 131 --- .../javax/imageio/metadata/IIOMetadata.java | 17 - .../imageio/stream/ImageInputStream.java | 18 - .../java/org/dstadler/compat/BmpReader.java | 61 -- .../org/dstadler/compat/IOMetadataImpl.java | 67 -- .../dstadler/compat/ImageInputStreamImpl.java | 41 - .../java/org/dstadler/compat/JpgReader.java | 85 -- .../java/org/dstadler/compat/PngReader.java | 77 -- poishadow/xmlbeans.patch | 79 -- poitest/build.gradle | 25 +- .../poitest/ApplicationTest.java | 44 +- .../poi/poifs/crypt/TestSignatureInfo.java | 14 - .../poiandroidtest/poitest/MainActivity.java | 386 ------- .../poitest/dummy/DummyContent.java | 80 -- .../poitest/dummy/DummyItemWithCode.java | 23 - .../poitest/test/TestIssue28.java | 55 - .../poitest/test/TestIssue75.java | 38 - .../poitest/test/TestIssue84.java | 27 - .../poitest/test/TestIssue89.java | 45 - settings.gradle | 1 - 26 files changed, 6 insertions(+), 2741 deletions(-) delete mode 100644 poishadow/build.gradle delete mode 100644 poishadow/src/main/java/org/apache/poi/java/awt/Color.java delete mode 100644 poishadow/src/main/java/org/apache/poi/java/awt/Dimension.java delete mode 100644 poishadow/src/main/java/org/apache/poi/java/awt/geom/Dimension2D.java delete mode 100644 poishadow/src/main/java/org/apache/poi/java/awt/image/BufferedImage.java delete mode 100644 poishadow/src/main/java/org/apache/poi/javax/imageio/ImageIO.java delete mode 100644 poishadow/src/main/java/org/apache/poi/javax/imageio/ImageReader.java delete mode 100644 poishadow/src/main/java/org/apache/poi/javax/imageio/metadata/IIOMetadata.java delete mode 100644 poishadow/src/main/java/org/apache/poi/javax/imageio/stream/ImageInputStream.java delete mode 100644 poishadow/src/main/java/org/dstadler/compat/BmpReader.java delete mode 100644 poishadow/src/main/java/org/dstadler/compat/IOMetadataImpl.java delete mode 100644 poishadow/src/main/java/org/dstadler/compat/ImageInputStreamImpl.java delete mode 100644 poishadow/src/main/java/org/dstadler/compat/JpgReader.java delete mode 100644 poishadow/src/main/java/org/dstadler/compat/PngReader.java delete mode 100644 poishadow/xmlbeans.patch delete mode 100644 poitest/src/main/java/org/apache/poi/poifs/crypt/TestSignatureInfo.java delete mode 100644 poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyContent.java delete mode 100644 poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyItemWithCode.java delete mode 100644 poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue28.java delete mode 100644 poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue75.java delete mode 100644 poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue84.java delete mode 100644 poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue89.java diff --git a/poishadow/build.gradle b/poishadow/build.gradle deleted file mode 100644 index b8e9e9b5a..000000000 --- a/poishadow/build.gradle +++ /dev/null @@ -1,64 +0,0 @@ -plugins { - id 'java' // java plugin must be explicitly applied for shadow plugin - id 'com.github.johnrengelman.shadow' version '7.1.2' -} - -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 - -repositories { - mavenCentral() -} - -dependencies { - implementation 'org.apache.poi:poi-ooxml:5.2.5' - implementation 'org.apache.poi:poi-scratchpad:5.2.5' - implementation 'com.fasterxml:aalto-xml:1.3.0' - implementation 'stax:stax-api:1.0.1' - implementation 'org.apache.logging.log4j:log4j-api:2.21.1' // newer log4j fails -} - -shadowJar { - // Apache POI uses service-files for Extractors, Renderers, ... - mergeServiceFiles { - // merging relocates some files, so exclude these as we want to keep them in place - exclude 'META-INF/services/javax.xml.stream.*' - } - - exclude 'repackage/**' - - exclude 'LICENSE.txt' - exclude 'NOTICE.txt' - exclude 'META-INF/LICENSE' - exclude 'META-INF/LICENSE.txt' - exclude 'META-INF/NOTICE' - exclude 'META-INF/NOTICE.txt' - exclude 'META-INF/maven/**' - - // these are only needed when handling Visio files, remove it if you would like to use Visio support - dependencies { - exclude(dependency('com.github.virtuald:curvesapi')) - exclude(dependency('commons-codec:commons-codec')) - exclude(dependency('commons-codec:commons-collections4')) - } - - // Relocate javax dependencies so Android does not choke - relocate 'javax.xml.namespace', 'org.apache.poi.javax.xml.namespace' - relocate 'javax.xml.stream', 'org.apache.poi.javax.xml.stream' - relocate 'javax.xml.XMLConstants', 'org.apache.poi.javax.xml.XMLConstants' - - // java.awt is not available, but class Color is used in APIs in POI, therefore - // relocate this class to another one where we can include a rewrite - relocate 'java.awt.Color', 'org.apache.poi.java.awt.Color' - relocate 'java.awt.geom.Dimension2D', 'org.apache.poi.java.awt.geom.Dimension2D' - relocate 'java.awt.Dimension', 'org.apache.poi.java.awt.Dimension' - relocate 'java.awt.image.BufferedImage', 'org.apache.poi.java.awt.image.BufferedImage' - - relocate 'javax.imageio.ImageIO', 'org.apache.poi.javax.imageio.ImageIO' - relocate 'javax.imageio.ImageReader', 'org.apache.poi.javax.imageio.ImageReader' - relocate 'javax.imageio.stream.ImageInputStream', 'org.apache.poi.javax.imageio.stream.ImageInputStream' - relocate 'javax.imageio.metadata.IIOMetadata', 'org.apache.poi.javax.imageio.metadata.IIOMetadata' -} - -jar.dependsOn shadowJar -test.dependsOn shadowJar diff --git a/poishadow/src/main/java/org/apache/poi/java/awt/Color.java b/poishadow/src/main/java/org/apache/poi/java/awt/Color.java deleted file mode 100644 index f728ae97e..000000000 --- a/poishadow/src/main/java/org/apache/poi/java/awt/Color.java +++ /dev/null @@ -1,959 +0,0 @@ -package org.apache.poi.java.awt; - -import java.beans.ConstructorProperties; - -/** - * This is just an example how a class from java.awt can - * be included in the shaded code so that it can be used - * on Android where some of these are missing. - * - * Taken from JDK 1.8.0_121_x64 on Windows - */ -public class Color { - - /** - * The color white. In the default sRGB space. - */ - public final static java.awt.Color white = new java.awt.Color(255, 255, 255); - - /** - * The color white. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color WHITE = white; - - /** - * The color light gray. In the default sRGB space. - */ - public final static java.awt.Color lightGray = new java.awt.Color(192, 192, 192); - - /** - * The color light gray. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color LIGHT_GRAY = lightGray; - - /** - * The color gray. In the default sRGB space. - */ - public final static java.awt.Color gray = new java.awt.Color(128, 128, 128); - - /** - * The color gray. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color GRAY = gray; - - /** - * The color dark gray. In the default sRGB space. - */ - public final static java.awt.Color darkGray = new java.awt.Color(64, 64, 64); - - /** - * The color dark gray. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color DARK_GRAY = darkGray; - - /** - * The color black. In the default sRGB space. - */ - public final static java.awt.Color black = new java.awt.Color(0, 0, 0); - - /** - * The color black. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color BLACK = black; - - /** - * The color red. In the default sRGB space. - */ - public final static java.awt.Color red = new java.awt.Color(255, 0, 0); - - /** - * The color red. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color RED = red; - - /** - * The color pink. In the default sRGB space. - */ - public final static java.awt.Color pink = new java.awt.Color(255, 175, 175); - - /** - * The color pink. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color PINK = pink; - - /** - * The color orange. In the default sRGB space. - */ - public final static java.awt.Color orange = new java.awt.Color(255, 200, 0); - - /** - * The color orange. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color ORANGE = orange; - - /** - * The color yellow. In the default sRGB space. - */ - public final static java.awt.Color yellow = new java.awt.Color(255, 255, 0); - - /** - * The color yellow. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color YELLOW = yellow; - - /** - * The color green. In the default sRGB space. - */ - public final static java.awt.Color green = new java.awt.Color(0, 255, 0); - - /** - * The color green. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color GREEN = green; - - /** - * The color magenta. In the default sRGB space. - */ - public final static java.awt.Color magenta = new java.awt.Color(255, 0, 255); - - /** - * The color magenta. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color MAGENTA = magenta; - - /** - * The color cyan. In the default sRGB space. - */ - public final static java.awt.Color cyan = new java.awt.Color(0, 255, 255); - - /** - * The color cyan. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color CYAN = cyan; - - /** - * The color blue. In the default sRGB space. - */ - public final static java.awt.Color blue = new java.awt.Color(0, 0, 255); - - /** - * The color blue. In the default sRGB space. - * @since 1.4 - */ - public final static java.awt.Color BLUE = blue; - - /** - * The color value. - * @serial - * @see #getRGB - */ - int value; - - /** - * The color value in the default sRGB ColorSpace as - * float components (no alpha). - * If null after object construction, this must be an - * sRGB color constructed with 8-bit precision, so compute from the - * int color value. - * @serial - * @see #getRGBColorComponents - * @see #getRGBComponents - */ - private float frgbvalue[] = null; - - /** - * The color value in the native ColorSpace as - * float components (no alpha). - * If null after object construction, this must be an - * sRGB color constructed with 8-bit precision, so compute from the - * int color value. - * @serial - * @see #getRGBColorComponents - * @see #getRGBComponents - */ - private float fvalue[] = null; - - /** - * The alpha value as a float component. - * If frgbvalue is null, this is not valid - * data, so compute from the int color value. - * @serial - * @see #getRGBComponents - * @see #getComponents - */ - private float falpha = 0.0f; - - /** - * Checks the color integer components supplied for validity. - * Throws an {@link IllegalArgumentException} if the value is out of - * range. - * @param r the Red component - * @param g the Green component - * @param b the Blue component - **/ - private static void testColorValueRange(int r, int g, int b, int a) { - boolean rangeError = false; - String badComponentString = ""; - - if ( a < 0 || a > 255) { - rangeError = true; - badComponentString = badComponentString + " Alpha"; - } - if ( r < 0 || r > 255) { - rangeError = true; - badComponentString = badComponentString + " Red"; - } - if ( g < 0 || g > 255) { - rangeError = true; - badComponentString = badComponentString + " Green"; - } - if ( b < 0 || b > 255) { - rangeError = true; - badComponentString = badComponentString + " Blue"; - } - if ( rangeError == true ) { - throw new IllegalArgumentException("Color parameter outside of expected range:" - + badComponentString); - } - } - - /** - * Checks the color float components supplied for - * validity. - * Throws an IllegalArgumentException if the value is out - * of range. - * @param r the Red component - * @param g the Green component - * @param b the Blue component - **/ - private static void testColorValueRange(float r, float g, float b, float a) { - boolean rangeError = false; - String badComponentString = ""; - if ( a < 0.0 || a > 1.0) { - rangeError = true; - badComponentString = badComponentString + " Alpha"; - } - if ( r < 0.0 || r > 1.0) { - rangeError = true; - badComponentString = badComponentString + " Red"; - } - if ( g < 0.0 || g > 1.0) { - rangeError = true; - badComponentString = badComponentString + " Green"; - } - if ( b < 0.0 || b > 1.0) { - rangeError = true; - badComponentString = badComponentString + " Blue"; - } - if ( rangeError == true ) { - throw new IllegalArgumentException("Color parameter outside of expected range:" - + badComponentString); - } - } - - /** - * Creates an opaque sRGB color with the specified red, green, - * and blue values in the range (0 - 255). - * The actual color used in rendering depends - * on finding the best match given the color space - * available for a given output device. - * Alpha is defaulted to 255. - * - * @throws IllegalArgumentException if r, g - * or b are outside of the range - * 0 to 255, inclusive - * @param r the red component - * @param g the green component - * @param b the blue component - * @see #getRed - * @see #getGreen - * @see #getBlue - * @see #getRGB - */ - public Color(int r, int g, int b) { - this(r, g, b, 255); - } - - /** - * Creates an sRGB color with the specified red, green, blue, and alpha - * values in the range (0 - 255). - * - * @throws IllegalArgumentException if r, g, - * b or a are outside of the range - * 0 to 255, inclusive - * @param r the red component - * @param g the green component - * @param b the blue component - * @param a the alpha component - * @see #getRed - * @see #getGreen - * @see #getBlue - * @see #getAlpha - * @see #getRGB - */ - @ConstructorProperties({"red", "green", "blue", "alpha"}) - public Color(int r, int g, int b, int a) { - value = ((a & 0xFF) << 24) | - ((r & 0xFF) << 16) | - ((g & 0xFF) << 8) | - ((b & 0xFF) << 0); - testColorValueRange(r,g,b,a); - } - - /** - * Creates an opaque sRGB color with the specified combined RGB value - * consisting of the red component in bits 16-23, the green component - * in bits 8-15, and the blue component in bits 0-7. The actual color - * used in rendering depends on finding the best match given the - * color space available for a particular output device. Alpha is - * defaulted to 255. - * - * @param rgb the combined RGB components - * @see java.awt.image.ColorModel#getRGBdefault - * @see #getRed - * @see #getGreen - * @see #getBlue - * @see #getRGB - */ - public Color(int rgb) { - value = 0xff000000 | rgb; - } - - /** - * Creates an sRGB color with the specified combined RGBA value consisting - * of the alpha component in bits 24-31, the red component in bits 16-23, - * the green component in bits 8-15, and the blue component in bits 0-7. - * If the hasalpha argument is false, alpha - * is defaulted to 255. - * - * @param rgba the combined RGBA components - * @param hasalpha true if the alpha bits are valid; - * false otherwise - * @see java.awt.image.ColorModel#getRGBdefault - * @see #getRed - * @see #getGreen - * @see #getBlue - * @see #getAlpha - * @see #getRGB - */ - public Color(int rgba, boolean hasalpha) { - if (hasalpha) { - value = rgba; - } else { - value = 0xff000000 | rgba; - } - } - - /** - * Creates an opaque sRGB color with the specified red, green, and blue - * values in the range (0.0 - 1.0). Alpha is defaulted to 1.0. The - * actual color used in rendering depends on finding the best - * match given the color space available for a particular output - * device. - * - * @throws IllegalArgumentException if r, g - * or b are outside of the range - * 0.0 to 1.0, inclusive - * @param r the red component - * @param g the green component - * @param b the blue component - * @see #getRed - * @see #getGreen - * @see #getBlue - * @see #getRGB - */ - public Color(float r, float g, float b) { - this( (int) (r*255+0.5), (int) (g*255+0.5), (int) (b*255+0.5)); - testColorValueRange(r,g,b,1.0f); - frgbvalue = new float[3]; - frgbvalue[0] = r; - frgbvalue[1] = g; - frgbvalue[2] = b; - falpha = 1.0f; - fvalue = frgbvalue; - } - - /** - * Creates an sRGB color with the specified red, green, blue, and - * alpha values in the range (0.0 - 1.0). The actual color - * used in rendering depends on finding the best match given the - * color space available for a particular output device. - * @throws IllegalArgumentException if r, g - * b or a are outside of the range - * 0.0 to 1.0, inclusive - * @param r the red component - * @param g the green component - * @param b the blue component - * @param a the alpha component - * @see #getRed - * @see #getGreen - * @see #getBlue - * @see #getAlpha - * @see #getRGB - */ - public Color(float r, float g, float b, float a) { - this((int)(r*255+0.5), (int)(g*255+0.5), (int)(b*255+0.5), (int)(a*255+0.5)); - frgbvalue = new float[3]; - frgbvalue[0] = r; - frgbvalue[1] = g; - frgbvalue[2] = b; - falpha = a; - fvalue = frgbvalue; - } - - - /** - * Returns the red component in the range 0-255 in the default sRGB - * space. - * @return the red component. - * @see #getRGB - */ - public int getRed() { - return (getRGB() >> 16) & 0xFF; - } - - /** - * Returns the green component in the range 0-255 in the default sRGB - * space. - * @return the green component. - * @see #getRGB - */ - public int getGreen() { - return (getRGB() >> 8) & 0xFF; - } - - /** - * Returns the blue component in the range 0-255 in the default sRGB - * space. - * @return the blue component. - * @see #getRGB - */ - public int getBlue() { - return (getRGB() >> 0) & 0xFF; - } - - /** - * Returns the alpha component in the range 0-255. - * @return the alpha component. - * @see #getRGB - */ - public int getAlpha() { - return (getRGB() >> 24) & 0xff; - } - - /** - * Returns the RGB value representing the color in the default sRGB - * {@link ColorModel}. - * (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are - * blue). - * @return the RGB value of the color in the default sRGB - * ColorModel. - * @see java.awt.image.ColorModel#getRGBdefault - * @see #getRed - * @see #getGreen - * @see #getBlue - * @since JDK1.0 - */ - public int getRGB() { - return value; - } - - private static final double FACTOR = 0.7; - - /** - * Creates a new Color that is a brighter version of this - * Color. - *

- * This method applies an arbitrary scale factor to each of the three RGB - * components of this Color to create a brighter version - * of this Color. - * The {@code alpha} value is preserved. - * Although brighter and - * darker are inverse operations, the results of a - * series of invocations of these two methods might be inconsistent - * because of rounding errors. - * @return a new Color object that is - * a brighter version of this Color - * with the same {@code alpha} value. - * @see java.awt.Color#darker - * @since JDK1.0 - */ - public java.awt.Color brighter() { - int r = getRed(); - int g = getGreen(); - int b = getBlue(); - int alpha = getAlpha(); - - /* From 2D group: - * 1. black.brighter() should return grey - * 2. applying brighter to blue will always return blue, brighter - * 3. non pure color (non zero rgb) will eventually return white - */ - int i = (int)(1.0/(1.0-FACTOR)); - if ( r == 0 && g == 0 && b == 0) { - return new java.awt.Color(i, i, i, alpha); - } - if ( r > 0 && r < i ) r = i; - if ( g > 0 && g < i ) g = i; - if ( b > 0 && b < i ) b = i; - - return new java.awt.Color(Math.min((int)(r/FACTOR), 255), - Math.min((int)(g/FACTOR), 255), - Math.min((int)(b/FACTOR), 255), - alpha); - } - - /** - * Creates a new Color that is a darker version of this - * Color. - *

- * This method applies an arbitrary scale factor to each of the three RGB - * components of this Color to create a darker version of - * this Color. - * The {@code alpha} value is preserved. - * Although brighter and - * darker are inverse operations, the results of a series - * of invocations of these two methods might be inconsistent because - * of rounding errors. - * @return a new Color object that is - * a darker version of this Color - * with the same {@code alpha} value. - * @see java.awt.Color#brighter - * @since JDK1.0 - */ - public java.awt.Color darker() { - return new java.awt.Color(Math.max((int)(getRed() *FACTOR), 0), - Math.max((int)(getGreen()*FACTOR), 0), - Math.max((int)(getBlue() *FACTOR), 0), - getAlpha()); - } - - /** - * Computes the hash code for this Color. - * @return a hash code value for this object. - * @since JDK1.0 - */ - public int hashCode() { - return value; - } - - /** - * Determines whether another object is equal to this - * Color. - *

- * The result is true if and only if the argument is not - * null and is a Color object that has the same - * red, green, blue, and alpha values as this object. - * @param obj the object to test for equality with this - * Color - * @return true if the objects are the same; - * false otherwise. - * @since JDK1.0 - */ - public boolean equals(Object obj) { - return obj instanceof java.awt.Color && ((java.awt.Color)obj).getRGB() == this.getRGB(); - } - - /** - * Returns a string representation of this Color. This - * method is intended to be used only for debugging purposes. The - * content and format of the returned string might vary between - * implementations. The returned string might be empty but cannot - * be null. - * - * @return a string representation of this Color. - */ - public String toString() { - return getClass().getName() + "[r=" + getRed() + ",g=" + getGreen() + ",b=" + getBlue() + "]"; - } - - /** - * Converts a String to an integer and returns the - * specified opaque Color. This method handles string - * formats that are used to represent octal and hexadecimal numbers. - * @param nm a String that represents - * an opaque color as a 24-bit integer - * @return the new Color object. - * @see java.lang.Integer#decode - * @exception NumberFormatException if the specified string cannot - * be interpreted as a decimal, - * octal, or hexadecimal integer. - * @since JDK1.1 - */ - public static java.awt.Color decode(String nm) throws NumberFormatException { - Integer intval = Integer.decode(nm); - int i = intval.intValue(); - return new java.awt.Color((i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF); - } - - /** - * Finds a color in the system properties. - *

- * The argument is treated as the name of a system property to - * be obtained. The string value of this property is then interpreted - * as an integer which is then converted to a Color - * object. - *

- * If the specified property is not found or could not be parsed as - * an integer then null is returned. - * @param nm the name of the color property - * @return the Color converted from the system - * property. - * @see java.lang.System#getProperty(java.lang.String) - * @see java.lang.Integer#getInteger(java.lang.String) - * @see java.awt.Color#Color(int) - * @since JDK1.0 - */ - public static java.awt.Color getColor(String nm) { - return getColor(nm, null); - } - - /** - * Finds a color in the system properties. - *

- * The first argument is treated as the name of a system property to - * be obtained. The string value of this property is then interpreted - * as an integer which is then converted to a Color - * object. - *

- * If the specified property is not found or cannot be parsed as - * an integer then the Color specified by the second - * argument is returned instead. - * @param nm the name of the color property - * @param v the default Color - * @return the Color converted from the system - * property, or the specified Color. - * @see java.lang.System#getProperty(java.lang.String) - * @see java.lang.Integer#getInteger(java.lang.String) - * @see java.awt.Color#Color(int) - * @since JDK1.0 - */ - public static java.awt.Color getColor(String nm, java.awt.Color v) { - Integer intval = Integer.getInteger(nm); - if (intval == null) { - return v; - } - int i = intval.intValue(); - return new java.awt.Color((i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF); - } - - /** - * Finds a color in the system properties. - *

- * The first argument is treated as the name of a system property to - * be obtained. The string value of this property is then interpreted - * as an integer which is then converted to a Color - * object. - *

- * If the specified property is not found or could not be parsed as - * an integer then the integer value v is used instead, - * and is converted to a Color object. - * @param nm the name of the color property - * @param v the default color value, as an integer - * @return the Color converted from the system - * property or the Color converted from - * the specified integer. - * @see java.lang.System#getProperty(java.lang.String) - * @see java.lang.Integer#getInteger(java.lang.String) - * @see java.awt.Color#Color(int) - * @since JDK1.0 - */ - public static java.awt.Color getColor(String nm, int v) { - Integer intval = Integer.getInteger(nm); - int i = (intval != null) ? intval.intValue() : v; - return new java.awt.Color((i >> 16) & 0xFF, (i >> 8) & 0xFF, (i >> 0) & 0xFF); - } - - /** - * Converts the components of a color, as specified by the HSB - * model, to an equivalent set of values for the default RGB model. - *

- * The saturation and brightness components - * should be floating-point values between zero and one - * (numbers in the range 0.0-1.0). The hue component - * can be any floating-point number. The floor of this number is - * subtracted from it to create a fraction between 0 and 1. This - * fractional number is then multiplied by 360 to produce the hue - * angle in the HSB color model. - *

- * The integer that is returned by HSBtoRGB encodes the - * value of a color in bits 0-23 of an integer value that is the same - * format used by the method {@link #getRGB() getRGB}. - * This integer can be supplied as an argument to the - * Color constructor that takes a single integer argument. - * @param hue the hue component of the color - * @param saturation the saturation of the color - * @param brightness the brightness of the color - * @return the RGB value of the color with the indicated hue, - * saturation, and brightness. - * @see java.awt.Color#getRGB() - * @see java.awt.Color#Color(int) - * @see java.awt.image.ColorModel#getRGBdefault() - * @since JDK1.0 - */ - public static int HSBtoRGB(float hue, float saturation, float brightness) { - int r = 0, g = 0, b = 0; - if (saturation == 0) { - r = g = b = (int) (brightness * 255.0f + 0.5f); - } else { - float h = (hue - (float)Math.floor(hue)) * 6.0f; - float f = h - (float)java.lang.Math.floor(h); - float p = brightness * (1.0f - saturation); - float q = brightness * (1.0f - saturation * f); - float t = brightness * (1.0f - (saturation * (1.0f - f))); - switch ((int) h) { - case 0: - r = (int) (brightness * 255.0f + 0.5f); - g = (int) (t * 255.0f + 0.5f); - b = (int) (p * 255.0f + 0.5f); - break; - case 1: - r = (int) (q * 255.0f + 0.5f); - g = (int) (brightness * 255.0f + 0.5f); - b = (int) (p * 255.0f + 0.5f); - break; - case 2: - r = (int) (p * 255.0f + 0.5f); - g = (int) (brightness * 255.0f + 0.5f); - b = (int) (t * 255.0f + 0.5f); - break; - case 3: - r = (int) (p * 255.0f + 0.5f); - g = (int) (q * 255.0f + 0.5f); - b = (int) (brightness * 255.0f + 0.5f); - break; - case 4: - r = (int) (t * 255.0f + 0.5f); - g = (int) (p * 255.0f + 0.5f); - b = (int) (brightness * 255.0f + 0.5f); - break; - case 5: - r = (int) (brightness * 255.0f + 0.5f); - g = (int) (p * 255.0f + 0.5f); - b = (int) (q * 255.0f + 0.5f); - break; - } - } - return 0xff000000 | (r << 16) | (g << 8) | (b << 0); - } - - /** - * Converts the components of a color, as specified by the default RGB - * model, to an equivalent set of values for hue, saturation, and - * brightness that are the three components of the HSB model. - *

- * If the hsbvals argument is null, then a - * new array is allocated to return the result. Otherwise, the method - * returns the array hsbvals, with the values put into - * that array. - * @param r the red component of the color - * @param g the green component of the color - * @param b the blue component of the color - * @param hsbvals the array used to return the - * three HSB values, or null - * @return an array of three elements containing the hue, saturation, - * and brightness (in that order), of the color with - * the indicated red, green, and blue components. - * @see java.awt.Color#getRGB() - * @see java.awt.Color#Color(int) - * @see java.awt.image.ColorModel#getRGBdefault() - * @since JDK1.0 - */ - public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) { - float hue, saturation, brightness; - if (hsbvals == null) { - hsbvals = new float[3]; - } - int cmax = (r > g) ? r : g; - if (b > cmax) cmax = b; - int cmin = (r < g) ? r : g; - if (b < cmin) cmin = b; - - brightness = ((float) cmax) / 255.0f; - if (cmax != 0) - saturation = ((float) (cmax - cmin)) / ((float) cmax); - else - saturation = 0; - if (saturation == 0) - hue = 0; - else { - float redc = ((float) (cmax - r)) / ((float) (cmax - cmin)); - float greenc = ((float) (cmax - g)) / ((float) (cmax - cmin)); - float bluec = ((float) (cmax - b)) / ((float) (cmax - cmin)); - if (r == cmax) - hue = bluec - greenc; - else if (g == cmax) - hue = 2.0f + redc - bluec; - else - hue = 4.0f + greenc - redc; - hue = hue / 6.0f; - if (hue < 0) - hue = hue + 1.0f; - } - hsbvals[0] = hue; - hsbvals[1] = saturation; - hsbvals[2] = brightness; - return hsbvals; - } - - /** - * Creates a Color object based on the specified values - * for the HSB color model. - *

- * The s and b components should be - * floating-point values between zero and one - * (numbers in the range 0.0-1.0). The h component - * can be any floating-point number. The floor of this number is - * subtracted from it to create a fraction between 0 and 1. This - * fractional number is then multiplied by 360 to produce the hue - * angle in the HSB color model. - * @param h the hue component - * @param s the saturation of the color - * @param b the brightness of the color - * @return a Color object with the specified hue, - * saturation, and brightness. - * @since JDK1.0 - */ - public static java.awt.Color getHSBColor(float h, float s, float b) { - return new java.awt.Color(HSBtoRGB(h, s, b)); - } - - /** - * Returns a float array containing the color and alpha - * components of the Color, as represented in the default - * sRGB color space. - * If compArray is null, an array of length - * 4 is created for the return value. Otherwise, - * compArray must have length 4 or greater, - * and it is filled in with the components and returned. - * @param compArray an array that this method fills with - * color and alpha components and returns - * @return the RGBA components in a float array. - */ - public float[] getRGBComponents(float[] compArray) { - float[] f; - if (compArray == null) { - f = new float[4]; - } else { - f = compArray; - } - if (frgbvalue == null) { - f[0] = ((float)getRed())/255f; - f[1] = ((float)getGreen())/255f; - f[2] = ((float)getBlue())/255f; - f[3] = ((float)getAlpha())/255f; - } else { - f[0] = frgbvalue[0]; - f[1] = frgbvalue[1]; - f[2] = frgbvalue[2]; - f[3] = falpha; - } - return f; - } - - /** - * Returns a float array containing only the color - * components of the Color, in the default sRGB color - * space. If compArray is null, an array of - * length 3 is created for the return value. Otherwise, - * compArray must have length 3 or greater, and it is - * filled in with the components and returned. - * @param compArray an array that this method fills with color - * components and returns - * @return the RGB components in a float array. - */ - public float[] getRGBColorComponents(float[] compArray) { - float[] f; - if (compArray == null) { - f = new float[3]; - } else { - f = compArray; - } - if (frgbvalue == null) { - f[0] = ((float)getRed())/255f; - f[1] = ((float)getGreen())/255f; - f[2] = ((float)getBlue())/255f; - } else { - f[0] = frgbvalue[0]; - f[1] = frgbvalue[1]; - f[2] = frgbvalue[2]; - } - return f; - } - - /** - * Returns a float array containing the color and alpha - * components of the Color, in the - * ColorSpace of the Color. - * If compArray is null, an array with - * length equal to the number of components in the associated - * ColorSpace plus one is created for - * the return value. Otherwise, compArray must have at - * least this length and it is filled in with the components and - * returned. - * @param compArray an array that this method fills with the color and - * alpha components of this Color in its - * ColorSpace and returns - * @return the color and alpha components in a float - * array. - */ - public float[] getComponents(float[] compArray) { - if (fvalue == null) - return getRGBComponents(compArray); - float[] f; - int n = fvalue.length; - if (compArray == null) { - f = new float[n + 1]; - } else { - f = compArray; - } - for (int i = 0; i < n; i++) { - f[i] = fvalue[i]; - } - f[n] = falpha; - return f; - } - - /** - * Returns a float array containing only the color - * components of the Color, in the - * ColorSpace of the Color. - * If compArray is null, an array with - * length equal to the number of components in the associated - * ColorSpace is created for - * the return value. Otherwise, compArray must have at - * least this length and it is filled in with the components and - * returned. - * @param compArray an array that this method fills with the color - * components of this Color in its - * ColorSpace and returns - * @return the color components in a float array. - */ - public float[] getColorComponents(float[] compArray) { - if (fvalue == null) - return getRGBColorComponents(compArray); - float[] f; - int n = fvalue.length; - if (compArray == null) { - f = new float[n]; - } else { - f = compArray; - } - for (int i = 0; i < n; i++) { - f[i] = fvalue[i]; - } - return f; - } -} diff --git a/poishadow/src/main/java/org/apache/poi/java/awt/Dimension.java b/poishadow/src/main/java/org/apache/poi/java/awt/Dimension.java deleted file mode 100644 index c5f8ef34e..000000000 --- a/poishadow/src/main/java/org/apache/poi/java/awt/Dimension.java +++ /dev/null @@ -1,202 +0,0 @@ -package org.apache.poi.java.awt; - -import java.awt.geom.Dimension2D; -import java.beans.Transient; - -/** - * The {@code Dimension} class encapsulates the width and - * height of a component (in integer precision) in a single object. - * The class is - * associated with certain properties of components. Several methods - * defined by the {@code Component} class and the - * {@code LayoutManager} interface return a - * {@code Dimension} object. - *

- * Normally the values of {@code width} - * and {@code height} are non-negative integers. - * The constructors that allow you to create a dimension do - * not prevent you from setting a negative value for these properties. - * If the value of {@code width} or {@code height} is - * negative, the behavior of some methods defined by other objects is - * undefined. - * - * @author Sami Shaio - * @author Arthur van Hoff - * @see java.awt.Component - * @see java.awt.LayoutManager - * @since 1.0 - */ -public class Dimension extends Dimension2D implements java.io.Serializable { - - /** - * The width dimension; negative values can be used. - * - * @serial - * @see #getSize - * @see #setSize - * @since 1.0 - */ - public int width; - - /** - * The height dimension; negative values can be used. - * - * @serial - * @see #getSize - * @see #setSize - * @since 1.0 - */ - public int height; - - /* - * JDK 1.1 serialVersionUID - */ - private static final long serialVersionUID = 4723952579491349524L; - - - /** - * Creates an instance of {@code Dimension} with a width - * of zero and a height of zero. - */ - public Dimension() { - this(0, 0); - } - - /** - * Creates an instance of {@code Dimension} whose width - * and height are the same as for the specified dimension. - * - * @param d the specified dimension for the - * {@code width} and - * {@code height} values - */ - public Dimension(java.awt.Dimension d) { - this(d.width, d.height); - } - - /** - * Constructs a {@code Dimension} and initializes - * it to the specified width and specified height. - * - * @param width the specified width - * @param height the specified height - */ - public Dimension(int width, int height) { - this.width = width; - this.height = height; - } - - /** - * {@inheritDoc} - * @since 1.2 - */ - public double getWidth() { - return width; - } - - /** - * {@inheritDoc} - * @since 1.2 - */ - public double getHeight() { - return height; - } - - /** - * Sets the size of this {@code Dimension} object to - * the specified width and height in double precision. - * Note that if {@code width} or {@code height} - * are larger than {@code Integer.MAX_VALUE}, they will - * be reset to {@code Integer.MAX_VALUE}. - * - * @param width the new width for the {@code Dimension} object - * @param height the new height for the {@code Dimension} object - * @since 1.2 - */ - public void setSize(double width, double height) { - this.width = (int) Math.ceil(width); - this.height = (int) Math.ceil(height); - } - - /** - * Gets the size of this {@code Dimension} object. - * This method is included for completeness, to parallel the - * {@code getSize} method defined by {@code Component}. - * - * @return the size of this dimension, a new instance of - * {@code Dimension} with the same width and height - * @see java.awt.Dimension#setSize - * @see java.awt.Component#getSize - * @since 1.1 - */ - @Transient - public java.awt.Dimension getSize() { - return new java.awt.Dimension(width, height); - } - - /** - * Sets the size of this {@code Dimension} object to the specified size. - * This method is included for completeness, to parallel the - * {@code setSize} method defined by {@code Component}. - * @param d the new size for this {@code Dimension} object - * @see java.awt.Dimension#getSize - * @see java.awt.Component#setSize - * @since 1.1 - */ - public void setSize(java.awt.Dimension d) { - setSize(d.width, d.height); - } - - /** - * Sets the size of this {@code Dimension} object - * to the specified width and height. - * This method is included for completeness, to parallel the - * {@code setSize} method defined by {@code Component}. - * - * @param width the new width for this {@code Dimension} object - * @param height the new height for this {@code Dimension} object - * @see java.awt.Dimension#getSize - * @see java.awt.Component#setSize - * @since 1.1 - */ - public void setSize(int width, int height) { - this.width = width; - this.height = height; - } - - /** - * Checks whether two dimension objects have equal values. - */ - public boolean equals(Object obj) { - if (obj instanceof java.awt.Dimension) { - java.awt.Dimension d = (java.awt.Dimension)obj; - return (width == d.width) && (height == d.height); - } - return false; - } - - /** - * Returns the hash code for this {@code Dimension}. - * - * @return a hash code for this {@code Dimension} - */ - public int hashCode() { - int sum = width + height; - return sum * (sum + 1)/2 + width; - } - - /** - * Returns a string representation of the values of this - * {@code Dimension} object's {@code height} and - * {@code width} fields. This method is intended to be used only - * for debugging purposes, and the content and format of the returned - * string may vary between implementations. The returned string may be - * empty but may not be {@code null}. - * - * @return a string representation of this {@code Dimension} - * object - */ - public String toString() { - return getClass().getName() + "[width=" + width + ",height=" + height + "]"; - } -} \ No newline at end of file diff --git a/poishadow/src/main/java/org/apache/poi/java/awt/geom/Dimension2D.java b/poishadow/src/main/java/org/apache/poi/java/awt/geom/Dimension2D.java deleted file mode 100644 index 9860e530e..000000000 --- a/poishadow/src/main/java/org/apache/poi/java/awt/geom/Dimension2D.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.apache.poi.java.awt.geom; - - -/** - * The {@code Dimension2D} class is to encapsulate a width - * and a height dimension. - *

- * This class is only the abstract superclass for all objects that - * store a 2D dimension. - * The actual storage representation of the sizes is left to - * the subclass. - * - * @author Jim Graham - * @since 1.2 - */ -public abstract class Dimension2D implements Cloneable { - - /** - * This is an abstract class that cannot be instantiated directly. - * Type-specific implementation subclasses are available for - * instantiation and provide a number of formats for storing - * the information necessary to satisfy the various accessor - * methods below. - * - * @see java.awt.Dimension - * @since 1.2 - */ - protected Dimension2D() { - } - - /** - * Returns the width of this {@code Dimension} in double - * precision. - * @return the width of this {@code Dimension}. - * @since 1.2 - */ - public abstract double getWidth(); - - /** - * Returns the height of this {@code Dimension} in double - * precision. - * @return the height of this {@code Dimension}. - * @since 1.2 - */ - public abstract double getHeight(); - - /** - * Sets the size of this {@code Dimension} object to the - * specified width and height. - * This method is included for completeness, to parallel the - * {@link java.awt.Component#getSize getSize} method of - * {@link java.awt.Component}. - * @param width the new width for the {@code Dimension} - * object - * @param height the new height for the {@code Dimension} - * object - * @since 1.2 - */ - public abstract void setSize(double width, double height); - - /** - * Sets the size of this {@code Dimension2D} object to - * match the specified size. - * This method is included for completeness, to parallel the - * {@code getSize} method of {@code Component}. - * @param d the new size for the {@code Dimension2D} - * object - * @since 1.2 - */ - public void setSize(java.awt.geom.Dimension2D d) { - setSize(d.getWidth(), d.getHeight()); - } - - /** - * Creates a new object of the same class as this object. - * - * @return a clone of this instance. - * @exception OutOfMemoryError if there is not enough memory. - * @see java.lang.Cloneable - * @since 1.2 - */ - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - // this shouldn't happen, since we are Cloneable - throw new InternalError(e); - } - } -} diff --git a/poishadow/src/main/java/org/apache/poi/java/awt/image/BufferedImage.java b/poishadow/src/main/java/org/apache/poi/java/awt/image/BufferedImage.java deleted file mode 100644 index f1d9d4de4..000000000 --- a/poishadow/src/main/java/org/apache/poi/java/awt/image/BufferedImage.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.apache.poi.java.awt.image; - -/** - * Shadow class for java.awt.image.BufferedImage. Adds some compatibility to systems that do - * not have access to javax.awt. - */ -public class BufferedImage { - /** - * The pixel width of the image. - */ - private final int width; - - /** - * The pixel height of the image. - */ - private final int height; - - /** - * Constructor - * - * @param width The pixel width of the image. - * @param height The pixel height of the image. - */ - public BufferedImage(int width, int height) { - this.width = width; - this.height = height; - } - - /** - * Returns The pixel width of the image. - * - * @return The pixel width of the image. - */ - public int getWidth() { - return width; - } - - /** - * Returns The pixel height of the image. - * - * @return The pixel height of the image. - */ - public int getHeight() { - return height; - } - -} diff --git a/poishadow/src/main/java/org/apache/poi/javax/imageio/ImageIO.java b/poishadow/src/main/java/org/apache/poi/javax/imageio/ImageIO.java deleted file mode 100644 index d74788516..000000000 --- a/poishadow/src/main/java/org/apache/poi/javax/imageio/ImageIO.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.apache.poi.javax.imageio; - - -import org.apache.poi.javax.imageio.stream.ImageInputStream; -import org.dstadler.compat.BmpReader; -import org.dstadler.compat.ImageInputStreamImpl; -import org.dstadler.compat.JpgReader; -import org.dstadler.compat.PngReader; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -/** - * Shadow class for {@link javax.imageio.ImageIO}. Adds some compatibility to systems that do - * not have access to javax.imageio. - */ -public final class ImageIO { - - /** - * List of available {@link ImageReader}s. - */ - private static final List imageReaders = new ArrayList<>(); - - static { - //Initializes the image readers. - imageReaders.add(new PngReader()); - imageReaders.add(new JpgReader()); - imageReaders.add(new BmpReader()); - } - - /** - * Creates an {@link ImageInputStreamImpl} that wraps the given inputStream into - * a {@link java.io.BufferedInputStream}. - * - * @param input must be a {@link InputStream}. - * @return an {@link ImageInputStreamImpl} that wraps the given inputStream into - * a {@link java.io.BufferedInputStream}. - * @throws IOException If an error occurs while reading. - */ - public static ImageInputStream createImageInputStream(Object input) throws IOException { - if (!(input instanceof InputStream)) { - throw new IllegalArgumentException("input is not an instance of InputStream"); - } - return new ImageInputStreamImpl((InputStream) input); - } - - /** - * Returns a iterator of usable {@link ImageReader}s based on the given input. - * @param input Must be a {@link ImageInputStream}. - * @return a iterator of usable {@link ImageReader}s based on the given input. - */ - public static Iterator getImageReaders(Object input) { - if (!(input instanceof ImageInputStream)) { - throw new IllegalArgumentException("input is not an instance of ImageInputStream"); - } - - for (ImageReader reader : imageReaders) { - if (reader.canRead(((ImageInputStream) input).getInputStream())) { - ArrayList returnList = new ArrayList<>(); - returnList.add(reader); - return returnList.iterator(); - } - } - - return Collections.emptyIterator(); - } -} diff --git a/poishadow/src/main/java/org/apache/poi/javax/imageio/ImageReader.java b/poishadow/src/main/java/org/apache/poi/javax/imageio/ImageReader.java deleted file mode 100644 index fe468d8b0..000000000 --- a/poishadow/src/main/java/org/apache/poi/javax/imageio/ImageReader.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.apache.poi.javax.imageio; - -import org.apache.commons.io.IOUtils; -import org.apache.poi.java.awt.image.BufferedImage; -import org.apache.poi.javax.imageio.metadata.IIOMetadata; -import org.apache.poi.javax.imageio.stream.ImageInputStream; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.OptionalInt; -import java.util.stream.IntStream; - -/** - * Shadow class for {@link javax.imageio.ImageReader}. Adds some compatibility to systems that do - * not have access to javax.imageio. - */ -public abstract class ImageReader { - /** - * The buffer used when reading. - */ - protected ByteBuffer buffer; - - /** - * Sets the input stream. - * - * @param input Must be a {@link ImageInputStream}. - */ - public void setInput(Object input) { - if (!(input instanceof ImageInputStream)) { - throw new IllegalArgumentException("input is not an instance of InputStream"); - } - ImageInputStream imageInputStream = (ImageInputStream) input; - - try { - if (!canRead(imageInputStream.getInputStream())) { - throw new IllegalArgumentException("Incorrect input type!"); - } - - this.buffer = ByteBuffer.wrap(IOUtils.toByteArray(imageInputStream.getInputStream())); - } catch (IOException e) { - throw new IllegalArgumentException("Incorrect input type!"); - } - } - - /** - * Gets the first index of the given byte[] within the {@link ByteBuffer}. - * - * @param buf The {@link ByteBuffer} to search. - * @param b the byte array to search for. - * @return empty if not found, otherwise the first index found. - */ - protected static OptionalInt indexOf(ByteBuffer buf, byte[] b) { - if (b.length == 0) { - return OptionalInt.empty(); - } - return IntStream.rangeClosed(buf.position(), buf.limit() - b.length) - .filter(i -> IntStream.range(0, b.length).allMatch(j -> buf.get(i + j) == b[j])) - .findFirst(); - } - - /** - * Gets the indices of the given byte[] within the {@link ByteBuffer}. - * - * @param buf The {@link ByteBuffer} to search. - * @param b the byte array to search for. - * @return empty int array if not found, otherwise an int array of all found indices. - */ - protected static int[] indicesOf(ByteBuffer buf, byte[] b) { - if (b.length == 0) { - return new int[0]; - } - return IntStream.rangeClosed(buf.position(), buf.limit() - b.length) - .filter(i -> IntStream.range(0, b.length).allMatch(j -> buf.get(i + j) == b[j])) - .toArray(); - } - - /** - * Returns true if the magic bytes given match the same starting bytes in the given inputStream. - * - * @param magic the magic bytes to match. - * @param inputStream The input stream to use. - * @return true if the magic bytes given match the same starting bytes in the given inputStream. - */ - protected boolean magicBytesPresent(byte[] magic, BufferedInputStream inputStream) { - byte[] bytes = new byte[magic.length]; - inputStream.mark(magic.length); - - try { - inputStream.read(bytes, 0, magic.length); - inputStream.reset(); - } catch (IOException e) { - return false; - } - - return Arrays.equals(bytes, magic); - } - - /** - * Returns a {@link BufferedImage} by reading the buffer. - * - * @param imageIndex this is ignored. - * @return a {@link BufferedImage} by reading the buffer. - */ - public abstract BufferedImage read(int imageIndex); - - /** - * Returns true if the inherited class can read this input stream as a specific image. - * - * @param inputStream The input stream to use. - * @return true if the inherited class can read this input stream as a specific image. - */ - protected abstract boolean canRead(BufferedInputStream inputStream); - - /** - * Returns a {@link IIOMetadata} by reading the buffer. - * - * @param imageIndex ignored. - * @return a {@link IIOMetadata} by reading the buffer. - * @throws IOException If an error occurs during reading. - */ - public abstract IIOMetadata getImageMetadata(int imageIndex) throws IOException; - - /** - * Disposes of any used resources. - */ - public void dispose() { - buffer = null; - } -} diff --git a/poishadow/src/main/java/org/apache/poi/javax/imageio/metadata/IIOMetadata.java b/poishadow/src/main/java/org/apache/poi/javax/imageio/metadata/IIOMetadata.java deleted file mode 100644 index 8a3fa4e13..000000000 --- a/poishadow/src/main/java/org/apache/poi/javax/imageio/metadata/IIOMetadata.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.apache.poi.javax.imageio.metadata; - -import org.w3c.dom.Node; - -/** - * Shadow class for {@link javax.imageio.metadata.IIOMetadata}. Adds some compatibility to systems - * that do not have access to javax.imageio. - */ -public abstract class IIOMetadata { - /** - * Returns an {@link org.w3c.dom.Element} describing metadata for images. - * - * @param formatName the desired metadata format. - * @return an {@link org.w3c.dom.Element} describing metadata for images. - */ - public abstract Node getAsTree(String formatName); -} diff --git a/poishadow/src/main/java/org/apache/poi/javax/imageio/stream/ImageInputStream.java b/poishadow/src/main/java/org/apache/poi/javax/imageio/stream/ImageInputStream.java deleted file mode 100644 index 6f09f01d2..000000000 --- a/poishadow/src/main/java/org/apache/poi/javax/imageio/stream/ImageInputStream.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.apache.poi.javax.imageio.stream; - -import java.io.BufferedInputStream; -import java.io.Closeable; - -/** - * The shadow interface for {@link javax.imageio.stream.ImageInputStream}. Adds some compatibility - * to systems that do not have access to javax.imageio. - */ -public interface ImageInputStream extends Closeable { - - /** - * Returns the input stream to use - * - * @return the input stream to use - */ - BufferedInputStream getInputStream(); -} diff --git a/poishadow/src/main/java/org/dstadler/compat/BmpReader.java b/poishadow/src/main/java/org/dstadler/compat/BmpReader.java deleted file mode 100644 index edd17a574..000000000 --- a/poishadow/src/main/java/org/dstadler/compat/BmpReader.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.dstadler.compat; - -import org.apache.poi.java.awt.image.BufferedImage; -import org.apache.poi.javax.imageio.ImageReader; -import org.apache.poi.javax.imageio.metadata.IIOMetadata; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.nio.ByteOrder; - -/** - * Image reader for BMP files. - */ -public class BmpReader extends ImageReader { - /** - * The BMP's magic bytes - */ - private static final byte[] BMP_MAGIC_BYTES = new byte[]{0x42, 0x4D}; - - /** - * {@inheritDoc} - */ - @Override - public BufferedImage read(int imageIndex) { - buffer.order(ByteOrder.LITTLE_ENDIAN); - - //set to with offset which is followed by height - buffer.position(0x12); - int width = buffer.getInt(); - int height = buffer.getInt(); - buffer.rewind(); - - return new BufferedImage(width, height); - } - - /** - * Specific for BMP image files.

- * {@inheritDoc} - */ - @Override - protected boolean canRead(BufferedInputStream inputStream) { - return magicBytesPresent(BMP_MAGIC_BYTES, inputStream); - } - - /** - * {@inheritDoc} - */ - @Override - public IIOMetadata getImageMetadata(int imageIndex) throws IOException { - buffer.order(ByteOrder.LITTLE_ENDIAN); - - //set to XpixelsPerM offset which is followed by YpixelsPerM - buffer.position(0x26); - int yPixelsPerMeter = buffer.getInt(); - int xPixelsPerMeter = buffer.getInt(); - - buffer.rewind(); - return new IOMetadataImpl(1000.0F / xPixelsPerMeter, - 1000.0F / yPixelsPerMeter); - } -} diff --git a/poishadow/src/main/java/org/dstadler/compat/IOMetadataImpl.java b/poishadow/src/main/java/org/dstadler/compat/IOMetadataImpl.java deleted file mode 100644 index ff592e75e..000000000 --- a/poishadow/src/main/java/org/dstadler/compat/IOMetadataImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.dstadler.compat; - -import org.apache.poi.javax.imageio.metadata.IIOMetadata; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -/** - * The compatibility implementation for {@link IIOMetadata}. - */ -public class IOMetadataImpl extends IIOMetadata { - /** - * The horizontal pixel size - */ - private final Float horizontalPixelSize; - - /** - * The vertical pixel size - */ - private final Float verticalPixelSize; - - /** - * Constructor - * - * @param horizontalPixelSize The horizontal pixel size - * @param verticalPixelSize The vertical pixel size - */ - protected IOMetadataImpl(Float horizontalPixelSize, Float verticalPixelSize) { - this.horizontalPixelSize = horizontalPixelSize; - this.verticalPixelSize = verticalPixelSize; - } - - /** - * Currently only returns horizontal and vertical pixles sizes.

- * {@inheritDoc} - */ - @Override - public Node getAsTree(String formatName) { - DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = null; - try { - docBuilder = docFactory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - throw new RuntimeException(e); - } - Document doc = docBuilder.newDocument(); - Element rootElement = doc.createElement("Dimension"); - - if (horizontalPixelSize != null) { - Element horizontalElement = doc.createElement("HorizontalPixelSize"); - rootElement.appendChild(horizontalElement); - horizontalElement.setAttribute("value", String.valueOf(horizontalPixelSize)); - } - - if (verticalPixelSize != null) { - Element verticalElement = doc.createElement("VerticalPixelSize"); - rootElement.appendChild(verticalElement); - verticalElement.setAttribute("value", String.valueOf(verticalPixelSize)); - } - - return rootElement; - } -} diff --git a/poishadow/src/main/java/org/dstadler/compat/ImageInputStreamImpl.java b/poishadow/src/main/java/org/dstadler/compat/ImageInputStreamImpl.java deleted file mode 100644 index 3dd402806..000000000 --- a/poishadow/src/main/java/org/dstadler/compat/ImageInputStreamImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.dstadler.compat; - -import org.apache.poi.javax.imageio.stream.ImageInputStream; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; - -/** - * The compatibility implementation for {@link ImageInputStream}. - */ -public class ImageInputStreamImpl implements ImageInputStream { - /** - * The input stream. - */ - private final BufferedInputStream stream; - - /** - * Constructor - * - * @param inputStream the input stream to use. - */ - public ImageInputStreamImpl(InputStream inputStream){ - stream = new BufferedInputStream(inputStream); - } - - /** - * {@inheritDoc} - */ - public BufferedInputStream getInputStream() { - return stream; - } - - /** - * {@inheritDoc} - */ - @Override - public void close() throws IOException { - stream.close(); - } -} diff --git a/poishadow/src/main/java/org/dstadler/compat/JpgReader.java b/poishadow/src/main/java/org/dstadler/compat/JpgReader.java deleted file mode 100644 index 1e151056a..000000000 --- a/poishadow/src/main/java/org/dstadler/compat/JpgReader.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.dstadler.compat; - -import org.apache.poi.java.awt.image.BufferedImage; -import org.apache.poi.javax.imageio.ImageReader; -import org.apache.poi.javax.imageio.metadata.IIOMetadata; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.util.OptionalInt; - -/** - * Image reader for JPG files. - */ -public class JpgReader extends ImageReader { - /** - * Magic bytes for JFIF JPG files. - */ - private static final byte[] JFIF_MAGIC_BYTES = new byte[]{(byte) 0xFF, (byte) 0xD8, - (byte) 0xFF, (byte) 0xE0}; - - /** - * Magic bytes for EXIF JPG files. - */ - private static final byte[] EXIF_MAGIC_BYTES = new byte[]{(byte) 0xFF, (byte) 0xD8, - (byte) 0xFF, (byte) 0xE1}; - - /** - * {@inheritDoc} - */ - @Override - public BufferedImage read(int imageIndex) { - //Start Of Frame (Baseline DCT), SOFn segment - //Get the last SOF segment since that is what has the size - byte[] sofn = {(byte) 0xFF, (byte) 0xC0}; - int[] indicesOfSof = indicesOf(buffer, sofn); - int lastSofn = indicesOfSof[indicesOfSof.length - 1]; - - buffer.position(lastSofn + 5); - int height = buffer.getShort(); - int width = buffer.getShort(); - buffer.rewind(); - - return new BufferedImage(width, height); - } - - /** - * Specific for JPG image files.

- * {@inheritDoc} - */ - @Override - protected boolean canRead(BufferedInputStream inputStream) { - return magicBytesPresent(JFIF_MAGIC_BYTES, inputStream) - || magicBytesPresent(EXIF_MAGIC_BYTES, inputStream); - } - - /** - * {@inheritDoc} - */ - @Override - public IIOMetadata getImageMetadata(int var1) throws IOException { - //JFIF extension APP0 segment - byte[] app0 = {(byte) 0xFF, (byte) 0xE0}; - OptionalInt indexOfApp0 = indexOf(buffer, app0); - Float horizontal = null; - Float vertical = null; - - if (indexOfApp0.isPresent()) { - buffer.position(indexOfApp0.getAsInt() + 11); - int unit = Byte.toUnsignedInt(buffer.get()); - int xDensity = buffer.getShort(); - int yDensity = buffer.getShort(); - - // Pixel sizes - if (unit != 0) { - // 1 == dpi, 2 == dpc - float scale = (unit == 1) ? 25.4F : 10.0F; - horizontal = scale / xDensity; - vertical = scale / yDensity; - } - } - - buffer.rewind(); - return new IOMetadataImpl(horizontal, vertical); - } -} diff --git a/poishadow/src/main/java/org/dstadler/compat/PngReader.java b/poishadow/src/main/java/org/dstadler/compat/PngReader.java deleted file mode 100644 index a489fc61b..000000000 --- a/poishadow/src/main/java/org/dstadler/compat/PngReader.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.dstadler.compat; - -import org.apache.poi.java.awt.image.BufferedImage; -import org.apache.poi.javax.imageio.ImageReader; -import org.apache.poi.javax.imageio.metadata.IIOMetadata; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.util.OptionalInt; - -/** - * Image reader for PNG files. - */ -public class PngReader extends ImageReader { - /** - * Magic bytes for a PNG file. - */ - private final static byte[] PNG_MAGIC_BYTES = new byte[]{(byte) (137 & 0xFF), - (byte) (80 & 0xFF), (byte) (78 & 0xFF), (byte) (71 & 0xFF), (byte) (13 & 0xFF), - (byte) (10 & 0xFF), (byte) (26 & 0xFF), (byte) (10 & 0xFF)}; - - /** - * {@inheritDoc} - */ - @Override - public BufferedImage read(int imageIndex) { - //Move position to PNG header; 11.2.2 IHDR Image header - buffer.position(16); - int width = buffer.getInt(); - int height = buffer.getInt(); - buffer.rewind(); - - return new BufferedImage(width, height); - } - - /** - * Specific for PNG image files.

- * {@inheritDoc} - */ - @Override - protected boolean canRead(BufferedInputStream inputStream) { - return magicBytesPresent(PNG_MAGIC_BYTES, inputStream); - } - - /** - * {@inheritDoc} - */ - @Override - public IIOMetadata getImageMetadata(int var1) throws IOException { - //Find the pHYs chunk; 11.3.5.3 pHYs Physical pixel dimensions - byte[] physChunk = {'p', 'H', 'Y', 's'}; - OptionalInt indexOfPhys = indexOf(buffer, physChunk); - - int ppuX = 0; - int ppuY = 0; - //If the pHYs chunk is present, use the pixel sizes - if (indexOfPhys.isPresent()) { - buffer.position(indexOfPhys.getAsInt() + physChunk.length); - int ppuXValue = buffer.getInt(); - int ppuYValue = buffer.getInt(); - - //The following values are defined for the unit specifier: - // 0 = unit is unknown - // 1 = unit is the meter - int unit = Byte.toUnsignedInt(buffer.get()); - if (unit == 1) { - ppuX = ppuXValue; - ppuY = ppuYValue; - } - } - - buffer.rewind(); - Float horizontal = ppuX == 0 ? null : 1000.0F / ppuX; - Float vertical = ppuY == 0 ? null : 1000.0F / ppuY; - return new IOMetadataImpl(horizontal, vertical); - } -} diff --git a/poishadow/xmlbeans.patch b/poishadow/xmlbeans.patch deleted file mode 100644 index fdfcab262..000000000 --- a/poishadow/xmlbeans.patch +++ /dev/null @@ -1,79 +0,0 @@ ---- /tmp/xmlbeans-3.1.0/org/apache/xmlbeans/impl/store/Locale.java 2019-03-16 00:29:18.000000000 +0100 -+++ ./poishadow/src/main/java/org/apache/xmlbeans/impl/store/Locale.java 2021-10-06 15:43:45.279351109 +0200 -@@ -32,7 +32,6 @@ - import java.util.Map; - - import java.lang.ref.ReferenceQueue; --import java.lang.ref.Reference; - import java.lang.ref.PhantomReference; - import java.lang.ref.SoftReference; - -@@ -62,6 +61,8 @@ - import org.apache.xmlbeans.impl.common.XmlLocale; - import org.apache.xmlbeans.impl.common.ResolverUtil; - import org.apache.xmlbeans.impl.common.SystemCache; -+import org.apache.xmlbeans.impl.common.XBLogger; -+import org.apache.xmlbeans.impl.common.XBLogFactory; - - import org.apache.xmlbeans.impl.store.Saaj.SaajCallback; - -@@ -104,9 +105,19 @@ - import org.w3c.dom.NamedNodeMap; - import org.w3c.dom.Element; - -+/** -+ * This class is to replace Locale class within XMLBeans 3.x (bundled with POI 4.0.x and POI 4.1.x) -+ * that will crash in Android environment. -+ *

-+ * There ar two changes to avoid crash:
-+ * 1. Fix http://xml.org/sax/properties/declaration-handler error based on this commit
-+ * 2. Fix "namespace-prefix" is not supported when 'namespace' is enabled error. check source code line 3396. -+ */ - public final class Locale - implements DOMImplementation, SaajCallback, XmlLocale - { -+ private static final XBLogger logger = XBLogFactory.getLogger(Locale.class); -+ - static final int ROOT = Cur.ROOT; - static final int ELEM = Cur.ELEM; - static final int ATTR = Cur.ATTR; -@@ -193,7 +204,7 @@ - * This option is checked in XmlObjectBase._copy(XmlOptions), the locale is used as the synchronization domain. - * useNewLocale = true: copy will use a new locale, false: copy will use the same locale as the source - * @deprecated Replace usages with CopyUseNewSynchronizationDomain option -- * @see org.apache.xmlbeans.XmlOptions#setCopyUseNewSynchronizationDomain(boolean) -+ * @see XmlOptions#setCopyUseNewSynchronizationDomain(boolean) - */ - public static final String COPY_USE_NEW_LOCALE = "COPY_USE_NEW_LOCALE"; - -@@ -3381,14 +3392,12 @@ - - try - { -- _xr.setFeature( -- "http://xml.org/sax/features/namespace-prefixes", true); -+ //_xr.setFeature("http://xml.org/sax/features/namespace-prefixes", true); - _xr.setFeature("http://xml.org/sax/features/namespaces", true); - _xr.setFeature("http://xml.org/sax/features/validation", false); - _xr.setProperty( - "http://xml.org/sax/properties/lexical-handler", this); - _xr.setContentHandler(this); -- _xr.setProperty("http://xml.org/sax/properties/declaration-handler", this); - _xr.setDTDHandler(this); - _xr.setErrorHandler(this); - } -@@ -3396,6 +3405,14 @@ - { - throw new RuntimeException(e.getMessage(), e); - } -+ try -+ { -+ _xr.setProperty("http://xml.org/sax/properties/declaration-handler", this); -+ } -+ catch (Throwable e) -+ { -+ logger.log(XBLogger.WARN, "SAX Declaration Handler is not supported", e); -+ } - } - - void setEntityResolver(EntityResolver er) diff --git a/poitest/build.gradle b/poitest/build.gradle index 0bbd1d34c..a8dc1007f 100644 --- a/poitest/build.gradle +++ b/poitest/build.gradle @@ -2,22 +2,10 @@ apply plugin: 'com.android.application' dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4' - implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - // commons-text 1.8 fails due to Java 8 dependency - implementation 'org.apache.commons:commons-text:1.11.0' - // for unit-tests copied from Apache POI source, 1.64 did not work! - //implementation 'org.bouncycastle:bcpkix-jdk15on:1.59' - // there is a unit-tests executed in normal code currently... - implementation 'org.junit.vintage:junit-vintage-engine:5.10.1' - // newer versions of xmlsec are compiled with JDK 8 which does not work in Android Studio 2.x! - /*implementation ('org.apache.santuario:xmlsec:2.2.1') { - // break compilation because it includes stax-api which is under forbidden package 'javax.xml.stream' - exclude group: 'org.codehaus.woodstox' - }*/ - - implementation files('../poishadow/build/libs/poishadow-all.jar') + //implementation files('../poishadow/build/libs/poishadow-all.jar') + implementation 'org.apache.logging.log4j:log4j-core:2.22.0' // Testing-only dependencies androidTestImplementation 'androidx.test:core:1.5.0' @@ -28,15 +16,13 @@ dependencies { //androidTestImplementation 'org.hamcrest:hamcrest-library:2.2' } -preBuild.dependsOn ':poishadow:shadowJar' - android { compileSdkVersion 34 compileOptions { coreLibraryDesugaringEnabled true - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } defaultConfig { @@ -46,9 +32,6 @@ android { versionCode 4 versionName '5.2.5' - // Enabling multidex support. - multiDexEnabled true - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/poitest/src/androidTest/java/org/dstadler/poiandroidtest/poitest/ApplicationTest.java b/poitest/src/androidTest/java/org/dstadler/poiandroidtest/poitest/ApplicationTest.java index eb865466f..ff3e2de18 100644 --- a/poitest/src/androidTest/java/org/dstadler/poiandroidtest/poitest/ApplicationTest.java +++ b/poitest/src/androidTest/java/org/dstadler/poiandroidtest/poitest/ApplicationTest.java @@ -1,21 +1,12 @@ package org.dstadler.poiandroidtest.poitest; -import org.apache.commons.io.output.NullOutputStream; +import androidx.test.ext.junit.runners.AndroidJUnit4; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.dstadler.poiandroidtest.poitest.dummy.DummyContent; -import org.dstadler.poiandroidtest.poitest.test.TestIssue28; -import org.dstadler.poiandroidtest.poitest.test.TestIssue84; -import org.dstadler.poiandroidtest.poitest.test.TestIssue89; import org.junit.Test; import org.junit.runner.RunWith; -import java.io.IOException; - -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import static org.junit.Assert.fail; - /** * Testing Fundamentals */ @@ -23,39 +14,8 @@ public class ApplicationTest { private static final Logger LOG = LogManager.getLogger(ApplicationTest.class); - @Test - public void test() { - // just some very simple things to verify that testing works basically - DummyContent.addItem(new DummyContent.DummyItem("1", "bla", "some text")); - } - @Test public void testLog() { LOG.info("Testing..."); } - - @Test - public void test28() throws IOException { - TestIssue28.saveExcelFile(NullOutputStream.INSTANCE); - } - - @Test - public void test84() throws IOException { - try { - TestIssue84.saveExcelFile(NullOutputStream.INSTANCE); - fail("Usually throws an exception because there are missing AWT classes"); - } catch (NoClassDefFoundError e) { - // expected here - } - } - - @Test - public void test89() { - try { - TestIssue89.saveExcelFile(NullOutputStream.INSTANCE); - fail("Usually throws an exception because there are missing AWT classes"); - } catch (NoClassDefFoundError e) { - // expected here - } - } } diff --git a/poitest/src/main/java/org/apache/poi/poifs/crypt/TestSignatureInfo.java b/poitest/src/main/java/org/apache/poi/poifs/crypt/TestSignatureInfo.java deleted file mode 100644 index b5a2b92fe..000000000 --- a/poitest/src/main/java/org/apache/poi/poifs/crypt/TestSignatureInfo.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.apache.poi.poifs.crypt; - -import org.apache.poi.poifs.crypt.dsig.SignatureInfo; - -import static junit.framework.Assert.assertNotNull; - -public class TestSignatureInfo { - public void testConstruct() { - // simple test which just verifies that we can load the class and all dependent classes - // NOTE: this will currently crash because of missing classes - SignatureInfo info = new SignatureInfo(); - assertNotNull(info); - } -} diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/MainActivity.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/MainActivity.java index 2e29b19e0..a1eca0cfb 100644 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/MainActivity.java +++ b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/MainActivity.java @@ -1,398 +1,12 @@ package org.dstadler.poiandroidtest.poitest; import android.app.Activity; -import android.app.AlertDialog; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; -import android.os.ParcelFileDescriptor; -import android.widget.ArrayAdapter; -import android.widget.ListView; - -import org.apache.commons.io.output.CountingOutputStream; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.Version; -import org.apache.poi.common.usermodel.HyperlinkType; -import org.apache.poi.extractor.ExtractorFactory; -import org.apache.poi.extractor.POITextExtractor; -import org.apache.poi.hslf.usermodel.HSLFSlide; -import org.apache.poi.hslf.usermodel.HSLFSlideShow; -import org.apache.poi.poifs.crypt.TestSignatureInfo; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Hyperlink; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; -import org.apache.poi.xslf.usermodel.XMLSlideShow; -import org.apache.poi.xslf.usermodel.XSLFSlide; -import org.apache.poi.xssf.usermodel.DefaultIndexedColorMap; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFColor; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.poi.xwpf.usermodel.BreakType; -import org.apache.poi.xwpf.usermodel.Document; -import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.apache.poi.xwpf.usermodel.XWPFParagraph; -import org.apache.poi.xwpf.usermodel.XWPFRun; -import org.dstadler.poiandroidtest.poitest.dummy.DummyContent; -import org.dstadler.poiandroidtest.poitest.dummy.DummyItemWithCode; -import org.dstadler.poiandroidtest.poitest.test.TestIssue28; -import org.dstadler.poiandroidtest.poitest.test.TestIssue75; -import org.dstadler.poiandroidtest.poitest.test.TestIssue84; -import org.dstadler.poiandroidtest.poitest.test.TestIssue89; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; public class MainActivity extends Activity { - // Request code for creating a PDF document. - private static final int CREATE_DOCX_FILE = 2; - - private int idCount = 0; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - - // set some system-properties to instruct the code to use the fasterxml parsers - System.setProperty("org.apache.poi.javax.xml.stream.XMLInputFactory", "com.fasterxml.aalto.stax.InputFactoryImpl"); - System.setProperty("org.apache.poi.javax.xml.stream.XMLOutputFactory", "com.fasterxml.aalto.stax.OutputFactoryImpl"); - System.setProperty("org.apache.poi.javax.xml.stream.XMLEventFactory", "com.fasterxml.aalto.stax.EventFactoryImpl"); - - try { - // create all the list items - setupContent(); - - // populate the list - final ListView listview = findViewById(R.id.mylist); - final ArrayList list = new ArrayList<>(); - for (DummyContent.DummyItem item : DummyContent.ITEMS) { - list.add(item.toString()); - } - - final StableArrayAdapter adapter = new StableArrayAdapter(this, - android.R.layout.simple_list_item_1, list); - listview.setAdapter(adapter); - - listview.setOnItemClickListener((parent, view, position, id) -> { - // when an item is clicked, show a message-box with the resulting content - DummyContent.DummyItem content = DummyContent.ITEMS.get(position); - MessageBox box = new MessageBox(view.getContext()); - box.show(content.toString(), content.getLongContent()); - }); - - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - - public static class MessageBox { - final Context context; - - public MessageBox(Context context) { - this.context = context; - } - - void show(String title, String message) { - dialog = new AlertDialog.Builder(context) // Pass a reference to your main activity here - .setTitle(title) - .setMessage(message) - .setPositiveButton("OK", (dialogInterface, i) -> dialog.cancel()) - .show(); - } - - private AlertDialog dialog; - } - - private static class StableArrayAdapter extends ArrayAdapter { - HashMap mIdMap = new HashMap<>(); - - public StableArrayAdapter(Context context, int textViewResourceId, - List objects) { - super(context, textViewResourceId, objects); - for (int i = 0; i < objects.size(); ++i) { - mIdMap.put(objects.get(i), i); - } - } - - @Override - public long getItemId(int position) { - String item = getItem(position); - return mIdMap.get(item); - } - - @Override - public boolean hasStableIds() { - return true; - } - } - - private void writeWorkbook(String name) throws java.io.IOException { - try (Workbook wb = new XSSFWorkbook()) { - Sheet sheet = wb.createSheet("Sheet1"); - Row row = sheet.createRow(0); - Cell cell = row.createCell(0); - cell.setCellValue("cell-1"); - cell = row.createCell(1); - cell.setCellValue("cell-2"); - cell = row.createCell(2); - cell.setCellValue("cell-3"); - - XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle(); - style.setFillBackgroundColor(new XSSFColor( - new org.apache.poi.java.awt.Color(1, 2, 3), new DefaultIndexedColorMap())); - - Hyperlink link = wb.getCreationHelper().createHyperlink(HyperlinkType.URL); - link.setAddress("http://www.google.at"); - link.setLabel("Google"); - cell.setHyperlink(link); - - cell.setCellStyle(style); - - sheet.setPrintGridlines(true); - - try (OutputStream stream = openFileOutput(name, Context.MODE_PRIVATE)) { - wb.write(stream); - } - } - } - - private void setupContent() throws IOException { - writeWorkbook("test.xlsx"); - - int i = 0; - InputStream input = openFileInput("test.xlsx"); - try (Workbook wb = WorkbookFactory.create(input)) { - - // refresh the content as we re-enter here if the user navigates back from the detail view - DummyContent.initialize(); - - // replace the dummy-content to show that we could write and read the cell-values - Row row = wb.getSheetAt(0).getRow(0); - for (Map.Entry entry : DummyContent.ITEM_MAP.entrySet()) { - Cell cell = row.getCell(i); - entry.getValue().setContent(cell.getStringCellValue()); - - // read hyperlink back in and add it to the displayed text - Hyperlink hyperlink = cell.getHyperlink(); - if (hyperlink != null) { - entry.getValue().appendContent(hyperlink.getAddress()); - } - - i++; - } - } - - DummyContent.addItem(new DummyItemWithCode("v" + (idCount++), "POI Version", - () -> "Apache " + Version.getProduct() + " " + Version.getVersion())); - - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), - "DOCX with image", - () -> { - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); - intent.putExtra(Intent.EXTRA_TITLE, "DocWithImage.docx"); - - // Optionally, specify a URI for the directory that should be opened in - // the system file picker when your app creates the document. - //intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, "DocWithImage.docx"); - - startActivityForResult(intent, CREATE_DOCX_FILE); - - return "Writing to selected file"; - })); - - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test Callable", - () -> "This is the result from the callable")); - - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test Signature Info", - () -> { - TestSignatureInfo test = new TestSignatureInfo(); - test.testConstruct(); - return "Signature Info constructed successfully"; - })); - - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test Issue 28", () -> { - try (OutputStream outputStream = openFileOutput("issue28.xlsx", Context.MODE_PRIVATE)) { - TestIssue28.saveExcelFile(outputStream); - } - return "Issue 28 tested successfully"; - })); - - // reproducer for https://github.com/centic9/poi-on-android/issues/75 - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test resizing JPEG (#75)", () -> { - try (InputStream pictureStream = getResources().openRawResource(R.raw.logo); - CountingOutputStream outputStream = new CountingOutputStream(openFileOutput("issue75.xlsx", Context.MODE_PRIVATE))) { - TestIssue75.saveExcelFile(pictureStream, outputStream, Workbook.PICTURE_TYPE_JPEG); - - return "Issue 75 - XSSFWorkbook constructed successfully, wrote " + outputStream.getByteCount() + " bytes"; - } - })); - - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test resizing PNG (#75)", () -> { - try (InputStream pictureStream = getResources().openRawResource(R.raw.logo_png); - CountingOutputStream outputStream = new CountingOutputStream(openFileOutput("resizePng.xlsx", Context.MODE_PRIVATE))) { - TestIssue75.saveExcelFile(pictureStream, outputStream, Workbook.PICTURE_TYPE_PNG); - - return "Test resizing PNG file - XSSFWorkbook constructed successfully, wrote " + outputStream.getByteCount() + " bytes"; - } - })); - - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test resizing BMP (#75)", () -> { - try (InputStream pictureStream = getResources().openRawResource(R.raw.logo_bmp); - CountingOutputStream outputStream = new CountingOutputStream(openFileOutput("resizeBmp.xlsx", Context.MODE_PRIVATE))) { - TestIssue75.saveExcelFile(pictureStream, outputStream, Workbook.PICTURE_TYPE_DIB); - - return "Test resizing BMP file - XSSFWorkbook constructed successfully, wrote " + outputStream.getByteCount() + " bytes"; - } - })); - - // reproducer for https://github.com/centic9/poi-on-android/issues/84 - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test Issue 84 - Crashes!!", () -> { - try (OutputStream outputStream = openFileOutput("issue84.xlsx", Context.MODE_PRIVATE)) { - TestIssue84.saveExcelFile(outputStream); - } - - return "Issue 84 - XMLSlideShow constructed successfully"; - })); - - // reproducer for https://github.com/centic9/poi-on-android/issues/89 - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test Issue 89 - Crashes!!", () -> { - try (OutputStream outputStream = openFileOutput("issue89.xlsx", Context.MODE_PRIVATE)) { - TestIssue89.saveExcelFile(outputStream); - } - - return "Issue 89 - SXSSFWorkbook constructed successfully"; - })); - - // reproducer for https://github.com/centic9/poi-on-android/issues/98 - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test Issue 98", () -> { - StringBuilder text = new StringBuilder(); - for (int resource : new int[] { - R.raw.simple, - R.raw.sample2, - R.raw.sample, - R.raw.lorem_ipsum, - } ) { - try (InputStream pictureStream = getResources().openRawResource(resource); - POITextExtractor extractor = ExtractorFactory.createExtractor(pictureStream)) { - - text.append("\nResource-").append(resource).append(": ").append(extractor.getText()); - } - } - return "Issue 98 - Had text: " + text; - })); - - // reproducer for https://github.com/centic9/poi-on-android/issues/103 - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "Test Issue 103", () -> { - try (InputStream inputStream = getResources().openRawResource(R.raw.sample); - XMLSlideShow slideShow = new XMLSlideShow(inputStream)) { - - return "Issue 103 - XMLSlideShow constructed successfully: " + slideShow.getSlides().size(); - } - })); - - try (InputStream docFile = getResources().openRawResource(R.raw.lorem_ipsum)) { - XWPFDocument doc = new XWPFDocument(docFile); - try { - for(XWPFParagraph paragraph : doc.getParagraphs()) { - String content = StringUtils.abbreviate(paragraph.getText(), 20); - if(StringUtils.isEmpty(content)) { - content = ""; - } - DummyContent.addItem(new DummyContent.DummyItem("z" + i, content, paragraph.getText())); - i++; - } - - final XWPFParagraph title = doc.createParagraph(); - final XWPFRun titleRun = title.createRun(); - titleRun.setCharacterSpacing(2); - FileOutputStream stream = openFileOutput("test.docx", Context.MODE_PRIVATE); - try { - doc.write(stream); - } finally { - stream.close(); - } - - int sheetCount = doc.getProperties().getExtendedProperties().getPages(); - - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), "SheetCount " + sheetCount, - () -> "Called")); - } finally { - doc.close(); - } - } - - try (InputStream slidesFile = getResources().openRawResource(R.raw.sample)) { - try (XMLSlideShow slides = new XMLSlideShow(slidesFile)) { - for (XSLFSlide slide : slides.getSlides()) { - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), - "Slide - " + slide.getSlideName(), - slide::getTitle)); - } - } - } - - try (InputStream slidesFile = getResources().openRawResource(R.raw.sample2)) { - try (HSLFSlideShow slides = new HSLFSlideShow(slidesFile)) { - for (HSLFSlide slide : slides.getSlides()) { - DummyContent.addItem(new DummyItemWithCode("c" + (idCount++), - "Slide - " + slide.getSlideName(), - slide::getTitle)); - } - } - } - } - - // Copied from Apache POI Utils class to not require code from java.awt - public static int toEMU(double points) { - return (int)Math.rint(12700.0D * points); - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent resultData) { - if (requestCode == CREATE_DOCX_FILE - && resultCode == Activity.RESULT_OK) { - // The result data contains a URI for the document or directory that - // the user selected. - if (resultData != null) { - Uri uri = resultData.getData(); - // Perform operations on the document using its URI. - - try (InputStream docFile = getResources().openRawResource(R.raw.lorem_ipsum)) { - XWPFDocument doc = new XWPFDocument(docFile); - - try (InputStream pictureStream = getResources().openRawResource(R.raw.logo)) { - XWPFParagraph p = doc.createParagraph(); - - XWPFRun r = p.createRun(); - r.setText("logo.jpg"); - r.addBreak(); - r.addPicture(pictureStream, Document.PICTURE_TYPE_JPEG, - "logo.jpg", toEMU(200), - toEMU(200)); // 200x200 pixels - r.addBreak(BreakType.PAGE); - } - - try (ParcelFileDescriptor docx = getContentResolver().openFileDescriptor(uri, "w")) { - try (OutputStream outputStream = new FileOutputStream(docx.getFileDescriptor())) { - doc.write(outputStream); - } - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - } } } diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyContent.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyContent.java deleted file mode 100644 index babbb2d3c..000000000 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyContent.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.dstadler.poiandroidtest.poitest.dummy; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Helper class for providing sample content for user interfaces created by - * Android template wizards. - *

- */ -public class DummyContent { - - /** - * An array of sample (dummy) items. - */ - public static List ITEMS = new ArrayList<>(); - - /** - * A map of sample (dummy) items, by ID. - */ - public static Map ITEM_MAP = new HashMap<>(); - - static { - initialize(); - } - - public static void initialize() { - DummyContent.ITEM_MAP.clear(); - DummyContent.ITEMS.clear(); - - // Add 3 sample items. - addItem(new DummyItem("l1", "Item 1", "Long Item 1")); - addItem(new DummyItem("l2", "Item 2", "Long Item 2")); - addItem(new DummyItem("l3", "Item 3", "Long Item 3")); - } - - public static void addItem(DummyItem item) { - ITEMS.add(item); - ITEM_MAP.put(item.id, item); - } - - /** - * A dummy item representing a piece of content. - */ - public static class DummyItem { - private final String id; - private String content; - private final String longContent; - - public DummyItem(String id, String content, String longContent) { - this.id = id; - this.content = content; - this.longContent = longContent; - } - - public void setContent(String content) { - this.content = content; - } - - public void appendContent(String content) { - this.content += " - " + content; - } - - public String getId() { - return id; - } - - public String getLongContent() { - return longContent; - } - - @Override - public String toString() { - return content; - } - } - -} diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyItemWithCode.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyItemWithCode.java deleted file mode 100644 index 142399ed9..000000000 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/dummy/DummyItemWithCode.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.dstadler.poiandroidtest.poitest.dummy; - -import org.apache.commons.lang3.exception.ExceptionUtils; - -import java.util.concurrent.Callable; - -public class DummyItemWithCode extends DummyContent.DummyItem { - private final Callable callable; - - public DummyItemWithCode(String id, String content, Callable callable) { - super(id, content, null); - this.callable = callable; - } - - @Override - public String getLongContent() { - try { - return callable.call(); - } catch (Exception e) { - return ExceptionUtils.getStackTrace(e); - } - } -} diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue28.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue28.java deleted file mode 100644 index 1d41ff11b..000000000 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue28.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.dstadler.poiandroidtest.poitest.test; - -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.IndexedColors; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; - -import java.io.IOException; -import java.io.OutputStream; - -public class TestIssue28 { - public static void saveExcelFile(OutputStream outputStream) throws IOException { - - try (Workbook wb = new HSSFWorkbook()) { - - CellStyle cs = wb.createCellStyle(); - cs.setFillForegroundColor(IndexedColors.LIME.getIndex()); - - Sheet sheet1 = wb.createSheet("work"); - - Row row = sheet1.createRow(0); - Cell c = row.createCell(0); - c.setCellValue("Name"); - c.setCellStyle(cs); - c = row.createCell(1); - c = row.createCell(2); - c.setCellValue("M"); - c.setCellStyle(cs); - c = row.createCell(3); - c.setCellValue("A"); - c.setCellStyle(cs); - c = row.createCell(4); - c.setCellValue("E"); - c.setCellStyle(cs); - int rowOne = 1; - - final Row row1 = sheet1.createRow(rowOne); - Cell cell1 = row1.createCell(0); - cell1.setCellValue("Name"); - cell1 = row1.createCell(1); - cell1.setCellValue("Morning"); - cell1 = row1.createCell(2); - cell1.setCellValue("Afternoon"); - cell1 = row1.createCell(3); - cell1.setCellValue("Evening"); - - sheet1.setColumnWidth(2, (15 * 500)); - - wb.write(outputStream); - } - } -} diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue75.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue75.java deleted file mode 100644 index e2a744a3e..000000000 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue75.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.dstadler.poiandroidtest.poitest.test; - -import org.apache.poi.ss.usermodel.ClientAnchor; -import org.apache.poi.ss.usermodel.CreationHelper; -import org.apache.poi.ss.usermodel.Drawing; -import org.apache.poi.ss.usermodel.Picture; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.util.IOUtils; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -public class TestIssue75 { - public static void saveExcelFile(InputStream picture, OutputStream outputStream, int workBookPictureType) throws IOException { - try (Workbook workbook = new XSSFWorkbook()) { - - CreationHelper helper = workbook.getCreationHelper(); - Sheet sheet = workbook.createSheet("Sheet 1"); - Drawing drawing = sheet.createDrawingPatriarch(); - - ClientAnchor anchor = helper.createClientAnchor(); - anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE); - int pictureIndex = workbook.addPicture(IOUtils.toByteArray(picture), workBookPictureType); - - anchor.setCol1(0); - anchor.setRow1(2); - anchor.setRow2(3); - anchor.setCol2(1); - Picture pict = drawing.createPicture(anchor, pictureIndex); - pict.resize(); - - workbook.write(outputStream); - } - } -} diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue84.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue84.java deleted file mode 100644 index 5601ae66c..000000000 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue84.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.dstadler.poiandroidtest.poitest.test; - -import org.apache.poi.java.awt.Color; -import org.apache.poi.xslf.usermodel.XMLSlideShow; -import org.apache.poi.xslf.usermodel.XSLFSlide; -import org.apache.poi.xslf.usermodel.XSLFTextBox; -import org.apache.poi.xslf.usermodel.XSLFTextParagraph; -import org.apache.poi.xslf.usermodel.XSLFTextRun; - -import java.io.IOException; -import java.io.OutputStream; - -public class TestIssue84 { - public static void saveExcelFile(OutputStream outputStream) throws IOException { - try (XMLSlideShow ppt = new XMLSlideShow()) { - XSLFSlide slide = ppt.createSlide(); - XSLFTextBox shape = slide.createTextBox(); - XSLFTextParagraph p = shape.addNewTextParagraph(); - XSLFTextRun r1 = p.addNewTextRun(); - r1.setText("The"); - r1.setFontColor(Color.blue); - r1.setFontSize(24.0); - - ppt.write(outputStream); - } - } -} diff --git a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue89.java b/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue89.java deleted file mode 100644 index 1c2038175..000000000 --- a/poitest/src/main/java/org/dstadler/poiandroidtest/poitest/test/TestIssue89.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.dstadler.poiandroidtest.poitest.test; - -import org.apache.poi.common.usermodel.HyperlinkType; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Hyperlink; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.xssf.streaming.SXSSFWorkbook; -import org.apache.poi.xssf.usermodel.DefaultIndexedColorMap; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFColor; - -import java.io.OutputStream; - -public class TestIssue89 { - public static void saveExcelFile(OutputStream outputStream) { - try (Workbook wb1 = new SXSSFWorkbook(100)) { - Sheet sheet = wb1.createSheet("Sheet1"); - Row row1 = sheet.createRow(0); - Cell cell = row1.createCell(0); - cell.setCellValue("cell-1"); - cell = row1.createCell(1); - cell.setCellValue("cell-2"); - cell = row1.createCell(2); - cell.setCellValue("cell-3"); - - XSSFCellStyle style = (XSSFCellStyle) wb1.createCellStyle(); - style.setFillBackgroundColor(new XSSFColor(new org.apache.poi.java.awt.Color(1, 2, 3), new DefaultIndexedColorMap())); - - Hyperlink link = wb1.getCreationHelper().createHyperlink(HyperlinkType.URL); - link.setAddress("http://www.google.at"); - link.setLabel("Google"); - cell.setHyperlink(link); - - cell.setCellStyle(style); - - sheet.setPrintGridlines(true); - - wb1.write(outputStream); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } -} diff --git a/settings.gradle b/settings.gradle index 56c4f3021..56386ee52 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,3 @@ pluginManagement { } include ':poitest' -include ':poishadow' \ No newline at end of file