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

(-)src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java (-31 / +2 lines)
Lines 24-37 Link Here
24
import java.io.IOException;
24
import java.io.IOException;
25
import java.io.InputStream;
25
import java.io.InputStream;
26
import java.io.OutputStream;
26
import java.io.OutputStream;
27
import java.lang.reflect.Field;
28
import java.util.ArrayList;
27
import java.util.ArrayList;
29
import java.util.List;
28
import java.util.List;
30
29
31
import org.apache.poi.ddf.EscherRecord;
30
import org.apache.poi.ddf.EscherRecord;
32
import org.apache.poi.hssf.model.InternalWorkbook;
31
import org.apache.poi.hssf.model.InternalWorkbook;
33
import org.apache.poi.hssf.record.DrawingGroupRecord;
32
import org.apache.poi.hssf.record.DrawingGroupRecord;
34
import org.apache.poi.hssf.record.EscherAggregate;
35
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
33
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
36
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
34
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
37
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
35
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
Lines 137-143 Link Here
137
    public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {
135
    public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {
138
        NPOIFSFileSystem fs = new NPOIFSFileSystem(xlsWorkbook);
136
        NPOIFSFileSystem fs = new NPOIFSFileSystem(xlsWorkbook);
139
        HSSFWorkbook workbook = new HSSFWorkbook(fs);
137
        HSSFWorkbook workbook = new HSSFWorkbook(fs);
140
        InternalWorkbook internalWorkbook = getInternalWorkbook(workbook);
138
        InternalWorkbook internalWorkbook = workbook.getInternalWorkbook();
141
        DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);
139
        DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);
142
        r.decode();
140
        r.decode();
143
141
Lines 155-161 Link Here
155
            HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();
153
            HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();
156
            if(p != null ) {
154
            if(p != null ) {
157
                builder.append(tab).append("<sheet").append(i).append(">\n");
155
                builder.append(tab).append("<sheet").append(i).append(">\n");
158
                builder.append(getHSSFPatriarchBoundAggregate(p).toXml(tab + "\t"));
156
                builder.append(p.getBoundAggregate().toXml(tab + "\t"));
159
                builder.append(tab).append("</sheet").append(i).append(">\n");
157
                builder.append(tab).append("</sheet").append(i).append(">\n");
160
            }
158
            }
161
        }
159
        }
Lines 164-194 Link Here
164
        fos.close();
162
        fos.close();
165
    }
163
    }
166
164
167
    private static EscherAggregate getHSSFPatriarchBoundAggregate(HSSFPatriarch patriarch) {
168
        Field boundAggregateField = null;
169
        try {
170
            boundAggregateField = patriarch.getClass().getDeclaredField("_boundAggregate");
171
            boundAggregateField.setAccessible(true);
172
            return (EscherAggregate) boundAggregateField.get(patriarch);
173
        } catch (NoSuchFieldException e) {
174
            e.printStackTrace();
175
        } catch (IllegalAccessException e) {
176
            e.printStackTrace();
177
        }
178
        return null;
179
    }
180
181
    private static InternalWorkbook getInternalWorkbook(HSSFWorkbook workbook) {
182
        Field internalSheetField = null;
183
        try {
184
            internalSheetField = workbook.getClass().getDeclaredField("workbook");
185
            internalSheetField.setAccessible(true);
186
            return (InternalWorkbook) internalSheetField.get(workbook);
187
        } catch (NoSuchFieldException e) {
188
            e.printStackTrace();
189
        } catch (IllegalAccessException e) {
190
            e.printStackTrace();
191
        }
192
        return null;
193
    }
194
}
165
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFComment.java (-2 / +2 lines)
Lines 87-93 Link Here
87
    @Override
87
    @Override
88
    void afterInsert(HSSFPatriarch patriarch) {
88
    void afterInsert(HSSFPatriarch patriarch) {
89
        super.afterInsert(patriarch);
89
        super.afterInsert(patriarch);
90
        patriarch._getBoundAggregate().addTailRecord(getNoteRecord());
90
        patriarch.getBoundAggregate().addTailRecord(getNoteRecord());
91
    }
91
    }
