From: Josh Micich Date: Mon, 25 Aug 2008 07:56:37 +0000 (+0000) Subject: JDK 1.4 fixes for new hpbf stuff. Some clean-up X-Git-Tag: REL_3_2_FINAL~139 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3277d492ddfc0f103f21ce55344e45e9f64fc0c3;p=poi.git JDK 1.4 fixes for new hpbf stuff. Some clean-up git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@688642 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java b/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java index 32880a0125..49de0d0876 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hpbf; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -34,7 +34,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; * for HPBF, our implementation of the publisher * file format. */ -public class HPBFDocument extends POIDocument { +public final class HPBFDocument extends POIDocument { private MainContents mainContents; private QuillContents quillContents; private EscherStm escherStm; @@ -59,28 +59,12 @@ public class HPBFDocument extends POIDocument { // Go looking for our interesting child // streams - try { - mainContents = new MainContents(dir); - } catch(FileNotFoundException e) { - throw new IllegalArgumentException("File invalid - missing required main Contents part", e); - } - try { - quillContents = new QuillContents(dir); - } catch(FileNotFoundException e) { - throw new IllegalArgumentException("File invalid - missing required Quill CONTENTS part", e); - } + mainContents = new MainContents(dir); + quillContents = new QuillContents(dir); // Now the Escher bits - try { - escherStm = new EscherStm(dir); - } catch(FileNotFoundException e) { - throw new IllegalArgumentException("File invalid - missing required EscherStm part", e); - } - try { - escherDelayStm = new EscherDelayStm(dir); - } catch(FileNotFoundException e) { - throw new IllegalArgumentException("File invalid - missing required EscherDelayStm part", e); - } + escherStm = new EscherStm(dir); + escherDelayStm = new EscherDelayStm(dir); } public MainContents getMainContents() { diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java index 08ce4a5f6c..032484626e 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java @@ -14,22 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hpbf.model; -import java.io.FileNotFoundException; import java.io.IOException; import org.apache.poi.poifs.filesystem.DirectoryNode; -public class EscherDelayStm extends EscherPart { - public EscherDelayStm(DirectoryNode baseDir) throws FileNotFoundException, - IOException { - super(baseDir); - } +public final class EscherDelayStm extends EscherPart { + private static final String[] PATH = { "Escher", "EscherDelayStm", }; - public String[] getPath() { - return new String[] { - "Escher", "EscherDelayStm" - }; + public EscherDelayStm(DirectoryNode baseDir) throws IOException { + super(baseDir, PATH); } } diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java index c99c64fa07..00e685f8f2 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hpbf.model; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; @@ -34,9 +34,8 @@ public abstract class EscherPart extends HPBFPart { * Creates the Escher Part, and finds our child * escher records */ - public EscherPart(DirectoryNode baseDir) throws FileNotFoundException, - IOException { - super(baseDir); + public EscherPart(DirectoryNode baseDir, String[] parts) throws IOException { + super(baseDir, parts); // Now create our Escher children DefaultEscherRecordFactory erf = diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java index ac41127393..2ed79ea341 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java @@ -14,22 +14,16 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ + package org.apache.poi.hpbf.model; -import java.io.FileNotFoundException; import java.io.IOException; import org.apache.poi.poifs.filesystem.DirectoryNode; -public class EscherStm extends EscherPart { - public EscherStm(DirectoryNode baseDir) throws FileNotFoundException, - IOException { - super(baseDir); - } - - public String[] getPath() { - return new String[] { - "Escher", "EscherStm" - }; +public final class EscherStm extends EscherPart { + private static final String[] PATH = { "Escher", "EscherStm", }; + public EscherStm(DirectoryNode baseDir) throws IOException { + super(baseDir, PATH); } } diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java b/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java index e25d98be97..9db15c6642 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java @@ -30,23 +30,35 @@ import org.apache.poi.poifs.filesystem.DocumentEntry; */ public abstract class HPBFPart { protected byte[] data; - - public HPBFPart(DirectoryNode baseDir) throws FileNotFoundException, IOException { - String[] path = getPath(); + /** + * @param path the path to the part, eg Contents or Quill, QuillSub, CONTENTS + */ + public HPBFPart(DirectoryNode baseDir, String[] path) throws IOException { + DirectoryNode dir = getDir(path, baseDir); String name = path[path.length-1]; - DocumentEntry docProps = - (DocumentEntry)dir.getEntry(name); + DocumentEntry docProps; + try { + docProps = (DocumentEntry)dir.getEntry(name); + } catch (FileNotFoundException e) { + throw new IllegalArgumentException("File invalid - failed to find document entry '" + + name + "'"); + } // Grab the data from the part stream data = new byte[docProps.getSize()]; dir.createDocumentInputStream(name).read(data); } - private DirectoryNode getDir(String[] path, DirectoryNode baseDir) throws FileNotFoundException { + private DirectoryNode getDir(String[] path, DirectoryNode baseDir) { DirectoryNode dir = baseDir; for(int i=0; i QuillSub -> CONTENTS */ -public class QuillContents extends HPBFPart { +public final class QuillContents extends HPBFPart { + private static final String[] PATH = { "Quill", "QuillSub", "CONTENTS", }; private QCBit[] bits; - public QuillContents(DirectoryNode baseDir) - throws FileNotFoundException, IOException { - super(baseDir); + public QuillContents(DirectoryNode baseDir) throws IOException { + super(baseDir, PATH); // Now parse the first 512 bytes, and produce // all our bits @@ -85,10 +84,4 @@ public class QuillContents extends HPBFPart { // TODO throw new IllegalStateException("Not done yet!"); } - - public String[] getPath() { - return new String[] { - "Quill", "QuillSub", "CONTENTS" - }; - } }