mirror of https://github.com/apache/poi.git
POIFS Property refactoring ready for NIO support
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1051025 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
84eab42b56
commit
569cd51d33
|
@ -83,10 +83,7 @@ public class POIFSHeaderDumper {
|
||||||
|
|
||||||
// Properties Table
|
// Properties Table
|
||||||
PropertyTable properties =
|
PropertyTable properties =
|
||||||
new PropertyTable(
|
new PropertyTable(header_block, data_blocks);
|
||||||
header_block.getBigBlockSize(),
|
|
||||||
header_block.getPropertyStart(),
|
|
||||||
data_blocks);
|
|
||||||
|
|
||||||
// Mini Fat
|
// Mini Fat
|
||||||
BlockList sbat =
|
BlockList sbat =
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class POIFSReader
|
||||||
HeaderBlock header_block = new HeaderBlock(stream);
|
HeaderBlock header_block = new HeaderBlock(stream);
|
||||||
|
|
||||||
// read the rest of the stream into blocks
|
// read the rest of the stream into blocks
|
||||||
RawDataBlockList data_blocks = new RawDataBlockList(stream, header_block.getBigBlockSize());
|
RawDataBlockList data_blocks = new RawDataBlockList(stream, header_block.getBigBlockSize());
|
||||||
|
|
||||||
// set up the block allocation table (necessary for the
|
// set up the block allocation table (necessary for the
|
||||||
// data_blocks to be manageable
|
// data_blocks to be manageable
|
||||||
|
@ -91,9 +91,7 @@ public class POIFSReader
|
||||||
|
|
||||||
// get property table from the document
|
// get property table from the document
|
||||||
PropertyTable properties =
|
PropertyTable properties =
|
||||||
new PropertyTable(header_block.getBigBlockSize(),
|
new PropertyTable(header_block, data_blocks);
|
||||||
header_block.getPropertyStart(),
|
|
||||||
data_blocks);
|
|
||||||
|
|
||||||
// process documents
|
// process documents
|
||||||
processProperties(SmallBlockTableReader
|
processProperties(SmallBlockTableReader
|
||||||
|
|
|
@ -156,9 +156,7 @@ public class POIFSFileSystem
|
||||||
|
|
||||||
// get property table from the document
|
// get property table from the document
|
||||||
PropertyTable properties =
|
PropertyTable properties =
|
||||||
new PropertyTable(bigBlockSize,
|
new PropertyTable(header_block, data_blocks);
|
||||||
header_block.getPropertyStart(),
|
|
||||||
data_blocks);
|
|
||||||
|
|
||||||
// init documents
|
// init documents
|
||||||
processProperties(
|
processProperties(
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.apache.poi.poifs.storage.ListManagedBlock;
|
||||||
|
|
||||||
class PropertyFactory
|
class PropertyFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
// no need for an accessible constructor
|
// no need for an accessible constructor
|
||||||
private PropertyFactory()
|
private PropertyFactory()
|
||||||
{
|
{
|
||||||
|
@ -56,48 +55,52 @@ class PropertyFactory
|
||||||
*
|
*
|
||||||
* @exception IOException if any of the blocks are empty
|
* @exception IOException if any of the blocks are empty
|
||||||
*/
|
*/
|
||||||
|
static List<Property> convertToProperties(ListManagedBlock [] blocks)
|
||||||
static List convertToProperties(ListManagedBlock [] blocks)
|
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
List properties = new ArrayList();
|
List<Property> properties = new ArrayList<Property>();
|
||||||
|
|
||||||
for (int j = 0; j < blocks.length; j++)
|
for (int j = 0; j < blocks.length; j++) {
|
||||||
{
|
byte[] data = blocks[ j ].getData();
|
||||||
byte[] data = blocks[ j ].getData();
|
convertToProperties(data, properties);
|
||||||
int property_count = data.length
|
|
||||||
/ POIFSConstants.PROPERTY_SIZE;
|
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
for (int k = 0; k < property_count; k++)
|
|
||||||
{
|
|
||||||
switch (data[ offset + PropertyConstants.PROPERTY_TYPE_OFFSET ])
|
|
||||||
{
|
|
||||||
|
|
||||||
case PropertyConstants.DIRECTORY_TYPE :
|
|
||||||
properties
|
|
||||||
.add(new DirectoryProperty(properties.size(),
|
|
||||||
data, offset));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PropertyConstants.DOCUMENT_TYPE :
|
|
||||||
properties.add(new DocumentProperty(properties.size(),
|
|
||||||
data, offset));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PropertyConstants.ROOT_TYPE :
|
|
||||||
properties.add(new RootProperty(properties.size(),
|
|
||||||
data, offset));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default :
|
|
||||||
properties.add(null);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
offset += POIFSConstants.PROPERTY_SIZE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void convertToProperties(byte[] data, List<Property> properties)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
int property_count = data.length / POIFSConstants.PROPERTY_SIZE;
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
|
for (int k = 0; k < property_count; k++) {
|
||||||
|
switch (data[ offset + PropertyConstants.PROPERTY_TYPE_OFFSET ]) {
|
||||||
|
case PropertyConstants.DIRECTORY_TYPE :
|
||||||
|
properties.add(
|
||||||
|
new DirectoryProperty(properties.size(), data, offset)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PropertyConstants.DOCUMENT_TYPE :
|
||||||
|
properties.add(
|
||||||
|
new DocumentProperty(properties.size(), data, offset)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PropertyConstants.ROOT_TYPE :
|
||||||
|
properties.add(
|
||||||
|
new RootProperty(properties.size(), data, offset)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
properties.add(null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += POIFSConstants.PROPERTY_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end package scope class PropertyFactory
|
} // end package scope class PropertyFactory
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.poi.poifs.common.POIFSBigBlockSize;
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.poifs.filesystem.BATManaged;
|
import org.apache.poi.poifs.filesystem.BATManaged;
|
||||||
import org.apache.poi.poifs.storage.BlockWritable;
|
import org.apache.poi.poifs.storage.BlockWritable;
|
||||||
|
import org.apache.poi.poifs.storage.HeaderBlock;
|
||||||
import org.apache.poi.poifs.storage.PropertyBlock;
|
import org.apache.poi.poifs.storage.PropertyBlock;
|
||||||
import org.apache.poi.poifs.storage.RawDataBlockList;
|
import org.apache.poi.poifs.storage.RawDataBlockList;
|
||||||
|
|
||||||
|
@ -63,17 +64,16 @@ public final class PropertyTable implements BATManaged, BlockWritable {
|
||||||
* @exception IOException if anything goes wrong (which should be
|
* @exception IOException if anything goes wrong (which should be
|
||||||
* a result of the input being NFG)
|
* a result of the input being NFG)
|
||||||
*/
|
*/
|
||||||
public PropertyTable(final POIFSBigBlockSize bigBlockSize,
|
public PropertyTable(final HeaderBlock headerBlock,
|
||||||
final int startBlock,
|
|
||||||
final RawDataBlockList blockList)
|
final RawDataBlockList blockList)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
_bigBigBlockSize = bigBlockSize;
|
_bigBigBlockSize = headerBlock.getBigBlockSize();
|
||||||
_start_block = POIFSConstants.END_OF_CHAIN;
|
_start_block = POIFSConstants.END_OF_CHAIN;
|
||||||
_blocks = null;
|
_blocks = null;
|
||||||
_properties =
|
_properties = PropertyFactory.convertToProperties(
|
||||||
PropertyFactory
|
blockList.fetchBlocks(headerBlock.getPropertyStart(), -1)
|
||||||
.convertToProperties(blockList.fetchBlocks(startBlock, -1));
|
);
|
||||||
populatePropertyTree(( DirectoryProperty ) _properties.get(0));
|
populatePropertyTree(( DirectoryProperty ) _properties.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ public final class PropertyTable implements BATManaged, BlockWritable {
|
||||||
*/
|
*/
|
||||||
public void preWrite()
|
public void preWrite()
|
||||||
{
|
{
|
||||||
Property[] properties = _properties.toArray(new Property[ 0 ]);
|
Property[] properties = _properties.toArray(new Property[_properties.size()]);
|
||||||
|
|
||||||
// give each property its index
|
// give each property its index
|
||||||
for (int k = 0; k < properties.length; k++)
|
for (int k = 0; k < properties.length; k++)
|
||||||
|
|
|
@ -27,6 +27,7 @@ import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
|
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
|
||||||
|
import org.apache.poi.poifs.storage.HeaderBlock;
|
||||||
import org.apache.poi.poifs.storage.RawDataBlockList;
|
import org.apache.poi.poifs.storage.RawDataBlockList;
|
||||||
import org.apache.poi.poifs.storage.RawDataUtil;
|
import org.apache.poi.poifs.storage.RawDataUtil;
|
||||||
|
|
||||||
|
@ -438,9 +439,12 @@ public final class TestPropertyTable extends TestCase {
|
||||||
new BlockAllocationTableReader(
|
new BlockAllocationTableReader(
|
||||||
POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 1, bat_array, 0, -2, data_blocks);
|
POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 1, bat_array, 0, -2, data_blocks);
|
||||||
|
|
||||||
|
// Fake up a header
|
||||||
|
HeaderBlock header_block = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
|
||||||
|
header_block.setPropertyStart(0);
|
||||||
|
|
||||||
// get property table from the document
|
// get property table from the document
|
||||||
PropertyTable table = new PropertyTable(
|
PropertyTable table = new PropertyTable(header_block, data_blocks);
|
||||||
POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 0, data_blocks);
|
|
||||||
|
|
||||||
assertEquals(30 * 64, table.getRoot().getSize());
|
assertEquals(30 * 64, table.getRoot().getSize());
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
|
@ -303,8 +303,12 @@ public final class TestSmallBlockTableReader extends TestCase {
|
||||||
// table
|
// table
|
||||||
new BlockAllocationTableReader(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 1, bat_array, 0, -2, data_blocks);
|
new BlockAllocationTableReader(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 1, bat_array, 0, -2, data_blocks);
|
||||||
|
|
||||||
|
// Fake up a header
|
||||||
|
HeaderBlock header_block = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
|
||||||
|
header_block.setPropertyStart(0);
|
||||||
|
|
||||||
// get property table from the document
|
// get property table from the document
|
||||||
PropertyTable properties = new PropertyTable(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, 0, data_blocks);
|
PropertyTable properties = new PropertyTable(header_block, data_blocks);
|
||||||
RootProperty root = properties.getRoot();
|
RootProperty root = properties.getRoot();
|
||||||
BlockList bl = SmallBlockTableReader.getSmallDocumentBlocks(
|
BlockList bl = SmallBlockTableReader.getSmallDocumentBlocks(
|
||||||
POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, data_blocks, root, 14);
|
POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, data_blocks, root, 14);
|
||||||
|
|
Loading…
Reference in New Issue