#58597: Remove setAccessible (more coming soon)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1713770 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2015-11-11 07:41:54 +00:00
parent b0b4c020ed
commit b62cc549fe
22 changed files with 74 additions and 91 deletions

View File

@ -24,14 +24,12 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.hssf.model.InternalWorkbook; import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.DrawingGroupRecord; import org.apache.poi.hssf.record.DrawingGroupRecord;
import org.apache.poi.hssf.record.EscherAggregate;
import org.apache.poi.hssf.usermodel.HSSFPatriarch; import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
@ -137,7 +135,7 @@ public class BiffDrawingToXml {
public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException { public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {
NPOIFSFileSystem fs = new NPOIFSFileSystem(xlsWorkbook); NPOIFSFileSystem fs = new NPOIFSFileSystem(xlsWorkbook);
HSSFWorkbook workbook = new HSSFWorkbook(fs); HSSFWorkbook workbook = new HSSFWorkbook(fs);
InternalWorkbook internalWorkbook = getInternalWorkbook(workbook); InternalWorkbook internalWorkbook = workbook.getInternalWorkbook();
DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid); DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);
r.decode(); r.decode();
@ -155,7 +153,7 @@ public class BiffDrawingToXml {
HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch(); HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();
if(p != null ) { if(p != null ) {
builder.append(tab).append("<sheet").append(i).append(">\n"); builder.append(tab).append("<sheet").append(i).append(">\n");
builder.append(getHSSFPatriarchBoundAggregate(p).toXml(tab + "\t")); builder.append(p.getBoundAggregate().toXml(tab + "\t"));
builder.append(tab).append("</sheet").append(i).append(">\n"); builder.append(tab).append("</sheet").append(i).append(">\n");
} }
} }
@ -164,31 +162,4 @@ public class BiffDrawingToXml {
fos.close(); fos.close();
} }
private static EscherAggregate getHSSFPatriarchBoundAggregate(HSSFPatriarch patriarch) {
Field boundAggregateField = null;
try {
boundAggregateField = patriarch.getClass().getDeclaredField("_boundAggregate");
boundAggregateField.setAccessible(true);
return (EscherAggregate) boundAggregateField.get(patriarch);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
private static InternalWorkbook getInternalWorkbook(HSSFWorkbook workbook) {
Field internalSheetField = null;
try {
internalSheetField = workbook.getClass().getDeclaredField("workbook");
internalSheetField.setAccessible(true);
return (InternalWorkbook) internalSheetField.get(workbook);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
} }

View File

@ -87,7 +87,7 @@ public class HSSFComment extends HSSFTextbox implements Comment {
@Override @Override
void afterInsert(HSSFPatriarch patriarch) { void afterInsert(HSSFPatriarch patriarch) {
super.afterInsert(patriarch); super.afterInsert(patriarch);
patriarch._getBoundAggregate().addTailRecord(getNoteRecord()); patriarch.getBoundAggregate().addTailRecord(getNoteRecord());
} }
@Override @Override
@ -253,7 +253,7 @@ public class HSSFComment extends HSSFTextbox implements Comment {
public void afterRemove(HSSFPatriarch patriarch){ public void afterRemove(HSSFPatriarch patriarch){
super.afterRemove(patriarch); super.afterRemove(patriarch);
patriarch._getBoundAggregate().removeTailRecord(getNoteRecord()); patriarch.getBoundAggregate().removeTailRecord(getNoteRecord());
} }
@Override @Override

View File

@ -126,7 +126,7 @@ public final class HSSFObjectData extends HSSFPicture {
@Override @Override
void afterInsert(HSSFPatriarch patriarch) { void afterInsert(HSSFPatriarch patriarch) {
EscherAggregate agg = patriarch._getBoundAggregate(); EscherAggregate agg = patriarch.getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
EscherBSERecord bse = EscherBSERecord bse =
patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex()); patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());

View File

@ -495,7 +495,8 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
* Returns the aggregate escher record we're bound to * Returns the aggregate escher record we're bound to
* @return - low level representation of sheet drawing data * @return - low level representation of sheet drawing data
*/ */
protected EscherAggregate _getBoundAggregate() { @Internal
public EscherAggregate getBoundAggregate() {
return _boundAggregate; return _boundAggregate;
} }

View File

@ -211,7 +211,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
@Override @Override
void afterInsert(HSSFPatriarch patriarch) { void afterInsert(HSSFPatriarch patriarch) {
EscherAggregate agg = patriarch._getBoundAggregate(); EscherAggregate agg = patriarch.getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
EscherBSERecord bse = EscherBSERecord bse =
patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex()); patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());

View File

@ -116,7 +116,7 @@ public class HSSFPolygon extends HSSFSimpleShape {
@Override @Override
protected void afterRemove(HSSFPatriarch patriarch) { protected void afterRemove(HSSFPatriarch patriarch) {
patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID)); patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
} }
/** /**

View File

@ -122,7 +122,7 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
@Override @Override
protected void afterRemove(HSSFPatriarch patriarch) { protected void afterRemove(HSSFPatriarch patriarch) {
patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildContainers().get(0) patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildContainers().get(0)
.getChildById(EscherClientDataRecord.RECORD_ID)); .getChildById(EscherClientDataRecord.RECORD_ID));
for ( int i=0; i<shapes.size(); i++ ) { for ( int i=0; i<shapes.size(); i++ ) {
HSSFShape shape = shapes.get(i); HSSFShape shape = shapes.get(i);
@ -314,7 +314,7 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer {
@Override @Override
void afterInsert(HSSFPatriarch patriarch){ void afterInsert(HSSFPatriarch patriarch){
EscherAggregate agg = patriarch._getBoundAggregate(); EscherAggregate agg = patriarch.getBoundAggregate();
EscherContainerRecord containerRecord = getEscherContainer().getChildById(EscherContainerRecord.SP_CONTAINER); EscherContainerRecord containerRecord = getEscherContainer().getChildById(EscherContainerRecord.SP_CONTAINER);
agg.associateShapeToObjRecord(containerRecord.getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); agg.associateShapeToObjRecord(containerRecord.getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
} }

View File

@ -148,7 +148,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
} }
if (getDrawingPatriarch() != null) { if (getDrawingPatriarch() != null) {
HSSFPatriarch patr = HSSFPatriarch.createPatriarch(this.getDrawingPatriarch(), sheet); HSSFPatriarch patr = HSSFPatriarch.createPatriarch(this.getDrawingPatriarch(), sheet);
sheet._sheet.getRecords().add(pos, patr._getBoundAggregate()); sheet._sheet.getRecords().add(pos, patr.getBoundAggregate());
sheet._patriarch = patr; sheet._patriarch = patr;
} }
return sheet; return sheet;

View File

@ -144,9 +144,9 @@ public class HSSFSimpleShape extends HSSFShape
@Override @Override
protected void afterRemove(HSSFPatriarch patriarch) { protected void afterRemove(HSSFPatriarch patriarch) {
patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID)); patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
if (null != getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID)){ if (null != getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID)){
patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID)); patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
} }
} }
@ -177,7 +177,7 @@ public class HSSFSimpleShape extends HSSFShape
@Override @Override
void afterInsert(HSSFPatriarch patriarch){ void afterInsert(HSSFPatriarch patriarch){
EscherAggregate agg = patriarch._getBoundAggregate(); EscherAggregate agg = patriarch.getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
if (null != getTextObjectRecord()){ if (null != getTextObjectRecord()){
@ -244,7 +244,7 @@ public class HSSFSimpleShape extends HSSFShape
escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID); escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
escherTextbox.setOptions((short) 0x0000); escherTextbox.setOptions((short) 0x0000);
getEscherContainer().addChildRecord(escherTextbox); getEscherContainer().addChildRecord(escherTextbox);
getPatriarch()._getBoundAggregate().associateShapeToObjRecord(escherTextbox, _textObjectRecord); getPatriarch().getBoundAggregate().associateShapeToObjRecord(escherTextbox, _textObjectRecord);
} }
return _textObjectRecord; return _textObjectRecord;
} }

View File

@ -128,7 +128,7 @@ public class HSSFTextbox extends HSSFSimpleShape {
@Override @Override
void afterInsert(HSSFPatriarch patriarch) { void afterInsert(HSSFPatriarch patriarch) {
EscherAggregate agg = patriarch._getBoundAggregate(); EscherAggregate agg = patriarch.getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
if (getTextObjectRecord() != null){ if (getTextObjectRecord() != null){
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord()); agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord());
@ -240,7 +240,7 @@ public class HSSFTextbox extends HSSFSimpleShape {
@Override @Override
protected void afterRemove(HSSFPatriarch patriarch) { protected void afterRemove(HSSFPatriarch patriarch) {
patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID)); patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID)); patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
} }
} }

View File

@ -89,6 +89,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.WorkbookUtil; import org.apache.poi.ss.util.WorkbookUtil;
import org.apache.poi.util.Configurator; import org.apache.poi.util.Configurator;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@ -2147,4 +2148,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
public DirectoryNode getRootDirectory(){ public DirectoryNode getRootDirectory(){
return directory; return directory;
} }
@Internal
public InternalWorkbook getInternalWorkbook() {
return workbook;
}
} }

View File

@ -21,7 +21,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Field;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Iterator; import java.util.Iterator;
@ -73,11 +72,11 @@ public class POIFSDump {
dump(root, file); dump(root, file);
if (dumpProps) { if (dumpProps) {
HeaderBlock header = getHeaderBlock(fs); HeaderBlock header = fs.getHeaderBlock();
dump(fs, header.getPropertyStart(), "properties", file); dump(fs, header.getPropertyStart(), "properties", file);
} }
if (dumpMini) { if (dumpMini) {
NPropertyTable props = getPropertyTable(fs); NPropertyTable props = fs.getPropertyTable();
int startBlock = props.getRoot().getStartBlock(); int startBlock = props.getRoot().getStartBlock();
if (startBlock == POIFSConstants.END_OF_CHAIN) { if (startBlock == POIFSConstants.END_OF_CHAIN) {
System.err.println("No Mini Stream in file"); System.err.println("No Mini Stream in file");
@ -86,19 +85,6 @@ public class POIFSDump {
} }
} }
} }
}
protected static HeaderBlock getHeaderBlock(NPOIFSFileSystem fs) throws Exception {
Field headerF = NPOIFSFileSystem.class.getDeclaredField("_header");
headerF.setAccessible(true);
HeaderBlock header = (HeaderBlock)headerF.get(fs);
return header;
}
protected static NPropertyTable getPropertyTable(NPOIFSFileSystem fs) throws Exception {
Field ptF = NPOIFSFileSystem.class.getDeclaredField("_property_table");
ptF.setAccessible(true);
NPropertyTable table = (NPropertyTable)ptF.get(fs);
return table;
} }
public static void dump(DirectoryEntry root, File parent) throws IOException { public static void dump(DirectoryEntry root, File parent) throws IOException {

View File

@ -19,8 +19,6 @@ package org.apache.poi.poifs.dev;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.apache.poi.poifs.common.POIFSBigBlockSize; import org.apache.poi.poifs.common.POIFSBigBlockSize;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
@ -118,11 +116,8 @@ public class POIFSHeaderDumper {
System.out.println("Raw Blocks Details:"); System.out.println("Raw Blocks Details:");
System.out.println(" Number of blocks: " + data_blocks.blockCount()); System.out.println(" Number of blocks: " + data_blocks.blockCount());
Method gbm = data_blocks.getClass().getSuperclass().getDeclaredMethod("get", int.class);
gbm.setAccessible(true);
for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) { for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) {
ListManagedBlock block = (ListManagedBlock)gbm.invoke(data_blocks, Integer.valueOf(i)); ListManagedBlock block = data_blocks.get(i);
byte[] data = new byte[Math.min(48, block.getData().length)]; byte[] data = new byte[Math.min(48, block.getData().length)];
System.arraycopy(block.getData(), 0, data, 0, data.length); System.arraycopy(block.getData(), 0, data, 0, data.length);
@ -135,9 +130,7 @@ public class POIFSHeaderDumper {
public static void displayBATReader(String type, BlockAllocationTableReader batReader) throws Exception { public static void displayBATReader(String type, BlockAllocationTableReader batReader) throws Exception {
System.out.println("Sectors, as referenced from the "+type+" FAT:"); System.out.println("Sectors, as referenced from the "+type+" FAT:");
Field entriesF = batReader.getClass().getDeclaredField("_entries"); IntList entries = batReader.getEntries();
entriesF.setAccessible(true);
IntList entries = (IntList)entriesF.get(batReader);
for(int i=0; i<entries.size(); i++) { for(int i=0; i<entries.size(); i++) {
int bn = entries.get(i); int bn = entries.get(i);

View File

@ -55,6 +55,7 @@ import org.apache.poi.poifs.storage.HeaderBlockConstants;
import org.apache.poi.poifs.storage.HeaderBlockWriter; import org.apache.poi.poifs.storage.HeaderBlockWriter;
import org.apache.poi.util.CloseIgnoringInputStream; import org.apache.poi.util.CloseIgnoringInputStream;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LongField; import org.apache.poi.util.LongField;
/** /**
@ -970,5 +971,15 @@ public class NPOIFSFileSystem extends BlockStore
protected int getBlockStoreBlockSize() { protected int getBlockStoreBlockSize() {
return getBigBlockSize(); return getBigBlockSize();
} }
@Internal
public NPropertyTable getPropertyTable() {
return _property_table;
}
@Internal
public HeaderBlock getHeaderBlock() {
return _header;
}
} }

View File

@ -312,4 +312,9 @@ public final class BlockAllocationTableReader {
} }
raw_blocks.setBAT(this); raw_blocks.setBAT(this);
} }
@Internal
public IntList getEntries() {
return _entries;
}
} }

View File

@ -19,6 +19,8 @@ package org.apache.poi.poifs.storage;
import java.io.IOException; import java.io.IOException;
import org.apache.poi.util.Internal;
/** /**
* A simple implementation of BlockList * A simple implementation of BlockList
* *
@ -59,10 +61,11 @@ abstract class BlockListImpl implements BlockList {
} }
/** /**
* Unit testing method. Gets, without sanity checks or * Internal method. Gets, without sanity checks or
* removing. * removing.
*/ */
protected ListManagedBlock get(final int index) { @Internal
public ListManagedBlock get(final int index) {
return _blocks[index]; return _blocks[index];
} }

View File

@ -38,6 +38,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.xmlbeans.XmlOptions; import org.apache.xmlbeans.XmlOptions;
@ -510,4 +511,15 @@ public class POIXMLDocumentPart {
protected void onDocumentRemove() throws IOException { protected void onDocumentRemove() throws IOException {
} }
/**
* Internal method, do not use!
* <p>
* This method only exists to allow access to protected {@link POIXMLDocumentPart#onDocumentRead()}
* from {@link org.apache.poi.xwpf.usermodel.XWPFDocument} without reflection. It should be removed.
*/
@Internal @Deprecated
public static void _invokeOnDocumentRead(POIXMLDocumentPart part) throws IOException {
part.onDocumentRead();
}
} }

View File

@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -48,7 +47,6 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.poifs.crypt.HashAlgorithm;
import org.apache.poi.util.DocumentHelper;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.apache.poi.util.IdentifierManager; import org.apache.poi.util.IdentifierManager;
import org.apache.poi.util.Internal; import org.apache.poi.util.Internal;
@ -153,6 +151,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
} }
} }
@SuppressWarnings("deprecation")
@Override @Override
protected void onDocumentRead() throws IOException { protected void onDocumentRead() throws IOException {
try { try {
@ -224,13 +223,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
for (POIXMLDocumentPart gp : p.getRelations()) { for (POIXMLDocumentPart gp : p.getRelations()) {
// Trigger the onDocumentRead for all the child parts // Trigger the onDocumentRead for all the child parts
// Otherwise we'll hit issues on Styles, Settings etc on save // Otherwise we'll hit issues on Styles, Settings etc on save
try { // TODO: Refactor this to not need to access protected method
Method onDocumentRead = gp.getClass().getDeclaredMethod("onDocumentRead"); // from other package! Remove the static helper method once fixed!!!
onDocumentRead.setAccessible(true); POIXMLDocumentPart._invokeOnDocumentRead(gp);
onDocumentRead.invoke(gp);
} catch (Exception e) {
throw new POIXMLException(e);
}
} }
} }
} }