92
92
93
    @Override
93
    @Override
Lines 253-259 Link Here
253
253
254
    public void afterRemove(HSSFPatriarch patriarch){
254
    public void afterRemove(HSSFPatriarch patriarch){
255
        super.afterRemove(patriarch);
255
        super.afterRemove(patriarch);
256
        patriarch._getBoundAggregate().removeTailRecord(getNoteRecord());
256
        patriarch.getBoundAggregate().removeTailRecord(getNoteRecord());
257
    }
257
    }
258
258
259
    @Override
259
    @Override
(-)src/java/org/apache/poi/hssf/usermodel/HSSFObjectData.java (-1 / +1 lines)
Lines 126-132 Link Here
126
126
127
    @Override
127
    @Override
128
    void afterInsert(HSSFPatriarch patriarch) {
128
    void afterInsert(HSSFPatriarch patriarch) {
129
        EscherAggregate agg = patriarch._getBoundAggregate();
129
        EscherAggregate agg = patriarch.getBoundAggregate();
130
        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
130
        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
131
        EscherBSERecord bse =
131
        EscherBSERecord bse =
132
                patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
132
                patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
(-)src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java (-1 / +2 lines)
Lines 495-501 Link Here
495
     * Returns the aggregate escher record we're bound to
495
     * Returns the aggregate escher record we're bound to
496
     * @return - low level representation of sheet drawing data
496
     * @return - low level representation of sheet drawing data
497
     */
497
     */
498
    protected EscherAggregate _getBoundAggregate() {
498
    @Internal
499
    public EscherAggregate getBoundAggregate() {
499
        return _boundAggregate;
500
        return _boundAggregate;
500
    }
501
    }
501
502
(-)src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java (-1 / +1 lines)
Lines 211-217 Link Here
211
211
212
    @Override
212
    @Override
213
    void afterInsert(HSSFPatriarch patriarch) {
213
    void afterInsert(HSSFPatriarch patriarch) {
214
        EscherAggregate agg = patriarch._getBoundAggregate();
214
        EscherAggregate agg = patriarch.getBoundAggregate();
215
        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
215
        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
216
        EscherBSERecord bse =
216
        EscherBSERecord bse =
217
                patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
217
                patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
(-)src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java (-1 / +1 lines)
Lines 116-122 Link Here
116
116
117
    @Override
117
    @Override
118
    protected void afterRemove(HSSFPatriarch patriarch) {
118
    protected void afterRemove(HSSFPatriarch patriarch) {
119
        patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
119
        patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
120
    }
120
    }
121
121
122
    /**
122
    /**
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java (-2 / +2 lines)
Lines 122-128 Link Here
122
122
123
    @Override
123
    @Override
124
    protected void afterRemove(HSSFPatriarch patriarch) {
124
    protected void afterRemove(HSSFPatriarch patriarch) {
125
        patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildContainers().get(0)
125
        patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildContainers().get(0)
126
                .getChildById(EscherClientDataRecord.RECORD_ID));
126
                .getChildById(EscherClientDataRecord.RECORD_ID));
127
        for ( int i=0; i<shapes.size(); i++ ) {
127
        for ( int i=0; i<shapes.size(); i++ ) {
128
            HSSFShape shape = shapes.get(i);
128
            HSSFShape shape = shapes.get(i);
Lines 314-320 Link Here
314
314
315
    @Override
315
    @Override
316
    void afterInsert(HSSFPatriarch patriarch){
316
    void afterInsert(HSSFPatriarch patriarch){
317
        EscherAggregate agg = patriarch._getBoundAggregate();
317
        EscherAggregate agg = patriarch.getBoundAggregate();
318
        EscherContainerRecord containerRecord = getEscherContainer().getChildById(EscherContainerRecord.SP_CONTAINER);
318
        EscherContainerRecord containerRecord = getEscherContainer().getChildById(EscherContainerRecord.SP_CONTAINER);
319
        agg.associateShapeToObjRecord(containerRecord.getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
319
        agg.associateShapeToObjRecord(containerRecord.getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
320
    }
320
    }
(-)src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (-1 / +1 lines)
Lines 148-154 Link Here
148
        }
148
        }
149
        if (getDrawingPatriarch() != null) {
149
        if (getDrawingPatriarch() != null) {
150
            HSSFPatriarch patr = HSSFPatriarch.createPatriarch(this.getDrawingPatriarch(), sheet);
150
            HSSFPatriarch patr = HSSFPatriarch.createPatriarch(this.getDrawingPatriarch(), sheet);
151
            sheet._sheet.getRecords().add(pos, patr._getBoundAggregate());
151
            sheet._sheet.getRecords().add(pos, patr.getBoundAggregate());
152
            sheet._patriarch = patr;
152
            sheet._patriarch = patr;
153
        }
153
        }
154
        return sheet;
154
        return sheet;
(-)src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java (-4 / +4 lines)
Lines 144-152 Link Here
144
144
145
    @Override
145
    @Override
146
    protected void afterRemove(HSSFPatriarch patriarch) {
146
    protected void afterRemove(HSSFPatriarch patriarch) {
147
        patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
147
        patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
148
        if (null != getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID)){
148
        if (null != getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID)){
149
            patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
149
            patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
150
        }
150
        }
151
    }
151
    }
152
152
Lines 177-183 Link Here
177
177
178
    @Override
178
    @Override
179
    void afterInsert(HSSFPatriarch patriarch){
179
    void afterInsert(HSSFPatriarch patriarch){
180
        EscherAggregate agg = patriarch._getBoundAggregate();
180
        EscherAggregate agg = patriarch.getBoundAggregate();
181
        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
181
        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
182
182
183
        if (null != getTextObjectRecord()){
183
        if (null != getTextObjectRecord()){
Lines 244-250 Link Here
244
            escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
244
            escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
245
            escherTextbox.setOptions((short) 0x0000);
245
            escherTextbox.setOptions((short) 0x0000);
246
            getEscherContainer().addChildRecord(escherTextbox);
246
            getEscherContainer().addChildRecord(escherTextbox);
247
            getPatriarch()._getBoundAggregate().associateShapeToObjRecord(escherTextbox, _textObjectRecord);
247
            getPatriarch().getBoundAggregate().associateShapeToObjRecord(escherTextbox, _textObjectRecord);
248
        }
248
        }
249
        return _textObjectRecord;
249
        return _textObjectRecord;
250
    }
250
    }
(-)src/java/org/apache/poi/hssf/usermodel/HSSFTextbox.java (-3 / +3 lines)
Lines 128-134 Link Here
128
128
129
    @Override
129
    @Override
130
    void afterInsert(HSSFPatriarch patriarch) {
130
    void afterInsert(HSSFPatriarch patriarch) {
131
        EscherAggregate agg = patriarch._getBoundAggregate();
131
        EscherAggregate agg = patriarch.getBoundAggregate();
132
        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
132
        agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
133
        if (getTextObjectRecord() != null){
133
        if (getTextObjectRecord() != null){
134
            agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord());
134
            agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord());
Lines 240-246 Link Here
240
240
241
    @Override
241
    @Override
242
    protected void afterRemove(HSSFPatriarch patriarch) {
242
    protected void afterRemove(HSSFPatriarch patriarch) {
243
        patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
243
        patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
244
        patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
244
        patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
245
    }
245
    }
246
}
246
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (+6 lines)
Lines 89-94 Link Here
89
import org.apache.poi.ss.util.WorkbookUtil;
89
import org.apache.poi.ss.util.WorkbookUtil;
90
import org.apache.poi.util.Configurator;
90
import org.apache.poi.util.Configurator;
91
import org.apache.poi.util.HexDump;
91
import org.apache.poi.util.HexDump;
92
import org.apache.poi.util.Internal;
92
import org.apache.poi.util.LittleEndian;
93
import org.apache.poi.util.LittleEndian;
93
import org.apache.poi.util.POILogFactory;
94
import org.apache.poi.util.POILogFactory;
94
import org.apache.poi.util.POILogger;
95
import org.apache.poi.util.POILogger;
Lines 2147-2150 Link Here
2147
    public DirectoryNode getRootDirectory(){
2148
    public DirectoryNode getRootDirectory(){
2148
        return directory;
2149
        return directory;
2149
    }
2150
    }
2151
    
2152
    @Internal
2153
    public InternalWorkbook getInternalWorkbook() {
2154
        return workbook;
2155
    }
2150
}
2156
}
(-)src/java/org/apache/poi/poifs/dev/POIFSDump.java (-17 / +3 lines)
Lines 21-27 Link Here
21
import java.io.FileOutputStream;
21
import java.io.FileOutputStream;
22
import java.io.IOException;
22
import java.io.IOException;
23
import java.io.OutputStream;
23
import java.io.OutputStream;
24
import java.lang.reflect.Field;
25
import java.nio.ByteBuffer;
24
import java.nio.ByteBuffer;
26
import java.util.Iterator;
25
import java.util.Iterator;
27
26
Lines 73-83 Link Here
73
            dump(root, file);
72
            dump(root, file);
74
            
73
            
75
            if (dumpProps) {
74
            if (dumpProps) {
76
                HeaderBlock header = getHeaderBlock(fs);
75
                HeaderBlock header = fs.getHeaderBlock();
77
                dump(fs, header.getPropertyStart(), "properties", file);
76
                dump(fs, header.getPropertyStart(), "properties", file);
78
            }
77
            }
79
            if (dumpMini) {
78
            if (dumpMini) {
80
                NPropertyTable props = getPropertyTable(fs);
79
                NPropertyTable props = fs.getPropertyTable();
81
                int startBlock = props.getRoot().getStartBlock(); 
80
                int startBlock = props.getRoot().getStartBlock(); 
82
                if (startBlock == POIFSConstants.END_OF_CHAIN) {
81
                if (startBlock == POIFSConstants.END_OF_CHAIN) {
83
                    System.err.println("No Mini Stream in file");
82
                    System.err.println("No Mini Stream in file");
Lines 86-106 Link Here
86
                }
85
                }
87
            }
86
            }
88
        }
87
        }
89
   }
88
    }
90
    
89
    
91
    protected static HeaderBlock getHeaderBlock(NPOIFSFileSystem fs) throws Exception {
92
        Field headerF = NPOIFSFileSystem.class.getDeclaredField("_header");
93
        headerF.setAccessible(true);
94
        HeaderBlock header = (HeaderBlock)headerF.get(fs);
95
        return header;
96
    }
97
    protected static NPropertyTable getPropertyTable(NPOIFSFileSystem fs) throws Exception {
98
        Field ptF = NPOIFSFileSystem.class.getDeclaredField("_property_table");
99
        ptF.setAccessible(true);
100
        NPropertyTable table = (NPropertyTable)ptF.get(fs);
101
        return table;
102
    }
103
104
    public static void dump(DirectoryEntry root, File parent) throws IOException {
90
    public static void dump(DirectoryEntry root, File parent) throws IOException {
105
        for(Iterator<Entry> it = root.getEntries(); it.hasNext();){
91
        for(Iterator<Entry> it = root.getEntries(); it.hasNext();){
106
            Entry entry = it.next();
92
            Entry entry = it.next();
(-)src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java (-9 / +2 lines)
Lines 19-26 Link Here
19
19
20
import java.io.FileInputStream;
20
import java.io.FileInputStream;
21
import java.io.InputStream;
21
import java.io.InputStream;
22
import java.lang.reflect.Field;
23
import java.lang.reflect.Method;
24
22
25
import org.apache.poi.poifs.common.POIFSBigBlockSize;
23
import org.apache.poi.poifs.common.POIFSBigBlockSize;
26
import org.apache.poi.poifs.common.POIFSConstants;
24
import org.apache.poi.poifs.common.POIFSConstants;
Lines 118-128 Link Here
118
        System.out.println("Raw Blocks Details:");
116
        System.out.println("Raw Blocks Details:");
119
        System.out.println(" Number of blocks: " + data_blocks.blockCount());
117
        System.out.println(" Number of blocks: " + data_blocks.blockCount());
120
118
121
        Method gbm = data_blocks.getClass().getSuperclass().getDeclaredMethod("get", int.class);
122
        gbm.setAccessible(true);
123
124
        for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) {
119
        for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) {
125
            ListManagedBlock block = (ListManagedBlock)gbm.invoke(data_blocks, Integer.valueOf(i));
120
            ListManagedBlock block = data_blocks.get(i);
126
            byte[] data = new byte[Math.min(48, block.getData().length)];
121
            byte[] data = new byte[Math.min(48, block.getData().length)];
127
            System.arraycopy(block.getData(), 0, data, 0, data.length);
122
            System.arraycopy(block.getData(), 0, data, 0, data.length);
128
123
Lines 135-143 Link Here
135
130
136
    public static void displayBATReader(String type, BlockAllocationTableReader batReader) throws Exception {
131
    public static void displayBATReader(String type, BlockAllocationTableReader batReader) throws Exception {
137
        System.out.println("Sectors, as referenced from the "+type+" FAT:");
132
        System.out.println("Sectors, as referenced from the "+type+" FAT:");
138
        Field entriesF = batReader.getClass().getDeclaredField("_entries");
133
        IntList entries = batReader.getEntries();
139
        entriesF.setAccessible(true);
140
        IntList entries = (IntList)entriesF.get(batReader);
141
134
142
        for(int i=0; i<entries.size(); i++) {
135
        for(int i=0; i<entries.size(); i++) {
143
            int bn = entries.get(i);
136
            int bn = entries.get(i);
(-)src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java (+11 lines)
Lines 55-60 Link Here
55
import org.apache.poi.poifs.storage.HeaderBlockWriter;
55
import org.apache.poi.poifs.storage.HeaderBlockWriter;
56
import org.apache.poi.util.CloseIgnoringInputStream;
56
import org.apache.poi.util.CloseIgnoringInputStream;
57
import org.apache.poi.util.IOUtils;
57
import org.apache.poi.util.IOUtils;
58
import org.apache.poi.util.Internal;
58
import org.apache.poi.util.LongField;
59
import org.apache.poi.util.LongField;
59
60
60
/**
61
/**
Lines 970-974 Link Here
970
    protected int getBlockStoreBlockSize() {
971
    protected int getBlockStoreBlockSize() {
971
       return getBigBlockSize();
972
       return getBigBlockSize();
972
    }
973
    }
974
975
    @Internal
976
    public NPropertyTable getPropertyTable() {
977
        return _property_table;
978
    }
979
980
    @Internal
981
    public HeaderBlock getHeaderBlock() {
982
        return _header;
983
    }
973
}
984
}
974
985
(-)src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java (+5 lines)
Lines 312-315 Link Here
312
        }
312
        }
313
        raw_blocks.setBAT(this);
313
        raw_blocks.setBAT(this);
314
    }
314
    }
315
316
    @Internal
317
    public IntList getEntries() {
318
        return _entries;
319
    }
315
}
320
}
(-)src/java/org/apache/poi/poifs/storage/BlockListImpl.java (-2 / +5 lines)
Lines 19-24 Link Here
19
19
20
import java.io.IOException;
20
import java.io.IOException;
21
21
22
import org.apache.poi.util.Internal;
23
22
/**
24
/**
23
 * A simple implementation of BlockList
25
 * A simple implementation of BlockList
24
 *
26
 *
Lines 59-68 Link Here
59
    }
61
    }
60
62
61
    /**
63
    /**
62
     * Unit testing method. Gets, without sanity checks or
64
     * Internal method. Gets, without sanity checks or
63
     *  removing.
65
     *  removing.
64
     */
66
     */
65
    protected ListManagedBlock get(final int index) {
67
    @Internal
68
    public ListManagedBlock get(final int index) {
66
        return _blocks[index];
69
        return _blocks[index];
67
    }
70
    }
68
71
(-)src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (+12 lines)
Lines 38-43 Link Here
38
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
38
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
39
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
39
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
40
import org.apache.poi.openxml4j.opc.TargetMode;
40
import org.apache.poi.openxml4j.opc.TargetMode;
41
import org.apache.poi.util.Internal;
41
import org.apache.poi.util.POILogFactory;
42
import org.apache.poi.util.POILogFactory;
42
import org.apache.poi.util.POILogger;
43
import org.apache.poi.util.POILogger;
43
import org.apache.xmlbeans.XmlOptions;
44
import org.apache.xmlbeans.XmlOptions;
Lines 510-513 Link Here
510
    protected void onDocumentRemove() throws IOException {
511
    protected void onDocumentRemove() throws IOException {
511
512
512
    }
513
    }
514
515
    /**
516
     * Internal method, do not use!
517
     * <p>
518
     * This method only exists to allow access to protected {@link POIXMLDocumentPart#onDocumentRead()}
519
     * from {@link org.apache.poi.xwpf.usermodel.XWPFDocument} without reflection. It should be removed.
520
     */
521
    @Internal @Deprecated
522
    public static void _invokeOnDocumentRead(POIXMLDocumentPart part) throws IOException {
523
        part.onDocumentRead();
524
    }
513
}
525
}
(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (-9 / +4 lines)
Lines 20-26 Link Here
20
import java.io.IOException;
20
import java.io.IOException;
21
import java.io.InputStream;
21
import java.io.InputStream;
22
import java.io.OutputStream;
22
import java.io.OutputStream;
23
import java.lang.reflect.Method;
24
import java.util.ArrayList;
23
import java.util.ArrayList;
25
import java.util.Arrays;
24
import java.util.Arrays;
26
import java.util.Collection;
25
import java.util.Collection;
Lines 48-54 Link Here
48
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
47
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
49
import org.apache.poi.openxml4j.opc.TargetMode;
48
import org.apache.poi.openxml4j.opc.TargetMode;
50
import org.apache.poi.poifs.crypt.HashAlgorithm;
49
import org.apache.poi.poifs.crypt.HashAlgorithm;
51
import org.apache.poi.util.DocumentHelper;
52
import org.apache.poi.util.IOUtils;
50
import org.apache.poi.util.IOUtils;
53
import org.apache.poi.util.IdentifierManager;
51
import org.apache.poi.util.IdentifierManager;
54
import org.apache.poi.util.Internal;
52
import org.apache.poi.util.Internal;
Lines 153-158 Link Here
153
        }
151
        }
154
    }
