From b35e6d5bf0cc90430b12b4e70ffe21c8fede0574 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 20 Aug 2008 18:50:15 +0000 Subject: [PATCH] More HPBF stuff, and some tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@687423 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/apache/poi/hpbf/HPBFDocument.java | 32 +++++++- .../apache/poi/hpbf/model/EscherDelayStm.java | 35 ++++++++ .../org/apache/poi/hpbf/model/EscherPart.java | 81 +++++++++++++++++++ .../org/apache/poi/hpbf/model/EscherStm.java | 35 ++++++++ .../org/apache/poi/hpbf/model/HPBFPart.java | 25 ++++++ .../apache/poi/hpbf/model/MainContents.java | 5 ++ .../apache/poi/hpbf/model/QuillContents.java | 5 ++ .../org/apache/poi/hpbf/TestHPBFDocument.java | 60 ++++++++++++++ 8 files changed, 275 insertions(+), 3 deletions(-) create mode 100644 src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java create mode 100644 src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java create mode 100644 src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java create mode 100644 src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java diff --git a/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java b/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java index 9b72a884d1..32880a0125 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java @@ -18,9 +18,12 @@ package org.apache.poi.hpbf; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import org.apache.poi.POIDocument; +import org.apache.poi.hpbf.model.EscherDelayStm; +import org.apache.poi.hpbf.model.EscherStm; import org.apache.poi.hpbf.model.MainContents; import org.apache.poi.hpbf.model.QuillContents; import org.apache.poi.poifs.filesystem.DirectoryNode; @@ -34,6 +37,8 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; public class HPBFDocument extends POIDocument { private MainContents mainContents; private QuillContents quillContents; + private EscherStm escherStm; + private EscherDelayStm escherDelayStm; /** * Opens a new publisher document @@ -41,6 +46,9 @@ public class HPBFDocument extends POIDocument { public HPBFDocument(POIFSFileSystem fs) throws IOException { this(fs.getRoot(), fs); } + public HPBFDocument(InputStream inp) throws IOException { + this(new POIFSFileSystem(inp)); + } /** * Opens an embeded publisher document, @@ -54,12 +62,24 @@ public class HPBFDocument extends POIDocument { try { mainContents = new MainContents(dir); } catch(FileNotFoundException e) { - throw new IllegalArgumentException("File invalid - missing required main Contents part"); + 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"); + throw new IllegalArgumentException("File invalid - missing required Quill CONTENTS part", e); + } + + // 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); } } @@ -69,7 +89,13 @@ public class HPBFDocument extends POIDocument { public QuillContents getQuillContents() { return quillContents; } - + public EscherStm getEscherStm() { + return escherStm; + } + public EscherDelayStm getEscherDelayStm() { + return escherDelayStm; + } + public void write(OutputStream out) throws IOException { throw new IllegalStateException("Writing is not yet implemented, see http://poi.apache.org/hpbf/"); } diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java new file mode 100644 index 0000000000..08ce4a5f6c --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java @@ -0,0 +1,35 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + 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 String[] getPath() { + return new String[] { + "Escher", "EscherDelayStm" + }; + } +} diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java new file mode 100644 index 0000000000..c99c64fa07 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java @@ -0,0 +1,81 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + 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; + +import org.apache.poi.ddf.DefaultEscherRecordFactory; +import org.apache.poi.ddf.EscherRecord; +import org.apache.poi.poifs.filesystem.DirectoryNode; + +/** + * Parent class of all Escher parts + */ +public abstract class EscherPart extends HPBFPart { + private EscherRecord[] records; + + /** + * Creates the Escher Part, and finds our child + * escher records + */ + public EscherPart(DirectoryNode baseDir) throws FileNotFoundException, + IOException { + super(baseDir); + + // Now create our Escher children + DefaultEscherRecordFactory erf = + new DefaultEscherRecordFactory(); + + ArrayList ec = new ArrayList(); + int left = data.length; + while(left > 0) { + EscherRecord er = erf.createRecord(data, 0); + er.fillFields(data, 0, erf); + left -= er.getRecordSize(); + + ec.add(er); + } + + records = (EscherRecord[]) + ec.toArray(new EscherRecord[ec.size()]); + } + + public EscherRecord[] getEscherRecords() { + return records; + } + + /** + * Serialises our Escher children back + * into bytes. + */ + protected void generateData() { + int size = 0; + for(int i=0; i 0); + assertTrue(doc.getQuillContents().getData().length > 0); + assertTrue(doc.getEscherStm().getData().length > 0); + assertTrue(doc.getEscherDelayStm().getData().length == 0); + } + + // TODO +// public void testWrite() throws Exception { +// } +} -- 2.39.5