View File

@ -72,7 +72,7 @@ public class HSSFTestHelper {
} }
public static EscherAggregate getEscherAggregate(HSSFPatriarch patriarch){ public static EscherAggregate getEscherAggregate(HSSFPatriarch patriarch){
return patriarch._getBoundAggregate(); return patriarch.getBoundAggregate();
} }
public static int allocateNewShapeId(HSSFPatriarch patriarch){ public static int allocateNewShapeId(HSSFPatriarch patriarch){

View File

@ -85,13 +85,13 @@ public final class TestCloneSheet extends TestCase {
HSSFSheet s = b.createSheet("Test"); HSSFSheet s = b.createSheet("Test");
HSSFPatriarch patriarch = s.createDrawingPatriarch(); HSSFPatriarch patriarch = s.createDrawingPatriarch();
EscherAggregate agg1 = patriarch._getBoundAggregate(); EscherAggregate agg1 = patriarch.getBoundAggregate();
HSSFSheet s2 = s.cloneSheet(b); HSSFSheet s2 = s.cloneSheet(b);
patriarch = s2.getDrawingPatriarch(); patriarch = s2.getDrawingPatriarch();
EscherAggregate agg2 = patriarch._getBoundAggregate(); EscherAggregate agg2 = patriarch.getBoundAggregate();
EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1); EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1);
EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1); EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1);