152
    }
155
153
154
    @SuppressWarnings("deprecation")
156
    @Override
155
    @Override
157
    protected void onDocumentRead() throws IOException {
156
    protected void onDocumentRead() throws IOException {
158
        try {
157
        try {
Lines 224-236 Link Here
224
                    for (POIXMLDocumentPart gp : p.getRelations()) {
223
                    for (POIXMLDocumentPart gp : p.getRelations()) {
225
                        // Trigger the onDocumentRead for all the child parts
224
                        // Trigger the onDocumentRead for all the child parts
226
                        // Otherwise we'll hit issues on Styles, Settings etc on save
225
                        // Otherwise we'll hit issues on Styles, Settings etc on save
227
                        try {
226
                        // TODO: Refactor this to not need to access protected method
228
                            Method onDocumentRead = gp.getClass().getDeclaredMethod("onDocumentRead");
227
                        // from other package! Remove the static helper method once fixed!!!
229
                            onDocumentRead.setAccessible(true);
228
                        POIXMLDocumentPart._invokeOnDocumentRead(gp);
230
                            onDocumentRead.invoke(gp);
231
                        } catch (Exception e) {
232
                            throw new POIXMLException(e);
233
                        }
234
                    }
229
                    }
235
                }
230
                }
236
            }
231
            }
