View | Details | Raw Unified | Return to bug 53058
Collapse All | Expand All

(-)src/java/org/apache/poi/ddf/EscherSplitMenuColorsRecord.java (+12 lines)
Lines 99-104 Link Here
99
                "";
99
                "";
100
    }
100
    }
101
101
102
    @Override
103
    public String toXml(String tab) {
104
        StringBuilder builder = new StringBuilder();
105
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
106
                .append(tab).append("\t").append("<Color1>0x").append(HexDump.toHex(field_1_color1)).append("</Color1>\n")
107
                .append(tab).append("\t").append("<Color2>0x").append(HexDump.toHex(field_2_color2)).append("</Color2>\n")
108
                .append(tab).append("\t").append("<Color3>0x").append(HexDump.toHex(field_3_color3)).append("</Color3>\n")
109
                .append(tab).append("\t").append("<Color4>0x").append(HexDump.toHex(field_4_color4)).append("</Color4>\n");
110
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
111
        return builder.toString();
112
    }
113
102
    public int getColor1()
114
    public int getColor1()
103
    {
115
    {
104
        return field_1_color1;
116
        return field_1_color1;
(-)src/java/org/apache/poi/ddf/EscherMetafileBlip.java (+19 lines)
Lines 262-267 Link Here
262
                 " Remaining Data: " + HexDump.toHex(remainingData, 32)));
262
                 " Remaining Data: " + HexDump.toHex(remainingData, 32)));
263
    }
263
    }
264
264
265
    @Override
266
    public String toXml(String tab) {
267
        String extraData = "";
268
        StringBuilder builder = new StringBuilder();
269
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
270
                .append(tab).append("\t").append("<UID>0x").append(HexDump.toHex( field_1_UID ) + '\n' +
271
                                (field_2_UID == null ? "" : ("  UID2: 0x" + HexDump.toHex( field_2_UID ) + '\n'))).append("</UID>\n")
272
                .append(tab).append("\t").append("<UncompressedSize>0x").append(HexDump.toHex( field_2_cb )).append("</UncompressedSize>\n")
273
                .append(tab).append("\t").append("<Bounds>").append(getBounds()).append("</Bounds>\n")
274
                .append(tab).append("\t").append("<SizeInEMU>").append(getSizeEMU()).append("</SizeInEMU>\n")
275
                .append(tab).append("\t").append("<CompressedSize>0x").append(HexDump.toHex( field_5_cbSave )).append("</CompressedSize>\n")
276
                .append(tab).append("\t").append("<Compression>0x").append(HexDump.toHex( field_6_fCompression )).append("</Compression>\n")
277
                .append(tab).append("\t").append("<Filter>0x").append(HexDump.toHex( field_7_fFilter )).append("</Filter>\n")
278
                .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n")
279
                .append(tab).append("\t").append("<RemainingData>0x").append(HexDump.toHex(remainingData, 32)).append("</RemainingData>\n");
280
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
281
        return builder.toString();
282
    }
283
265
    /**
284
    /**
266
     * Return the blip signature
285
     * Return the blip signature
267
     *
286
     *
(-)src/java/org/apache/poi/ddf/EscherBlipRecord.java (+10 lines)
Lines 81-84 Link Here
81
                "  Instance: 0x" + HexDump.toHex( getInstance() ) + '\n' +
81
                "  Instance: 0x" + HexDump.toHex( getInstance() ) + '\n' +
82
                "  Extra Data:" + '\n' + extraData;
82
                "  Extra Data:" + '\n' + extraData;
83
    }
83
    }
84
85
    @Override
86
    public String toXml(String tab) {
87
        String extraData = HexDump.toHex(field_pictureData, 32);
88
        StringBuilder builder = new StringBuilder();
89
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
90
                .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
91
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
92
        return builder.toString();
93
    }
84
}
94
}
(-)src/java/org/apache/poi/ddf/EscherChildAnchorRecord.java (+12 lines)
Lines 97-102 Link Here
97
97
98
    }
98
    }
99
99
100
    @Override
101
    public String toXml(String tab) {
102
        StringBuilder builder = new StringBuilder();
103
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
104
                .append(tab).append("\t").append("<X1>").append(field_1_dx1).append("</X1>\n")
105
                .append(tab).append("\t").append("<Y1>").append(field_2_dy1).append("</Y1>\n")
106
                .append(tab).append("\t").append("<X2>").append(field_3_dx2).append("</X2>\n")
107
                .append(tab).append("\t").append("<Y2>").append(field_4_dy2).append("</Y2>\n");
108
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
109
        return builder.toString();
110
    }
111
100
    /**
112
    /**
101
     * Retrieves offset within the parent coordinate space for the top left point.
113
     * Retrieves offset within the parent coordinate space for the top left point.
102
     */
