2004-04-09 09:05:39 -04:00
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
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
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
==================================================================== */
|
2009-06-01 17:07:20 -04:00
|
|
|
|
2002-05-11 10:48:00 -04:00
|
|
|
package org.apache.poi.hpsf;
|
|
|
|
|
2016-11-27 08:12:00 -05:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2003-10-31 11:39:05 -05:00
|
|
|
import org.apache.poi.util.HexDump;
|
2015-09-01 17:46:30 -04:00
|
|
|
import org.apache.poi.util.StringUtil;
|
2003-10-31 11:39:05 -05:00
|
|
|
|
2002-05-11 10:48:00 -04:00
|
|
|
/**
|
2002-07-17 12:23:22 -04:00
|
|
|
* <p>Represents a class ID (16 bytes). Unlike other little-endian
|
|
|
|
* type the {@link ClassID} is not just 16 bytes stored in the wrong
|
|
|
|
* order. Instead, it is a double word (4 bytes) followed by two
|
|
|
|
* words (2 bytes each) followed by 8 bytes.</p>
|
2002-05-11 10:48:00 -04:00
|
|
|
*/
|
2002-07-17 12:23:22 -04:00
|
|
|
public class ClassID
|
|
|
|
{
|
2017-01-04 20:10:45 -05:00
|
|
|
public static final ClassID OLE10_PACKAGE = new ClassID("{0003000C-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID PPT_SHOW = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
|
|
|
|
public static final ClassID XLS_WORKBOOK = new ClassID("{00020841-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID TXT_ONLY = new ClassID("{5e941d80-bf96-11cd-b579-08002b30bfeb}");
|
|
|
|
|
|
|
|
// Excel V3
|
|
|
|
public static final ClassID EXCEL_V3 = new ClassID("{00030000-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID EXCEL_V3_CHART = new ClassID("{00030001-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID EXCEL_V3_MACRO = new ClassID("{00030002-0000-0000-C000-000000000046}");
|
|
|
|
// Excel V5
|
|
|
|
public static final ClassID EXCEL95 = new ClassID("{00020810-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID EXCEL95_CHART = new ClassID("{00020811-0000-0000-C000-000000000046}");
|
|
|
|
// Excel V8
|
|
|
|
public static final ClassID EXCEL97 = new ClassID("{00020820-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID EXCEL97_CHART = new ClassID("{00020821-0000-0000-C000-000000000046}");
|
|
|
|
// Excel V11
|
|
|
|
public static final ClassID EXCEL2003 = new ClassID("{00020812-0000-0000-C000-000000000046}");
|
|
|
|
// Excel V12
|
|
|
|
public static final ClassID EXCEL2007 = new ClassID("{00020830-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID EXCEL2007_MACRO= new ClassID("{00020832-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID EXCEL2007_XLSB = new ClassID("{00020833-0000-0000-C000-000000000046}");
|
|
|
|
// Excel V14
|
|
|
|
public static final ClassID EXCEL2010 = new ClassID("{00024500-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID EXCEL2010_CHART= new ClassID("{00024505-0014-0000-C000-000000000046}");
|
|
|
|
public static final ClassID EXCEL2010_ODS = new ClassID("{EABCECDB-CC1C-4A6F-B4E3-7F888A5ADFC8}");
|
|
|
|
|
|
|
|
public static final ClassID WORD97 = new ClassID("{00020906-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID WORD95 = new ClassID("{00020900-0000-0000-C000-000000000046}");
|
|
|
|
public static final ClassID WORD2007 = new ClassID("{F4754C9B-64F5-4B40-8AF4-679732AC0607}");
|
|
|
|
public static final ClassID WORD2007_MACRO = new ClassID("{18A06B6B-2F3F-4E2B-A611-52BE631B2D22}");
|
|
|
|
|
|
|
|
public static final ClassID POWERPOINT97 = new ClassID("{64818D10-4F9B-11CF-86EA-00AA00B929E8}");
|
|
|
|
public static final ClassID POWERPOINT95 = new ClassID("{EA7BAE70-FB3B-11CD-A903-00AA00510EA3}");
|
|
|
|
public static final ClassID POWERPOINT2007 = new ClassID("{CF4F55F4-8F87-4D47-80BB-5808164BB3F8}");
|
|
|
|
public static final ClassID POWERPOINT2007_MACRO = new ClassID("{DC020317-E6E2-4A62-B9FA-B3EFE16626F4}");
|
|
|
|
|
|
|
|
public static final ClassID EQUATION30 = new ClassID("{0002CE02-0000-0000-C000-000000000046}");
|
2013-10-13 03:39:40 -04:00
|
|
|
|
2016-11-27 08:12:00 -05:00
|
|
|
/** <p>The number of bytes occupied by this object in the byte
|
|
|
|
* stream.</p> */
|
|
|
|
public static final int LENGTH = 16;
|
2013-10-13 03:39:40 -04:00
|
|
|
|
2002-05-11 10:48:00 -04:00
|
|
|
/**
|
2002-07-17 12:23:22 -04:00
|
|
|
* <p>The bytes making out the class ID in correct order,
|
|
|
|
* i.e. big-endian.</p>
|
|
|
|
*/
|
2016-11-27 08:12:00 -05:00
|
|
|
private final byte[] bytes = new byte[LENGTH];
|
2002-07-17 12:23:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Creates a {@link ClassID} and reads its value from a byte
|
|
|
|
* array.</p>
|
2002-05-11 10:48:00 -04:00
|
|
|
*
|
2002-07-17 12:23:22 -04:00
|
|
|
* @param src The byte array to read from.
|
|
|
|
* @param offset The offset of the first byte to read.
|
2002-05-11 10:48:00 -04:00
|
|
|
*/
|
2016-11-27 08:12:00 -05:00
|
|
|
public ClassID(final byte[] src, final int offset) {
|
2002-07-17 12:23:22 -04:00
|
|
|
read(src, offset);
|
2002-05-11 10:48:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-22 09:27:16 -05:00
|
|
|
/**
|
|
|
|
* <p>Creates a {@link ClassID} and initializes its value with
|
|
|
|
* 0x00 bytes.</p>
|
|
|
|
*/
|
2016-11-27 08:12:00 -05:00
|
|
|
public ClassID() {
|
|
|
|
Arrays.fill(bytes, (byte)0);
|
2003-02-22 09:27:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-13 03:39:40 -04:00
|
|
|
/**
|
|
|
|
* <p>Creates a {@link ClassID} from a human-readable representation of the Class ID in standard
|
|
|
|
* format <code>"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"</code>.</p>
|
|
|
|
*
|
|
|
|
* @param externalForm representation of the Class ID represented by this object.
|
|
|
|
*/
|
|
|
|
public ClassID(String externalForm) {
|
|
|
|
String clsStr = externalForm.replaceAll("[{}-]", "");
|
|
|
|
for (int i=0; i<clsStr.length(); i+=2) {
|
|
|
|
bytes[i/2] = (byte)Integer.parseInt(clsStr.substring(i, i+2), 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-11 10:48:00 -04:00
|
|
|
|
2003-08-02 15:02:28 -04:00
|
|
|
/**
|
|
|
|
* @return The number of bytes occupied by this object in the byte
|
|
|
|
* stream.
|
|
|
|
*/
|
2016-11-27 08:12:00 -05:00
|
|
|
public int length() {
|
2002-05-11 10:48:00 -04:00
|
|
|
return LENGTH;
|
|
|
|
}
|
|
|
|
|
2002-05-19 14:09:26 -04:00
|
|
|
|
2002-07-17 12:23:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Gets the bytes making out the class ID. They are returned in
|
|
|
|
* correct order, i.e. big-endian.</p>
|
2003-08-30 05:13:53 -04:00
|
|
|
*
|
2003-08-02 15:02:28 -04:00
|
|
|
* @return the bytes making out the class ID.
|
2002-07-17 12:23:22 -04:00
|
|
|
*/
|
2016-11-27 08:12:00 -05:00
|
|
|
public byte[] getBytes() {
|
2003-08-02 15:02:28 -04:00
|
|
|
return bytes;
|
2002-05-19 14:09:26 -04:00
|
|
|
}
|
|
|
|
|
2002-05-11 10:48:00 -04:00
|
|
|
|
2002-07-17 12:23:22 -04:00
|
|
|
|
2004-08-13 18:38:52 -04:00
|
|
|
/**
|
|
|
|
* <p>Sets the bytes making out the class ID.</p>
|
|
|
|
*
|
|
|
|
* @param bytes The bytes making out the class ID in big-endian format. They
|
|
|
|
* are copied without their order being changed.
|
|
|
|
*/
|
2016-11-27 08:12:00 -05:00
|
|
|
public void setBytes(final byte[] bytes) {
|
|
|
|
System.arraycopy(bytes, 0, this.bytes, 0, LENGTH);
|
2004-08-13 18:38:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-05-11 10:48:00 -04:00
|
|
|
/**
|
2003-02-22 09:27:16 -05:00
|
|
|
* <p>Reads the class ID's value from a byte array by turning
|
|
|
|
* little-endian into big-endian.</p>
|
2002-07-17 12:23:22 -04:00
|
|
|
*
|
|
|
|
* @param src The byte array to read from
|
2002-05-11 10:48:00 -04:00
|
|
|
*
|
2002-07-17 12:23:22 -04:00
|
|
|
* @param offset The offset within the <var>src</var> byte array
|
|
|
|
*
|
|
|
|
* @return A byte array containing the class ID.
|
2002-05-11 10:48:00 -04:00
|
|
|
*/
|
2016-11-27 08:12:00 -05:00
|
|
|
public byte[] read(final byte[] src, final int offset) {
|
2002-07-17 12:23:22 -04:00
|
|
|
/* Read double word. */
|
|
|
|
bytes[0] = src[3 + offset];
|
|
|
|
bytes[1] = src[2 + offset];
|
|
|
|
bytes[2] = src[1 + offset];
|
|
|
|
bytes[3] = src[0 + offset];
|
2002-07-17 08:01:50 -04:00
|
|
|
|
2002-07-17 12:23:22 -04:00
|
|
|
/* Read first word. */
|
|
|
|
bytes[4] = src[5 + offset];
|
|
|
|
bytes[5] = src[4 + offset];
|
2002-07-17 08:01:50 -04:00
|
|
|
|
2002-07-17 12:23:22 -04:00
|
|
|
/* Read second word. */
|
|
|
|
bytes[6] = src[7 + offset];
|
|
|
|
bytes[7] = src[6 + offset];
|
2002-07-17 08:01:50 -04:00
|
|
|
|
2003-08-02 15:02:28 -04:00
|
|
|
/* Read 8 bytes. */
|
2016-11-27 08:12:00 -05:00
|
|
|
System.arraycopy(src, 8 + offset, bytes, 8, 8);
|
2002-07-17 08:01:50 -04:00
|
|
|
|
2002-07-17 12:23:22 -04:00
|
|
|
return bytes;
|
2002-05-11 10:48:00 -04:00
|
|
|
}
|
|
|
|
|
2003-02-22 09:27:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Writes the class ID to a byte array in the
|
2004-08-13 18:38:52 -04:00
|
|
|
* little-endian format.</p>
|
2003-02-22 09:27:16 -05:00
|
|
|
*
|
|
|
|
* @param dst The byte array to write to.
|
|
|
|
*
|
|
|
|
* @param offset The offset within the <var>dst</var> byte array.
|
|
|
|
*
|
2003-08-30 05:13:53 -04:00
|
|
|
* @exception ArrayStoreException if there is not enough room for the class
|
2003-08-02 15:02:28 -04:00
|
|
|
* ID 16 bytes in the byte array after the <var>offset</var> position.
|
2003-02-22 09:27:16 -05:00
|
|
|
*/
|
|
|
|
public void write(final byte[] dst, final int offset)
|
2016-11-27 08:12:00 -05:00
|
|
|
throws ArrayStoreException {
|
2003-08-02 15:02:28 -04:00
|
|
|
/* Check array size: */
|
2016-11-27 08:12:00 -05:00
|
|
|
if (dst.length < LENGTH) {
|
2003-08-02 15:02:28 -04:00
|
|
|
throw new ArrayStoreException
|
|
|
|
("Destination byte[] must have room for at least 16 bytes, " +
|
|
|
|
"but has a length of only " + dst.length + ".");
|
2016-11-27 08:12:00 -05:00
|
|
|
}
|
|
|
|
|
2003-02-22 09:27:16 -05:00
|
|
|
/* Write double word. */
|
2003-08-02 15:02:28 -04:00
|
|
|
dst[0 + offset] = bytes[3];
|
|
|
|
dst[1 + offset] = bytes[2];
|
|
|
|
dst[2 + offset] = bytes[1];
|
|
|
|
dst[3 + offset] = bytes[0];
|
2003-02-22 09:27:16 -05:00
|
|
|
|
|
|
|
/* Write first word. */
|
2003-08-02 15:02:28 -04:00
|
|
|
dst[4 + offset] = bytes[5];
|
|
|
|
dst[5 + offset] = bytes[4];
|
2003-02-22 09:27:16 -05:00
|
|
|
|
|
|
|
/* Write second word. */
|
2003-08-02 15:02:28 -04:00
|
|
|
dst[6 + offset] = bytes[7];
|
|
|
|
dst[7 + offset] = bytes[6];
|
2003-02-22 09:27:16 -05:00
|
|
|
|
2003-08-02 15:02:28 -04:00
|
|
|
/* Write 8 bytes. */
|
2016-11-27 08:12:00 -05:00
|
|
|
System.arraycopy(bytes, 8, dst, 8 + offset, 8);
|
2003-02-22 09:27:16 -05:00
|
|
|
}
|
|
|
|
|
2003-08-03 16:16:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Checks whether this <code>ClassID</code> is equal to another
|
|
|
|
* object.</p>
|
|
|
|
*
|
|
|
|
* @param o the object to compare this <code>PropertySet</code> with
|
|
|
|
* @return <code>true</code> if the objects are equal, else
|
2016-07-03 14:25:05 -04:00
|
|
|
* <code>false</code>.
|
2003-08-03 16:16:46 -04:00
|
|
|
*/
|
2016-07-03 14:25:05 -04:00
|
|
|
@Override
|
2016-11-27 08:12:00 -05:00
|
|
|
public boolean equals(final Object o) {
|
|
|
|
if (o == null || !(o instanceof ClassID)) {
|
2003-08-03 16:16:46 -04:00
|
|
|
return false;
|
2016-11-27 08:12:00 -05:00
|
|
|
}
|
2003-08-03 16:16:46 -04:00
|
|
|
final ClassID cid = (ClassID) o;
|
2016-11-27 08:12:00 -05:00
|
|
|
if (bytes.length != cid.bytes.length) {
|
2003-08-03 16:16:46 -04:00
|
|
|
return false;
|
2016-11-27 08:12:00 -05:00
|
|
|
}
|
|
|
|
for (int i = 0; i < bytes.length; i++) {
|
|
|
|
if (bytes[i] != cid.bytes[i]) {
|
2003-08-03 16:16:46 -04:00
|
|
|
return false;
|
2016-11-27 08:12:00 -05:00
|
|
|
}
|
|
|
|
}
|
2003-08-03 16:16:46 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-11-07 14:24:29 -05:00
|
|
|
|
|
|
|
|
2003-10-31 11:39:05 -05:00
|
|
|
/**
|
2003-11-07 14:24:29 -05:00
|
|
|
* @see Object#hashCode()
|
2003-10-31 11:39:05 -05:00
|
|
|
*/
|
2016-07-03 14:25:05 -04:00
|
|
|
@Override
|
2016-11-27 08:12:00 -05:00
|
|
|
public int hashCode() {
|
2015-09-01 17:46:30 -04:00
|
|
|
return new String(bytes, StringUtil.UTF8).hashCode();
|
2003-10-31 11:39:05 -05:00
|
|
|
}
|
2003-08-30 05:13:53 -04:00
|
|
|
|
|
|
|
/**
|
2003-11-07 14:24:29 -05:00
|
|
|
* <p>Returns a human-readable representation of the Class ID in standard
|
|
|
|
* format <code>"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"</code>.</p>
|
|
|
|
*
|
|
|
|
* @return String representation of the Class ID represented by this object.
|
2003-08-30 05:13:53 -04:00
|
|
|
*/
|
2016-07-03 14:25:05 -04:00
|
|
|
@Override
|
2016-11-27 08:12:00 -05:00
|
|
|
public String toString() {
|
|
|
|
StringBuilder sbClassId = new StringBuilder(38);
|
2003-11-07 14:24:29 -05:00
|
|
|
sbClassId.append('{');
|
2016-11-27 08:12:00 -05:00
|
|
|
for (int i = 0; i < LENGTH; i++) {
|
2003-11-07 14:24:29 -05:00
|
|
|
sbClassId.append(HexDump.toHex(bytes[i]));
|
2016-11-27 08:12:00 -05:00
|
|
|
if (i == 3 || i == 5 || i == 7 || i == 9) {
|
2003-11-07 14:24:29 -05:00
|
|
|
sbClassId.append('-');
|
2016-11-27 08:12:00 -05:00
|
|
|
}
|
2003-11-07 14:24:29 -05:00
|
|
|
}
|
|
|
|
sbClassId.append('}');
|
|
|
|
return sbClassId.toString();
|
2003-08-30 05:13:53 -04:00
|
|
|
}
|
2002-05-11 10:48:00 -04:00
|
|
|
}
|