(-)src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java (-1 / +1 lines)
Lines 72-78 Link Here
72
    }
72
    }
73
73
74
    public static EscherAggregate getEscherAggregate(HSSFPatriarch patriarch){
74
    public static EscherAggregate getEscherAggregate(HSSFPatriarch patriarch){
75
        return patriarch._getBoundAggregate();
75
        return patriarch.getBoundAggregate();
76
    }
76
    }
77
77
78
    public static int allocateNewShapeId(HSSFPatriarch patriarch){
78
    public static int allocateNewShapeId(HSSFPatriarch patriarch){
(-)src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java (-2 / +2 lines)
Lines 85-97 Link Here
85
        HSSFSheet s = b.createSheet("Test");
85
        HSSFSheet s = b.createSheet("Test");
86
        HSSFPatriarch patriarch = s.createDrawingPatriarch();
86
        HSSFPatriarch patriarch = s.createDrawingPatriarch();
87
87
88
        EscherAggregate agg1 = patriarch._getBoundAggregate();
88
        EscherAggregate agg1 = patriarch.getBoundAggregate();
89
89
90
        HSSFSheet s2 = s.cloneSheet(b);
90
        HSSFSheet s2 = s.cloneSheet(b);
91
91
92
        patriarch = s2.getDrawingPatriarch();
92
        patriarch = s2.getDrawingPatriarch();
93
93
94
        EscherAggregate agg2 = patriarch._getBoundAggregate();
94
        EscherAggregate agg2 = patriarch.getBoundAggregate();
95
95
96
        EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1);
96
        EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1);
