From ec1a527cf48628b7e5e38b55c8cd1f5b21c4cc28 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 17 Jan 2007 16:05:26 +0000 Subject: [PATCH] Initial, basic support for InteractiveInfoAtom git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@497058 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hslf/record/InteractiveInfoAtom.java | 152 ++++++++++++++++++ .../apache/poi/hslf/record/RecordTypes.java | 2 +- .../org/apache/poi/hslf/data/WithLinks.ppt | Bin 0 -> 20480 bytes .../hslf/record/TestInteractiveInfoAtom.java | 125 ++++++++++++++ 4 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/data/WithLinks.ppt create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java new file mode 100644 index 0000000000..40200d1301 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java @@ -0,0 +1,152 @@ +/* ==================================================================== + 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.Date; + +import org.apache.poi.hslf.util.SystemTimeUtils; +import org.apache.poi.util.LittleEndian; + +/** + * Tne atom that holds metadata on Links in the document. + * (The actual link is held Document.ExObjList.ExHyperlink) + * + * @author Nick Burch + */ + +public class InteractiveInfoAtom extends RecordAtom +{ + /** + * Record header. + */ + private byte[] _header; + + /** + * Record data. + */ + private byte[] _data; + + /** + * Constructs a brand new link related atom record. + */ + protected InteractiveInfoAtom() { + _header = new byte[8]; + _data = new byte[16]; + + 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 InteractiveInfoAtom(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 16 bytes long + if(_data.length < 16) { + throw new IllegalArgumentException("The length of the data for a InteractiveInfoAtom must be at least 16 bytes, but was only " + _data.length); + } + + // First 4 bytes - no idea, normally 0 + // Second 4 bytes - the id of the link (from 1 onwards) + // Third 4 bytes - no idea, normally 4 + // Fourth 4 bytes - no idea, normally 8 + } + + /** + * Gets the link number. You will normally look the + * ExHyperlink with this number to get the details. + * @return the link number + */ + public int getNumber() { + return LittleEndian.getInt(_data,4); + } + + /** + * Sets the link number + * @param number the link number. + */ + public void setNumber(int number) { + LittleEndian.putInt(_data,4,number); + } + + /** + * Get the first number - meaning unknown + */ + public int _getNumber1() { + return LittleEndian.getInt(_data,0); + } + protected void _setNumber1(int val) { + LittleEndian.putInt(_data, 0, val); + } + + /** + * Get the third number - meaning unknown + */ + public int _getNumber3() { + return LittleEndian.getInt(_data,8); + } + protected void _setNumber3(int val) { + LittleEndian.putInt(_data, 8, val); + } + + /** + * Get the fourth number - meaning unknown + */ + public int _getNumber4() { + return LittleEndian.getInt(_data,12); + } + protected void _setNumber4(int val) { + LittleEndian.putInt(_data, 12, val); + } + + /** + * Gets the record type. + * @return the record type. + */ + public long getRecordType() { return RecordTypes.InteractiveInfoAtom.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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java index ccc41d7097..c483363703 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java @@ -121,7 +121,7 @@ public class RecordTypes { public static final Type ExControl = new Type(4078,null); public static final Type SlideListWithText = new Type(4080,SlideListWithText.class); public static final Type InteractiveInfo = new Type(4082,null); - public static final Type InteractiveInfoAtom = new Type(4083,null); + public static final Type InteractiveInfoAtom = new Type(4083,InteractiveInfoAtom.class); public static final Type UserEditAtom = new Type(4085,UserEditAtom.class); public static final Type CurrentUserAtom = new Type(4086,null); public static final Type DateTimeMCAtom = new Type(4087,null); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/WithLinks.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/WithLinks.ppt new file mode 100644 index 0000000000000000000000000000000000000000..6c4a8fdd58be661c11762c198e125aaf5f5f39a8 GIT binary patch literal 20480 zcmeHP4{%(?dH>$M(_c$|CmU?nQ2W^tkrIq0EdRkK#Byvf9*m{Irb(H!NFd1)mUOCg z#*~ugs10tL20H`e#7QO?O6w`f&?)UqDWzCRY4J2}p`kQ{8B$X`C2{|70@`8&e*OJ+ z-|F7oz0=)E7U1I5?Av|2-+te>-+ue;xBK?={Bw23ANrH|uS!<9QfxWnRY`fE+(P~m z^Bxn4AkVThp68ijWY33lNCNNsymAbq7{oF}j`=4LD-o*@s}W}))*#j*&O~$&p#oBe zI16z$;suBoBF;gai#QMQ7ZB$oUW9lt;x8gDKwOCEA}&H)j7a+Re)>s2J%_}2&a!%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>mmsUVm0 zmI^WmS}F?u9I;d>`(2z|^jXKS?15Pl5EQPUd+IPff;Uv1ar2-@mGb0pqS{YSSUYiBP4^R^z%MZx z*1YLe*1WljN`nuXzL#n0!|v|UA7G@{BBF0y^8Vu*^{&5O@b)s4#s7NotH{-WjSFQj za)*(77L~60xI2`Y}1e)`8FEXVI~u9g=3;%7Z_ zm*a1PEJJP`a#zbW$Tj0{CE{vXg}QZ^BP(%td$r)I7Q#BjQ3#Gh%sEB*G36;ZQwCFx zp}J>1vpX~Sf z@bQzt+5G=MoRiuALnKV1oU5(c#lbvYkNY?Su-I+*W#esO;1ib3f(Jt%hB$e`G9hrF zlD{Znut1l;fSPQm26fUkp%^@r6I~yM_3AFtFgV~H9v44`8$o_pR~GS{5Bl`;=wpzF zBAO_9VL4Qx9k+*W1!dld;_sMB4V1s>d$IKSKYa|HGTiXmiSg&XIR5V`{^lxpQ%?Wp z%0TC)jXr&@H^tJYu54oigm!4(E+uj1^i3)k>s%aCAzyl2G;G+@(C4~WEPcYxTcxp; V<34{`?%N_{ttWy3$_3N literal 0 HcmV?d00001 diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java new file mode 100644 index 0000000000..d001ac35de --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestInteractiveInfoAtom.java @@ -0,0 +1,125 @@ + +/* ==================================================================== + 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 InteractiveInfoAtom works properly. + * + * @author Nick Burch (nick at torchbox dot com) + */ +public class TestInteractiveInfoAtom extends TestCase { + // From a real file + private byte[] data_a = new byte[] { + 00, 00, 0xF3-256, 0x0F, 0x10, 00, 00, 00, + 00, 00, 00, 00, 01, 00, 00, 00, + 04, 00, 00, 00, 8, 00, 00, 00 + }; + private byte[] data_b = new byte[] { + 00, 00, 0xF3-256, 0x0F, 0x10, 00, 00, 00, + 00, 00, 00, 00, 04, 00, 00, 00, + 04, 00, 00, 00, 8, 00, 00, 00 + }; + + public void testRecordType() throws Exception { + InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length); + assertEquals(4083l, ia.getRecordType()); + } + + public void testGetNumber() throws Exception { + InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length); + InteractiveInfoAtom ib = new InteractiveInfoAtom(data_b, 0, data_b.length); + + assertEquals(1, ia.getNumber()); + assertEquals(4, ib.getNumber()); + } + + public void testGetRest() throws Exception { + InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length); + InteractiveInfoAtom ib = new InteractiveInfoAtom(data_b, 0, data_b.length); + + assertEquals(0, ia._getNumber1()); + assertEquals(0, ib._getNumber1()); + + assertEquals(4, ia._getNumber3()); + assertEquals(4, ib._getNumber3()); + + assertEquals(8, ia._getNumber4()); + assertEquals(8, ib._getNumber4()); + } + + public void testWrite() throws Exception { + InteractiveInfoAtom ia = new InteractiveInfoAtom(data_a, 0, data_a.length); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ia.writeOut(baos); + byte[] b = baos.toByteArray(); + + assertEquals(data_a.length, b.length); + for(int i=0; i