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

(-)src/java/org/apache/poi/ddf/EscherSplitMenuColorsRecord.java (+15 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("<").append(getClass().getSimpleName()).append(">\n")
106
                .append(tab).append("\t").append("<RecordId>0x").append(HexDump.toHex(RECORD_ID)).append("</RecordId>\n")
107
                .append(tab).append("\t").append("<Version>0x").append(HexDump.toHex(getVersion())).append("</Version>\n")
108
                .append(tab).append("\t").append("<Instance>0x").append(HexDump.toHex(getInstance())).append("</Instance>\n")
109
                .append(tab).append("\t").append("<Color1>0x").append(HexDump.toHex(field_1_color1)).append("</Color1>\n")
110
                .append(tab).append("\t").append("<Color2>0x").append(HexDump.toHex(field_2_color2)).append("</Color2>\n")
111
                .append(tab).append("\t").append("<Color3>0x").append(HexDump.toHex(field_3_color3)).append("</Color3>\n")
112
                .append(tab).append("\t").append("<Color4>0x").append(HexDump.toHex(field_4_color4)).append("</Color4>\n");
113
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
114
        return builder.toString();
115
    }
116
102
    public int getColor1()
117
    public int getColor1()
103
    {
118
    {
104
        return field_1_color1;
119
        return field_1_color1;
(-)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/EscherBSERecord.java (+22 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("<").append(getClass().getSimpleName()).append(">\n")
337
                .append(tab).append("\t").append("<RecordId>0x").append(HexDump.toHex(RECORD_ID)).append("</RecordId>\n")
338
                .append(tab).append("\t").append("<Version>0x").append(HexDump.toHex(getVersion())).append("</Version>\n")
339
                .append(tab).append("\t").append("<Instance>0x").append(HexDump.toHex(getInstance())).append("</Instance>\n")
340
                .append(tab).append("\t").append("<BlipTypeWin32>").append(field_1_blipTypeWin32).append("</BlipTypeWin32>\n")
341
                .append(tab).append("\t").append("<BlipTypeMacOS>").append(field_2_blipTypeMacOS).append("</BlipTypeMacOS>\n")
342
                .append(tab).append("\t").append("<SUID>").append(field_3_uid == null ? "" : HexDump.toHex(field_3_uid)).append("</SUID>\n")
343
                .append(tab).append("\t").append("<Tag>").append(field_4_tag).append("</Tag>\n")
344
                .append(tab).append("\t").append("<Size>").append(field_5_size).append("</Size>\n")
345
                .append(tab).append("\t").append("<Ref>").append(field_6_ref).append("</Ref>\n")
346
                .append(tab).append("\t").append("<Offset>").append(field_7_offset).append("</Offset>\n")
347
                .append(tab).append("\t").append("<Usage>").append(field_8_usage).append("</Usage>\n")
348
                .append(tab).append("\t").append("<Name>").append(field_9_name).append("</Name>\n")
349
                .append(tab).append("\t").append("<Unused2>").append(field_10_unused2).append("</Unused2>\n")
350
                .append(tab).append("\t").append("<Unused3>").append(field_11_unused3).append("</Unused3>\n");
351
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
352
        return builder.toString();
353
    }
354
333
    /**
355
    /**
334
     * Retrieve the string representation given a blip id.
356
     * Retrieve the string representation given a blip id.
335
     */
357
     */
(-)src/java/org/apache/poi/ddf/EscherDggRecord.java (+15 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("<").append(getClass().getSimpleName()).append(">\n")
149
                .append(tab).append("\t").append("<RecordId>0x").append(HexDump.toHex(RECORD_ID)).append("</RecordId>\n")
150
                .append(tab).append("\t").append("<Version>0x").append(HexDump.toHex(getVersion())).append("</Version>\n")
151
                .append(tab).append("\t").append("<Instance>0x").append(HexDump.toHex(getInstance())).append("</Instance>\n")
152
                .append(tab).append("\t").append("<ShapeIdMax>").append(field_1_shapeIdMax).append("</ShapeIdMax>\n")
153
                .append(tab).append("\t").append("<NumIdClusters>").append(getNumIdClusters()).append("</NumIdClusters>\n")
154
                .append(tab).append("\t").append("<NumShapesSaved>").append(field_3_numShapesSaved).append("</NumShapesSaved>\n")
155
                .append(tab).append("\t").append("<DrawingsSaved>").append(field_4_drawingsSaved).append("</DrawingsSaved>\n");
156
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
157
        return builder.toString();
158
    }
159
145
    public int getShapeIdMax() {
160
    public int getShapeIdMax() {
146
        return field_1_shapeIdMax;
161
        return field_1_shapeIdMax;
147
    }
162
    }
(-)src/java/org/apache/poi/ddf/EscherContainerRecord.java (+20 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("<").append(getClass().getSimpleName()).append(">\n")
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("<version>0x").append(HexDump.toHex(getVersion())).append("</version>\n")
265
                .append(tab).append("\t").append("<instance>0x").append(HexDump.toHex(getInstance())).append("</instance>\n")
266
                .append(tab).append("\t").append("<recordId>0x").append(HexDump.toHex(getRecordId())).append("</recordId>\n")
267
                .append(tab).append("\t").append("<numchildren>").append(HexDump.toHex(_childRecords.size())).append("</numchildren>\n");
268
        for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator
269
                .hasNext(); )
270
        {
271
            EscherRecord record = iterator.next();
272
            builder.append(record.toXml(tab+"\t"));
273
        }
274
        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
275
        return builder.toString();
276
    }
277
258
    public <T extends EscherRecord> T getChildById( short recordId )
278
    public <T extends EscherRecord> T getChildById( short recordId )
259
    {
279
    {
260
        for ( EscherRecord childRecord : _childRecords )
280
        for ( EscherRecord childRecord : _childRecords )
(-)src/java/org/apache/poi/ddf/EscherRecord.java (+17 lines)
Lines 297-300 Link Here
297
    {
297
    {
298
        _options = fVersion.setShortValue( _options, value );
298
        _options = fVersion.setShortValue( _options, value );
299
    }
299
    }
300
301
    /**
302
     * @param tab - each children must be a right of his parent
303
     * @return
304
     */
305
    public String toXml(String tab){
306
        StringBuilder builder = new StringBuilder();
307
        builder.append(tab).append("<").append(getClass().getSimpleName()).append(">\n")
308
                .append(tab).append("\t").append("<Options>").append(_options).append("</Options>\n")
309
                .append(tab).append("\t").append("<RecordId>").append(_recordId).append("</RecordId>\n")
310
                .append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
311
        return builder.toString();
312
    }
313
    
314
    public String toXml(){
315
        return toXml("");
316
    }
300
}
317
}
(-)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("D:\\temp\\test.xml");
23
        FileInputStream inp = new FileInputStream("D:\\temp\\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