You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by ni...@apache.org on 2007/01/17 19:09:26 UTC
svn commit: r497107 - in /jakarta/poi/trunk/src/scratchpad:
src/org/apache/poi/hslf/record/ testcases/org/apache/poi/hslf/record/
Author: nick
Date: Wed Jan 17 10:09:24 2007
New Revision: 497107
URL: http://svn.apache.org/viewvc?view=rev&rev=497107
Log:
Add ExObjList support
Added:
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java
Modified:
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java
jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java
jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java
Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java?view=diff&rev=497107&r1=497106&r2=497107
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Document.java Wed Jan 17 10:09:24 2007
@@ -39,6 +39,7 @@
private Environment environment;
private PPDrawingGroup ppDrawing;
private SlideListWithText[] slwts;
+ private ExObjList exObjList; // Can be null
/**
* Returns the DocumentAtom of this Document
@@ -54,6 +55,12 @@
* that contains information on pictures in the slides.
*/
public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; }
+ /**
+ * Returns the ExObjList, which holds the references to
+ * external objects used in the slides. This may be null, if
+ * there are no external references.
+ */
+ public ExObjList getExObjList() { return exObjList; }
/**
* Returns all the SlideListWithTexts that are defined for
@@ -115,6 +122,9 @@
}
if(_children[i] instanceof PPDrawingGroup) {
ppDrawing = (PPDrawingGroup)_children[i];
+ }
+ if(_children[i] instanceof ExObjList) {
+ exObjList = (ExObjList)_children[i];
}
}
Added: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java?view=auto&rev=497107
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java (added)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java Wed Jan 17 10:09:24 2007
@@ -0,0 +1,112 @@
+/*
+* 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.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * This class holds the links to exernal objects referenced
+ * from the document.
+ * @author Nick Burch
+ */
+public class ExObjList extends RecordContainer {
+ private byte[] _header;
+ private static long _type = 1033;
+
+ // Links to our more interesting children
+ private ExObjListAtom exObjListAtom;
+
+ /**
+ * Returns the ExObjListAtom of this list
+ */
+ public ExObjListAtom getExObjListAtom() { return exObjListAtom; }
+
+ /**
+ * Returns all the ExHyperlinks
+ */
+ public ExHyperlink[] getExHyperlinks() {
+ ArrayList links = new ArrayList();
+ for(int i=0; i<_children.length; i++) {
+ if(_children[i] instanceof ExHyperlink) {
+ links.add(_children[i]);
+ }
+ }
+
+ return (ExHyperlink[])links.toArray(new ExHyperlink[links.size()]);
+ }
+
+ /**
+ * Set things up, and find our more interesting children
+ */
+ protected ExObjList(byte[] source, int start, int len) {
+ // Grab the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Find our children
+ _children = Record.findChildRecords(source,start+8,len-8);
+ findInterestingChildren();
+ }
+
+ /**
+ * Go through our child records, picking out the ones that are
+ * interesting, and saving those for use by the easy helper
+ * methods.
+ */
+ private void findInterestingChildren() {
+ // First child should be the atom
+ if(_children[0] instanceof ExObjListAtom) {
+ exObjListAtom = (ExObjListAtom)_children[0];
+ } else {
+ throw new IllegalStateException("First child record wasn't a ExObjListAtom, was of type " + _children[0].getRecordType());
+ }
+ }
+
+ /**
+ * Create a new ExObjList, with blank fields
+ */
+ public ExObjList() {
+ _header = new byte[8];
+ _children = new Record[1];
+
+ // Setup our header block
+ _header[0] = 0x0f; // We are a container record
+ LittleEndian.putShort(_header, 2, (short)_type);
+
+ // Setup our child records
+ _children[0] = new ExObjListAtom();
+ findInterestingChildren();
+ }
+
+ /**
+ * We are of type 1033
+ */
+ public long getRecordType() { return _type; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ writeOut(_header[0],_header[1],_type,_children,out);
+ }
+
+}
Added: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java?view=auto&rev=497107
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java (added)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java Wed Jan 17 10:09:24 2007
@@ -0,0 +1,114 @@
+/* ====================================================================
+ 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.hslf.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * Tne atom that holds the seed info used by a ExObjList
+ *
+ * @author Nick Burch
+ */
+
+public class ExObjListAtom extends RecordAtom
+{
+ /**
+ * Record header.
+ */
+ private byte[] _header;
+
+ /**
+ * Record data.
+ */
+ private byte[] _data;
+
+ /**
+ * Constructs a brand new link related atom record.
+ */
+ protected ExObjListAtom() {
+ _header = new byte[8];
+ _data = new byte[4];
+
+ LittleEndian.putShort(_header, 2, (short)getRecordType());
+ LittleEndian.putInt(_header, 4, _data.length);
+
+ // It is fine for the other values to be zero
+ }
+
+ /**
+ * Constructs the link related atom record from its
+ * source data.
+ *
+ * @param source the source data as a byte array.
+ * @param start the start offset into the byte array.
+ * @param len the length of the slice in the byte array.
+ */
+ protected ExObjListAtom(byte[] source, int start, int len) {
+ // Get the header.
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Get the record data.
+ _data = new byte[len-8];
+ System.arraycopy(source,start+8,_data,0,len-8);
+
+ // Must be at least 4 bytes long
+ if(_data.length < 4) {
+ throw new IllegalArgumentException("The length of the data for a ExObjListAtom must be at least 4 bytes, but was only " + _data.length);
+ }
+ }
+
+ /**
+ * Gets the object ID seed, which will be used as the unique
+ * OLE identifier for the next OLE object added
+ * @return the object ID seed
+ */
+ public long getObjectIDSeed() {
+ return LittleEndian.getUInt(_data,0);
+ }
+
+ /**
+ * Sets the object ID seed
+ * @param seed the new ID seed
+ */
+ public void setObjectIDSeed(int seed) {
+ LittleEndian.putInt(_data,0,seed);
+ }
+
+ /**
+ * Gets the record type.
+ * @return the record type.
+ */
+ public long getRecordType() { return RecordTypes.ExObjListAtom.typeID; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ *
+ * @param out the output stream to write to.
+ * @throws IOException if an error occurs.
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ out.write(_header);
+ out.write(_data);
+ }
+}
Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java?view=diff&rev=497107&r1=497106&r2=497107
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java Wed Jan 17 10:09:24 2007
@@ -59,8 +59,8 @@
public static final Type DocRoutingSlip = new Type(1030,null);
public static final Type OutlineViewInfo = new Type(1031,null);
public static final Type SorterViewInfo = new Type(1032,null);
- public static final Type ExObjList = new Type(1033,DummyRecordWithChildren.class);
- public static final Type ExObjListAtom = new Type(1034,null);
+ public static final Type ExObjList = new Type(1033,ExObjList.class);
+ public static final Type ExObjListAtom = new Type(1034,ExObjListAtom.class);
public static final Type PPDrawingGroup = new Type(1035,PPDrawingGroup.class);
public static final Type PPDrawing = new Type(1036,PPDrawing.class);
public static final Type NamedShows = new Type(1040,null);
Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java?view=diff&rev=497107&r1=497106&r2=497107
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java (original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java Wed Jan 17 10:09:24 2007
@@ -23,6 +23,7 @@
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -100,16 +101,16 @@
public void testRealFile() throws Exception {
String dirname = System.getProperty("HSLF.testdata.path");
- HSLFSlideShow hss = new HSLFSlideShow(dirname + "WithLinks.ppt");
+ HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator + "WithLinks.ppt");
SlideShow ss = new SlideShow(hss);
// Get the document
Document doc = ss.getDocumentRecord();
// Get the ExObjList
- RecordContainer exObjList = null;
+ ExObjList exObjList = null;
for(int i=0; i<doc._children.length; i++) {
- if(doc._children[i].getRecordType() == RecordTypes.ExObjList.typeID) {
- exObjList = (RecordContainer)doc._children[i];
+ if(doc._children[i] instanceof ExObjList) {
+ exObjList = (ExObjList)doc._children[i];
}
}
assertNotNull(exObjList);
@@ -126,6 +127,10 @@
assertEquals(4, linksA.size());
ExHyperlink[] links = new ExHyperlink[linksA.size()];
linksA.toArray(links);
+
+ assertEquals(4, exObjList.getExHyperlinks().length);
+
+ // Check the other way
// Check they have what we expect in them
assertEquals(1, links[0].getExHyperlinkAtom().getNumber());
Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java?view=diff&rev=497107&r1=497106&r2=497107
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java (original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java Wed Jan 17 10:09:24 2007
@@ -27,7 +27,7 @@
import java.util.Date;
/**
- * Tests that InteractiveInfoAtom works properly.
+ * Tests that ExHyperlinkAtom works properly.
*
* @author Nick Burch (nick at torchbox dot com)
*/
Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java?view=auto&rev=497107
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java (added)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java Wed Jan 17 10:09:24 2007
@@ -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.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+/**
+ * Tests that ExObjList works properly.
+ *
+ * @author Nick Burch (nick at torchbox dot com)
+ */
+public class TestExObjList extends TestCase {
+ public void testRealFile() throws Exception {
+ String dirname = System.getProperty("HSLF.testdata.path");
+ HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator + "WithLinks.ppt");
+ SlideShow ss = new SlideShow(hss);
+
+ // Get the document
+ Document doc = ss.getDocumentRecord();
+ // Get the ExObjList
+ ExObjList exObjList = doc.getExObjList();
+ assertNotNull(exObjList);
+ assertEquals(1033l, exObjList.getRecordType());
+
+ // Check the atom
+ assertNotNull(exObjList.getExObjListAtom());
+ assertEquals(4, exObjList.getExObjListAtom().getObjectIDSeed());
+
+ // Check the Hyperlinks
+ assertEquals(4, exObjList.getExHyperlinks().length);
+
+ // Check the contents
+ ExHyperlink[] links = exObjList.getExHyperlinks();
+
+ // Check they have what we expect in them
+ assertEquals(1, links[0].getExHyperlinkAtom().getNumber());
+ assertEquals("http://jakarta.apache.org/poi/", links[0].getLinkURL());
+
+ assertEquals(2, links[1].getExHyperlinkAtom().getNumber());
+ assertEquals("http://slashdot.org/", links[1].getLinkURL());
+
+ assertEquals(3, links[2].getExHyperlinkAtom().getNumber());
+ assertEquals("http://jakarta.apache.org/poi/hssf/", links[2].getLinkURL());
+
+ assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
+ assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
+
+ }
+}
Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java?view=auto&rev=497107
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java (added)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjListAtom.java Wed Jan 17 10:09:24 2007
@@ -0,0 +1,106 @@
+
+/* ====================================================================
+ 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.hslf.record;
+
+
+import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Tests that ExObjListAtom works properly.
+ *
+ * @author Nick Burch (nick at torchbox dot com)
+ */
+public class TestExObjListAtom extends TestCase {
+ // From a real file
+ private byte[] data_a = new byte[] {
+ 00, 00, 0x0A, 0x04, 04, 00, 00, 00,
+ 01, 00, 00, 00
+ };
+ private byte[] data_b = new byte[] {
+ 00, 00, 0x0A, 0x04, 04, 00, 00, 00,
+ 04, 00, 00, 00
+ };
+
+ public void testRecordType() throws Exception {
+ ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
+ assertEquals(1034l, eoa.getRecordType());
+ }
+
+ public void testGetSeed() throws Exception {
+ ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
+ ExObjListAtom eob = new ExObjListAtom(data_b, 0, data_b.length);
+
+ assertEquals(1, eoa.getObjectIDSeed());
+ assertEquals(4, eob.getObjectIDSeed());
+ }
+
+ public void testWrite() throws Exception {
+ ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ eoa.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertEquals(data_a.length, b.length);
+ for(int i=0; i<data_a.length; i++) {
+ assertEquals(data_a[i],b[i]);
+ }
+ }
+
+ // Create A from scratch
+ public void testCreate() throws Exception {
+ ExObjListAtom eoa = new ExObjListAtom();
+
+ // Set seed
+ eoa.setObjectIDSeed(1);
+
+ // Check it's now the same as a
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ eoa.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ assertEquals(data_a.length, b.length);
+ for(int i=0; i<data_a.length; i++) {
+ assertEquals(data_a[i],b[i]);
+ }
+ }
+
+ // Try to turn a into b
+ public void testChange() throws Exception {
+ ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
+
+ // Change the number
+ eoa.setObjectIDSeed(4);
+
+ // Check bytes are now the same
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ eoa.writeOut(baos);
+ byte[] b = baos.toByteArray();
+
+ // Should now be the same
+ assertEquals(data_b.length, b.length);
+ for(int i=0; i<data_b.length; i++) {
+ assertEquals(data_b[i],b[i]);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
Re: svn commit: r497107 - in /jakarta/poi/trunk/src/scratchpad: src/org/apache/poi/hslf/record/ testcases/org/apache/poi/hslf/record/
Posted by David Fisher <df...@jmlafferty.com>.
Nick,
Thanks for this. I was going to ask Yegor to look into it.
Regards,
Dave
On Jan 17, 2007, at 12:09 PM, nick@apache.org wrote:
> Author: nick
> Date: Wed Jan 17 10:09:24 2007
> New Revision: 497107
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=497107
> Log:
> Add ExObjList support
>
> Added:
> jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> ExObjList.java
> jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> ExObjListAtom.java
> jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExObjList.java
> jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExObjListAtom.java
> Modified:
> jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> Document.java
> jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> RecordTypes.java
> jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExHyperlink.java
> jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExHyperlinkAtom.java
>
> Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/
> record/Document.java
> URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/
> src/org/apache/poi/hslf/record/Document.java?
> view=diff&rev=497107&r1=497106&r2=497107
> ======================================================================
> ========
> --- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> Document.java (original)
> +++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> Document.java Wed Jan 17 10:09:24 2007
> @@ -39,6 +39,7 @@
> private Environment environment;
> private PPDrawingGroup ppDrawing;
> private SlideListWithText[] slwts;
> + private ExObjList exObjList; // Can be null
>
> /**
> * Returns the DocumentAtom of this Document
> @@ -54,6 +55,12 @@
> * that contains information on pictures in the slides.
> */
> public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; }
> + /**
> + * Returns the ExObjList, which holds the references to
> + * external objects used in the slides. This may be null, if
> + * there are no external references.
> + */
> + public ExObjList getExObjList() { return exObjList; }
>
> /**
> * Returns all the SlideListWithTexts that are defined for
> @@ -115,6 +122,9 @@
> }
> if(_children[i] instanceof PPDrawingGroup) {
> ppDrawing = (PPDrawingGroup)_children[i];
> + }
> + if(_children[i] instanceof ExObjList) {
> + exObjList = (ExObjList)_children[i];
> }
> }
>
>
> Added: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/
> record/ExObjList.java
> URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/
> src/org/apache/poi/hslf/record/ExObjList.java?view=auto&rev=497107
> ======================================================================
> ========
> --- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> ExObjList.java (added)
> +++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> ExObjList.java Wed Jan 17 10:09:24 2007
> @@ -0,0 +1,112 @@
> +/*
> +* 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.hslf.record;
> +
> +import java.io.IOException;
> +import java.io.OutputStream;
> +import java.util.ArrayList;
> +
> +import org.apache.poi.util.LittleEndian;
> +
> +/**
> + * This class holds the links to exernal objects referenced
> + * from the document.
> + * @author Nick Burch
> + */
> +public class ExObjList extends RecordContainer {
> + private byte[] _header;
> + private static long _type = 1033;
> +
> + // Links to our more interesting children
> + private ExObjListAtom exObjListAtom;
> +
> + /**
> + * Returns the ExObjListAtom of this list
> + */
> + public ExObjListAtom getExObjListAtom() { return exObjListAtom; }
> +
> + /**
> + * Returns all the ExHyperlinks
> + */
> + public ExHyperlink[] getExHyperlinks() {
> + ArrayList links = new ArrayList();
> + for(int i=0; i<_children.length; i++) {
> + if(_children[i] instanceof ExHyperlink) {
> + links.add(_children[i]);
> + }
> + }
> +
> + return (ExHyperlink[])links.toArray(new ExHyperlink[links.size()]);
> + }
> +
> + /**
> + * Set things up, and find our more interesting children
> + */
> + protected ExObjList(byte[] source, int start, int len) {
> + // Grab the header
> + _header = new byte[8];
> + System.arraycopy(source,start,_header,0,8);
> +
> + // Find our children
> + _children = Record.findChildRecords(source,start+8,len-8);
> + findInterestingChildren();
> + }
> +
> + /**
> + * Go through our child records, picking out the ones that are
> + * interesting, and saving those for use by the easy helper
> + * methods.
> + */
> + private void findInterestingChildren() {
> + // First child should be the atom
> + if(_children[0] instanceof ExObjListAtom) {
> + exObjListAtom = (ExObjListAtom)_children[0];
> + } else {
> + throw new IllegalStateException("First child record wasn't a
> ExObjListAtom, was of type " + _children[0].getRecordType());
> + }
> + }
> +
> + /**
> + * Create a new ExObjList, with blank fields
> + */
> + public ExObjList() {
> + _header = new byte[8];
> + _children = new Record[1];
> +
> + // Setup our header block
> + _header[0] = 0x0f; // We are a container record
> + LittleEndian.putShort(_header, 2, (short)_type);
> +
> + // Setup our child records
> + _children[0] = new ExObjListAtom();
> + findInterestingChildren();
> + }
> +
> + /**
> + * We are of type 1033
> + */
> + public long getRecordType() { return _type; }
> +
> + /**
> + * Write the contents of the record back, so it can be written
> + * to disk
> + */
> + public void writeOut(OutputStream out) throws IOException {
> + writeOut(_header[0],_header[1],_type,_children,out);
> + }
> +
> +}
>
> Added: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/
> record/ExObjListAtom.java
> URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/
> src/org/apache/poi/hslf/record/ExObjListAtom.java?view=auto&rev=497107
> ======================================================================
> ========
> --- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> ExObjListAtom.java (added)
> +++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> ExObjListAtom.java Wed Jan 17 10:09:24 2007
> @@ -0,0 +1,114 @@
> +/*
> ====================================================================
> + 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.hslf.record;
> +
> +import java.io.IOException;
> +import java.io.OutputStream;
> +
> +import org.apache.poi.util.LittleEndian;
> +
> +/**
> + * Tne atom that holds the seed info used by a ExObjList
> + *
> + * @author Nick Burch
> + */
> +
> +public class ExObjListAtom extends RecordAtom
> +{
> + /**
> + * Record header.
> + */
> + private byte[] _header;
> +
> + /**
> + * Record data.
> + */
> + private byte[] _data;
> +
> + /**
> + * Constructs a brand new link related atom record.
> + */
> + protected ExObjListAtom() {
> + _header = new byte[8];
> + _data = new byte[4];
> +
> + LittleEndian.putShort(_header, 2, (short)getRecordType());
> + LittleEndian.putInt(_header, 4, _data.length);
> +
> + // It is fine for the other values to be zero
> + }
> +
> + /**
> + * Constructs the link related atom record from its
> + * source data.
> + *
> + * @param source the source data as a byte array.
> + * @param start the start offset into the byte array.
> + * @param len the length of the slice in the byte array.
> + */
> + protected ExObjListAtom(byte[] source, int start, int len) {
> + // Get the header.
> + _header = new byte[8];
> + System.arraycopy(source,start,_header,0,8);
> +
> + // Get the record data.
> + _data = new byte[len-8];
> + System.arraycopy(source,start+8,_data,0,len-8);
> +
> + // Must be at least 4 bytes long
> + if(_data.length < 4) {
> + throw new IllegalArgumentException("The length of the
> data for a ExObjListAtom must be at least 4 bytes, but was only " +
> _data.length);
> + }
> + }
> +
> + /**
> + * Gets the object ID seed, which will be used as the unique
> + * OLE identifier for the next OLE object added
> + * @return the object ID seed
> + */
> + public long getObjectIDSeed() {
> + return LittleEndian.getUInt(_data,0);
> + }
> +
> + /**
> + * Sets the object ID seed
> + * @param seed the new ID seed
> + */
> + public void setObjectIDSeed(int seed) {
> + LittleEndian.putInt(_data,0,seed);
> + }
> +
> + /**
> + * Gets the record type.
> + * @return the record type.
> + */
> + public long getRecordType() { return
> RecordTypes.ExObjListAtom.typeID; }
> +
> + /**
> + * Write the contents of the record back, so it can be written
> + * to disk
> + *
> + * @param out the output stream to write to.
> + * @throws IOException if an error occurs.
> + */
> + public void writeOut(OutputStream out) throws IOException {
> + out.write(_header);
> + out.write(_data);
> + }
> +}
>
> Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/
> record/RecordTypes.java
> URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/
> src/org/apache/poi/hslf/record/RecordTypes.java?
> view=diff&rev=497107&r1=497106&r2=497107
> ======================================================================
> ========
> --- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> RecordTypes.java (original)
> +++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/
> RecordTypes.java Wed Jan 17 10:09:24 2007
> @@ -59,8 +59,8 @@
> public static final Type DocRoutingSlip = new Type(1030,null);
> public static final Type OutlineViewInfo = new Type(1031,null);
> public static final Type SorterViewInfo = new Type(1032,null);
> - public static final Type ExObjList = new Type
> (1033,DummyRecordWithChildren.class);
> - public static final Type ExObjListAtom = new Type(1034,null);
> + public static final Type ExObjList = new Type
> (1033,ExObjList.class);
> + public static final Type ExObjListAtom = new Type
> (1034,ExObjListAtom.class);
> public static final Type PPDrawingGroup = new Type
> (1035,PPDrawingGroup.class);
> public static final Type PPDrawing = new Type
> (1036,PPDrawing.class);
> public static final Type NamedShows = new Type(1040,null);
>
> Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/
> hslf/record/TestExHyperlink.java
> URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/
> testcases/org/apache/poi/hslf/record/TestExHyperlink.java?
> view=diff&rev=497107&r1=497106&r2=497107
> ======================================================================
> ========
> --- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExHyperlink.java (original)
> +++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExHyperlink.java Wed Jan 17 10:09:24 2007
> @@ -23,6 +23,7 @@
>
> import junit.framework.TestCase;
> import java.io.ByteArrayOutputStream;
> +import java.io.File;
> import java.text.SimpleDateFormat;
> import java.util.ArrayList;
> import java.util.Date;
> @@ -100,16 +101,16 @@
>
> public void testRealFile() throws Exception {
> String dirname = System.getProperty("HSLF.testdata.path");
> - HSLFSlideShow hss = new HSLFSlideShow(dirname + "WithLinks.ppt");
> + HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator +
> "WithLinks.ppt");
> SlideShow ss = new SlideShow(hss);
>
> // Get the document
> Document doc = ss.getDocumentRecord();
> // Get the ExObjList
> - RecordContainer exObjList = null;
> + ExObjList exObjList = null;
> for(int i=0; i<doc._children.length; i++) {
> - if(doc._children[i].getRecordType() ==
> RecordTypes.ExObjList.typeID) {
> - exObjList = (RecordContainer)doc._children[i];
> + if(doc._children[i] instanceof ExObjList) {
> + exObjList = (ExObjList)doc._children[i];
> }
> }
> assertNotNull(exObjList);
> @@ -126,6 +127,10 @@
> assertEquals(4, linksA.size());
> ExHyperlink[] links = new ExHyperlink[linksA.size()];
> linksA.toArray(links);
> +
> + assertEquals(4, exObjList.getExHyperlinks().length);
> +
> + // Check the other way
>
> // Check they have what we expect in them
> assertEquals(1, links[0].getExHyperlinkAtom().getNumber());
>
> Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/
> hslf/record/TestExHyperlinkAtom.java
> URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/
> testcases/org/apache/poi/hslf/record/TestExHyperlinkAtom.java?
> view=diff&rev=497107&r1=497106&r2=497107
> ======================================================================
> ========
> --- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExHyperlinkAtom.java (original)
> +++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExHyperlinkAtom.java Wed Jan 17 10:09:24 2007
> @@ -27,7 +27,7 @@
> import java.util.Date;
>
> /**
> - * Tests that InteractiveInfoAtom works properly.
> + * Tests that ExHyperlinkAtom works properly.
> *
> * @author Nick Burch (nick at torchbox dot com)
> */
>
> Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/
> hslf/record/TestExObjList.java
> URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/
> testcases/org/apache/poi/hslf/record/TestExObjList.java?
> view=auto&rev=497107
> ======================================================================
> ========
> --- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExObjList.java (added)
> +++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExObjList.java Wed Jan 17 10:09:24 2007
> @@ -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.hslf.record;
> +
> +
> +import junit.framework.TestCase;
> +import java.io.ByteArrayOutputStream;
> +import java.io.File;
> +import java.text.SimpleDateFormat;
> +import java.util.ArrayList;
> +import java.util.Date;
> +
> +import org.apache.poi.hslf.HSLFSlideShow;
> +import org.apache.poi.hslf.usermodel.SlideShow;
> +
> +/**
> + * Tests that ExObjList works properly.
> + *
> + * @author Nick Burch (nick at torchbox dot com)
> + */
> +public class TestExObjList extends TestCase {
> + public void testRealFile() throws Exception {
> + String dirname = System.getProperty("HSLF.testdata.path");
> + HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator +
> "WithLinks.ppt");
> + SlideShow ss = new SlideShow(hss);
> +
> + // Get the document
> + Document doc = ss.getDocumentRecord();
> + // Get the ExObjList
> + ExObjList exObjList = doc.getExObjList();
> + assertNotNull(exObjList);
> + assertEquals(1033l, exObjList.getRecordType());
> +
> + // Check the atom
> + assertNotNull(exObjList.getExObjListAtom());
> + assertEquals(4, exObjList.getExObjListAtom().getObjectIDSeed());
> +
> + // Check the Hyperlinks
> + assertEquals(4, exObjList.getExHyperlinks().length);
> +
> + // Check the contents
> + ExHyperlink[] links = exObjList.getExHyperlinks();
> +
> + // Check they have what we expect in them
> + assertEquals(1, links[0].getExHyperlinkAtom().getNumber());
> + assertEquals("http://jakarta.apache.org/poi/", links
> [0].getLinkURL());
> +
> + assertEquals(2, links[1].getExHyperlinkAtom().getNumber());
> + assertEquals("http://slashdot.org/", links[1].getLinkURL());
> +
> + assertEquals(3, links[2].getExHyperlinkAtom().getNumber());
> + assertEquals("http://jakarta.apache.org/poi/hssf/", links
> [2].getLinkURL());
> +
> + assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
> + assertEquals("http://jakarta.apache.org/hslf/", links
> [3].getLinkURL());
> +
> + }
> +}
>
> Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/
> hslf/record/TestExObjListAtom.java
> URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/
> testcases/org/apache/poi/hslf/record/TestExObjListAtom.java?
> view=auto&rev=497107
> ======================================================================
> ========
> --- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExObjListAtom.java (added)
> +++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/
> record/TestExObjListAtom.java Wed Jan 17 10:09:24 2007
> @@ -0,0 +1,106 @@
> +
> +/*
> ====================================================================
> + 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.hslf.record;
> +
> +
> +import junit.framework.TestCase;
> +import java.io.ByteArrayOutputStream;
> +import java.text.SimpleDateFormat;
> +import java.util.Date;
> +
> +/**
> + * Tests that ExObjListAtom works properly.
> + *
> + * @author Nick Burch (nick at torchbox dot com)
> + */
> +public class TestExObjListAtom extends TestCase {
> + // From a real file
> + private byte[] data_a = new byte[] {
> + 00, 00, 0x0A, 0x04, 04, 00, 00, 00,
> + 01, 00, 00, 00
> + };
> + private byte[] data_b = new byte[] {
> + 00, 00, 0x0A, 0x04, 04, 00, 00, 00,
> + 04, 00, 00, 00
> + };
> +
> + public void testRecordType() throws Exception {
> + ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
> + assertEquals(1034l, eoa.getRecordType());
> + }
> +
> + public void testGetSeed() throws Exception {
> + ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
> + ExObjListAtom eob = new ExObjListAtom(data_b, 0, data_b.length);
> +
> + assertEquals(1, eoa.getObjectIDSeed());
> + assertEquals(4, eob.getObjectIDSeed());
> + }
> +
> + public void testWrite() throws Exception {
> + ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
> + ByteArrayOutputStream baos = new ByteArrayOutputStream();
> + eoa.writeOut(baos);
> + byte[] b = baos.toByteArray();
> +
> + assertEquals(data_a.length, b.length);
> + for(int i=0; i<data_a.length; i++) {
> + assertEquals(data_a[i],b[i]);
> + }
> + }
> +
> + // Create A from scratch
> + public void testCreate() throws Exception {
> + ExObjListAtom eoa = new ExObjListAtom();
> +
> + // Set seed
> + eoa.setObjectIDSeed(1);
> +
> + // Check it's now the same as a
> + ByteArrayOutputStream baos = new ByteArrayOutputStream();
> + eoa.writeOut(baos);
> + byte[] b = baos.toByteArray();
> +
> + assertEquals(data_a.length, b.length);
> + for(int i=0; i<data_a.length; i++) {
> + assertEquals(data_a[i],b[i]);
> + }
> + }
> +
> + // Try to turn a into b
> + public void testChange() throws Exception {
> + ExObjListAtom eoa = new ExObjListAtom(data_a, 0, data_a.length);
> +
> + // Change the number
> + eoa.setObjectIDSeed(4);
> +
> + // Check bytes are now the same
> + ByteArrayOutputStream baos = new ByteArrayOutputStream();
> + eoa.writeOut(baos);
> + byte[] b = baos.toByteArray();
> +
> + // Should now be the same
> + assertEquals(data_b.length, b.length);
> + for(int i=0; i<data_b.length; i++) {
> + assertEquals(data_b[i],b[i]);
> + }
> + }
> +}
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
> Mailing List: http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta POI Project: http://jakarta.apache.org/poi/
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/