97
        EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1);
97
        EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1);
(-)src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (-2 / +2 lines)
Lines 940-947 Link Here
940
        HSSFSheet sheet2 = wb2.getSheetAt(1);
940
        HSSFSheet sheet2 = wb2.getSheetAt(1);
941
941
942
        //check that id of the drawing group was updated
942
        //check that id of the drawing group was updated
943
        EscherDgRecord dg1 = (EscherDgRecord)sheet1.getDrawingPatriarch()._getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
943
        EscherDgRecord dg1 = (EscherDgRecord)sheet1.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
944
        EscherDgRecord dg2 = (EscherDgRecord)sheet2.getDrawingPatriarch()._getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
944
        EscherDgRecord dg2 = (EscherDgRecord)sheet2.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
945
        int dg_id_1 = dg1.getOptions() >> 4;
945
        int dg_id_1 = dg1.getOptions() >> 4;
946
        int dg_id_2 = dg2.getOptions() >> 4;
946
        int dg_id_2 = dg2.getOptions() >> 4;
947
        assertEquals(dg_id_1 + 1, dg_id_2);
947
        assertEquals(dg_id_1 + 1, dg_id_2);
(-)src/testcases/org/apache/poi/hssf/usermodel/TestPatriarch.java (-2 / +2 lines)
Lines 40-46 Link Here
40
40
41
        assertSame(patriarch, sh.getDrawingPatriarch());
41
        assertSame(patriarch, sh.getDrawingPatriarch());
42
42
43
        EscherAggregate agg = patriarch._getBoundAggregate();
43
        EscherAggregate agg = patriarch.getBoundAggregate();
44
44
45
        EscherDgRecord dg = agg.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
45
        EscherDgRecord dg = agg.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
46
        int lastId = dg.getLastMSOSPID();
46
        int lastId = dg.getLastMSOSPID();
Lines 50-56 Link Here
50
        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
50
        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
51
        sh = wb.getSheetAt(0);
51
        sh = wb.getSheetAt(0);
52
        patriarch = sh.createDrawingPatriarch();
52
        patriarch = sh.createDrawingPatriarch();
53
        dg = patriarch._getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
53
        dg = patriarch.getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
54
54
55
        assertEquals(lastId, dg.getLastMSOSPID());
55
        assertEquals(lastId, dg.getLastMSOSPID());
56
    }
56
    }

Return to bug 58597