View File

@ -940,8 +940,8 @@ public final class TestHSSFSheet extends BaseTestSheet {
HSSFSheet sheet2 = wb2.getSheetAt(1); HSSFSheet sheet2 = wb2.getSheetAt(1);
//check that id of the drawing group was updated //check that id of the drawing group was updated
EscherDgRecord dg1 = (EscherDgRecord)sheet1.getDrawingPatriarch()._getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID); EscherDgRecord dg1 = (EscherDgRecord)sheet1.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
EscherDgRecord dg2 = (EscherDgRecord)sheet2.getDrawingPatriarch()._getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID); EscherDgRecord dg2 = (EscherDgRecord)sheet2.getDrawingPatriarch().getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
int dg_id_1 = dg1.getOptions() >> 4; int dg_id_1 = dg1.getOptions() >> 4;
int dg_id_2 = dg2.getOptions() >> 4; int dg_id_2 = dg2.getOptions() >> 4;
assertEquals(dg_id_1 + 1, dg_id_2); assertEquals(dg_id_1 + 1, dg_id_2);

View File

@ -40,7 +40,7 @@ public class TestPatriarch extends TestCase {
assertSame(patriarch, sh.getDrawingPatriarch()); assertSame(patriarch, sh.getDrawingPatriarch());
EscherAggregate agg = patriarch._getBoundAggregate(); EscherAggregate agg = patriarch.getBoundAggregate();
EscherDgRecord dg = agg.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID); EscherDgRecord dg = agg.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
int lastId = dg.getLastMSOSPID(); int lastId = dg.getLastMSOSPID();
@ -50,7 +50,7 @@ public class TestPatriarch extends TestCase {
wb = HSSFTestDataSamples.writeOutAndReadBack(wb); wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
sh = wb.getSheetAt(0); sh = wb.getSheetAt(0);
patriarch = sh.createDrawingPatriarch(); patriarch = sh.createDrawingPatriarch();
dg = patriarch._getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID); dg = patriarch.getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
assertEquals(lastId, dg.getLastMSOSPID()); assertEquals(lastId, dg.getLastMSOSPID());
} }