poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r687423 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hpbf/ src/org/apache/poi/hpbf/model/ testcases/org/apache/poi/hpbf/
Date Wed, 20 Aug 2008 18:50:16 GMT
Author: nick
Date: Wed Aug 20 11:50:15 2008
New Revision: 687423

URL: http://svn.apache.org/viewvc?rev=687423&view=rev
Log:
More HPBF stuff, and some tests

Added:
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java   (with props)
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java   (with props)
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java   (with props)
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java   (with props)
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java?rev=687423&r1=687422&r2=687423&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java Wed Aug 20 11:50:15
2008
@@ -18,9 +18,12 @@
 
 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 @@
 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 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 @@
 		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 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/");
 	}

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java?rev=687423&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java Wed Aug 20
11:50:15 2008
@@ -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"
+		};
+	}
+}

Propchange: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherDelayStm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java?rev=687423&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java Wed Aug 20 11:50:15
2008
@@ -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<records.length; i++) {
+			size += records[i].getRecordSize(); 
+		}
+		
+		data = new byte[size];
+		size = 0;
+		for(int i=0; i<records.length; i++) {
+			int thisSize = 
+				records[i].serialize(size, data);
+			size += thisSize;
+		}
+	}
+}

Propchange: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java?rev=687423&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java Wed Aug 20 11:50:15
2008
@@ -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 EscherStm extends EscherPart {
+	public EscherStm(DirectoryNode baseDir) throws FileNotFoundException,
+			IOException {
+		super(baseDir);
+	}
+
+	public String[] getPath() {
+		return new String[] {
+				"Escher", "EscherStm"
+		};
+	}
+}

Propchange: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/EscherStm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java?rev=687423&r1=687422&r2=687423&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java Wed Aug 20 11:50:15
2008
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.hpbf.model;
 
+import java.io.ByteArrayInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 
@@ -51,10 +52,34 @@
 	}
 	
 	public void writeOut(DirectoryNode baseDir) throws IOException {
+		String[] path = getPath();
 		
+		// Ensure that all parent directories exist
+		DirectoryNode dir = baseDir;
+		for(int i=0; i<path.length-1; i++) {
+			try {
+				dir = (DirectoryNode)dir.getEntry(path[i]);
+			} catch(FileNotFoundException e) {
+				dir.createDirectory(path[i]);
+			}
+		}
+		
+		// Update the byte array with the latest data
+		generateData();
+		
+		// Write out
+		ByteArrayInputStream bais = new ByteArrayInputStream(data);
+		dir.createDocument(path[path.length-1], bais);
 	}
 	
 	/**
+	 * Called just before writing out, to trigger
+	 *  the data byte array to be updated with the
+	 *  latest contents.
+	 */
+	protected abstract void generateData();
+	
+	/**
 	 * Returns the raw data that makes up
 	 *  this document part.
 	 */

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java?rev=687423&r1=687422&r2=687423&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/MainContents.java Wed Aug 20 11:50:15
2008
@@ -33,4 +33,9 @@
 	public String[] getPath() {
 		return new String[] { "Contents" };
 	}
+
+	protected void generateData() {
+		// We don't parse the contents, so
+		//  nothing will have changed
+	}
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java?rev=687423&r1=687422&r2=687423&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java Wed Aug 20 11:50:15
2008
@@ -32,6 +32,11 @@
 		// Now parse the first 512 bytes, and produce
 		//  all our bits
 	}
+	
+	protected void generateData() {
+		// TODO
+		throw new IllegalStateException("Not done yet!");
+	}
 
 	public String[] getPath() {
 		return new String[] {

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java?rev=687423&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java Wed Aug 20
11:50:15 2008
@@ -0,0 +1,60 @@
+/* ====================================================================
+   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.File;
+import java.io.FileInputStream;
+
+import junit.framework.TestCase;
+
+public class TestHPBFDocument extends TestCase {
+	private String dir;
+
+	protected void setUp() throws Exception {
+		dir = System.getProperty("HPBF.testdata.path");
+	}
+
+	public void testOpen() throws Exception {
+		File f = new File(dir, "Sample.pub");
+		HPBFDocument doc = new HPBFDocument(
+				new FileInputStream(f)
+		);
+		
+		assertNotNull(doc);
+	}
+	
+	public void testBits() throws Exception {
+		File f = new File(dir, "Sample.pub");
+		HPBFDocument doc = new HPBFDocument(
+				new FileInputStream(f)
+		);
+
+		assertNotNull(doc.getMainContents());
+		assertNotNull(doc.getQuillContents());
+		assertNotNull(doc.getEscherStm());
+		assertNotNull(doc.getEscherDelayStm());
+		
+		assertTrue(doc.getMainContents().getData().length > 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 {
+//	}
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hpbf/TestHPBFDocument.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message