import java.io.IOException;\r
import java.io.InputStream;\r
import java.io.OutputStream;\r
-import java.lang.reflect.Field;\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import org.apache.poi.ddf.EscherRecord;\r
import org.apache.poi.hssf.model.InternalWorkbook;\r
import org.apache.poi.hssf.record.DrawingGroupRecord;\r
-import org.apache.poi.hssf.record.EscherAggregate;\r
import org.apache.poi.hssf.usermodel.HSSFPatriarch;\r
import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;\r
public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {\r
NPOIFSFileSystem fs = new NPOIFSFileSystem(xlsWorkbook);\r
HSSFWorkbook workbook = new HSSFWorkbook(fs);\r
- InternalWorkbook internalWorkbook = getInternalWorkbook(workbook);\r
+ InternalWorkbook internalWorkbook = workbook.getInternalWorkbook();\r
DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);\r
r.decode();\r
\r
HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();\r
if(p != null ) {\r
builder.append(tab).append("<sheet").append(i).append(">\n");\r
- builder.append(getHSSFPatriarchBoundAggregate(p).toXml(tab + "\t"));\r
+ builder.append(p.getBoundAggregate().toXml(tab + "\t"));\r
builder.append(tab).append("</sheet").append(i).append(">\n");\r
}\r
}\r
fos.close();\r
}\r
\r
- private static EscherAggregate getHSSFPatriarchBoundAggregate(HSSFPatriarch patriarch) {\r
- Field boundAggregateField = null;\r
- try {\r
- boundAggregateField = patriarch.getClass().getDeclaredField("_boundAggregate");\r
- boundAggregateField.setAccessible(true);\r
- return (EscherAggregate) boundAggregateField.get(patriarch);\r
- } catch (NoSuchFieldException e) {\r
- e.printStackTrace();\r
- } catch (IllegalAccessException e) {\r
- e.printStackTrace();\r
- }\r
- return null;\r
- }\r
-\r
- private static InternalWorkbook getInternalWorkbook(HSSFWorkbook workbook) {\r
- Field internalSheetField = null;\r
- try {\r
- internalSheetField = workbook.getClass().getDeclaredField("workbook");\r
- internalSheetField.setAccessible(true);\r
- return (InternalWorkbook) internalSheetField.get(workbook);\r
- } catch (NoSuchFieldException e) {\r
- e.printStackTrace();\r
- } catch (IllegalAccessException e) {\r
- e.printStackTrace();\r
- }\r
- return null;\r
- }\r
}\r
@Override
void afterInsert(HSSFPatriarch patriarch) {
super.afterInsert(patriarch);
- patriarch._getBoundAggregate().addTailRecord(getNoteRecord());
+ patriarch.getBoundAggregate().addTailRecord(getNoteRecord());
}
@Override
public void afterRemove(HSSFPatriarch patriarch){
super.afterRemove(patriarch);
- patriarch._getBoundAggregate().removeTailRecord(getNoteRecord());
+ patriarch.getBoundAggregate().removeTailRecord(getNoteRecord());
}
@Override
@Override
void afterInsert(HSSFPatriarch patriarch) {
- EscherAggregate agg = patriarch._getBoundAggregate();
+ EscherAggregate agg = patriarch.getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
EscherBSERecord bse =
patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
* Returns the aggregate escher record we're bound to
* @return - low level representation of sheet drawing data
*/
- protected EscherAggregate _getBoundAggregate() {
+ @Internal
+ public EscherAggregate getBoundAggregate() {
return _boundAggregate;
}
@Override
void afterInsert(HSSFPatriarch patriarch) {
- EscherAggregate agg = patriarch._getBoundAggregate();
+ EscherAggregate agg = patriarch.getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
EscherBSERecord bse =
patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex());
@Override
protected void afterRemove(HSSFPatriarch patriarch) {
- patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
+ patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
}
/**
@Override
protected void afterRemove(HSSFPatriarch patriarch) {
- patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildContainers().get(0)
+ patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildContainers().get(0)
.getChildById(EscherClientDataRecord.RECORD_ID));
for ( int i=0; i<shapes.size(); i++ ) {
HSSFShape shape = shapes.get(i);
@Override
void afterInsert(HSSFPatriarch patriarch){
- EscherAggregate agg = patriarch._getBoundAggregate();
+ EscherAggregate agg = patriarch.getBoundAggregate();
EscherContainerRecord containerRecord = getEscherContainer().getChildById(EscherContainerRecord.SP_CONTAINER);
agg.associateShapeToObjRecord(containerRecord.getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
}
}
if (getDrawingPatriarch() != null) {
HSSFPatriarch patr = HSSFPatriarch.createPatriarch(this.getDrawingPatriarch(), sheet);
- sheet._sheet.getRecords().add(pos, patr._getBoundAggregate());
+ sheet._sheet.getRecords().add(pos, patr.getBoundAggregate());
sheet._patriarch = patr;
}
return sheet;
@Override
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)){
- patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
+ patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
}
}
@Override
void afterInsert(HSSFPatriarch patriarch){
- EscherAggregate agg = patriarch._getBoundAggregate();
+ EscherAggregate agg = patriarch.getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
if (null != getTextObjectRecord()){
escherTextbox.setRecordId(EscherTextboxRecord.RECORD_ID);
escherTextbox.setOptions((short) 0x0000);
getEscherContainer().addChildRecord(escherTextbox);
- getPatriarch()._getBoundAggregate().associateShapeToObjRecord(escherTextbox, _textObjectRecord);
+ getPatriarch().getBoundAggregate().associateShapeToObjRecord(escherTextbox, _textObjectRecord);
}
return _textObjectRecord;
}
@Override
void afterInsert(HSSFPatriarch patriarch) {
- EscherAggregate agg = patriarch._getBoundAggregate();
+ EscherAggregate agg = patriarch.getBoundAggregate();
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord());
if (getTextObjectRecord() != null){
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID), getTextObjectRecord());
@Override
protected void afterRemove(HSSFPatriarch patriarch) {
- patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
- patriarch._getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
+ patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID));
+ patriarch.getBoundAggregate().removeShapeToObjRecord(getEscherContainer().getChildById(EscherTextboxRecord.RECORD_ID));
}
}
import org.apache.poi.ss.util.WorkbookUtil;
import org.apache.poi.util.Configurator;
import org.apache.poi.util.HexDump;
+import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
public DirectoryNode getRootDirectory(){
return directory;
}
+
+ @Internal
+ public InternalWorkbook getInternalWorkbook() {
+ return workbook;
+ }
}
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.Iterator;
dump(root, file);
if (dumpProps) {
- HeaderBlock header = getHeaderBlock(fs);
+ HeaderBlock header = fs.getHeaderBlock();
dump(fs, header.getPropertyStart(), "properties", file);
}
if (dumpMini) {
- NPropertyTable props = getPropertyTable(fs);
+ NPropertyTable props = fs.getPropertyTable();
int startBlock = props.getRoot().getStartBlock();
if (startBlock == POIFSConstants.END_OF_CHAIN) {
System.err.println("No Mini Stream in file");
}
}
}
- }
-
- 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 {
for(Iterator<Entry> it = root.getEntries(); it.hasNext();){
Entry entry = it.next();
import java.io.FileInputStream;
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.POIFSConstants;
System.out.println("Raw Blocks Details:");
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++) {
- 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)];
System.arraycopy(block.getData(), 0, data, 0, data.length);
public static void displayBATReader(String type, BlockAllocationTableReader batReader) throws Exception {
System.out.println("Sectors, as referenced from the "+type+" FAT:");
- Field entriesF = batReader.getClass().getDeclaredField("_entries");
- entriesF.setAccessible(true);
- IntList entries = (IntList)entriesF.get(batReader);
+ IntList entries = batReader.getEntries();
for(int i=0; i<entries.size(); i++) {
int bn = entries.get(i);
import org.apache.poi.poifs.storage.HeaderBlockWriter;
import org.apache.poi.util.CloseIgnoringInputStream;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.Internal;
import org.apache.poi.util.LongField;
/**
protected int getBlockStoreBlockSize() {
return getBigBlockSize();
}
+
+ @Internal
+ public NPropertyTable getPropertyTable() {
+ return _property_table;
+ }
+
+ @Internal
+ public HeaderBlock getHeaderBlock() {
+ return _header;
+ }
}
}
raw_blocks.setBAT(this);
}
+
+ @Internal
+ public IntList getEntries() {
+ return _entries;
+ }
}
import java.io.IOException;
+import org.apache.poi.util.Internal;
+
/**
* A simple implementation of BlockList
*
}
/**
- * Unit testing method. Gets, without sanity checks or
+ * Internal method. Gets, without sanity checks or
* removing.
*/
- protected ListManagedBlock get(final int index) {
+ @Internal
+ public ListManagedBlock get(final int index) {
return _blocks[index];
}
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.xmlbeans.XmlOptions;
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();
+ }
}
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.poifs.crypt.HashAlgorithm;
-import org.apache.poi.util.DocumentHelper;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.IdentifierManager;
import org.apache.poi.util.Internal;
}
}
+ @SuppressWarnings("deprecation")
@Override
protected void onDocumentRead() throws IOException {
try {
for (POIXMLDocumentPart gp : p.getRelations()) {
// Trigger the onDocumentRead for all the child parts
// Otherwise we'll hit issues on Styles, Settings etc on save
- try {
- Method onDocumentRead = gp.getClass().getDeclaredMethod("onDocumentRead");
- onDocumentRead.setAccessible(true);
- onDocumentRead.invoke(gp);
- } catch (Exception e) {
- throw new POIXMLException(e);
- }
+ // TODO: Refactor this to not need to access protected method
+ // from other package! Remove the static helper method once fixed!!!
+ POIXMLDocumentPart._invokeOnDocumentRead(gp);
}
}
}
}
public static EscherAggregate getEscherAggregate(HSSFPatriarch patriarch){
- return patriarch._getBoundAggregate();
+ return patriarch.getBoundAggregate();
}
public static int allocateNewShapeId(HSSFPatriarch patriarch){
HSSFSheet s = b.createSheet("Test");
HSSFPatriarch patriarch = s.createDrawingPatriarch();
- EscherAggregate agg1 = patriarch._getBoundAggregate();
+ EscherAggregate agg1 = patriarch.getBoundAggregate();
HSSFSheet s2 = s.cloneSheet(b);
patriarch = s2.getDrawingPatriarch();
- EscherAggregate agg2 = patriarch._getBoundAggregate();
+ EscherAggregate agg2 = patriarch.getBoundAggregate();
EscherSpRecord sp1 = (EscherSpRecord) agg1.getEscherContainer().getChild(1).getChild(0).getChild(1);
EscherSpRecord sp2 = (EscherSpRecord) agg2.getEscherContainer().getChild(1).getChild(0).getChild(1);
HSSFSheet sheet2 = wb2.getSheetAt(1);
//check that id of the drawing group was updated
- EscherDgRecord dg1 = (EscherDgRecord)sheet1.getDrawingPatriarch()._getBoundAggregate().findFirstWithId(EscherDgRecord.RECORD_ID);
- EscherDgRecord dg2 = (EscherDgRecord)sheet2.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);
int dg_id_1 = dg1.getOptions() >> 4;
int dg_id_2 = dg2.getOptions() >> 4;
assertEquals(dg_id_1 + 1, dg_id_2);
\r
assertSame(patriarch, sh.getDrawingPatriarch());\r
\r
- EscherAggregate agg = patriarch._getBoundAggregate();\r
+ EscherAggregate agg = patriarch.getBoundAggregate();\r
\r
EscherDgRecord dg = agg.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);\r
int lastId = dg.getLastMSOSPID();\r
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);\r
sh = wb.getSheetAt(0);\r
patriarch = sh.createDrawingPatriarch();\r
- dg = patriarch._getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);\r
+ dg = patriarch.getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);\r
\r
assertEquals(lastId, dg.getLastMSOSPID());\r
}\r