114
     */
(-)src/java/org/apache/poi/ddf/EscherSpRecord.java (+11 lines)
Lines 115-120 Link Here
115
115
116
    }
116
    }
117
117
118
    @Override
119
    public String toXml(String tab) {
120
        StringBuilder builder = new StringBuilder();
121
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
122
                .append(tab).append("\t").append("<ShapeType>").append(HexDump.toHex(getShapeType())).append("</ShapeType>\n")
123
                .append(tab).append("\t").append("<ShapeId>").append(field_1_shapeId).append("</ShapeId>\n")
124
                .append(tab).append("\t").append("<Flags>").append(decodeFlags(field_2_flags) + " (0x" + HexDump.toHex(field_2_flags) + ")").append("</Flags>\n");
125
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
126
        return builder.toString();
127
    }
128
118
    /**
129
    /**
119
     * Converts the shape flags into a more descriptive name.
130
     * Converts the shape flags into a more descriptive name.
120
     */
131
     */
(-)src/java/org/apache/poi/ddf/UnknownEscherRecord.java (+19 lines)
Lines 18-23 Link Here
18
package org.apache.poi.ddf;
18
package org.apache.poi.ddf;
19
19
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.Iterator;
21
import java.util.List;
22
import java.util.List;
22
23
23
import org.apache.poi.util.HexDump;
24
import org.apache.poi.util.HexDump;
Lines 141-146 Link Here
141
                "  numchildren: " + getChildRecords().size() + '\n' +
142
                "  numchildren: " + getChildRecords().size() + '\n' +
142
                theDumpHex +
143
                theDumpHex +
143
                children.toString();
144
                children.toString();
145
    }
146
147
    @Override
148
    public String toXml(String tab) {
149
        String theDumpHex = HexDump.toHex(thedata, 32);
150
        StringBuilder builder = new StringBuilder();
151
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
152
                .append(tab).append("\t").append("<IsContainer>").append(isContainerRecord()).append("</IsContainer>\n")
153
                .append(tab).append("\t").append("<Numchildren>").append(HexDump.toHex(_childRecords.size())).append("</Numchildren>\n");
154
        for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator
155
                .hasNext(); )
156
        {
157
            EscherRecord record = iterator.next();
158
            builder.append(record.toXml(tab+"\t"));
159
        }
160
        builder.append(theDumpHex).append("\n");
161
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
162
        return builder.toString();
144
    }
163
    }
145
164
146
    public void addChildRecord(EscherRecord childRecord) {
165
    public void addChildRecord(EscherRecord childRecord) {
(-)src/java/org/apache/poi/ddf/EscherDgRecord.java (+9 lines)
Lines 92-98 Link Here
92
                "  Instance: 0x" + HexDump.toHex(getInstance()) + '\n' +
92
                "  Instance: 0x" + HexDump.toHex(getInstance()) + '\n' +
93
                "  NumShapes: " + field_1_numShapes + '\n' +
93
                "  NumShapes: " + field_1_numShapes + '\n' +
94
                "  LastMSOSPID: " + field_2_lastMSOSPID + '\n';
94
                "  LastMSOSPID: " + field_2_lastMSOSPID + '\n';
95
    }
95
96
97
    @Override
98
    public String toXml(String tab) {
99
        StringBuilder builder = new StringBuilder();
100
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
101
                .append(tab).append("\t").append("<NumShapes>").append(field_1_numShapes).append("</NumShapes>\n")
102
                .append(tab).append("\t").append("<LastMSOSPID>").append(field_2_lastMSOSPID).append("</LastMSOSPID>\n");
103
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
104
        return builder.toString();
96
    }
105
    }
97
106
98
    /**
107
    /**
(-)src/java/org/apache/poi/hssf/record/EscherAggregate.java (-1 / +13 lines)
Lines 329-335 Link Here
329
329
330
		return result.toString();
330
		return result.toString();
331
	}
331
	}
332
332
    
333
    public String toXml(String tab){
334
        StringBuilder builder = new StringBuilder();
335
        builder.append(tab).append("<").append(getRecordName()).append(">\n");
336
        for ( Iterator iterator = getEscherRecords().iterator(); iterator.hasNext(); )
337
        {
338
            EscherRecord escherRecord = (EscherRecord) iterator.next();
339
            builder.append( escherRecord.toXml(tab+"\t") );
340
        }
341
        builder.append(tab).append("</").append(getRecordName()).append(">\n");
342
        return builder.toString();
343
    }
344
333
	/**
345
	/**
334
	 * Collapses the drawing records into an aggregate.
346
	 * Collapses the drawing records into an aggregate.
335
	 */
