From cfe2045c5d871d86a1e7fed2d5f21e6b7a2c5180 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 20 Aug 2008 18:14:11 +0000 Subject: [PATCH] Make an initial start on hpbf code git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@687403 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/apache/poi/hpbf/HPBFDocument.java | 76 +++++++++++++++++++ .../org/apache/poi/hpbf/model/HPBFPart.java | 68 +++++++++++++++++ .../apache/poi/hpbf/model/MainContents.java | 36 +++++++++ .../apache/poi/hpbf/model/QuillContents.java | 41 ++++++++++ 4 files changed, 221 insertions(+) create mode 100644 src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java create mode 100644 src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java create mode 100644 src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java create mode 100644 src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java diff --git a/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java b/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java new file mode 100644 index 000000000..9b72a884d --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java @@ -0,0 +1,76 @@ +/* ==================================================================== + 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; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.poi.POIDocument; +import org.apache.poi.hpbf.model.MainContents; +import org.apache.poi.hpbf.model.QuillContents; +import org.apache.poi.poifs.filesystem.DirectoryNode; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; + +/** + * This class provides the basic functionality + * for HPBF, our implementation of the publisher + * file format. + */ +public class HPBFDocument extends POIDocument { + private MainContents mainContents; + private QuillContents quillContents; + + /** + * Opens a new publisher document + */ + public HPBFDocument(POIFSFileSystem fs) throws IOException { + this(fs.getRoot(), fs); + } + + /** + * Opens an embeded publisher document, + * at the given directory. + */ + public HPBFDocument(DirectoryNode dir, POIFSFileSystem fs) throws IOException { + super(dir, fs); + + // 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"); + } + try { + quillContents = new QuillContents(dir); + } catch(FileNotFoundException e) { + throw new IllegalArgumentException("File invalid - missing required Quill CONTENTS part"); + } + } + + public MainContents getMainContents() { + return mainContents; + } + public QuillContents getQuillContents() { + return quillContents; + } + + 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/HPBFPart.java b/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java new file mode 100644 index 000000000..4183b98e8 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java @@ -0,0 +1,68 @@ +/* ==================================================================== + 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; +import org.apache.poi.poifs.filesystem.DocumentEntry; + +/** + * Parent class of all HPBF sub-parts, handling + * the fiddly reading in / writing out bits + * for all of them. + */ +public abstract class HPBFPart { + protected byte[] data; + + public HPBFPart(DirectoryNode baseDir) throws FileNotFoundException, IOException { + String[] path = getPath(); + DirectoryNode dir = getDir(path, baseDir); + String name = path[path.length-1]; + + DocumentEntry docProps = + (DocumentEntry)dir.getEntry(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 { + DirectoryNode dir = baseDir; + for(int i=0; i QuillSub -> CONTENTS + */ +public class QuillContents extends HPBFPart { + public QuillContents(DirectoryNode baseDir) + throws FileNotFoundException, IOException { + super(baseDir); + + // Now parse the first 512 bytes, and produce + // all our bits + } + + public String[] getPath() { + return new String[] { + "Quill", "QuillSub", "CONTENTS" + }; + } +}