<changes>
<release version="3.9-beta1" date="2012-??-??">
+ <action dev="poi-developers" type="add">53058 - Utility for representing drawings contained in a binary Excel file as a XML tree</action>
<action dev="poi-developers" type="add">53165 - HWPF support for fetching the description (alt text) of a picture</action>
<action dev="poi-developers" type="fix">48528 - support negative arguments to the DATE() function</action>
<action dev="poi-developers" type="fix">53092 - allow specifying of a TimeZone to DateUtil.getJavaDate(), for when it is known that a file comes from a different (known) timezone to the current machine</action>
stringBuilder.append( " " + property.toString() + nl );
}
- return stringBuilder.toString();
- }
-
-}
+ return stringBuilder.toString();\r
+ }\r
+\r
+ @Override\r
+ public String toXml(String tab) {\r
+ StringBuilder builder = new StringBuilder();\r
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))\r
+ .append(tab).append("\t").append("<Numchildren>").append(getChildRecords().size()).append("</Numchildren>\n")\r
+ .append(tab).append("\t").append("<IsContainer>").append(isContainerRecord()).append("</IsContainer>\n");\r
+ for (EscherProperty property: getEscherProperties()){\r
+ builder.append(property.toXml(tab+"\t"));\r
+ }\r
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");\r
+ return builder.toString();\r
+ }\r
+}\r
+ ", data: " + '\n' + results.toString();
}
+ public String toXml(String tab){
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
+ .append("\" name=\"").append(getName()).append("\" blipId=\"")
+ .append(isBlipId()).append("\">\n");
+ for (int i = 0; i < getNumberOfElementsInArray(); i++) {
+ builder.append("\t").append(tab).append("<Element>").append(HexDump.toHex(getElement(i))).append("</Element>\n");
+ }
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
/**
* We have this method because the way in which arrays in escher works
* is screwed for seemly arbitary reasons. While most properties are
" Extra Data:" + '\n' + extraData;
}
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<BlipTypeWin32>").append(field_1_blipTypeWin32).append("</BlipTypeWin32>\n")
+ .append(tab).append("\t").append("<BlipTypeMacOS>").append(field_2_blipTypeMacOS).append("</BlipTypeMacOS>\n")
+ .append(tab).append("\t").append("<SUID>").append(field_3_uid == null ? "" : HexDump.toHex(field_3_uid)).append("</SUID>\n")
+ .append(tab).append("\t").append("<Tag>").append(field_4_tag).append("</Tag>\n")
+ .append(tab).append("\t").append("<Size>").append(field_5_size).append("</Size>\n")
+ .append(tab).append("\t").append("<Ref>").append(field_6_ref).append("</Ref>\n")
+ .append(tab).append("\t").append("<Offset>").append(field_7_offset).append("</Offset>\n")
+ .append(tab).append("\t").append("<Usage>").append(field_8_usage).append("</Usage>\n")
+ .append(tab).append("\t").append("<Name>").append(field_9_name).append("</Name>\n")
+ .append(tab).append("\t").append("<Unused2>").append(field_10_unused2).append("</Unused2>\n")
+ .append(tab).append("\t").append("<Unused3>").append(field_11_unused3).append("</Unused3>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
/**
* Retrieve the string representation given a blip id.
*/
" Marker: 0x" + HexDump.toHex( field_2_marker ) + nl +
" Extra Data:" + nl + extraData;
}
+
+ @Override
+ public String toXml(String tab) {
+ String extraData;
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ try
+ {
+ HexDump.dump( this.field_pictureData, 0, b, 0 );
+ extraData = b.toString();
+ }
+ catch ( Exception e )
+ {
+ extraData = e.toString();
+ }
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<UID>0x").append(HexDump.toHex(field_1_UID)).append("</UID>\n")
+ .append(tab).append("\t").append("<Marker>0x").append(HexDump.toHex(field_2_marker)).append("</Marker>\n")
+ .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
}
" Instance: 0x" + HexDump.toHex( getInstance() ) + '\n' +
" Extra Data:" + '\n' + extraData;
}
+
+ @Override
+ public String toXml(String tab) {
+ String extraData = HexDump.toHex(field_pictureData, 32);
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
}
" Data:" + nl + extraData;
}
+ @Override
+ public String toXml(String tab) {
+ String extraData;
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ try
+ {
+ HexDump.dump( this.field_12_data, 0, b, 0 );
+ extraData = b.toString();
+ }
+ catch ( Exception e )
+ {
+ extraData = e.toString();
+ }
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<SecondaryUID>0x").append(HexDump.toHex(field_1_secondaryUID)).append("</SecondaryUID>\n")
+ .append(tab).append("\t").append("<CacheOfSize>").append(field_2_cacheOfSize).append("</CacheOfSize>\n")
+ .append(tab).append("\t").append("<BoundaryTop>").append(field_3_boundaryTop).append("</BoundaryTop>\n")
+ .append(tab).append("\t").append("<BoundaryLeft>").append(field_4_boundaryLeft).append("</BoundaryLeft>\n")
+ .append(tab).append("\t").append("<BoundaryWidth>").append(field_5_boundaryWidth).append("</BoundaryWidth>\n")
+ .append(tab).append("\t").append("<BoundaryHeight>").append(field_6_boundaryHeight).append("</BoundaryHeight>\n")
+ .append(tab).append("\t").append("<X>").append(field_7_width).append("</X>\n")
+ .append(tab).append("\t").append("<Y>").append(field_8_height).append("</Y>\n")
+ .append(tab).append("\t").append("<CacheOfSavedSize>").append(field_9_cacheOfSavedSize).append("</CacheOfSavedSize>\n")
+ .append(tab).append("\t").append("<CompressionFlag>").append(field_10_compressionFlag).append("</CompressionFlag>\n")
+ .append(tab).append("\t").append("<Filter>").append(field_11_filter).append("</Filter>\n")
+ .append(tab).append("\t").append("<Data>").append(extraData).append("</Data>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
/**
* Compress the contents of the provided array
*
package org.apache.poi.ddf;
+import org.apache.poi.util.HexDump;
+
/**
* Represents a boolean property. The actual utility of this property is in doubt because many
* of the properties marked as boolean seem to actually contain special values. In other words
// + ", value: " + (getValue() != 0);
// }
+ public String toXml(String tab){
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
+ .append("\" name=\"").append(getName()).append("\" blipId=\"")
+ .append(isBlipId()).append("\" value=\"").append(isTrue()).append("\"").append("/>\n");
+ return builder.toString();
+ }
}
}
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<X1>").append(field_1_dx1).append("</X1>\n")
+ .append(tab).append("\t").append("<Y1>").append(field_2_dy1).append("</Y1>\n")
+ .append(tab).append("\t").append("<X2>").append(field_3_dx2).append("</X2>\n")
+ .append(tab).append("\t").append("<Y2>").append(field_4_dy2).append("</Y2>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
/**
* Retrieves offset within the parent coordinate space for the top left point.
*/
}
+ @Override
+ public String toXml(String tab) {
+ String extraData;
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ try
+ {
+ HexDump.dump(this.remainingData, 0, b, 0);
+ extraData = b.toString();
+ }
+ catch ( Exception e )
+ {
+ extraData = "error\n";
+ }
+ if (extraData.contains("No Data")){
+ extraData = "No Data";
+ }
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<Flag>").append(field_1_flag).append("</Flag>\n")
+ .append(tab).append("\t").append("<Col1>").append(field_2_col1).append("</Col1>\n")
+ .append(tab).append("\t").append("<DX1>").append(field_3_dx1).append("</DX1>\n")
+ .append(tab).append("\t").append("<Row1>").append(field_4_row1).append("</Row1>\n")
+ .append(tab).append("\t").append("<DY1>").append(field_5_dy1).append("</DY1>\n")
+ .append(tab).append("\t").append("<Col2>").append(field_6_col2).append("</Col2>\n")
+ .append(tab).append("\t").append("<DX2>").append(field_7_dx2).append("</DX2>\n")
+ .append(tab).append("\t").append("<Row2>").append(field_8_row2).append("</Row2>\n")
+ .append(tab).append("\t").append("<DY2>").append(field_9_dy2).append("</DY2>\n")
+ .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
/**
* 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
*/
}
+ @Override
+ public String toXml(String tab) {
+ String extraData;
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ try
+ {
+ HexDump.dump(this.remainingData, 0, b, 0);
+ extraData = b.toString();
+ }
+ catch ( Exception e )
+ {
+ extraData = "error";
+ }
+ if (extraData.contains("No Data")){
+ extraData = "No Data";
+ }
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()),
+ HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
/**
* Any data recording this record.
*/
+ ", data: " + System.getProperty("line.separator") + dataStr;
}
+ public String toXml(String tab){
+ String dataStr = HexDump.toHex( _complexData, 32);
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
+ .append("\" name=\"").append(getName()).append("\" blipId=\"")
+ .append(isBlipId()).append("\">\n");
+ builder.append("\t").append(tab).append(dataStr);
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
}
+ children.toString();
}
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<RecordName>").append(getRecordName()).append("</RecordName>\n")
+ .append(tab).append("\t").append("<IsContainer>").append(isContainerRecord()).append("</IsContainer>\n")
+ .append(tab).append("\t").append("<Numchildren>").append(HexDump.toHex(_childRecords.size())).append("</Numchildren>\n");
+ for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator
+ .hasNext(); )
+ {
+ EscherRecord record = iterator.next();
+ builder.append(record.toXml(tab+"\t"));
+ }
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
public <T extends EscherRecord> T getChildById( short recordId )
{
for ( EscherRecord childRecord : _childRecords )
" Instance: 0x" + HexDump.toHex(getInstance()) + '\n' +
" NumShapes: " + field_1_numShapes + '\n' +
" LastMSOSPID: " + field_2_lastMSOSPID + '\n';
+ }
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<NumShapes>").append(field_1_numShapes).append("</NumShapes>\n")
+ .append(tab).append("\t").append("<LastMSOSPID>").append(field_2_lastMSOSPID).append("</LastMSOSPID>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
}
/**
}
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<ShapeIdMax>").append(field_1_shapeIdMax).append("</ShapeIdMax>\n")
+ .append(tab).append("\t").append("<NumIdClusters>").append(getNumIdClusters()).append("</NumIdClusters>\n")
+ .append(tab).append("\t").append("<NumShapesSaved>").append(field_3_numShapesSaved).append("</NumShapesSaved>\n")
+ .append(tab).append("\t").append("<DrawingsSaved>").append(field_4_drawingsSaved).append("</DrawingsSaved>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
public int getShapeIdMax() {
return field_1_shapeIdMax;
}
" Filter: " + HexDump.toHex( field_7_fFilter ) + '\n' +
" Extra Data:" + '\n' + extraData +
(remainingData == null ? null : ("\n" +
- " Remaining Data: " + HexDump.toHex(remainingData, 32)));
- }
-
- /**
- * Return the blip signature
- *
+ " Remaining Data: " + HexDump.toHex(remainingData, 32)));\r
+ }\r
+\r
+ @Override\r
+ public String toXml(String tab) {\r
+ String extraData = "";\r
+ StringBuilder builder = new StringBuilder();\r
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))\r
+ .append(tab).append("\t").append("<UID>0x").append(HexDump.toHex( field_1_UID ) + '\n' +\r
+ (field_2_UID == null ? "" : (" UID2: 0x" + HexDump.toHex( field_2_UID ) + '\n'))).append("</UID>\n")\r
+ .append(tab).append("\t").append("<UncompressedSize>0x").append(HexDump.toHex( field_2_cb )).append("</UncompressedSize>\n")\r
+ .append(tab).append("\t").append("<Bounds>").append(getBounds()).append("</Bounds>\n")\r
+ .append(tab).append("\t").append("<SizeInEMU>").append(getSizeEMU()).append("</SizeInEMU>\n")\r
+ .append(tab).append("\t").append("<CompressedSize>0x").append(HexDump.toHex( field_5_cbSave )).append("</CompressedSize>\n")\r
+ .append(tab).append("\t").append("<Compression>0x").append(HexDump.toHex( field_6_fCompression )).append("</Compression>\n")\r
+ .append(tab).append("\t").append("<Filter>0x").append(HexDump.toHex( field_7_fFilter )).append("</Filter>\n")\r
+ .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n")\r
+ .append(tab).append("\t").append("<RemainingData>0x").append(HexDump.toHex(remainingData, 32)).append("</RemainingData>\n");\r
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");\r
+ return builder.toString();\r
+ }\r
+\r
+ /**\r
+ * Return the blip signature\r
+ *\r
* @return the blip signature
*/
public short getSignature() {
==================================================================== */
package org.apache.poi.ddf;
+import org.apache.poi.util.HexDump;
import org.apache.poi.util.Internal;
/**
super.setVersion( value );
}
+
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())));
+ for (EscherProperty property: getEscherProperties()){
+ builder.append(property.toXml(tab+"\t"));
+ }
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
}
" Size in EMU: " + getSizeEMU() + '\n' +
" Compressed Size: " + HexDump.toHex( field_5_cbSave ) + '\n' +
" Compression: " + HexDump.toHex( field_6_fCompression ) + '\n' +
- " Filter: " + HexDump.toHex( field_7_fFilter ) + '\n' +
- " Extra Data:" + '\n' + extraData;
- }
-}
+ " Filter: " + HexDump.toHex( field_7_fFilter ) + '\n' +\r
+ " Extra Data:" + '\n' + extraData;\r
+ }\r
+\r
+ @Override\r
+ public String toXml(String tab) {\r
+ String extraData = "";\r
+ StringBuilder builder = new StringBuilder();\r
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))\r
+ .append(tab).append("\t").append("<UID>0x").append(HexDump.toHex( field_1_UID )).append("</UID>\n")\r
+ .append(tab).append("\t").append("<UncompressedSize>0x").append(HexDump.toHex( field_2_cb )).append("</UncompressedSize>\n")\r
+ .append(tab).append("\t").append("<Bounds>").append(getBounds()).append("</Bounds>\n")\r
+ .append(tab).append("\t").append("<SizeInEMU>").append(getSizeEMU()).append("</SizeInEMU>\n")\r
+ .append(tab).append("\t").append("<CompressedSize>0x").append(HexDump.toHex( field_5_cbSave )).append("</CompressedSize>\n")\r
+ .append(tab).append("\t").append("<Compression>0x").append(HexDump.toHex( field_6_fCompression )).append("</Compression>\n")\r
+ .append(tab).append("\t").append("<Filter>0x").append(HexDump.toHex( field_7_fFilter )).append("</Filter>\n")\r
+ .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");\r
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");\r
+ return builder.toString();\r
+ }\r
+}\r
public int getPropertySize() {
return 6;
}
+
+ public String toXml(String tab){
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"").append(getId()).append("\" name=\"").append(getName()).append("\" blipId=\"")
+ .append(isBlipId()).append("\"/>\n");
+ return builder.toString();
+ }
/**
* Escher properties consist of a simple fixed length part and a complex variable length part.
package org.apache.poi.ddf;
+import org.apache.poi.util.HexDump;
+
/**
* A color property.
*
return (byte) ( (propertyValue >> 16) & 0xFF );
}
+ public String toXml(String tab){
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
+ .append("\" name=\"").append(getName()).append("\" blipId=\"")
+ .append(isBlipId()).append("\" value=\"0x").append(HexDump.toHex(propertyValue)).append("\"/>\n");
+ return builder.toString();
+ }
}
import java.util.Collections;
import java.util.List;
-import org.apache.poi.util.BitField;
-import org.apache.poi.util.BitFieldFactory;
-import org.apache.poi.util.Internal;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.*;
/**
* The base abstract record from which all escher records are defined. Subclasses will need
{
_options = fVersion.setShortValue( _options, value );
}
+
+ /**
+ * @param tab - each children must be a right of his parent
+ * @return
+ */
+ public String toXml(String tab){
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append("<").append(getClass().getSimpleName()).append(">\n")
+ .append(tab).append("\t").append("<RecordId>0x").append(HexDump.toHex(_recordId)).append("</RecordId>\n")
+ .append(tab).append("\t").append("<Options>").append(_options).append("</Options>\n")
+ .append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
+ protected String formatXmlRecordHeader(String className, String recordId, String version, String instance){
+ StringBuilder builder = new StringBuilder();
+ builder.append("<").append(className).append(" recordId=\"0x").append(recordId).append("\" version=\"0x")
+ .append(version).append("\" instance=\"0x").append(instance).append("\">\n");
+ return builder.toString();
+ }
+
+ public String toXml(){
+ return toXml("");
+ }
}
+ ", value: " + propertyValue + " (0x" + HexDump.toHex(propertyValue) + ")";
}
+ public String toXml(String tab){
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
+ .append("\" name=\"").append(getName()).append("\" blipId=\"")
+ .append(isBlipId()).append("\" complex=\"").append(isComplex()).append("\" value=\"").append("0x")
+ .append(HexDump.toHex(propertyValue)).append("\"/>\n");
+ return builder.toString();
+ }
}
}
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<ShapeType>").append(HexDump.toHex(getShapeType())).append("</ShapeType>\n")
+ .append(tab).append("\t").append("<ShapeId>").append(field_1_shapeId).append("</ShapeId>\n")
+ .append(tab).append("\t").append("<Flags>").append(decodeFlags(field_2_flags) + " (0x" + HexDump.toHex(field_2_flags) + ")").append("</Flags>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
/**
* Converts the shape flags into a more descriptive name.
*/
" RectHeight: " + field_4_rectY2 + '\n';
}
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<RectX>").append(field_1_rectX1).append("</RectX>\n")
+ .append(tab).append("\t").append("<RectY>").append(field_2_rectY1).append("</RectY>\n")
+ .append(tab).append("\t").append("<RectWidth>").append(field_3_rectX2).append("</RectWidth>\n")
+ .append(tab).append("\t").append("<RectHeight>").append(field_4_rectY2).append("</RectHeight>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
/**
* The starting top-left coordinate of child records.
*/
"";
}
+ @Override
+ public String toXml(String tab) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<Color1>0x").append(HexDump.toHex(field_1_color1)).append("</Color1>\n")
+ .append(tab).append("\t").append("<Color2>0x").append(HexDump.toHex(field_2_color2)).append("</Color2>\n")
+ .append(tab).append("\t").append("<Color3>0x").append(HexDump.toHex(field_3_color3)).append("</Color3>\n")
+ .append(tab).append("\t").append("<Color4>0x").append(HexDump.toHex(field_4_color4)).append("</Color4>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
public int getColor1()
{
return field_1_color1;
theDumpHex;
}
+ @Override
+ public String toXml(String tab) {
+ String theDumpHex = "";
+ try
+ {
+ if (thedata.length != 0)
+ {
+ theDumpHex += HexDump.dump(thedata, 0, 0);
+ }
+ }
+ catch ( Exception e )
+ {
+ theDumpHex = "Error!!";
+ }
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<IsContainer>").append(isContainerRecord()).append("</IsContainer>\n")
+ .append(tab).append("\t").append("<Numchildren>").append(getChildRecords().size()).append("</Numchildren>\n")
+ .append(tab).append("\t").append("<ExtraData>").append(theDumpHex).append("</ExtraData>\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
}
package org.apache.poi.ddf;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.apache.poi.util.HexDump;
children.toString();
}
+ @Override
+ public String toXml(String tab) {
+ String theDumpHex = HexDump.toHex(thedata, 32);
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
+ .append(tab).append("\t").append("<IsContainer>").append(isContainerRecord()).append("</IsContainer>\n")
+ .append(tab).append("\t").append("<Numchildren>").append(HexDump.toHex(_childRecords.size())).append("</Numchildren>\n");
+ for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator
+ .hasNext(); )
+ {
+ EscherRecord record = iterator.next();
+ builder.append(record.toXml(tab+"\t"));
+ }
+ builder.append(theDumpHex).append("\n");
+ builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
+ return builder.toString();
+ }
+
public void addChildRecord(EscherRecord childRecord) {
getChildRecords().add( childRecord );
}
--- /dev/null
+/*\r
+ * ====================================================================\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ====================================================================\r
+ */\r
+\r
+package org.apache.poi.hssf.dev;\r
+\r
+import org.apache.poi.ddf.EscherRecord;\r
+import org.apache.poi.hssf.model.InternalWorkbook;\r
+import org.apache.poi.hssf.record.*;\r
+import org.apache.poi.hssf.usermodel.HSSFPatriarch;\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;\r
+\r
+import java.io.*;\r
+import java.lang.reflect.Field;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+/**\r
+ * Utility for representing drawings contained in a binary Excel file as a XML tree\r
+ *\r
+ * @author Evgeniy Berlog\r
+ * date: 10.04.12\r
+ */\r
+public class BiffDrawingToXml {\r
+\r
+ private static final String SHEET_NAME_PARAM = "-sheet-name";\r
+ private static final String SHEET_INDEXES_PARAM = "-sheet-indexes";\r
+ private static final String EXCLUDE_WORKBOOK_RECORDS = "-exclude-workbook";\r
+\r
+ private static int getAttributeIndex(String attribute, String[] params) {\r
+ for (int i = 0; i < params.length; i++) {\r
+ String param = params[i];\r
+ if (attribute.equals(param)) {\r
+ return i;\r
+ }\r
+ }\r
+ return -1;\r
+ }\r
+\r
+ private static boolean isExcludeWorkbookRecords(String[] params) {\r
+ return -1 != getAttributeIndex(EXCLUDE_WORKBOOK_RECORDS, params);\r
+ }\r
+\r
+ private static List<Integer> getIndexesByName(String[] params, HSSFWorkbook workbook) {\r
+ List<Integer> list = new ArrayList<Integer>();\r
+ int pos = getAttributeIndex(SHEET_NAME_PARAM, params);\r
+ if (-1 != pos) {\r
+ if (pos >= params.length) {\r
+ throw new IllegalArgumentException("sheet name param value was not specified");\r
+ }\r
+ String sheetName = params[pos + 1];\r
+ int sheetPos = workbook.getSheetIndex(sheetName);\r
+ if (-1 == sheetPos){\r
+ throw new IllegalArgumentException("specified sheet name has not been found in xls file");\r
+ }\r
+ list.add(sheetPos);\r
+ }\r
+ return list;\r
+ }\r
+\r
+ private static List<Integer> getIndexesByIdArray(String[] params) {\r
+ List<Integer> list = new ArrayList<Integer>();\r
+ int pos = getAttributeIndex(SHEET_INDEXES_PARAM, params);\r
+ if (-1 != pos) {\r
+ if (pos >= params.length) {\r
+ throw new IllegalArgumentException("sheet list value was not specified");\r
+ }\r
+ String sheetParam = params[pos + 1];\r
+ String[] sheets = sheetParam.split(",");\r
+ for (String sheet : sheets) {\r
+ list.add(Integer.parseInt(sheet));\r
+ }\r
+ }\r
+ return list;\r
+ }\r
+\r
+ private static List<Integer> getSheetsIndexes(String[] params, HSSFWorkbook workbook) {\r
+ List<Integer> list = new ArrayList<Integer>();\r
+ list.addAll(getIndexesByIdArray(params));\r
+ list.addAll(getIndexesByName(params, workbook));\r
+ if (0 == list.size()) {\r
+ int size = workbook.getNumberOfSheets();\r
+ for (int i = 0; i < size; i++) {\r
+ list.add(i);\r
+ }\r
+ }\r
+ return list;\r
+ }\r
+\r
+ private static String getInputFileName(String[] params) {\r
+ return params[params.length - 1];\r
+ }\r
+\r
+ private static String getOutputFileName(String input) {\r
+ if (input.contains("xls")) {\r
+ return input.replace(".xls", ".xml");\r
+ }\r
+ return input + ".xml";\r
+ }\r
+\r
+ public static void main(String[] params) throws IOException {\r
+ if (0 == params.length) {\r
+ System.out.println("Usage: BiffDrawingToXml [options] inputWorkbook");\r
+ System.out.println("Options:");\r
+ System.out.println(" -exclude-workbook exclude workbook-level records");\r
+ System.out.println(" -sheet-indexes <indexes> output sheets with specified indexes");\r
+ System.out.println(" -sheet-namek <names> output sheets with specified name");\r
+ return;\r
+ }\r
+ String input = getInputFileName(params);\r
+ FileInputStream inp = new FileInputStream(input);\r
+ String output = getOutputFileName(input);\r
+ FileOutputStream outputStream = new FileOutputStream(output);\r
+ writeToFile(outputStream, inp, isExcludeWorkbookRecords(params), params);\r
+ inp.close();\r
+ outputStream.close();\r
+ }\r
+\r
+ public static void writeToFile(FileOutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {\r
+ POIFSFileSystem fs = new POIFSFileSystem(xlsWorkbook);\r
+ HSSFWorkbook workbook = new HSSFWorkbook(fs);\r
+ InternalWorkbook internalWorkbook = getInternalWorkbook(workbook);\r
+ DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);\r
+ r.decode();\r
+\r
+ StringBuilder builder = new StringBuilder();\r
+ builder.append("<workbook>\n");\r
+ String tab = "\t";\r
+ if (!excludeWorkbookRecords) {\r
+ List<EscherRecord> escherRecords = r.getEscherRecords();\r
+ for (EscherRecord record : escherRecords) {\r
+ builder.append(record.toXml(tab));\r
+ }\r
+ }\r
+ List<Integer> sheets = getSheetsIndexes(params, workbook);\r
+ for (Integer i : sheets) {\r
+ HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();\r
+ if(p != null ) {\r
+ builder.append(tab).append("<sheet").append(i).append(">\n");\r
+ builder.append(getHSSFPatriarchBoundAggregate(p).toXml(tab + "\t"));\r
+ builder.append(tab).append("</sheet").append(i).append(">\n");\r
+ }\r
+ }\r
+ builder.append("</workbook>\n");\r
+ fos.write(builder.toString().getBytes());\r
+ fos.close();\r
+ }\r
+\r
+ private static EscherAggregate getHSSFPatriarchBoundAggregate(HSSFPatriarch patriarch) {\r
+ Field boundAggregateField = null;\r
+ try {\r
+ boundAggregateField = patriarch.getClass().getDeclaredField("_boundAggregate");\r
+ boundAggregateField.setAccessible(true);\r
+ return (EscherAggregate) boundAggregateField.get(patriarch);\r
+ } catch (NoSuchFieldException e) {\r
+ e.printStackTrace();\r
+ } catch (IllegalAccessException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
+\r
+ private static InternalWorkbook getInternalWorkbook(HSSFWorkbook workbook) {\r
+ Field internalSheetField = null;\r
+ try {\r
+ internalSheetField = workbook.getClass().getDeclaredField("workbook");\r
+ internalSheetField.setAccessible(true);\r
+ return (InternalWorkbook) internalSheetField.get(workbook);\r
+ } catch (NoSuchFieldException e) {\r
+ e.printStackTrace();\r
+ } catch (IllegalAccessException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
+}\r
return result.toString();
}
+
+ public String toXml(String tab){
+ StringBuilder builder = new StringBuilder();
+ builder.append(tab).append("<").append(getRecordName()).append(">\n");
+ for ( Iterator iterator = getEscherRecords().iterator(); iterator.hasNext(); )
+ {
+ EscherRecord escherRecord = (EscherRecord) iterator.next();
+ builder.append( escherRecord.toXml(tab+"\t") );
+ }
+ builder.append(tab).append("</").append(getRecordName()).append(">\n");
+ return builder.toString();
+ }
/**
* Collapses the drawing records into an aggregate.