347
	 */
(-)src/java/org/apache/poi/ddf/EscherOptRecord.java (+12 lines)
Lines 16-21 Link Here
16
==================================================================== */
16
==================================================================== */
17
package org.apache.poi.ddf;
17
package org.apache.poi.ddf;
18
18
19
import org.apache.poi.util.HexDump;
19
import org.apache.poi.util.Internal;
20
import org.apache.poi.util.Internal;
20
21
21
/**
22
/**
Lines 70-74 Link Here
70
                    + " can have only '0x3' version" );
71
                    + " can have only '0x3' version" );
71
72
72
        super.setVersion( value );
73
        super.setVersion( value );
74
    }
75
76
    @Override
77
    public String toXml(String tab) {
78
        StringBuilder builder = new StringBuilder();
79
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())));
80
        for (EscherProperty property: getEscherProperties()){
81
            builder.append(property.toXml(tab+"\t"));
82
        }
83
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
84
        return builder.toString();
73
    }
85
    }
74
}
86
}
(-)src/java/org/apache/poi/ddf/EscherClientDataRecord.java (+24 lines)
Lines 99-104 Link Here
99
99
100
    }
100
    }
101
101
102
    @Override
103
    public String toXml(String tab) {
104
        String extraData;
105
        ByteArrayOutputStream b = new ByteArrayOutputStream();
106
        try
107
        {
108
            HexDump.dump(this.remainingData, 0, b, 0);
109
            extraData = b.toString();
110
        }
111
        catch ( Exception e )
112
        {
113
            extraData = "error";
114
        }
115
        if (extraData.contains("No Data")){
116
            extraData = "No Data";
117
        }
118
        StringBuilder builder = new StringBuilder();
119
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()),
120
                HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
121
                .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
122
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
123
        return builder.toString();
124
    }
125
102
    /**
126
    /**
103
     * Any data recording this record.
127
     * Any data recording this record.
104
     */
128
     */
(-)src/java/org/apache/poi/ddf/EscherBSERecord.java (+19 lines)
Lines 330-335 Link Here
330
                "  Extra Data:" + '\n' + extraData;
330
                "  Extra Data:" + '\n' + extraData;
331
    }
331
    }
332
332
333
    @Override
334
    public String toXml(String tab) {
335
        StringBuilder builder = new StringBuilder();
336
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
337
                .append(tab).append("\t").append("<BlipTypeWin32>").append(field_1_blipTypeWin32).append("</BlipTypeWin32>\n")
338
                .append(tab).append("\t").append("<BlipTypeMacOS>").append(field_2_blipTypeMacOS).append("</BlipTypeMacOS>\n")
339
                .append(tab).append("\t").append("<SUID>").append(field_3_uid == null ? "" : HexDump.toHex(field_3_uid)).append("</SUID>\n")
340
                .append(tab).append("\t").append("<Tag>").append(field_4_tag).append("</Tag>\n")
341
                .append(tab).append("\t").append("<Size>").append(field_5_size).append("</Size>\n")
342
                .append(tab).append("\t").append("<Ref>").append(field_6_ref).append("</Ref>\n")
343
                .append(tab).append("\t").append("<Offset>").append(field_7_offset).append("</Offset>\n")
344
                .append(tab).append("\t").append("<Usage>").append(field_8_usage).append("</Usage>\n")
345
                .append(tab).append("\t").append("<Name>").append(field_9_name).append("</Name>\n")
346
                .append(tab).append("\t").append("<Unused2>").append(field_10_unused2).append("</Unused2>\n")
347
                .append(tab).append("\t").append("<Unused3>").append(field_11_unused3).append("</Unused3>\n");
348
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
349
        return builder.toString();
350
    }
351
333
    /**
352
    /**
334
     * Retrieve the string representation given a blip id.
353
     * Retrieve the string representation given a blip id.
335
     */
354
     */
(-)src/java/org/apache/poi/ddf/EscherComplexProperty.java (+10 lines)
Lines 134-137 Link Here
134
                + ", data: " + System.getProperty("line.separator") + dataStr;
134
                + ", data: " + System.getProperty("line.separator") + dataStr;
135
    }
135
    }
