import java.util.*;
+import org.apache.poi.hpsf.ClassID;
+
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.dev.POIFSViewable;
import org.apache.poi.util.ByteField;
static final private int _previous_property_offset = 0x44;
static final private int _next_property_offset = 0x48;
static final private int _child_property_offset = 0x4C;
+ static final private int _storage_clsid_offset = 0x50;
+ static final private int _user_flags_offset = 0x60;
static final private int _seconds_1_offset = 0x64;
static final private int _days_1_offset = 0x68;
static final private int _seconds_2_offset = 0x6C;
private IntegerField _previous_property;
private IntegerField _next_property;
private IntegerField _child_property;
+ private ClassID _storage_clsid;
+ private IntegerField _user_flags;
private IntegerField _seconds_1;
private IntegerField _days_1;
private IntegerField _seconds_2;
_NO_INDEX, _raw_data);
_child_property = new IntegerField(_child_property_offset,
_NO_INDEX, _raw_data);
+ _storage_clsid = new ClassID(_raw_data,_storage_clsid_offset);
+ _user_flags = new IntegerField(_user_flags_offset, 0, _raw_data);
_seconds_1 = new IntegerField(_seconds_1_offset, 0,
_raw_data);
_days_1 = new IntegerField(_days_1_offset, 0, _raw_data);
_raw_data);
_child_property = new IntegerField(_child_property_offset,
_raw_data);
+ _storage_clsid = new ClassID(_raw_data,_storage_clsid_offset);
+ _user_flags = new IntegerField(_user_flags_offset, 0, _raw_data);
_seconds_1 = new IntegerField(_seconds_1_offset, _raw_data);
_days_1 = new IntegerField(_days_1_offset, _raw_data);
_seconds_2 = new IntegerField(_seconds_2_offset, _raw_data);
abstract public boolean isDirectory();
+ /**
+ * Sets the storage clsid, which is the Class ID of a COM object which
+ * reads and writes this stream
+ * @return storage Class ID for this property stream
+ */
+ public ClassID getStorageClsid()
+ {
+ return _storage_clsid;
+ }
+
/**
* Set the name; silently truncates the name if it's too long.
*
* @param name the new name
*/
-
protected final void setName(final String name)
{
char[] char_array = name.toCharArray();
* LittleEndianConsts.SHORT_SIZE), _raw_data);
}
+ /**
+ * Sets the storage class ID for this property stream. This is the Class ID
+ * of the COM object which can read and write this property stream
+ * @param clsidStorage Storage Class ID
+ */
+ public void setStorageClsid( ClassID clsidStorage)
+ {
+ _storage_clsid = clsidStorage;
+ if( clsidStorage == null) {
+ Arrays.fill( _raw_data, _storage_clsid_offset, _storage_clsid_offset + ClassID.LENGTH, (byte) 0);
+ } else {
+ clsidStorage.write( _raw_data, _storage_clsid_offset);
+ }
+ }
/**
* Set the property type. Makes no attempt to validate the value.
*
--- /dev/null
+/* ====================================================================\r
+ * The Apache Software License, Version 1.1\r
+ *\r
+ * Copyright (c) 2003 The Apache Software Foundation. All rights\r
+ * reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in\r
+ * the documentation and/or other materials provided with the\r
+ * distribution.\r
+ *\r
+ * 3. The end-user documentation included with the redistribution,\r
+ * if any, must include the following acknowledgment:\r
+ * "This product includes software developed by the\r
+ * Apache Software Foundation (http://www.apache.org/)."\r
+ * Alternately, this acknowledgment may appear in the software itself,\r
+ * if and wherever such third-party acknowledgments normally appear.\r
+ *\r
+ * 4. The names "Apache" and "Apache Software Foundation" and\r
+ * "Apache POI" must not be used to endorse or promote products\r
+ * derived from this software without prior written permission. For\r
+ * written permission, please contact apache@apache.org.\r
+ *\r
+ * 5. Products derived from this software may not be called "Apache",\r
+ * "Apache POI", nor may "Apache" appear in their name, without\r
+ * prior written permission of the Apache Software Foundation.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED\r
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR\r
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT\r
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * ====================================================================\r
+ *\r
+ * This software consists of voluntary contributions made by many\r
+ * individuals on behalf of the Apache Software Foundation. For more\r
+ * information on the Apache Software Foundation, please see\r
+ * <http://www.apache.org/>.\r
+ */\r
+\r
+package org.apache.poi.hpsf.basic;\r
+\r
+import junit.framework.Assert;\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.poi.hpsf.ClassID;\r
+\r
+/**\r
+ * <p>Tests ClassID structure.</p>\r
+ *\r
+ * @author Michael Zalewski (zalewski@optonline.net)\r
+ */\r
+public class TestClassID extends TestCase\r
+{\r
+ /**\r
+ * <p>Constructor</p>\r
+ * \r
+ * @param name the test case's name\r
+ */\r
+ public TestClassID(final String name)\r
+ {\r
+ super(name);\r
+ }\r
+\r
+ /**\r
+ * Various tests of overridden .equals()\r
+ */\r
+ public void testEquals()\r
+ {\r
+ ClassID clsidTest1 = new ClassID(\r
+ new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08\r
+ , 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }\r
+ , 0\r
+ );\r
+ ClassID clsidTest2 = new ClassID(\r
+ new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08\r
+ , 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }\r
+ , 0\r
+ );\r
+ ClassID clsidTest3 = new ClassID(\r
+ new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08\r
+ , 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x11 }\r
+ , 0\r
+ );\r
+ Assert.assertEquals( clsidTest1, clsidTest1);\r
+ Assert.assertEquals( clsidTest1, clsidTest2);\r
+ Assert.assertFalse( clsidTest1.equals( clsidTest3));\r
+ Assert.assertFalse( clsidTest1.equals( null));\r
+ }\r
+ /**\r
+ * Try to write to a buffer that is too small. This should\r
+ * throw an Exception\r
+ */\r
+ public void testWriteArrayStoreException()\r
+ {\r
+ ClassID clsidTest = new ClassID(\r
+ new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08\r
+ , 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }\r
+ , 0\r
+ );\r
+ boolean bExceptionOccurred = false;\r
+ try {\r
+ clsidTest.write( new byte[ 15], 0);\r
+ } catch( Exception e) {\r
+ bExceptionOccurred = true;\r
+ }\r
+ Assert.assertTrue( bExceptionOccurred);\r
+\r
+ bExceptionOccurred = false;\r
+ try {\r
+ clsidTest.write( new byte[ 16], 1);\r
+ } catch( Exception e) {\r
+ bExceptionOccurred = true;\r
+ }\r
+ Assert.assertTrue( bExceptionOccurred);\r
+\r
+ // These should work without throwing an Exception\r
+ bExceptionOccurred = false;\r
+ try {\r
+ clsidTest.write( new byte[ 16], 0);\r
+ clsidTest.write( new byte[ 17], 1);\r
+ } catch( Exception e) {\r
+ bExceptionOccurred = true;\r
+ }\r
+ Assert.assertFalse( bExceptionOccurred);\r
+ }\r
+ /**\r
+ * <p>Tests the {@link PropertySet} methods. The test file has two\r
+ * property set: the first one is a {@link SummaryInformation},\r
+ * the second one is a {@link DocumentSummaryInformation}.</p>\r
+ */\r
+ public void testClassID()\r
+ {\r
+ ClassID clsidTest = new ClassID(\r
+ new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08\r
+ , 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }\r
+ , 0\r
+ );\r
+ Assert.assertEquals( \r
+ clsidTest.toString().toUpperCase()\r
+ , "{04030201-0605-0807-090A-0B0C0D0E0F10}"\r
+ );\r
+ }\r
+\r
+\r
+\r
+ /**\r
+ * <p>Runs the test cases stand-alone.</p>\r
+ */\r
+ public static void main(final String[] args)\r
+ {\r
+ System.setProperty("HPSF.testdata.path",\r
+ "./src/testcases/org/apache/poi/hpsf/data");\r
+ junit.textui.TestRunner.run(TestClassID.class);\r
+ }\r
+\r
+}\r
( byte ) 0xFE, ( byte ) 0xFF, ( byte ) 0xFF, ( byte ) 0xFF,
( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
+
( byte ) 0x57, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00,
( byte ) 0x72, ( byte ) 0x00, ( byte ) 0x6B, ( byte ) 0x00,
( byte ) 0x62, ( byte ) 0x00, ( byte ) 0x6F, ( byte ) 0x00,
( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
( byte ) 0x00, ( byte ) 0x10, ( byte ) 0x00, ( byte ) 0x00,
( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
+
( byte ) 0x05, ( byte ) 0x00, ( byte ) 0x53, ( byte ) 0x00,
( byte ) 0x75, ( byte ) 0x00, ( byte ) 0x6D, ( byte ) 0x00,
( byte ) 0x6D, ( byte ) 0x00, ( byte ) 0x61, ( byte ) 0x00,
( byte ) 0x08, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
( byte ) 0x00, ( byte ) 0x10, ( byte ) 0x00, ( byte ) 0x00,
( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x00,
+
( byte ) 0x05, ( byte ) 0x00, ( byte ) 0x44, ( byte ) 0x00,
( byte ) 0x6F, ( byte ) 0x00, ( byte ) 0x63, ( byte ) 0x00,
( byte ) 0x75, ( byte ) 0x00, ( byte ) 0x6D, ( byte ) 0x00,