You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 21:37:10 UTC
svn commit: r1890122 [2/16] - in /poi/trunk/poi-scratchpad/src:
main/java/org/apache/poi/hdgf/ main/java/org/apache/poi/hdgf/chunks/
main/java/org/apache/poi/hdgf/dev/ main/java/org/apache/poi/hdgf/exceptions/
main/java/org/apache/poi/hdgf/extractor/ m...
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/StreamStore.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/StreamStore.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/StreamStore.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/StreamStore.java Sat May 22 21:37:08 2021
@@ -25,26 +25,26 @@ import org.apache.poi.util.IOUtils;
* In future, may also handle writing it back out again
*/
public class StreamStore { // TODO - instantiable superclass
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 10_000_000;
+ //arbitrarily selected; may need to increase
+ private static final int MAX_RECORD_LENGTH = 10_000_000;
- private byte[] contents;
+ private byte[] contents;
- /**
- * Creates a new, non compressed Stream Store
- */
- protected StreamStore(byte[] data, int offset, int length) {
- contents = IOUtils.safelyClone(data, offset, length, MAX_RECORD_LENGTH);
- }
+ /**
+ * Creates a new, non compressed Stream Store
+ */
+ protected StreamStore(byte[] data, int offset, int length) {
+ contents = IOUtils.safelyClone(data, offset, length, MAX_RECORD_LENGTH);
+ }
- protected void prependContentsWith(byte[] b) {
- byte[] newContents = IOUtils.safelyAllocate(contents.length + (long)b.length, MAX_RECORD_LENGTH);
- System.arraycopy(b, 0, newContents, 0, b.length);
- System.arraycopy(contents, 0, newContents, b.length, contents.length);
- contents = newContents;
- }
- protected void copyBlockHeaderToContents() {}
+ protected void prependContentsWith(byte[] b) {
+ byte[] newContents = IOUtils.safelyAllocate(contents.length + (long)b.length, MAX_RECORD_LENGTH);
+ System.arraycopy(b, 0, newContents, 0, b.length);
+ System.arraycopy(contents, 0, newContents, b.length, contents.length);
+ contents = newContents;
+ }
+ protected void copyBlockHeaderToContents() {}
- protected byte[] getContents() { return contents; }
- public byte[] _getContents() { return contents; }
+ protected byte[] getContents() { return contents; }
+ public byte[] _getContents() { return contents; }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/StringsStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/StringsStream.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/StringsStream.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/StringsStream.java Sat May 22 21:37:08 2021
@@ -25,8 +25,8 @@ import org.apache.poi.hdgf.pointers.Poin
* of ChunkStream, it seems
*/
public final class StringsStream extends Stream {
- protected StringsStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory) {
- super(pointer, store);
-// super(pointer, store, chunkFactory);
- }
+ protected StringsStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory) {
+ super(pointer, store);
+// super(pointer, store, chunkFactory);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/TrailerStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/TrailerStream.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/TrailerStream.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/TrailerStream.java Sat May 22 21:37:08 2021
@@ -28,7 +28,7 @@ import org.apache.poi.hdgf.pointers.Poin
* a special series of byte near the start of the file.
*/
public class TrailerStream extends PointerContainingStream { // TODO - instantiable superclass
- protected TrailerStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory, PointerFactory pointerFactory) {
- super(pointer, store, chunkFactory, pointerFactory);
- }
+ protected TrailerStream(Pointer pointer, StreamStore store, ChunkFactory chunkFactory, PointerFactory pointerFactory) {
+ super(pointer, store, chunkFactory, pointerFactory);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/UnknownStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/UnknownStream.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/UnknownStream.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/UnknownStream.java Sat May 22 21:37:08 2021
@@ -24,7 +24,7 @@ import org.apache.poi.hdgf.pointers.Poin
* about how to process / handle it
*/
public final class UnknownStream extends Stream {
- protected UnknownStream(Pointer pointer, StreamStore store) {
- super(pointer, store);
- }
+ protected UnknownStream(Pointer pointer, StreamStore store) {
+ super(pointer, store);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherDelayStm.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherDelayStm.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherDelayStm.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherDelayStm.java Sat May 22 21:37:08 2021
@@ -24,9 +24,9 @@ import org.apache.poi.poifs.filesystem.D
*
*/
public final class EscherDelayStm extends EscherPart {
- private static final String[] PATH = { "Escher", "EscherDelayStm", };
+ private static final String[] PATH = { "Escher", "EscherDelayStm", };
- public EscherDelayStm(DirectoryNode baseDir) throws IOException {
- super(baseDir, PATH);
- }
+ public EscherDelayStm(DirectoryNode baseDir) throws IOException {
+ super(baseDir, PATH);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherPart.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherPart.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherPart.java Sat May 22 21:37:08 2021
@@ -30,58 +30,58 @@ import org.apache.poi.util.IOUtils;
*/
public abstract class EscherPart extends HPBFPart {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 1_000_000;
+ //arbitrarily selected; may need to increase
+ private static final int MAX_RECORD_LENGTH = 1_000_000;
- private EscherRecord[] records;
+ private EscherRecord[] records;
- /**
- * Creates the Escher Part, and finds our child
- * escher records
- */
- public EscherPart(DirectoryNode baseDir, String[] parts) throws IOException {
- super(baseDir, parts);
-
- // Now create our Escher children
- DefaultEscherRecordFactory erf =
- new DefaultEscherRecordFactory();
+ /**
+ * Creates the Escher Part, and finds our child
+ * escher records
+ */
+ public EscherPart(DirectoryNode baseDir, String[] parts) throws IOException {
+ super(baseDir, parts);
+
+ // Now create our Escher children
+ DefaultEscherRecordFactory erf =
+ new DefaultEscherRecordFactory();
- ArrayList<EscherRecord> ec = new ArrayList<>();
+ ArrayList<EscherRecord> ec = new ArrayList<>();
byte[] data = getData();
- 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 = ec.toArray(new EscherRecord[0]);
- }
-
- 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();
- }
+ 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 = ec.toArray(new EscherRecord[0]);
+ }
+
+ 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();
+ }
byte[] data = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
- size = 0;
- for(int i=0; i<records.length; i++) {
- int thisSize =
- records[i].serialize(size, data);
- size += thisSize;
- }
-
- setData(data);
- }
+ size = 0;
+ for(int i=0; i<records.length; i++) {
+ int thisSize =
+ records[i].serialize(size, data);
+ size += thisSize;
+ }
+
+ setData(data);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherStm.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherStm.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherStm.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherStm.java Sat May 22 21:37:08 2021
@@ -24,8 +24,8 @@ import org.apache.poi.poifs.filesystem.D
*
*/
public final class EscherStm extends EscherPart {
- private static final String[] PATH = { "Escher", "EscherStm", };
- public EscherStm(DirectoryNode baseDir) throws IOException {
- super(baseDir, PATH);
- }
+ private static final String[] PATH = { "Escher", "EscherStm", };
+ public EscherStm(DirectoryNode baseDir) throws IOException {
+ super(baseDir, PATH);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/HPBFPart.java Sat May 22 21:37:08 2021
@@ -31,85 +31,85 @@ import org.apache.poi.util.IOUtils;
* for all of them.
*/
public abstract class HPBFPart {
- private byte[] data;
- private final String[] path;
+ private byte[] data;
+ private final String[] path;
- /**
- * @param path the path to the part, eg Contents or Quill, QuillSub, CONTENTS
- */
- public HPBFPart(DirectoryNode baseDir, String[] path) throws IOException {
- this.path = path;
+ /**
+ * @param path the path to the part, eg Contents or Quill, QuillSub, CONTENTS
+ */
+ public HPBFPart(DirectoryNode baseDir, String[] path) throws IOException {
+ this.path = path;
- DirectoryNode dir = getDir(baseDir, path);
- String name = path[path.length-1];
+ DirectoryNode dir = getDir(baseDir, path);
+ String name = path[path.length-1];
- if (!dir.hasEntry(name)) {
+ if (!dir.hasEntry(name)) {
throw new IllegalArgumentException("File invalid - failed to find document entry '" + name + "'");
- }
+ }
- // Grab the data from the part stream
- try (InputStream is = dir.createDocumentInputStream(name)) {
- data = IOUtils.toByteArray(is);
- }
- }
-
- private static DirectoryNode getDir(DirectoryNode baseDir, String[] path) {
- DirectoryNode dir = baseDir;
- for(int i=0; i<path.length-1; i++) {
- try {
- dir = (DirectoryNode)dir.getEntry(path[i]);
- } catch (FileNotFoundException e) {
- throw new IllegalArgumentException("File invalid - failed to find directory entry '"
- + path[i] + "': " + e);
- }
- }
- return dir;
- }
-
- 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.
- */
- public final byte[] getData() {
- return data;
- }
-
- protected final void setData(byte[] data) {
- this.data = data.clone();
- }
-
- /**
- * Returns
- */
- public final String[] getPath() {
- return path;
- }
+ // Grab the data from the part stream
+ try (InputStream is = dir.createDocumentInputStream(name)) {
+ data = IOUtils.toByteArray(is);
+ }
+ }
+
+ private static DirectoryNode getDir(DirectoryNode baseDir, String[] path) {
+ DirectoryNode dir = baseDir;
+ for(int i=0; i<path.length-1; i++) {
+ try {
+ dir = (DirectoryNode)dir.getEntry(path[i]);
+ } catch (FileNotFoundException e) {
+ throw new IllegalArgumentException("File invalid - failed to find directory entry '"
+ + path[i] + "': " + e);
+ }
+ }
+ return dir;
+ }
+
+ 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.
+ */
+ public final byte[] getData() {
+ return data;
+ }
+
+ protected final void setData(byte[] data) {
+ this.data = data.clone();
+ }
+
+ /**
+ * Returns
+ */
+ public final String[] getPath() {
+ return path;
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/MainContents.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/MainContents.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/MainContents.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/MainContents.java Sat May 22 21:37:08 2021
@@ -25,14 +25,14 @@ import org.apache.poi.poifs.filesystem.D
* The main Contents. Not yet understood
*/
public final class MainContents extends HPBFPart {
- private static final String[] PATH = { "Contents", };
+ private static final String[] PATH = { "Contents", };
- public MainContents(DirectoryNode baseDir) throws IOException {
- super(baseDir, PATH);
- }
+ public MainContents(DirectoryNode baseDir) throws IOException {
+ super(baseDir, PATH);
+ }
- protected void generateData() {
- // We don't parse the contents, so
- // nothing will have changed
- }
+ protected void generateData() {
+ // We don't parse the contents, so
+ // nothing will have changed
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/QuillContents.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/QuillContents.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/QuillContents.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/QuillContents.java Sat May 22 21:37:08 2021
@@ -34,73 +34,73 @@ import org.apache.poi.util.LocaleUtil;
* Read Quill Contents (/Quill/QuillSub/CONTENTS) from an HPBF (Publisher .pub) document
*/
public final class QuillContents extends HPBFPart {
- private static final Logger LOG = LogManager.getLogger(QuillContents.class);
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 1_000_000;
+ private static final Logger LOG = LogManager.getLogger(QuillContents.class);
+ //arbitrarily selected; may need to increase
+ private static final int MAX_RECORD_LENGTH = 1_000_000;
- private static final String[] PATH = { "Quill", "QuillSub", "CONTENTS", };
- private final QCBit[] bits;
+ private static final String[] PATH = { "Quill", "QuillSub", "CONTENTS", };
+ private final QCBit[] bits;
- public QuillContents(DirectoryNode baseDir) throws IOException {
- super(baseDir, PATH);
+ public QuillContents(DirectoryNode baseDir) throws IOException {
+ super(baseDir, PATH);
- // Now parse the first 512 bytes, and produce
- // all our bits
+ // Now parse the first 512 bytes, and produce
+ // all our bits
byte[] data = getData();
- // Check first 8 bytes
- String f8 = new String(data, 0, 8, LocaleUtil.CHARSET_1252);
- if(! f8.equals("CHNKINK ")) {
- throw new IllegalArgumentException("Expecting 'CHNKINK ' but was '"+f8+"'");
- }
- // Ignore the next 24, for now at least
-
- // Now, parse all our QC Bits
- bits = new QCBit[20];
- for(int i=0; i<20; i++) {
- int offset = 0x20 + i*24;
- if(data[offset] == 0x18 && data[offset+1] == 0x00) {
- // Has some data
- String thingType = new String(data, offset+2, 4, LocaleUtil.CHARSET_1252);
- int optA = LittleEndian.getUShort(data, offset+6);
- int optB = LittleEndian.getUShort(data, offset+8);
- int optC = LittleEndian.getUShort(data, offset+10);
- String bitType = new String(data, offset+12, 4, LocaleUtil.CHARSET_1252);
- int from = (int)LittleEndian.getUInt(data, offset+16);
- int len = (int)LittleEndian.getUInt(data, offset+20);
-
- byte[] bitData = IOUtils.safelyClone(data, from, len, MAX_RECORD_LENGTH);
-
- // Create
- if(bitType.equals("TEXT")) {
- bits[i] = new QCTextBit(thingType, bitType, bitData);
- } else if(bitType.equals("PLC ")) {
- try {
- bits[i] = QCPLCBit.createQCPLCBit(thingType, bitType, bitData);
- } catch (ArrayIndexOutOfBoundsException e) {
- // bug 60685: fall back so that the rest of the document can be read
- LOG.atWarn().log("Unable to read Quill Contents PLC Bit record. Ignoring this record.");
- bits[i] = new UnknownQCBit(thingType, bitType, bitData);
- }
- } else {
- bits[i] = new UnknownQCBit(thingType, bitType, bitData);
- }
- bits[i].setOptA(optA);
- bits[i].setOptB(optB);
- bits[i].setOptC(optC);
- bits[i].setDataOffset(from);
- } else {
- // Doesn't have data
- }
- }
- }
-
- public QCBit[] getBits() {
- return bits;
- }
-
- protected void generateData() {
- // TODO
- throw new IllegalStateException("Not done yet!");
- }
+ // Check first 8 bytes
+ String f8 = new String(data, 0, 8, LocaleUtil.CHARSET_1252);
+ if(! f8.equals("CHNKINK ")) {
+ throw new IllegalArgumentException("Expecting 'CHNKINK ' but was '"+f8+"'");
+ }
+ // Ignore the next 24, for now at least
+
+ // Now, parse all our QC Bits
+ bits = new QCBit[20];
+ for(int i=0; i<20; i++) {
+ int offset = 0x20 + i*24;
+ if(data[offset] == 0x18 && data[offset+1] == 0x00) {
+ // Has some data
+ String thingType = new String(data, offset+2, 4, LocaleUtil.CHARSET_1252);
+ int optA = LittleEndian.getUShort(data, offset+6);
+ int optB = LittleEndian.getUShort(data, offset+8);
+ int optC = LittleEndian.getUShort(data, offset+10);
+ String bitType = new String(data, offset+12, 4, LocaleUtil.CHARSET_1252);
+ int from = (int)LittleEndian.getUInt(data, offset+16);
+ int len = (int)LittleEndian.getUInt(data, offset+20);
+
+ byte[] bitData = IOUtils.safelyClone(data, from, len, MAX_RECORD_LENGTH);
+
+ // Create
+ if(bitType.equals("TEXT")) {
+ bits[i] = new QCTextBit(thingType, bitType, bitData);
+ } else if(bitType.equals("PLC ")) {
+ try {
+ bits[i] = QCPLCBit.createQCPLCBit(thingType, bitType, bitData);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // bug 60685: fall back so that the rest of the document can be read
+ LOG.atWarn().log("Unable to read Quill Contents PLC Bit record. Ignoring this record.");
+ bits[i] = new UnknownQCBit(thingType, bitType, bitData);
+ }
+ } else {
+ bits[i] = new UnknownQCBit(thingType, bitType, bitData);
+ }
+ bits[i].setOptA(optA);
+ bits[i].setOptB(optB);
+ bits[i].setOptC(optC);
+ bits[i].setDataOffset(from);
+ } else {
+ // Doesn't have data
+ }
+ }
+ }
+
+ public QCBit[] getBits() {
+ return bits;
+ }
+
+ protected void generateData() {
+ // TODO
+ throw new IllegalStateException("Not done yet!");
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCBit.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCBit.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCBit.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCBit.java Sat May 22 21:37:08 2021
@@ -21,66 +21,66 @@ package org.apache.poi.hpbf.model.qcbits
* Parent of all Quill CONTENTS bits
*/
public abstract class QCBit {
- private String thingType;
- private String bitType;
- private byte[] data;
-
- private int optA;
- private int optB;
- private int optC;
-
- private int dataOffset;
-
- public QCBit(String thingType, String bitType, byte[] data) {
- this.thingType = thingType;
- this.bitType = bitType;
- this.data = data.clone();
- }
-
- /**
- * Returns the type of the thing, eg TEXT, FONT
- * or TOKN
- */
- public String getThingType() { return thingType; }
- /**
- * Returns the type of the bit data, eg TEXT
- * or PLC
- */
- public String getBitType() { return bitType; }
- public final byte[] getData() { return data; }
- protected final void setData(byte[] data) {
- this.data = data.clone();
- }
-
- public int getOptA() {
- return optA;
- }
- public void setOptA(int optA) {
- this.optA = optA;
- }
-
- public int getOptB() {
- return optB;
- }
- public void setOptB(int optB) {
- this.optB = optB;
- }
-
- public int getOptC() {
- return optC;
- }
- public void setOptC(int optC) {
- this.optC = optC;
- }
-
- public int getDataOffset() {
- return dataOffset;
- }
- public void setDataOffset(int offset) {
- this.dataOffset = offset;
- }
-
- public int getLength() {
- return data.length;
- }
+ private String thingType;
+ private String bitType;
+ private byte[] data;
+
+ private int optA;
+ private int optB;
+ private int optC;
+
+ private int dataOffset;
+
+ public QCBit(String thingType, String bitType, byte[] data) {
+ this.thingType = thingType;
+ this.bitType = bitType;
+ this.data = data.clone();
+ }
+
+ /**
+ * Returns the type of the thing, eg TEXT, FONT
+ * or TOKN
+ */
+ public String getThingType() { return thingType; }
+ /**
+ * Returns the type of the bit data, eg TEXT
+ * or PLC
+ */
+ public String getBitType() { return bitType; }
+ public final byte[] getData() { return data; }
+ protected final void setData(byte[] data) {
+ this.data = data.clone();
+ }
+
+ public int getOptA() {
+ return optA;
+ }
+ public void setOptA(int optA) {
+ this.optA = optA;
+ }
+
+ public int getOptB() {
+ return optB;
+ }
+ public void setOptB(int optB) {
+ this.optB = optB;
+ }
+
+ public int getOptC() {
+ return optC;
+ }
+ public void setOptC(int optC) {
+ this.optC = optC;
+ }
+
+ public int getDataOffset() {
+ return dataOffset;
+ }
+ public void setDataOffset(int offset) {
+ this.dataOffset = offset;
+ }
+
+ public int getLength() {
+ return data.length;
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCPLCBit.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCPLCBit.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCPLCBit.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCPLCBit.java Sat May 22 21:37:08 2021
@@ -26,155 +26,155 @@ import org.apache.poi.util.StringUtil;
* format is determined by the type of the PLCs.
*/
public abstract class QCPLCBit extends QCBit {
- private int numberOfPLCs;
- private int typeOfPLCS;
- /**
- * The data which goes before the main PLC entries.
- * This is apparently always made up of 2 byte
- * un-signed ints..
- */
- private int[] preData;
- /** The first value of each PLC, normally 4 bytes */
- private long[] plcValA;
- /** The second value of each PLC, normally 4 bytes */
- private long[] plcValB;
-
-
- private QCPLCBit(String thingType, String bitType, byte[] data) {
- super(thingType, bitType, data);
-
- // First four bytes are the number
- numberOfPLCs = (int)LittleEndian.getUInt(data, 0);
-
- // Next four bytes are the type
- typeOfPLCS = (int)LittleEndian.getUInt(data, 4);
-
- // Init the arrays that we can
- plcValA = new long[numberOfPLCs];
- plcValB = new long[numberOfPLCs];
- }
+ private int numberOfPLCs;
+ private int typeOfPLCS;
+ /**
+ * The data which goes before the main PLC entries.
+ * This is apparently always made up of 2 byte
+ * un-signed ints..
+ */
+ private int[] preData;
+ /** The first value of each PLC, normally 4 bytes */
+ private long[] plcValA;
+ /** The second value of each PLC, normally 4 bytes */
+ private long[] plcValB;
+
+
+ private QCPLCBit(String thingType, String bitType, byte[] data) {
+ super(thingType, bitType, data);
+
+ // First four bytes are the number
+ numberOfPLCs = (int)LittleEndian.getUInt(data, 0);
+
+ // Next four bytes are the type
+ typeOfPLCS = (int)LittleEndian.getUInt(data, 4);
+
+ // Init the arrays that we can
+ plcValA = new long[numberOfPLCs];
+ plcValB = new long[numberOfPLCs];
+ }
+
+
+
+ public int getNumberOfPLCs() {
+ return numberOfPLCs;
+ }
+ public int getTypeOfPLCS() {
+ return typeOfPLCS;
+ }
+ public int[] getPreData() {
+ return preData;
+ }
+ public long[] getPlcValA() {
+ return plcValA;
+ }
+ public long[] getPlcValB() {
+ return plcValB;
+ }
- public int getNumberOfPLCs() {
- return numberOfPLCs;
- }
- public int getTypeOfPLCS() {
- return typeOfPLCS;
- }
-
- public int[] getPreData() {
- return preData;
- }
-
- public long[] getPlcValA() {
- return plcValA;
- }
- public long[] getPlcValB() {
- return plcValB;
- }
-
- final void setPreData(int[] preData) {
- this.preData = preData.clone();
- }
+ final void setPreData(int[] preData) {
+ this.preData = preData.clone();
+ }
- final void setPlcValA(long[] plcValA) {
+ final void setPlcValA(long[] plcValA) {
this.plcValA = plcValA.clone();
}
- final void setPlcValB(long[] plcValB) {
+ final void setPlcValB(long[] plcValB) {
this.plcValB = plcValB.clone();
}
-
+
+
+ public static QCPLCBit createQCPLCBit(String thingType, String bitType, byte[] data) {
+ // Grab the type
+ int type = (int)LittleEndian.getUInt(data, 4);
+ switch(type) {
+ case 0:
+ return new Type0(thingType, bitType, data);
+ case 4:
+ return new Type4(thingType, bitType, data);
+ case 8:
+ return new Type8(thingType, bitType, data);
+ case 12: // 0xc
+ return new Type12(thingType, bitType, data);
+ default:
+ throw new IllegalArgumentException("Sorry, I don't know how to deal with PLCs of type " + type);
+ }
+ }
- public static QCPLCBit createQCPLCBit(String thingType, String bitType, byte[] data) {
- // Grab the type
- int type = (int)LittleEndian.getUInt(data, 4);
- switch(type) {
- case 0:
- return new Type0(thingType, bitType, data);
- case 4:
- return new Type4(thingType, bitType, data);
- case 8:
- return new Type8(thingType, bitType, data);
- case 12: // 0xc
- return new Type12(thingType, bitType, data);
- default:
- throw new IllegalArgumentException("Sorry, I don't know how to deal with PLCs of type " + type);
- }
- }
-
-
- /**
- * Type 0 seem to be somewhat rare. They have 8 bytes of pre-data,
- * then 2x 2 byte values.
- */
- public static class Type0 extends QCPLCBit {
- private Type0(String thingType, String bitType, byte[] data) {
- super(thingType, bitType, data);
- // Grab our 4x pre-data
+ /**
+ * Type 0 seem to be somewhat rare. They have 8 bytes of pre-data,
+ * then 2x 2 byte values.
+ */
+ public static class Type0 extends QCPLCBit {
+ private Type0(String thingType, String bitType, byte[] data) {
+ super(thingType, bitType, data);
+
+ // Grab our 4x pre-data
int[] preData = {
LittleEndian.getUShort(data, 8 + 0),
LittleEndian.getUShort(data, 8 + 2),
LittleEndian.getUShort(data, 8 + 4),
LittleEndian.getUShort(data, 8 + 6)
};
- setPreData(preData);
+ setPreData(preData);
// And grab the 2 byte values
- int cntPlcs = getNumberOfPLCs();
+ int cntPlcs = getNumberOfPLCs();
long[] plcValA = new long[cntPlcs];
long[] plcValB = new long[cntPlcs];
for(int i=0; i<cntPlcs; i++) {
- plcValA[i] = LittleEndian.getUShort(data, 16+(4*i));
- plcValB[i] = LittleEndian.getUShort(data, 16+(4*i)+2);
- }
- setPlcValA(plcValA);
+ plcValA[i] = LittleEndian.getUShort(data, 16+(4*i));
+ plcValB[i] = LittleEndian.getUShort(data, 16+(4*i)+2);
+ }
+ setPlcValA(plcValA);
setPlcValB(plcValB);
- }
- }
+ }
+ }
- /**
- * Type 4 is quite common. They have 8 bytes of pre-data,
- * then 2x 4 byte values.
- */
- public static class Type4 extends QCPLCBit {
- private Type4(String thingType, String bitType, byte[] data) {
- super(thingType, bitType, data);
+ /**
+ * Type 4 is quite common. They have 8 bytes of pre-data,
+ * then 2x 4 byte values.
+ */
+ public static class Type4 extends QCPLCBit {
+ private Type4(String thingType, String bitType, byte[] data) {
+ super(thingType, bitType, data);
- // Grab our 4x pre-data
+ // Grab our 4x pre-data
int[] preData = {
LittleEndian.getUShort(data, 8 + 0),
LittleEndian.getUShort(data, 8 + 2),
LittleEndian.getUShort(data, 8 + 4),
LittleEndian.getUShort(data, 8 + 6)
};
- setPreData(preData);
+ setPreData(preData);
- // And grab the 4 byte values
+ // And grab the 4 byte values
int cntPlcs = getNumberOfPLCs();
long[] plcValA = new long[cntPlcs];
long[] plcValB = new long[cntPlcs];
for(int i=0; i<cntPlcs; i++) {
- plcValA[i] = LittleEndian.getUInt(data, 16+(8*i));
- plcValB[i] = LittleEndian.getUInt(data, 16+(8*i)+4);
- }
+ plcValA[i] = LittleEndian.getUInt(data, 16+(8*i));
+ plcValB[i] = LittleEndian.getUInt(data, 16+(8*i)+4);
+ }
setPlcValA(plcValA);
setPlcValB(plcValB);
- }
- }
+ }
+ }
- /**
- * Type 8 is quite common. They have 14 bytes of pre-data,
- * then 2x 4 byte values.
- */
- public static class Type8 extends QCPLCBit {
- private Type8(String thingType, String bitType, byte[] data) {
- super(thingType, bitType, data);
+ /**
+ * Type 8 is quite common. They have 14 bytes of pre-data,
+ * then 2x 4 byte values.
+ */
+ public static class Type8 extends QCPLCBit {
+ private Type8(String thingType, String bitType, byte[] data) {
+ super(thingType, bitType, data);
- // Grab our 7x pre-data
+ // Grab our 7x pre-data
int[] preData = {
LittleEndian.getUShort(data, 8 + 0),
LittleEndian.getUShort(data, 8 + 2),
@@ -186,124 +186,124 @@ public abstract class QCPLCBit extends Q
};
setPreData(preData);
- // And grab the 4 byte values
+ // And grab the 4 byte values
int cntPlcs = getNumberOfPLCs();
long[] plcValA = new long[cntPlcs];
long[] plcValB = new long[cntPlcs];
for(int i=0; i<cntPlcs; i++) {
- plcValA[i] = LittleEndian.getUInt(data, 22+(8*i));
- plcValB[i] = LittleEndian.getUInt(data, 22+(8*i)+4);
- }
+ plcValA[i] = LittleEndian.getUInt(data, 22+(8*i));
+ plcValB[i] = LittleEndian.getUInt(data, 22+(8*i)+4);
+ }
setPlcValA(plcValA);
setPlcValB(plcValB);
- }
- }
+ }
+ }
- /**
- * Type 12 holds hyperlinks, and is very complex.
- * There is normally one of these for each text
- * area that contains at least one hyperlinks.
- * The character offsets are relative to the start
- * of the text area that this applies to.
- */
- public static class Type12 extends QCPLCBit {
- private String[] hyperlinks;
-
- private static final int oneStartsAt = 0x4c;
- private static final int twoStartsAt = 0x68;
- private static final int threePlusIncrement = 22;
+ /**
+ * Type 12 holds hyperlinks, and is very complex.
+ * There is normally one of these for each text
+ * area that contains at least one hyperlinks.
+ * The character offsets are relative to the start
+ * of the text area that this applies to.
+ */
+ public static class Type12 extends QCPLCBit {
+ private String[] hyperlinks;
+
+ private static final int oneStartsAt = 0x4c;
+ private static final int twoStartsAt = 0x68;
+ private static final int threePlusIncrement = 22;
- private Type12(String thingType, String bitType, byte[] data) {
- super(thingType, bitType, data);
+ private Type12(String thingType, String bitType, byte[] data) {
+ super(thingType, bitType, data);
int cntPlcs = getNumberOfPLCs();
-
- // How many hyperlinks do we really have?
- // (zero hyperlinks gets numberOfPLCs=1)
+
+ // How many hyperlinks do we really have?
+ // (zero hyperlinks gets numberOfPLCs=1)
hyperlinks = new String[data.length == 0x34 ? 0 : cntPlcs];
- // We have 4 bytes, then the start point of each
- // hyperlink, then the end point of the text.
+ // We have 4 bytes, then the start point of each
+ // hyperlink, then the end point of the text.
int[] preData = new int[1 + cntPlcs + 1];
- for(int i=0; i<preData.length; i++) {
- preData[i] = (int)LittleEndian.getUInt(data, 8+(i*4));
- }
- setPreData(preData);
-
- // Then we have a whole bunch of stuff, which grows
- // with the number of hyperlinks
- // For now, we think these are shorts
- int at = 8+4+(cntPlcs*4)+4;
- int until = 0x34;
- if(cntPlcs == 1 && hyperlinks.length == 1) {
- until = oneStartsAt;
- } else if(cntPlcs >= 2) {
- until = twoStartsAt + (cntPlcs-2)*threePlusIncrement;
- }
+ for(int i=0; i<preData.length; i++) {
+ preData[i] = (int)LittleEndian.getUInt(data, 8+(i*4));
+ }
+ setPreData(preData);
+
+ // Then we have a whole bunch of stuff, which grows
+ // with the number of hyperlinks
+ // For now, we think these are shorts
+ int at = 8+4+(cntPlcs*4)+4;
+ int until = 0x34;
+ if(cntPlcs == 1 && hyperlinks.length == 1) {
+ until = oneStartsAt;
+ } else if(cntPlcs >= 2) {
+ until = twoStartsAt + (cntPlcs-2)*threePlusIncrement;
+ }
long[] plcValA = new long[(until - at) / 2];
long[] plcValB = new long[0];
- for(int i=0; i<plcValA.length; i++) {
- plcValA[i] = LittleEndian.getUShort(data, at+(i*2));
- }
+ for(int i=0; i<plcValA.length; i++) {
+ plcValA[i] = LittleEndian.getUShort(data, at+(i*2));
+ }
setPlcValA(plcValA);
setPlcValB(plcValB);
- // Finally, we have a series of lengths + hyperlinks
- at = until;
- for(int i=0; i<hyperlinks.length; i++) {
- int len = LittleEndian.getUShort(data, at);
- int first = LittleEndian.getUShort(data, at+2);
- if(first == 0) {
- // Crazy special case
- // Length is in bytes, from the start
- // Hyperlink appears to be empty
- hyperlinks[i] = "";
- at += len;
- } else {
- // Normal case. Length is in characters
- hyperlinks[i] = StringUtil.getFromUnicodeLE(data, at+2, len);
- at += 2 + (2*len);
- }
- }
- }
-
- /**
- * Returns the number of hyperlinks, which should
- * either be zero, or the number of PLC bits
- */
- public int getNumberOfHyperlinks() {
- return hyperlinks.length;
- }
-
- /**
- * Returns the URL of the hyperlink at the
- * given index.
- * @param number The hyperlink number, zero based
- */
- public String getHyperlink(int number) {
- return hyperlinks[number];
- }
- /**
- * Returns where in the text (in characters) the
- * hyperlink at the given index starts
- * applying to.
- * This position is relative to the text area that this
- * PLCBit applies to.
- * @param number The hyperlink number, zero based
- */
- public int getTextStartAt(int number) {
- return getPreData()[1+number];
- }
- /**
- * Returns where in the text that this block
- * of hyperlinks stops applying to. Normally,
- * but not always the end of the text.
- * This position is relative to the text area that this
- * PLCBit applies to.
- */
- public int getAllTextEndAt() {
- return getPreData()[getNumberOfPLCs()+1];
- }
- }
+ // Finally, we have a series of lengths + hyperlinks
+ at = until;
+ for(int i=0; i<hyperlinks.length; i++) {
+ int len = LittleEndian.getUShort(data, at);
+ int first = LittleEndian.getUShort(data, at+2);
+ if(first == 0) {
+ // Crazy special case
+ // Length is in bytes, from the start
+ // Hyperlink appears to be empty
+ hyperlinks[i] = "";
+ at += len;
+ } else {
+ // Normal case. Length is in characters
+ hyperlinks[i] = StringUtil.getFromUnicodeLE(data, at+2, len);
+ at += 2 + (2*len);
+ }
+ }
+ }
+
+ /**
+ * Returns the number of hyperlinks, which should
+ * either be zero, or the number of PLC bits
+ */
+ public int getNumberOfHyperlinks() {
+ return hyperlinks.length;
+ }
+
+ /**
+ * Returns the URL of the hyperlink at the
+ * given index.
+ * @param number The hyperlink number, zero based
+ */
+ public String getHyperlink(int number) {
+ return hyperlinks[number];
+ }
+ /**
+ * Returns where in the text (in characters) the
+ * hyperlink at the given index starts
+ * applying to.
+ * This position is relative to the text area that this
+ * PLCBit applies to.
+ * @param number The hyperlink number, zero based
+ */
+ public int getTextStartAt(int number) {
+ return getPreData()[1+number];
+ }
+ /**
+ * Returns where in the text that this block
+ * of hyperlinks stops applying to. Normally,
+ * but not always the end of the text.
+ * This position is relative to the text area that this
+ * PLCBit applies to.
+ */
+ public int getAllTextEndAt() {
+ return getPreData()[getNumberOfPLCs()+1];
+ }
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCTextBit.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCTextBit.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCTextBit.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/QCTextBit.java Sat May 22 21:37:08 2021
@@ -25,24 +25,24 @@ import org.apache.poi.util.StringUtil;
*/
public final class QCTextBit extends QCBit {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 1_000_000;
+ //arbitrarily selected; may need to increase
+ private static final int MAX_RECORD_LENGTH = 1_000_000;
- public QCTextBit(String thingType, String bitType, byte[] data) {
- super(thingType, bitType, data);
- }
+ public QCTextBit(String thingType, String bitType, byte[] data) {
+ super(thingType, bitType, data);
+ }
- /**
- * Returns the text. Note that line endings
- * are \r and not \n
- */
- public String getText() {
- return StringUtil.getFromUnicodeLE(getData());
- }
+ /**
+ * Returns the text. Note that line endings
+ * are \r and not \n
+ */
+ public String getText() {
+ return StringUtil.getFromUnicodeLE(getData());
+ }
- public void setText(String text) {
+ public void setText(String text) {
byte[] data = IOUtils.safelyAllocate(text.length() * 2L, MAX_RECORD_LENGTH);
- StringUtil.putUnicodeLE(text, data, 0);
- setData(data);
- }
+ StringUtil.putUnicodeLE(text, data, 0);
+ setData(data);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/UnknownQCBit.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/UnknownQCBit.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/UnknownQCBit.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/qcbits/UnknownQCBit.java Sat May 22 21:37:08 2021
@@ -22,7 +22,7 @@ package org.apache.poi.hpbf.model.qcbits
* how to handle explicitly
*/
public final class UnknownQCBit extends QCBit {
- public UnknownQCBit(String thingType, String bitType, byte[] data) {
- super(thingType, bitType, data);
- }
+ public UnknownQCBit(String thingType, String bitType, byte[] data) {
+ super(thingType, bitType, data);
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/DIB.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/DIB.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/DIB.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/DIB.java Sat May 22 21:37:08 2021
@@ -110,7 +110,7 @@ public final class DIB extends Bitmap {
int fileSize = data.length + HEADER_SIZE;
int offset = fileSize - imageSize;
- // specifies the size, in bytes, of the bitmap file - must add the length of the header
+ // specifies the size, in bytes, of the bitmap file - must add the length of the header
LittleEndian.putInt(header, 2, fileSize);
// Reserved; set to zero
LittleEndian.putInt(header, 6, 0);
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPDrawingTextListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPDrawingTextListing.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPDrawingTextListing.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPDrawingTextListing.java Sat May 22 21:37:08 2021
@@ -33,56 +33,56 @@ import org.apache.poi.hslf.usermodel.HSL
* searches those for text. Prints out any text it finds
*/
public final class PPDrawingTextListing {
- public static void main(String[] args) throws IOException {
- if(args.length < 1) {
- System.err.println("Need to give a filename");
- System.exit(1);
- }
-
- try (HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0])) {
-
- // Find PPDrawings at any second level position
- Record[] records = ss.getRecords();
- for (int i = 0; i < records.length; i++) {
- Record[] children = records[i].getChildRecords();
- if (children != null && children.length != 0) {
- for (int j = 0; j < children.length; j++) {
- if (children[j] instanceof PPDrawing) {
- System.out.println("Found PPDrawing at " + j + " in top level record " + i + " (" + records[i].getRecordType() + ")");
-
- // Look for EscherTextboxWrapper's
- PPDrawing ppd = (PPDrawing) children[j];
- EscherTextboxWrapper[] wrappers = ppd.getTextboxWrappers();
- System.out.println(" Has " + wrappers.length + " textbox wrappers within");
-
- // Loop over the wrappers, showing what they contain
- for (int k = 0; k < wrappers.length; k++) {
- EscherTextboxWrapper tbw = wrappers[k];
- System.out.println(" " + k + " has " + tbw.getChildRecords().length + " PPT atoms within");
-
- // Loop over the records, printing the text
- Record[] pptatoms = tbw.getChildRecords();
- for (Record pptatom : pptatoms) {
- String text = null;
- if (pptatom instanceof TextBytesAtom) {
- TextBytesAtom tba = (TextBytesAtom) pptatom;
- text = tba.getText();
- }
- if (pptatom instanceof TextCharsAtom) {
- TextCharsAtom tca = (TextCharsAtom) pptatom;
- text = tca.getText();
- }
-
- if (text != null) {
- text = text.replace('\r', '\n');
- System.out.println(" ''" + text + "''");
- }
- }
- }
- }
- }
- }
- }
- }
- }
+ public static void main(String[] args) throws IOException {
+ if(args.length < 1) {
+ System.err.println("Need to give a filename");
+ System.exit(1);
+ }
+
+ try (HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0])) {
+
+ // Find PPDrawings at any second level position
+ Record[] records = ss.getRecords();
+ for (int i = 0; i < records.length; i++) {
+ Record[] children = records[i].getChildRecords();
+ if (children != null && children.length != 0) {
+ for (int j = 0; j < children.length; j++) {
+ if (children[j] instanceof PPDrawing) {
+ System.out.println("Found PPDrawing at " + j + " in top level record " + i + " (" + records[i].getRecordType() + ")");
+
+ // Look for EscherTextboxWrapper's
+ PPDrawing ppd = (PPDrawing) children[j];
+ EscherTextboxWrapper[] wrappers = ppd.getTextboxWrappers();
+ System.out.println(" Has " + wrappers.length + " textbox wrappers within");
+
+ // Loop over the wrappers, showing what they contain
+ for (int k = 0; k < wrappers.length; k++) {
+ EscherTextboxWrapper tbw = wrappers[k];
+ System.out.println(" " + k + " has " + tbw.getChildRecords().length + " PPT atoms within");
+
+ // Loop over the records, printing the text
+ Record[] pptatoms = tbw.getChildRecords();
+ for (Record pptatom : pptatoms) {
+ String text = null;
+ if (pptatom instanceof TextBytesAtom) {
+ TextBytesAtom tba = (TextBytesAtom) pptatom;
+ text = tba.getText();
+ }
+ if (pptatom instanceof TextCharsAtom) {
+ TextCharsAtom tca = (TextCharsAtom) pptatom;
+ text = tca.getText();
+ }
+
+ if (text != null) {
+ text = text.replace('\r', '\n');
+ System.out.println(" ''" + text + "''");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java Sat May 22 21:37:08 2021
@@ -131,7 +131,7 @@ public final class PPTXMLDump {
out.write("\"");
}
out.write(">" + CR);
- padding++;
+ padding++;
//this check works both for Escher and PowerPoint records
boolean isContainer = (info & 0x000F) == 0x000F;
if (isContainer) {
@@ -141,7 +141,7 @@ public final class PPTXMLDump {
//dump first 100 bytes of the atom data
dump(out, data, pos, Math.min(size, data.length-pos), padding, true);
}
- padding--;
+ padding--;
write(out, "</"+recname + ">" + CR, padding);
pos += size;
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java Sat May 22 21:37:08 2021
@@ -31,63 +31,63 @@ import org.apache.poi.hslf.usermodel.HSL
* and reports how many, and what sorts of things they contain
*/
public final class SLWTListing {
- public static void main(String[] args) throws IOException {
- if(args.length < 1) {
- System.err.println("Need to give a filename");
- System.exit(1);
- }
-
- HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
-
- // Find the documents, and then their SLWT
- Record[] records = ss.getRecords();
- for(int i=0; i<records.length; i++) {
- if(records[i] instanceof Document) {
- Document doc = (Document)records[i];
- SlideListWithText[] slwts = doc.getSlideListWithTexts();
-
- System.out.println("Document at " + i + " had " + slwts.length + " SlideListWithTexts");
- if(slwts.length == 0) {
- System.err.println("** Warning: Should have had at least 1! **");
- }
- if(slwts.length > 3) {
- System.err.println("** Warning: Shouldn't have more than 3!");
- }
-
- // Check the SLWTs contain what we'd expect
- for(int j=0; j<slwts.length; j++) {
- SlideListWithText slwt = slwts[j];
- Record[] children = slwt.getChildRecords();
-
- System.out.println(" - SLWT at " + j + " had " + children.length + " children:");
-
- // Should only have SlideAtomSets if the second one
- int numSAS = slwt.getSlideAtomsSets().length;
- if(j == 1) {
- if(numSAS == 0) {
- System.err.println(" ** 2nd SLWT didn't have any SlideAtomSets!");
- } else {
- System.out.println(" - Contains " + numSAS + " SlideAtomSets");
- }
- } else {
- if(numSAS > 0) {
- System.err.println(" ** SLWT " + j + " had " + numSAS + " SlideAtomSets! (expected 0)");
- }
- }
-
- // Report the first 5 children, to give a flavour
- int upTo = 5;
- if(children.length < 5) { upTo = children.length; }
- for(int k=0; k<upTo; k++) {
- Record r = children[k];
- int typeID = (int)r.getRecordType();
- String typeName = RecordTypes.forTypeID(typeID).name();
- System.out.println(" - " + typeID + " (" + typeName + ")");
- }
- }
- }
- }
-
- ss.close();
- }
+ public static void main(String[] args) throws IOException {
+ if(args.length < 1) {
+ System.err.println("Need to give a filename");
+ System.exit(1);
+ }
+
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
+
+ // Find the documents, and then their SLWT
+ Record[] records = ss.getRecords();
+ for(int i=0; i<records.length; i++) {
+ if(records[i] instanceof Document) {
+ Document doc = (Document)records[i];
+ SlideListWithText[] slwts = doc.getSlideListWithTexts();
+
+ System.out.println("Document at " + i + " had " + slwts.length + " SlideListWithTexts");
+ if(slwts.length == 0) {
+ System.err.println("** Warning: Should have had at least 1! **");
+ }
+ if(slwts.length > 3) {
+ System.err.println("** Warning: Shouldn't have more than 3!");
+ }
+
+ // Check the SLWTs contain what we'd expect
+ for(int j=0; j<slwts.length; j++) {
+ SlideListWithText slwt = slwts[j];
+ Record[] children = slwt.getChildRecords();
+
+ System.out.println(" - SLWT at " + j + " had " + children.length + " children:");
+
+ // Should only have SlideAtomSets if the second one
+ int numSAS = slwt.getSlideAtomsSets().length;
+ if(j == 1) {
+ if(numSAS == 0) {
+ System.err.println(" ** 2nd SLWT didn't have any SlideAtomSets!");
+ } else {
+ System.out.println(" - Contains " + numSAS + " SlideAtomSets");
+ }
+ } else {
+ if(numSAS > 0) {
+ System.err.println(" ** SLWT " + j + " had " + numSAS + " SlideAtomSets! (expected 0)");
+ }
+ }
+
+ // Report the first 5 children, to give a flavour
+ int upTo = 5;
+ if(children.length < 5) { upTo = children.length; }
+ for(int k=0; k<upTo; k++) {
+ Record r = children[k];
+ int typeID = (int)r.getRecordType();
+ String typeName = RecordTypes.forTypeID(typeID).name();
+ System.out.println(" - " + typeID + " (" + typeName + ")");
+ }
+ }
+ }
+ }
+
+ ss.close();
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTTextListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTTextListing.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTTextListing.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTTextListing.java Sat May 22 21:37:08 2021
@@ -33,62 +33,62 @@ import org.apache.poi.hslf.usermodel.HSL
* what it finds.
*/
public final class SLWTTextListing {
- public static void main(String[] args) throws IOException {
- if(args.length < 1) {
- System.err.println("Need to give a filename");
- System.exit(1);
- }
-
- HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
-
- // Find the documents, and then their SLWT
- Record[] records = ss.getRecords();
- for(int i=0; i<records.length; i++) {
- if(records[i] instanceof Document) {
- Record docRecord = records[i];
- Record[] docChildren = docRecord.getChildRecords();
- for(int j=0; j<docChildren.length; j++) {
- if(docChildren[j] instanceof SlideListWithText) {
- System.out.println("Found SLWT at pos " + j + " in the Document at " + i);
- System.out.println(" Has " + docChildren[j].getChildRecords().length + " children");
-
- // Grab the SlideAtomSet's, which contain
- // a SlidePersistAtom and then a bunch of text
- // + related records
- SlideListWithText slwt = (SlideListWithText)docChildren[j];
- SlideListWithText.SlideAtomsSet[] thisSets = slwt.getSlideAtomsSets();
- System.out.println(" Has " + thisSets.length + " AtomSets in it");
-
- // Loop over the sets, showing what they contain
- for(int k=0; k<thisSets.length; k++) {
- SlidePersistAtom spa = thisSets[k].getSlidePersistAtom();
- System.out.println(" " + k + " has slide id " + spa.getSlideIdentifier() );
- System.out.println(" " + k + " has ref id " + spa.getRefID() );
-
- // Loop over the records, printing the text
- Record[] slwtc = thisSets[k].getSlideRecords();
- for(int l=0; l<slwtc.length; l++) {
- String text = null;
- if(slwtc[l] instanceof TextBytesAtom) {
- TextBytesAtom tba = (TextBytesAtom)slwtc[l];
- text = tba.getText();
- }
- if(slwtc[l] instanceof TextCharsAtom) {
- TextCharsAtom tca = (TextCharsAtom)slwtc[l];
- text = tca.getText();
- }
-
- if(text != null) {
- text = text.replace('\r','\n');
- System.out.println(" ''" + text + "''");
- }
- }
- }
- }
- }
- }
- }
-
- ss.close();
- }
+ public static void main(String[] args) throws IOException {
+ if(args.length < 1) {
+ System.err.println("Need to give a filename");
+ System.exit(1);
+ }
+
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
+
+ // Find the documents, and then their SLWT
+ Record[] records = ss.getRecords();
+ for(int i=0; i<records.length; i++) {
+ if(records[i] instanceof Document) {
+ Record docRecord = records[i];
+ Record[] docChildren = docRecord.getChildRecords();
+ for(int j=0; j<docChildren.length; j++) {
+ if(docChildren[j] instanceof SlideListWithText) {
+ System.out.println("Found SLWT at pos " + j + " in the Document at " + i);
+ System.out.println(" Has " + docChildren[j].getChildRecords().length + " children");
+
+ // Grab the SlideAtomSet's, which contain
+ // a SlidePersistAtom and then a bunch of text
+ // + related records
+ SlideListWithText slwt = (SlideListWithText)docChildren[j];
+ SlideListWithText.SlideAtomsSet[] thisSets = slwt.getSlideAtomsSets();
+ System.out.println(" Has " + thisSets.length + " AtomSets in it");
+
+ // Loop over the sets, showing what they contain
+ for(int k=0; k<thisSets.length; k++) {
+ SlidePersistAtom spa = thisSets[k].getSlidePersistAtom();
+ System.out.println(" " + k + " has slide id " + spa.getSlideIdentifier() );
+ System.out.println(" " + k + " has ref id " + spa.getRefID() );
+
+ // Loop over the records, printing the text
+ Record[] slwtc = thisSets[k].getSlideRecords();
+ for(int l=0; l<slwtc.length; l++) {
+ String text = null;
+ if(slwtc[l] instanceof TextBytesAtom) {
+ TextBytesAtom tba = (TextBytesAtom)slwtc[l];
+ text = tba.getText();
+ }
+ if(slwtc[l] instanceof TextCharsAtom) {
+ TextCharsAtom tca = (TextCharsAtom)slwtc[l];
+ text = tca.getText();
+ }
+
+ if(text != null) {
+ text = text.replace('\r','\n');
+ System.out.println(" ''" + text + "''");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ ss.close();
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java Sat May 22 21:37:08 2021
@@ -34,38 +34,38 @@ import org.apache.poi.hslf.usermodel.HSL
* Slides, Master Slides and Notes
*/
public final class SlideAndNotesAtomListing {
- public static void main(String[] args) throws IOException {
- if(args.length < 1) {
- System.err.println("Need to give a filename");
- System.exit(1);
- }
+ public static void main(String[] args) throws IOException {
+ if(args.length < 1) {
+ System.err.println("Need to give a filename");
+ System.exit(1);
+ }
- HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
- System.out.println();
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
+ System.out.println();
- // Find either Slides or Notes
- Record[] records = ss.getRecords();
- for(int i=0; i<records.length; i++) {
- Record r = records[i];
+ // Find either Slides or Notes
+ Record[] records = ss.getRecords();
+ for(int i=0; i<records.length; i++) {
+ Record r = records[i];
- // When we find them, print out their IDs
- if(r instanceof Slide) {
- Slide s = (Slide)r;
- SlideAtom sa = s.getSlideAtom();
- System.out.println("Found Slide at " + i);
- System.out.println(" Slide's master ID is " + sa.getMasterID());
- System.out.println(" Slide's notes ID is " + sa.getNotesID());
- System.out.println();
- }
- if(r instanceof Notes) {
- Notes n = (Notes)r;
- NotesAtom na = n.getNotesAtom();
- System.out.println("Found Notes at " + i);
- System.out.println(" Notes ID is " + na.getSlideID());
- System.out.println();
- }
- }
-
- ss.close();
- }
+ // When we find them, print out their IDs
+ if(r instanceof Slide) {
+ Slide s = (Slide)r;
+ SlideAtom sa = s.getSlideAtom();
+ System.out.println("Found Slide at " + i);
+ System.out.println(" Slide's master ID is " + sa.getMasterID());
+ System.out.println(" Slide's notes ID is " + sa.getNotesID());
+ System.out.println();
+ }
+ if(r instanceof Notes) {
+ Notes n = (Notes)r;
+ NotesAtom na = n.getNotesAtom();
+ System.out.println("Found Notes at " + i);
+ System.out.println(" Notes ID is " + na.getSlideID());
+ System.out.println();
+ }
+ }
+
+ ss.close();
+ }
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowDumper.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowDumper.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowDumper.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowDumper.java Sat May 22 21:37:08 2021
@@ -49,10 +49,10 @@ import org.apache.poi.util.LittleEndian;
*/
public final class SlideShowDumper {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
+ //arbitrarily selected; may need to increase
+ private static final int MAX_RECORD_LENGTH = 100_000;
- private byte[] docstream;
+ private byte[] docstream;
/** Do we try to use DDF to understand the escher objects? */
private boolean ddfEscher;
@@ -67,29 +67,29 @@ public final class SlideShowDumper {
*/
public static void main(String[] args) throws IOException
{
- if(args.length == 0) {
- System.err.println("Usage: SlideShowDumper [-escher|-basicescher] <filename>");
- return;
- }
-
- String filename = args[0];
- if(args.length > 1) {
- filename = args[1];
- }
-
- try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename))) {
- SlideShowDumper foo = new SlideShowDumper(poifs, System.out);
-
- if(args.length > 1) {
- if(args[0].equalsIgnoreCase("-escher")) {
- foo.setDDFEscher(true);
- } else {
- foo.setBasicEscher(true);
- }
- }
+ if(args.length == 0) {
+ System.err.println("Usage: SlideShowDumper [-escher|-basicescher] <filename>");
+ return;
+ }
+
+ String filename = args[0];
+ if(args.length > 1) {
+ filename = args[1];
+ }
+
+ try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename))) {
+ SlideShowDumper foo = new SlideShowDumper(poifs, System.out);
+
+ if(args.length > 1) {
+ if(args[0].equalsIgnoreCase("-escher")) {
+ foo.setDDFEscher(true);
+ } else {
+ foo.setBasicEscher(true);
+ }
+ }
- foo.printDump();
- }
+ foo.printDump();
+ }
}
/**
@@ -100,19 +100,19 @@ public final class SlideShowDumper {
* @throws IOException if there is a problem while parsing the document.
*/
public SlideShowDumper(POIFSFileSystem filesystem, PrintStream out) throws IOException {
- // Grab the document stream
- InputStream is = filesystem.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
- docstream = IOUtils.toByteArray(is);
- is.close();
- this.out = out;
+ // Grab the document stream
+ InputStream is = filesystem.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ docstream = IOUtils.toByteArray(is);
+ is.close();
+ this.out = out;
}
/**
* Control dumping of any Escher records found - should DDF be used?
*/
public void setDDFEscher(boolean grok) {
- ddfEscher = grok;
- basicEscher = !(grok);
+ ddfEscher = grok;
+ basicEscher = !(grok);
}
/**
@@ -120,205 +120,205 @@ public final class SlideShowDumper {
* basic groker be used?
*/
public void setBasicEscher(boolean grok) {
- basicEscher = grok;
- ddfEscher = !(grok);
+ basicEscher = grok;
+ ddfEscher = !(grok);
}
public void printDump() throws IOException {
- // The format of records in a powerpoint file are:
- // <little endian 2 byte "info">
- // <little endian 2 byte "type">
- // <little endian 4 byte "length">
- // If it has a zero length, following it will be another record
- // <xx xx yy yy 00 00 00 00> <xx xx yy yy zz zz zz zz>
- // If it has a length, depending on its type it may have children or data
- // If it has children, these will follow straight away
- // <xx xx yy yy zz zz zz zz <xx xx yy yy zz zz zz zz>>
- // If it has data, this will come straigh after, and run for the length
- // <xx xx yy yy zz zz zz zz dd dd dd dd dd dd dd>
- // All lengths given exclude the 8 byte record header
- // (Data records are known as Atoms)
+ // The format of records in a powerpoint file are:
+ // <little endian 2 byte "info">
+ // <little endian 2 byte "type">
+ // <little endian 4 byte "length">
+ // If it has a zero length, following it will be another record
+ // <xx xx yy yy 00 00 00 00> <xx xx yy yy zz zz zz zz>
+ // If it has a length, depending on its type it may have children or data
+ // If it has children, these will follow straight away
+ // <xx xx yy yy zz zz zz zz <xx xx yy yy zz zz zz zz>>
+ // If it has data, this will come straigh after, and run for the length
+ // <xx xx yy yy zz zz zz zz dd dd dd dd dd dd dd>
+ // All lengths given exclude the 8 byte record header
+ // (Data records are known as Atoms)
- // Document should start with:
- // 0F 00 E8 03 ## ## ## ##
+ // Document should start with:
+ // 0F 00 E8 03 ## ## ## ##
// (type 1000 = document, info 00 0f is normal, rest is document length)
- // 01 00 E9 03 28 00 00 00
- // (type 1001 = document atom, info 00 01 normal, 28 bytes long)
+ // 01 00 E9 03 28 00 00 00
+ // (type 1001 = document atom, info 00 01 normal, 28 bytes long)
- // When parsing a document, look to see if you know about that type
- // of the current record. If you know it's a type that has children,
- // process the record's data area looking for more records
- // If you know about the type and it doesn't have children, either do
- // something with the data (eg TextRun) or skip over it
- // Otherwise, check the first byte. If you do a BINARY_AND on it with
- // 0x0f (15) and get back 0x0f, you know it has children. Otherwise
- // it doesn't
+ // When parsing a document, look to see if you know about that type
+ // of the current record. If you know it's a type that has children,
+ // process the record's data area looking for more records
+ // If you know about the type and it doesn't have children, either do
+ // something with the data (eg TextRun) or skip over it
+ // Otherwise, check the first byte. If you do a BINARY_AND on it with
+ // 0x0f (15) and get back 0x0f, you know it has children. Otherwise
+ // it doesn't
- walkTree(0,0,docstream.length);
+ walkTree(0,0,docstream.length);
}
public void walkTree(int depth, int startPos, int maxLen) throws IOException {
- int pos = startPos;
- int endPos = startPos + maxLen;
- final String ind = (depth == 0) ? "%1$s" : "%1$"+depth+"s";
- while(pos <= endPos - 8) {
- long type = LittleEndian.getUShort(docstream,pos+2);
- long len = LittleEndian.getUInt(docstream,pos+4);
- byte opt = docstream[pos];
-
- String fmt = ind+"At position %2$d (%2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x)";
- out.println(String.format(Locale.ROOT, fmt, "", pos, type, len));
-
- // See if we know about the type of it
- String recordName = RecordTypes.forTypeID((short)type).name();
-
- // Jump over header, and think about going on more
- pos += 8;
- out.println(String.format(Locale.ROOT, ind+"That's a %2$s", "", recordName));
-
- // Now check if it's a container or not
- int container = opt & 0x0f;
-
- // BinaryTagData seems to contain records, but it
- // isn't tagged as doing so. Try stepping in anyway
- if(type == 5003L && opt == 0L) {
- container = 0x0f;
- }
+ int pos = startPos;
+ int endPos = startPos + maxLen;
+ final String ind = (depth == 0) ? "%1$s" : "%1$"+depth+"s";
+ while(pos <= endPos - 8) {
+ long type = LittleEndian.getUShort(docstream,pos+2);
+ long len = LittleEndian.getUInt(docstream,pos+4);
+ byte opt = docstream[pos];
+
+ String fmt = ind+"At position %2$d (%2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x)";
+ out.println(String.format(Locale.ROOT, fmt, "", pos, type, len));
+
+ // See if we know about the type of it
+ String recordName = RecordTypes.forTypeID((short)type).name();
+
+ // Jump over header, and think about going on more
+ pos += 8;
+ out.println(String.format(Locale.ROOT, ind+"That's a %2$s", "", recordName));
+
+ // Now check if it's a container or not
+ int container = opt & 0x0f;
+
+ // BinaryTagData seems to contain records, but it
+ // isn't tagged as doing so. Try stepping in anyway
+ if(type == 5003L && opt == 0L) {
+ container = 0x0f;
+ }
out.println();
- if (type != 0L && container == 0x0f) {
- if (type == 1035L || type == 1036L) {
- // Special Handling of 1035=PPDrawingGroup and 1036=PPDrawing
- if(ddfEscher) {
- // Seems to be:
- walkEscherDDF((depth+3),pos+8,(int)len-8);
- } else if(basicEscher) {
- walkEscherBasic((depth+3),pos+8,(int)len-8);
- }
- } else {
- // General container record handling code
- walkTree((depth+2),pos,(int)len);
- }
- }
+ if (type != 0L && container == 0x0f) {
+ if (type == 1035L || type == 1036L) {
+ // Special Handling of 1035=PPDrawingGroup and 1036=PPDrawing
+ if(ddfEscher) {
+ // Seems to be:
+ walkEscherDDF((depth+3),pos+8,(int)len-8);
+ } else if(basicEscher) {
+ walkEscherBasic((depth+3),pos+8,(int)len-8);
+ }
+ } else {
+ // General container record handling code
+ walkTree((depth+2),pos,(int)len);
+ }
+ }
- pos += (int)len;
- }
+ pos += (int)len;
+ }
}
/**
* Use the DDF code to walk the Escher records
*/
public void walkEscherDDF(int indent, int pos, int len) {
- if(len < 8) { return; }
+ if(len < 8) { return; }
- final String ind = (indent == 0) ? "%1$s" : "%1$"+indent+"s";
+ final String ind = (indent == 0) ? "%1$s" : "%1$"+indent+"s";
byte[] contents = IOUtils.safelyClone(docstream, pos, len, MAX_RECORD_LENGTH);
- DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();
- EscherRecord record = erf.createRecord(contents,0);
+ DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();
+ EscherRecord record = erf.createRecord(contents,0);
- // For now, try filling in the fields
- record.fillFields(contents,0,erf);
+ // For now, try filling in the fields
+ record.fillFields(contents,0,erf);
- long atomType = LittleEndian.getUShort(contents,2);
- // This lacks the 8 byte header size
- long atomLen = LittleEndian.getUShort(contents,4);
- // This (should) include the 8 byte header size
- int recordLen = record.getRecordSize();
+ long atomType = LittleEndian.getUShort(contents,2);
+ // This lacks the 8 byte header size
+ long atomLen = LittleEndian.getUShort(contents,4);
+ // This (should) include the 8 byte header size
+ int recordLen = record.getRecordSize();
String fmt = ind+"At position %2$d (%2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x) (%5$d) - record claims %6$d";
out.println(String.format(Locale.ROOT, fmt, "", pos, atomType, atomLen, atomLen+8, recordLen));
- // Check for corrupt / lying ones
- if(recordLen != 8 && (recordLen != (atomLen+8))) {
- out.println(String.format(Locale.ROOT, ind+"** Atom length of $2d ($3d) doesn't match record length of %4d", "", atomLen, atomLen+8, recordLen));
- }
+ // Check for corrupt / lying ones
+ if(recordLen != 8 && (recordLen != (atomLen+8))) {
+ out.println(String.format(Locale.ROOT, ind+"** Atom length of $2d ($3d) doesn't match record length of %4d", "", atomLen, atomLen+8, recordLen));
+ }
- // Print the record's details
+ // Print the record's details
String recordStr = record.toString().replace("\n", String.format(Locale.ROOT, "\n"+ind, ""));
out.println(String.format(Locale.ROOT, ind+"%2$s", "", recordStr));
if(record instanceof EscherContainerRecord) {
- walkEscherDDF((indent+3), pos + 8, (int)atomLen );
- }
+ walkEscherDDF((indent+3), pos + 8, (int)atomLen );
+ }
- // Handle records that seem to lie
- if(atomType == 61451L) {
- // Normally claims a size of 8
- recordLen = (int)atomLen + 8;
- }
- if(atomType == 61453L) {
- // Returns EscherContainerRecord, but really msofbtClientTextbox
- recordLen = (int)atomLen + 8;
- record.fillFields( contents, 0, erf );
- if(! (record instanceof EscherTextboxRecord)) {
- out.println(String.format(Locale.ROOT, ind+"%2$s", "", "** Really a msofbtClientTextbox !"));
- }
- }
-
- // Decide on what to do, based on how the lengths match up
- if(recordLen == 8 && atomLen > 8 ) {
- // Assume it has children, rather than being corrupted
- walkEscherDDF((indent+3), pos + 8, (int)atomLen );
-
- // Wind on our length + our header
- pos += atomLen;
- pos += 8;
- len -= atomLen;
- len -= 8;
- } else {
- // No children, wind on our real length
- pos += atomLen;
- pos += 8;
- len -= atomLen;
- len -= 8;
- }
-
- // Move on to the next one, if we're not at the end yet
- if(len >= 8) {
- walkEscherDDF(indent, pos, len );
- }
+ // Handle records that seem to lie
+ if(atomType == 61451L) {
+ // Normally claims a size of 8
+ recordLen = (int)atomLen + 8;
+ }
+ if(atomType == 61453L) {
+ // Returns EscherContainerRecord, but really msofbtClientTextbox
+ recordLen = (int)atomLen + 8;
+ record.fillFields( contents, 0, erf );
+ if(! (record instanceof EscherTextboxRecord)) {
+ out.println(String.format(Locale.ROOT, ind+"%2$s", "", "** Really a msofbtClientTextbox !"));
+ }
+ }
+
+ // Decide on what to do, based on how the lengths match up
+ if(recordLen == 8 && atomLen > 8 ) {
+ // Assume it has children, rather than being corrupted
+ walkEscherDDF((indent+3), pos + 8, (int)atomLen );
+
+ // Wind on our length + our header
+ pos += atomLen;
+ pos += 8;
+ len -= atomLen;
+ len -= 8;
+ } else {
+ // No children, wind on our real length
+ pos += atomLen;
+ pos += 8;
+ len -= atomLen;
+ len -= 8;
+ }
+
+ // Move on to the next one, if we're not at the end yet
+ if(len >= 8) {
+ walkEscherDDF(indent, pos, len );
+ }
}
/**
* Use the basic record format groking code to walk the Escher records
*/
public void walkEscherBasic(int indent, int pos, int len) throws IOException {
- if(len < 8) { return; }
+ if(len < 8) { return; }
- final String ind = (indent == 0) ? "%1$s" : "%1$"+indent+"s";
+ final String ind = (indent == 0) ? "%1$s" : "%1$"+indent+"s";
- long type = LittleEndian.getUShort(docstream,pos+2);
- long atomlen = LittleEndian.getUInt(docstream,pos+4);
+ long type = LittleEndian.getUShort(docstream,pos+2);
+ long atomlen = LittleEndian.getUInt(docstream,pos+4);
- String fmt = ind+"At position %2$d ($2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x)";
- out.println(String.format(Locale.ROOT, fmt, "", pos, type, atomlen));
+ String fmt = ind+"At position %2$d ($2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x)";
+ out.println(String.format(Locale.ROOT, fmt, "", pos, type, atomlen));
- String typeName = RecordTypes.forTypeID((short)type).name();
- out.println(String.format(Locale.ROOT, ind+"%2$s", "That's an Escher Record: ", typeName));
-
- // Record specific dumps
- if(type == 61453L) {
- // Text Box. Print out first 8 bytes of data, then 8 4 later
- HexDump.dump(docstream, 0, out, pos+8, 8);
- HexDump.dump(docstream, 0, out, pos+20, 8);
- out.println();
- }
+ String typeName = RecordTypes.forTypeID((short)type).name();
+ out.println(String.format(Locale.ROOT, ind+"%2$s", "That's an Escher Record: ", typeName));
+ // Record specific dumps
+ if(type == 61453L) {
+ // Text Box. Print out first 8 bytes of data, then 8 4 later
+ HexDump.dump(docstream, 0, out, pos+8, 8);
+ HexDump.dump(docstream, 0, out, pos+20, 8);
+ out.println();
+ }
- // Blank line before next entry
- out.println();
- // Look in children if we are a container
- if(type == 61443L || type == 61444L) {
- walkEscherBasic((indent+3), pos+8, (int)atomlen);
- }
+ // Blank line before next entry
+ out.println();
- // Keep going if not yet at end
- if(atomlen < len) {
- int atomleni = (int)atomlen;
- walkEscherBasic(indent, pos+atomleni+8, len-atomleni-8);
- }
+ // Look in children if we are a container
+ if(type == 61443L || type == 61444L) {
+ walkEscherBasic((indent+3), pos+8, (int)atomlen);
+ }
+
+ // Keep going if not yet at end
+ if(atomlen < len) {
+ int atomleni = (int)atomlen;
+ walkEscherBasic(indent, pos+atomleni+8, len-atomleni-8);
+ }
}
}
Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowRecordDumper.java Sat May 22 21:37:08 2021
@@ -165,14 +165,14 @@ public final class SlideShowRecordDumper
}
public void printEscherRecord(EscherRecord er, int indent) {
- if (er instanceof EscherContainerRecord) {
- printEscherContainerRecord( (EscherContainerRecord)er, indent );
- } else if (er instanceof EscherTextboxRecord) {
- printEscherTextBox( (EscherTextboxRecord)er, indent );
- } else {
- ps.print( tabs.substring(0, indent) );
- ps.println(er);
- }
+ if (er instanceof EscherContainerRecord) {
+ printEscherContainerRecord( (EscherContainerRecord)er, indent );
+ } else if (er instanceof EscherTextboxRecord) {
+ printEscherTextBox( (EscherTextboxRecord)er, indent );
+ } else {
+ ps.print( tabs.substring(0, indent) );
+ ps.println(er);
+ }
}
private void printEscherTextBox( EscherTextboxRecord tbRecord, int indent ) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org