136
136
137
    public String toXml(String tab){
138
        String dataStr = HexDump.toHex( _complexData, 32);
139
        StringBuilder builder = new StringBuilder();
140
        builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
141
                .append("\" name=\"").append(getName()).append("\" blipId=\"")
142
                .append(isBlipId()).append("\">\n");
143
        builder.append("\t").append(tab).append(dataStr);
144
        builder.append(tab).append("<").append(getClass().getSimpleName()).append("/>\n");
145
        return builder.toString();
146
    }
137
}
147
}
(-)src/java/org/apache/poi/ddf/EscherRecord.java (-4 / +25 lines)
Lines 22-31 Link Here
22
import java.util.Collections;
22
import java.util.Collections;
23
import java.util.List;
23
import java.util.List;
24
24
25
import org.apache.poi.util.BitField;
25
import org.apache.poi.util.*;
26
import org.apache.poi.util.BitFieldFactory;
27
import org.apache.poi.util.Internal;
28
import org.apache.poi.util.LittleEndian;
29
26
30
/**
27
/**
31
 * The base abstract record from which all escher records are defined.  Subclasses will need
28
 * The base abstract record from which all escher records are defined.  Subclasses will need
Lines 296-300 Link Here
296
    public void setVersion( short value )
293
    public void setVersion( short value )
297
    {
294
    {
298
        _options = fVersion.setShortValue( _options, value );
295
        _options = fVersion.setShortValue( _options, value );
296
    }
297
298
    /**
299
     * @param tab - each children must be a right of his parent
300
     * @return
301
     */
302
    public String toXml(String tab){
303
        StringBuilder builder = new StringBuilder();
304
        builder.append(tab).append("<").append(getClass().getSimpleName()).append(">\n")
305
                .append(tab).append("\t").append("<RecordId>0x").append(HexDump.toHex(_recordId)).append("</RecordId>\n")
306
                .append(tab).append("\t").append("<Options>").append(_options).append("</Options>\n")
307
                .append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
308
        return builder.toString();
309
    }
310
    
311
    protected String formatXmlRecordHeader(String className, String recordId, String version, String instance){
312
        StringBuilder builder = new StringBuilder();
313
        builder.append("<").append(className).append(" recordId=\"0x").append(recordId).append("\" version=\"0x")
314
                .append(version).append("\" instance=\"0x").append(instance).append("\">\n");
315
        return builder.toString();
316
    }
317
    
318
    public String toXml(){
319
        return toXml("");
299
    }
320
    }
300
}
321
}
(-)src/java/org/apache/poi/ddf/EscherPictBlip.java (+17 lines)
Lines 213-216 Link Here
213
                "  Filter: " + HexDump.toHex( field_7_fFilter ) + '\n' +
213
                "  Filter: " + HexDump.toHex( field_7_fFilter ) + '\n' +
214
                "  Extra Data:" + '\n' + extraData;
214
                "  Extra Data:" + '\n' + extraData;
215
    }
215
    }
216
217
    @Override
218
    public String toXml(String tab) {
219
        String extraData = "";
220
        StringBuilder builder = new StringBuilder();
221
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
222
                .append(tab).append("\t").append("<UID>0x").append(HexDump.toHex( field_1_UID )).append("</UID>\n")
223
                .append(tab).append("\t").append("<UncompressedSize>0x").append(HexDump.toHex( field_2_cb )).append("</UncompressedSize>\n")
224
                .append(tab).append("\t").append("<Bounds>").append(getBounds()).append("</Bounds>\n")
225
                .append(tab).append("\t").append("<SizeInEMU>").append(getSizeEMU()).append("</SizeInEMU>\n")
226
                .append(tab).append("\t").append("<CompressedSize>0x").append(HexDump.toHex( field_5_cbSave )).append("</CompressedSize>\n")
227
                .append(tab).append("\t").append("<Compression>0x").append(HexDump.toHex( field_6_fCompression )).append("</Compression>\n")
228
                .append(tab).append("\t").append("<Filter>0x").append(HexDump.toHex( field_7_fFilter )).append("</Filter>\n")
229
                .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
230
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
231
        return builder.toString();
232
    }
216
}
233
}
(-)src/java/org/apache/poi/ddf/EscherClientAnchorRecord.java (+32 lines)
Lines 160-165 Link Here
160
160
161
    }
161
    }
162
162
163
    @Override
