aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/ddf
diff options
context:
space:
mode:
authorEvgeniy Berlog <berlog@apache.org>2012-06-19 21:00:04 +0000
committerEvgeniy Berlog <berlog@apache.org>2012-06-19 21:00:04 +0000
commit0c5bf44cba0905d68de068a745c9666f8d028375 (patch)
treec51724c4ab79ec3010d4237680977f4bb06a854e /src/java/org/apache/poi/ddf
parent0e8a727b3580b518d3db0a73cf0faf3ed7a5a2d1 (diff)
downloadpoi-0c5bf44cba0905d68de068a745c9666f8d028375.tar.gz
poi-0c5bf44cba0905d68de068a745c9666f8d028375.zip
improved aggregating drawing records in documents with charts,
fixed reading EscherContainer records from byte array git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1351850 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/ddf')
-rw-r--r--src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java16
-rw-r--r--src/java/org/apache/poi/ddf/EscherContainerRecord.java32
2 files changed, 45 insertions, 3 deletions
diff --git a/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java b/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
index 4b39b81599..cf48a38d84 100644
--- a/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
+++ b/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
@@ -65,8 +65,7 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory {
// However, EscherTextboxRecord are containers of records for the
// host application, not of other Escher records, so treat them
// differently
- if ( ( options & (short) 0x000F ) == (short) 0x000F
- && recordId != EscherTextboxRecord.RECORD_ID ) {
+ if (isContainer(options, recordId)) {
EscherContainerRecord r = new EscherContainerRecord();
r.setRecordId( recordId );
r.setOptions( options );
@@ -145,4 +144,17 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory {
}
return result;
}
+
+ public static boolean isContainer(short options, short recordId){
+ if(recordId >= EscherContainerRecord.DGG_CONTAINER && recordId
+ <= EscherContainerRecord.SOLVER_CONTAINER){
+ return true;
+ } else {
+ if (recordId == EscherTextboxRecord.RECORD_ID) {
+ return false;
+ } else {
+ return ( options & (short) 0x000F ) == (short) 0x000F;
+ }
+ }
+ }
}
diff --git a/src/java/org/apache/poi/ddf/EscherContainerRecord.java b/src/java/org/apache/poi/ddf/EscherContainerRecord.java
index 4190594b54..860edd8071 100644
--- a/src/java/org/apache/poi/ddf/EscherContainerRecord.java
+++ b/src/java/org/apache/poi/ddf/EscherContainerRecord.java
@@ -25,6 +25,8 @@ import java.util.NoSuchElementException;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
/**
* Escher container records store other escher records as children.
@@ -42,6 +44,32 @@ public final class EscherContainerRecord extends EscherRecord {
public static final short SP_CONTAINER = (short)0xF004;
public static final short SOLVER_CONTAINER = (short)0xF005;
+ private static POILogger log = POILogFactory.getLogger(EscherContainerRecord.class);
+
+ /**
+ * in case if document contains any charts we have such document structure:
+ * BOF
+ * ...
+ * DrawingRecord
+ * ...
+ * ObjRecord|TxtObjRecord
+ * ...
+ * EOF
+ * ...
+ * BOF(Chart begin)
+ * ...
+ * DrawingRecord
+ * ...
+ * ObjRecord|TxtObjRecord
+ * ...
+ * EOF
+ * So, when we call EscherAggregate.createAggregate() we have not all needed data.
+ * When we got warning "WARNING: " + bytesRemaining + " bytes remaining but no space left"
+ * we should save value of bytesRemaining
+ * and add it to container size when we serialize it
+ */
+ private int _remainingLength;
+
private final List<EscherRecord> _childRecords = new ArrayList<EscherRecord>();
public int fillFields(byte[] data, int pOffset, EscherRecordFactory recordFactory) {
@@ -56,7 +84,8 @@ public final class EscherContainerRecord extends EscherRecord {
bytesRemaining -= childBytesWritten;
addChildRecord(child);
if (offset >= data.length && bytesRemaining > 0) {
- System.out.println("WARNING: " + bytesRemaining + " bytes remaining but no space left");
+ _remainingLength = bytesRemaining;
+ log.log(POILogger.WARN, "Not enough Escher data: " + bytesRemaining + " bytes remaining but no space left");
}
}
return bytesWritten;
@@ -74,6 +103,7 @@ public final class EscherContainerRecord extends EscherRecord {
EscherRecord r = iterator.next();
remainingBytes += r.getRecordSize();
}
+ remainingBytes += _remainingLength;
LittleEndian.putInt(data, offset+4, remainingBytes);
int pos = offset+8;
iterator = _childRecords.iterator();