ASF Bugzilla – Attachment 28896 Details for
Bug 53372
[GSOC] Improve reading usermodel objects from EscherAggregate
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch
Improve_reading_usermodel_objects_from_EscherAggregate.patch (text/plain), 12.73 KB, created by
Evgeniy Berlog
on 2012-06-06 17:33:37 UTC
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Evgeniy Berlog
Created:
2012-06-06 17:33:37 UTC
Size:
12.73 KB
patch
obsolete
>Index: src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java (revision 1345884) >+++ src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java (revision ) >@@ -18,6 +18,7 @@ > package org.apache.poi.hssf.usermodel; > import org.apache.poi.hssf.model.InternalSheet; > import org.apache.poi.hssf.model.InternalWorkbook; >+import org.apache.poi.hssf.record.EscherAggregate; > > /** > * Helper class for HSSF tests that aren't within the >@@ -33,5 +34,9 @@ > } > public static InternalSheet getSheetForTest(HSSFSheet sheet) { > return sheet.getSheet(); >+ } >+ >+ public static HSSFPatriarch createTestPatriarch(HSSFSheet sheet, EscherAggregate agg){ >+ return new HSSFPatriarch(sheet, agg); >- } >+ } > } >Index: src/java/org/apache/poi/hssf/usermodel/HSSFShape.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFShape.java (revision 1345884) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFShape.java (revision ) >@@ -17,6 +17,9 @@ > > package org.apache.poi.hssf.usermodel; > >+import org.apache.poi.ddf.EscherContainerRecord; >+import org.apache.poi.hssf.record.ObjRecord; >+ > /** > * An abstract shape. > * >@@ -40,7 +43,7 @@ > public static final int LINESTYLE_NONE = -1; > > // TODO - make all these fields private >- final HSSFShape parent; >+ HSSFShape parent; > HSSFAnchor anchor; > HSSFPatriarch _patriarch; > private int _lineStyleColor = 0x08000040; >@@ -49,13 +52,28 @@ > private int _lineStyle = LINESTYLE_SOLID; > private boolean _noFill = false; > >+ private EscherContainerRecord spContainer; >+ private ObjRecord objRecord; >+ >+ public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord){ >+ this.spContainer = spContainer; >+ this.objRecord = objRecord; >+ } > /** > * Create a new shape with the specified parent and anchor. > */ >- HSSFShape( HSSFShape parent, HSSFAnchor anchor ) >+ public HSSFShape( HSSFShape parent, HSSFAnchor anchor ) > { > this.parent = parent; > this.anchor = anchor; >+ } >+ >+ public EscherContainerRecord getSpContainer() { >+ return spContainer; >+ } >+ >+ public ObjRecord getObjRecord() { >+ return objRecord; > } > > /** >Index: src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java (revision ) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java (revision ) >@@ -0,0 +1,32 @@ >+package org.apache.poi.hssf.usermodel; >+ >+import org.apache.poi.ddf.EscherContainerRecord; >+import org.apache.poi.ddf.EscherRecord; >+import org.apache.poi.ddf.EscherSpgrRecord; >+import org.apache.poi.hssf.record.ObjRecord; >+/** >+ * @author evgeniy >+ * date: 05.06.12 >+ */ >+public class HSSFShapeFactory { >+ >+ public static HSSFShape createShape(EscherRecord container, ObjRecord objRecord){ >+ if (0 == container.getChildRecords().size()){ >+ throw new IllegalArgumentException("Couldn't create shape from empty escher container"); >+ } >+ if (container.getChild(0) instanceof EscherSpgrRecord){ >+ return new HSSFShapeGroup((EscherContainerRecord) container, objRecord); >+ } >+ >+ //TODO implement cases for all shapes >+ return new HSSFUnknownShape(container, objRecord); >+ } >+ >+ public static HSSFShapeGroup createShapeGroup(){ >+ return null; >+ } >+ >+ public static HSSFShapeGroup createSimpleShape(EscherRecord container, ObjRecord objRecord){ >+ return null; >+ } >+} >Index: src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (revision 1345884) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (revision ) >@@ -1739,11 +1739,12 @@ > > _patriarch = new HSSFPatriarch(this, agg); > agg.setPatriarch(_patriarch); >+ EscherAggregate.createShapeTree(EscherAggregate.getMainSpgrContainer(agg), agg.getPatriarch(), agg); > > // Have it process the records into high level objects > // as best it can do (this step may eat anything > // that isn't supported, you were warned...) >- agg.convertRecordsToUserModel(); >+// agg.convertRecordsToUserModel(); > > // Return what we could cope with > return _patriarch; >Index: src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java (revision ) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFUnknownShape.java (revision ) >@@ -0,0 +1,16 @@ >+package org.apache.poi.hssf.usermodel; >+ >+import org.apache.poi.ddf.EscherContainerRecord; >+import org.apache.poi.ddf.EscherRecord; >+import org.apache.poi.hssf.record.ObjRecord; >+ >+/** >+ * @author Evgeniy Berlog >+ * date: 05.06.12 >+ */ >+public class HSSFUnknownShape extends HSSFShape { >+ >+ public HSSFUnknownShape(EscherRecord spContainer, ObjRecord objRecord) { >+ super((EscherContainerRecord) spContainer, objRecord); >+ } >+} >Index: src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java (revision 1345884) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java (revision ) >@@ -17,6 +17,9 @@ > > package org.apache.poi.hssf.usermodel; > >+import org.apache.poi.ddf.EscherContainerRecord; >+import org.apache.poi.hssf.record.ObjRecord; >+ > import java.util.ArrayList; > import java.util.List; > import java.util.Iterator; >@@ -37,6 +40,9 @@ > int x2 = 1023; > int y2 = 255; > >+ public HSSFShapeGroup(EscherContainerRecord spContainer, ObjRecord objRecord) { >+ super(spContainer, objRecord); >+ } > > public HSSFShapeGroup( HSSFShape parent, HSSFAnchor anchor ) > { >Index: src/java/org/apache/poi/hssf/record/EscherAggregate.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/hssf/record/EscherAggregate.java (revision 1345884) >+++ src/java/org/apache/poi/hssf/record/EscherAggregate.java (revision ) >@@ -43,16 +43,8 @@ > import org.apache.poi.hssf.model.ConvertAnchor; > import org.apache.poi.hssf.model.DrawingManager2; > import org.apache.poi.hssf.model.TextboxShape; >-import org.apache.poi.hssf.usermodel.HSSFAnchor; >-import org.apache.poi.hssf.usermodel.HSSFChildAnchor; >-import org.apache.poi.hssf.usermodel.HSSFClientAnchor; >-import org.apache.poi.hssf.usermodel.HSSFPatriarch; >-import org.apache.poi.hssf.usermodel.HSSFPicture; >-import org.apache.poi.hssf.usermodel.HSSFShape; >-import org.apache.poi.hssf.usermodel.HSSFShapeContainer; >-import org.apache.poi.hssf.usermodel.HSSFShapeGroup; >-import org.apache.poi.hssf.usermodel.HSSFSimpleShape; >-import org.apache.poi.hssf.usermodel.HSSFTextbox; >+import org.apache.poi.hssf.usermodel.*; >+import org.apache.poi.hssf.usermodel.HSSFShapeFactory; > import org.apache.poi.util.POILogFactory; > import org.apache.poi.util.POILogger; > >@@ -413,7 +405,7 @@ > } > > // Decode the shapes >- // agg.escherRecords = new ArrayList(); >+ // agg.escherRecords = new ArrayList(); > int pos = 0; > while (pos < buffer.size()) { > EscherRecord r = recordFactory.createRecord(buffer.toByteArray(), pos); >@@ -453,10 +445,35 @@ > records.subList(locFirstDrawingRecord, locLastDrawingRecord).clear(); > records.add(locFirstDrawingRecord, agg); > >- > return agg; > } > >+ public static EscherContainerRecord getMainSpgrContainer(EscherAggregate agg){ >+ EscherContainerRecord topContainer = agg.getEscherContainer(); >+ return topContainer.getChildContainers().get(0); >+ } >+ >+ public static void createShapeTree(EscherContainerRecord container, HSSFShapeContainer shapeGroup, EscherAggregate agg){ >+ for (EscherRecord record: container.getChildRecords()){ >+ if (record instanceof EscherContainerRecord){ >+ if (EscherContainerRecord.SP_CONTAINER == record.getRecordId()){ >+ if (record.getChild(0) instanceof EscherSpgrRecord){ >+ //TODO set properties for HSSFDrawingPatriarch >+ continue; >+ } >+ shapeGroup.addShape(HSSFShapeFactory.createShape(record, (ObjRecord) agg.shapeToObj.get(container.getChildById(EscherClientDataRecord.RECORD_ID)))); >+ continue; >+ } >+ if (EscherContainerRecord.SPGR_CONTAINER == record.getRecordId()){ >+ EscherContainerRecord spContainer = (EscherContainerRecord) container.getChild(0); >+ HSSFShapeGroup group = (HSSFShapeGroup) HSSFShapeFactory.createShape(spContainer, (ObjRecord) agg.shapeToObj.get(spContainer.getChildById(EscherClientDataRecord.RECORD_ID))); >+ shapeGroup.addShape(group); >+ createShapeTree((EscherContainerRecord)record, group, agg); >+ } >+ } >+ } >+ } >+ > /** > * Serializes this aggregate to a byte array. Since this is an aggregate > * record it will effectively serialize the aggregated records. >@@ -466,7 +483,7 @@ > * @return The number of bytes serialized. > */ > public int serialize(int offset, byte[] data) { >- convertUserModelToRecords(); >+// convertUserModelToRecords(); > > // Determine buffer size > List records = getEscherRecords(); >@@ -486,7 +503,7 @@ > > public void afterRecordSerialize(int offset, short recordId, int size, EscherRecord record) { > if (recordId == EscherClientDataRecord.RECORD_ID || recordId == EscherTextboxRecord.RECORD_ID) { >- spEndingOffsets.add(Integer.valueOf(offset)); >+ spEndingOffsets.add(offset); > shapes.add(record); > } > } >@@ -501,12 +518,17 @@ > pos = offset; > int writtenEscherBytes = 0; > for (int i = 1; i < shapes.size(); i++) { >- int endOffset = ((Integer) spEndingOffsets.get(i)).intValue() - 1; >+ int endOffset; >+ if (i == shapes.size()-1){ >+ endOffset = buffer.length - 1; >+ } else { >+ endOffset = (Integer) spEndingOffsets.get(i) - 1; >+ } > int startOffset; > if (i == 1) > startOffset = 0; > else >- startOffset = ((Integer) spEndingOffsets.get(i - 1)).intValue(); >+ startOffset = (Integer) spEndingOffsets.get(i - 1); > > > byte[] drawingData = new byte[endOffset - startOffset + 1]; >@@ -570,7 +592,7 @@ > > public int getRecordSize() { > // TODO - convert this to RecordAggregate >- convertUserModelToRecords(); >+// convertUserModelToRecords(); > // To determine size of aggregate record we have to know size of each DrawingRecord because if DrawingRecord > // is split into several continue records we have to add header size to total EscherAggregate size > int continueRecordsHeadersSize = 0; >Index: src/java/org/apache/poi/hssf/usermodel/HSSFShapeContainer.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFShapeContainer.java (revision 1345884) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFShapeContainer.java (revision ) >@@ -31,4 +31,10 @@ > */ > List getChildren(); > >+ /** >+ * add shape to the list of child records >+ * @param shape >+ */ >+ public void addShape(HSSFShape shape); >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 53372
:
28896
|
28899
|
28903
|
28906