164
    public String toXml(String tab) {
165
        String extraData;
166
        ByteArrayOutputStream b = new ByteArrayOutputStream();
167
        try
168
        {
169
            HexDump.dump(this.remainingData, 0, b, 0);
170
            extraData = b.toString();
171
        }
172
        catch ( Exception e )
173
        {
174
            extraData = "error\n";
175
        }
176
        if (extraData.contains("No Data")){
177
            extraData = "No Data";
178
        }
179
        StringBuilder builder = new StringBuilder();
180
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
181
                .append(tab).append("\t").append("<Flag>").append(field_1_flag).append("</Flag>\n")
182
                .append(tab).append("\t").append("<Col1>").append(field_2_col1).append("</Col1>\n")
183
                .append(tab).append("\t").append("<DX1>").append(field_3_dx1).append("</DX1>\n")
184
                .append(tab).append("\t").append("<Row1>").append(field_4_row1).append("</Row1>\n")
185
                .append(tab).append("\t").append("<DY1>").append(field_5_dy1).append("</DY1>\n")
186
                .append(tab).append("\t").append("<Col2>").append(field_6_col2).append("</Col2>\n")
187
                .append(tab).append("\t").append("<DX2>").append(field_7_dx2).append("</DX2>\n")
188
                .append(tab).append("\t").append("<Row2>").append(field_8_row2).append("</Row2>\n")
189
                .append(tab).append("\t").append("<DY2>").append(field_9_dy2).append("</DY2>\n")
190
                .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
191
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
192
        return builder.toString();
193
    }
194
163
    /**
195
    /**
164
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
196
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
165
     */
197
     */
(-)src/java/org/apache/poi/ddf/EscherBoolProperty.java (+9 lines)
Lines 18-23 Link Here
18
18
19
package org.apache.poi.ddf;
19
package org.apache.poi.ddf;
20
20
21
import org.apache.poi.util.HexDump;
22
21
/**
23
/**
22
 * Represents a boolean property.  The actual utility of this property is in doubt because many
24
 * Represents a boolean property.  The actual utility of this property is in doubt because many
23
 * of the properties marked as boolean seem to actually contain special values.  In other words
25
 * of the properties marked as boolean seem to actually contain special values.  In other words
Lines 65-68 Link Here
65
//                + ", value: " + (getValue() != 0);
67
//                + ", value: " + (getValue() != 0);
66
//    }
68
//    }
67
69
70
    public String toXml(String tab){
71
        StringBuilder builder = new StringBuilder();
72
        builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
73
                .append("\" name=\"").append(getName()).append("\" blipId=\"")
74
                .append(isBlipId()).append("\" value=\"").append(isTrue()).append("\"").append("/>\n");
75
        return builder.toString();
76
    }
68
}
77
}
(-)src/java/org/apache/poi/ddf/EscherProperty.java (-1 / +8 lines)
Lines 72-78 Link Here
72
    public int getPropertySize() {
72
    public int getPropertySize() {
73
        return 6;
73
        return 6;
74
    }
74
    }
75
75
    
76
    public String toXml(String tab){
77
        StringBuilder builder = new StringBuilder();
78
        builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"").append(getId()).append("\" name=\"").append(getName()).append("\" blipId=\"")
79
                .append(isBlipId()).append("\"/>\n");
80
        return builder.toString();
81
    }
82
76
    /**
83
    /**
77
     * Escher properties consist of a simple fixed length part and a complex variable length part.
84
     * Escher properties consist of a simple fixed length part and a complex variable length part.
78
     * The fixed length part is serialized first.
85
     * The fixed length part is serialized first.
(-)src/java/org/apache/poi/ddf/EscherArrayProperty.java (+12 lines)
Lines 135-140 Link Here
135
                + ", data: " + '\n' + results.toString();
135
                + ", data: " + '\n' + results.toString();
136
    }
136
    }
137
137
138
    public String toXml(String tab){
139
        StringBuilder builder = new StringBuilder();
140
        builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
141
                .append("\" name=\"").append(getName()).append("\" blipId=\"")
142
                .append(isBlipId()).append("\">\n");
143
        for (int i = 0; i < getNumberOfElementsInArray(); i++) {
144
            builder.append("\t").append(tab).append("<Element>").append(HexDump.toHex(getElement(i))).append("</Element>\n");
145
        }
146
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
147
        return builder.toString();
148
    }
149
138
    /**
150
    /**
139
     * We have this method because the way in which arrays in escher works
151
     * We have this method because the way in which arrays in escher works
140
     * is screwed for seemly arbitary reasons.  While most properties are
152
     * is screwed for seemly arbitary reasons.  While most properties are
(-)src/java/org/apache/poi/ddf/EscherBitmapBlip.java (+22 lines)
Lines 114-117 Link Here
114
                "  Marker: 0x" + HexDump.toHex( field_2_marker ) + nl +
114
                "  Marker: 0x" + HexDump.toHex( field_2_marker ) + nl +
115
                "  Extra Data:" + nl + extraData;
115
                "  Extra Data:" + nl + extraData;
116
    }
116
    }
117
118
    @Override
119
    public String toXml(String tab) {
120
        String extraData;
121
        ByteArrayOutputStream b = new ByteArrayOutputStream();
122
        try
123
        {
124
            HexDump.dump( this.field_pictureData, 0, b, 0 );
125
            extraData = b.toString();
126
        }
127
        catch ( Exception e )
128
        {
129
            extraData = e.toString();
130
        }
131
        StringBuilder builder = new StringBuilder();
132
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
133
                .append(tab).append("\t").append("<UID>0x").append(HexDump.toHex(field_1_UID)).append("</UID>\n")
134
                .append(tab).append("\t").append("<Marker>0x").append(HexDump.toHex(field_2_marker)).append("</Marker>\n")
135
                .append(tab).append("\t").append("<ExtraData>").append(extraData).append("</ExtraData>\n");
136
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
137
        return builder.toString();
138
    }
117
}
139
}
(-)src/java/org/apache/poi/ddf/EscherDggRecord.java (+12 lines)
Lines 142-147 Link Here
142
142
143
    }
143
    }
144
144
145
    @Override
146
    public String toXml(String tab) {
147
        StringBuilder builder = new StringBuilder();
148
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
149
                .append(tab).append("\t").append("<ShapeIdMax>").append(field_1_shapeIdMax).append("</ShapeIdMax>\n")
150
                .append(tab).append("\t").append("<NumIdClusters>").append(getNumIdClusters()).append("</NumIdClusters>\n")
151
                .append(tab).append("\t").append("<NumShapesSaved>").append(field_3_numShapesSaved).append("</NumShapesSaved>\n")
152
                .append(tab).append("\t").append("<DrawingsSaved>").append(field_4_drawingsSaved).append("</DrawingsSaved>\n");
153
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
154
        return builder.toString();
155
    }
156
145
    public int getShapeIdMax() {
157
    public int getShapeIdMax() {
146
        return field_1_shapeIdMax;
158
        return field_1_shapeIdMax;
147
    }
159
    }
(-)src/java/org/apache/poi/ddf/EscherSpgrRecord.java (+12 lines)
Lines 97-102 Link Here
97
                "  RectHeight: " + field_4_rectY2 + '\n';
97
                "  RectHeight: " + field_4_rectY2 + '\n';
98
    }
98
    }
99
99
100
    @Override
101
    public String toXml(String tab) {
102
        StringBuilder builder = new StringBuilder();
103
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
104
                .append(tab).append("\t").append("<RectX>").append(field_1_rectX1).append("</RectX>\n")
105
                .append(tab).append("\t").append("<RectY>").append(field_2_rectY1).append("</RectY>\n")
106
                .append(tab).append("\t").append("<RectWidth>").append(field_3_rectX2).append("</RectWidth>\n")
107
                .append(tab).append("\t").append("<RectHeight>").append(field_4_rectY2).append("</RectHeight>\n");
108
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
109
        return builder.toString();
110
    }
111
100
    /**
112
    /**
101
     * The starting top-left coordinate of child records.
113
     * The starting top-left coordinate of child records.
102
     */
114
     */
(-)src/java/org/apache/poi/ddf/EscherRGBProperty.java (+9 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.ddf;
18
package org.apache.poi.ddf;
19
19
20
import org.apache.poi.util.HexDump;
21
20
/**
22
/**
21
 * A color property.
23
 * A color property.
22
 *
24
 *
Lines 51-54 Link Here
51
        return (byte) ( (propertyValue >> 16) & 0xFF );
53
        return (byte) ( (propertyValue >> 16) & 0xFF );
52
    }
54
    }
53
55
56
    public String toXml(String tab){
57
        StringBuilder builder = new StringBuilder();
58
        builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
59
                .append("\" name=\"").append(getName()).append("\" blipId=\"")
60
                .append(isBlipId()).append("\" value=\"0x").append(HexDump.toHex(propertyValue)).append("\"/>\n");
61
        return builder.toString();
62
    }
54
}
63
}
(-)src/java/org/apache/poi/ddf/EscherBlipWMFRecord.java (+31 lines)
Lines 350-355 Link Here
350
                "  Data:" + nl + extraData;
350
                "  Data:" + nl + extraData;
351
    }
351
    }
352
352
353
    @Override
354
    public String toXml(String tab) {
355
        String extraData;
356
        ByteArrayOutputStream b = new ByteArrayOutputStream();
357
        try
358
        {
359
            HexDump.dump( this.field_12_data, 0, b, 0 );
360
            extraData = b.toString();
361
        }
362
        catch ( Exception e )
363
        {
364
            extraData = e.toString();
365
        }
366
        StringBuilder builder = new StringBuilder();
367
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
368
                .append(tab).append("\t").append("<SecondaryUID>0x").append(HexDump.toHex(field_1_secondaryUID)).append("</SecondaryUID>\n")
369
                .append(tab).append("\t").append("<CacheOfSize>").append(field_2_cacheOfSize).append("</CacheOfSize>\n")
370
                .append(tab).append("\t").append("<BoundaryTop>").append(field_3_boundaryTop).append("</BoundaryTop>\n")
371
                .append(tab).append("\t").append("<BoundaryLeft>").append(field_4_boundaryLeft).append("</BoundaryLeft>\n")
372
                .append(tab).append("\t").append("<BoundaryWidth>").append(field_5_boundaryWidth).append("</BoundaryWidth>\n")
373
                .append(tab).append("\t").append("<BoundaryHeight>").append(field_6_boundaryHeight).append("</BoundaryHeight>\n")
374
                .append(tab).append("\t").append("<X>").append(field_7_width).append("</X>\n")
375
                .append(tab).append("\t").append("<Y>").append(field_8_height).append("</Y>\n")
376
                .append(tab).append("\t").append("<CacheOfSavedSize>").append(field_9_cacheOfSavedSize).append("</CacheOfSavedSize>\n")
377
                .append(tab).append("\t").append("<CompressionFlag>").append(field_10_compressionFlag).append("</CompressionFlag>\n")
378
                .append(tab).append("\t").append("<Filter>").append(field_11_filter).append("</Filter>\n")
379
                .append(tab).append("\t").append("<Data>").append(extraData).append("</Data>\n");
380
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
381
        return builder.toString();
382
    }
383
353
    /**
384
    /**
354
     * Compress the contents of the provided array
385
     * Compress the contents of the provided array
355
     *
386
     *
(-)src/java/org/apache/poi/ddf/EscherSimpleProperty.java (+8 lines)
Lines 118-121 Link Here
118
                + ", value: " + propertyValue + " (0x" + HexDump.toHex(propertyValue) + ")";
118
                + ", value: " + propertyValue + " (0x" + HexDump.toHex(propertyValue) + ")";
119
    }
119
    }
120
120
121
    public String toXml(String tab){
122
        StringBuilder builder = new StringBuilder();
123
        builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId()))
124
                .append("\" name=\"").append(getName()).append("\" blipId=\"")
125
                .append(isBlipId()).append("\" complex=\"").append(isComplex()).append("\" value=\"").append("0x")
126
                .append(HexDump.toHex(propertyValue)).append("\"/>\n");
127
        return builder.toString();
128
    }
121
}
129
}
(-)src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java (+12 lines)
Lines 176-179 Link Here
176
        return stringBuilder.toString();
176
        return stringBuilder.toString();
177
    }
177
    }
178
178
179
    @Override
180
    public String toXml(String tab) {
181
        StringBuilder builder = new StringBuilder();
182
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
183
                .append(tab).append("\t").append("<Numchildren>").append(getChildRecords().size()).append("</Numchildren>\n")
184
                .append(tab).append("\t").append("<IsContainer>").append(isContainerRecord()).append("</IsContainer>\n");
185
        for (EscherProperty property: getEscherProperties()){
186
            builder.append(property.toXml(tab+"\t"));
187
        }
188
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
189
        return builder.toString();
190
    }
179
}
191
}
(-)src/java/org/apache/poi/ddf/EscherContainerRecord.java (+17 lines)
Lines 255-260 Link Here
255
                + children.toString();
255
                + children.toString();
256
    }
256
    }
257
257
258
    @Override
259
    public String toXml(String tab) {
260
        StringBuilder builder = new StringBuilder();
261
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
262
                .append(tab).append("\t").append("<RecordName>").append(getRecordName()).append("</RecordName>\n")
263
                .append(tab).append("\t").append("<IsContainer>").append(isContainerRecord()).append("</IsContainer>\n")
264
                .append(tab).append("\t").append("<Numchildren>").append(HexDump.toHex(_childRecords.size())).append("</Numchildren>\n");
265
        for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator
266
                .hasNext(); )
267
        {
268
            EscherRecord record = iterator.next();
269
            builder.append(record.toXml(tab+"\t"));
270
        }
271
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
272
        return builder.toString();
273
    }
274
258
    public <T extends EscherRecord> T getChildById( short recordId )
275
    public <T extends EscherRecord> T getChildById( short recordId )
259
    {
276
    {
260
        for ( EscherRecord childRecord : _childRecords )
277
        for ( EscherRecord childRecord : _childRecords )
(-)src/java/org/apache/poi/ddf/EscherTextboxRecord.java (+22 lines)
Lines 139-144 Link Here
139
                theDumpHex;
139
                theDumpHex;
140
    }
140
    }
141
141
142
    @Override
143
    public String toXml(String tab) {
144
        String theDumpHex = "";
145
        try
146
        {
147
            if (thedata.length != 0)
148
            {
149
                theDumpHex += HexDump.dump(thedata, 0, 0);
150
            }
151
        }
152
        catch ( Exception e )
153
        {
154
            theDumpHex = "Error!!";
155
        }
156
        StringBuilder builder = new StringBuilder();
157
        builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
158
                .append(tab).append("\t").append("<IsContainer>").append(isContainerRecord()).append("</IsContainer>\n")
159
                .append(tab).append("\t").append("<Numchildren>").append(getChildRecords().size()).append("</Numchildren>\n")
160
                .append(tab).append("\t").append("<ExtraData>").append(theDumpHex).append("</ExtraData>\n");
161
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
162
        return builder.toString();
163
    }
142
}
164
}
143
165
144
166
(-)src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java (+79 lines)
Line 0 Link Here
1
package org.apache.poi.hssf.dev;
2
3
import org.apache.poi.ddf.EscherRecord;
4
import org.apache.poi.hssf.model.InternalWorkbook;
5
import org.apache.poi.hssf.record.*;
6
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
7
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
8
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
9
10
import java.io.*;
11
import java.lang.reflect.Field;
12
import java.util.List;
13
14
/**
15
 * Utility for representing drawings contained in a binary Excel file as a XML tree
16
 * @author Evgeniy Berlog
17
 * date: 10.04.12
18
 */
19
public class BiffDrawingToXml {
20
    
21
    public static void main(String[] params) throws IOException {
22
        FileOutputStream test = new FileOutputStream("workbook.xml");
23
        FileInputStream inp = new FileInputStream("workbook.xls");
24
        writeToFile(test, inp);
25
    }
26
27
    public static void writeToFile(FileOutputStream fos, InputStream xlsWorkbook) throws IOException {
28
        POIFSFileSystem fs = new POIFSFileSystem(xlsWorkbook);
29
        HSSFWorkbook workbook = new HSSFWorkbook(fs);
30
        InternalWorkbook internalWorkbook = getInternalWorkbook(workbook);
31
        DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid( DrawingGroupRecord.sid );
32
        r.decode();
33
34
        StringBuilder builder = new StringBuilder();
35
        builder.append("<workbook>\n");
36
        String tab = "\t";
37
        List <EscherRecord>escherRecords = r.getEscherRecords();
38
        for (EscherRecord record : escherRecords){
39
            builder.append(record.toXml(tab));
40
        }
41
        int sheetCount = workbook.getNumberOfSheets();
42
        for(int i=0; i < sheetCount; i++)  {
43
            builder.append(tab).append("<sheet").append(i).append(">\n");
44
            builder.append(getHSSFPatriarchBoundAggregate(workbook.getSheetAt(i).getDrawingPatriarch()).toXml(tab + "\t"));
45
            builder.append(tab).append("</sheet").append(i).append(">\n");
46
        }
47
        builder.append("</workbook>\n");
48
        fos.write(builder.toString().getBytes());
49
        fos.close();
50
    }
51
52
    private static EscherAggregate getHSSFPatriarchBoundAggregate(HSSFPatriarch patriarch) {
53
        Field boundAggregateField = null;
54
        try {
55
            boundAggregateField = patriarch.getClass().getDeclaredField("_boundAggregate");
56
            boundAggregateField.setAccessible(true);
57
            return (EscherAggregate) boundAggregateField.get(patriarch);
58
        } catch (NoSuchFieldException e) {
59
            e.printStackTrace();
60
        } catch (IllegalAccessException e) {
61
            e.printStackTrace();
62
        }
63
        return null;
64
    }
65
66
    private static InternalWorkbook getInternalWorkbook(HSSFWorkbook workbook) {
67
        Field internalSheetField = null;
68
        try {
69
            internalSheetField = workbook.getClass().getDeclaredField("workbook");
70
            internalSheetField.setAccessible(true);
71
            return (InternalWorkbook) internalSheetField.get(workbook);
72
        } catch (NoSuchFieldException e) {
73
            e.printStackTrace();
74
        } catch (IllegalAccessException e) {
75
            e.printStackTrace();
76
        }
77
        return null;
78
    }
79
}

Return to bug 53058