本文整理汇总了Java中org.apache.poi.poifs.filesystem.DocumentEntry类的典型用法代码示例。如果您正苦于以下问题:Java DocumentEntry类的具体用法?Java DocumentEntry怎么用?Java DocumentEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentEntry类属于org.apache.poi.poifs.filesystem包,在下文中一共展示了DocumentEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkRecipientDirectoryEntry
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
/**
* Parses a recipient directory entry which holds informations about one of possibly multiple recipients.
* The parsed information is put into the {@link OutlookMessage} object.
*
* @param dir The current node in the .msg file.
* @param msg The resulting {@link OutlookMessage} object.
* @throws IOException Thrown if the .msg file could not be parsed.
*/
private void checkRecipientDirectoryEntry(final DirectoryEntry dir, final OutlookMessage msg)
throws IOException {
final OutlookRecipient recipient = new OutlookRecipient();
// we iterate through all entries in the current directory
for (final Iterator<?> iter = dir.getEntries(); iter.hasNext(); ) {
final Entry entry = (Entry) iter.next();
// check whether the entry is either a directory entry
// or a document entry, while we are just interested in document entries on this level
if (!entry.isDirectoryEntry() && entry.isDocumentEntry()) {
// a document entry contains information about the mail (e.g, from, to, subject, ...)
checkRecipientDocumentEntry((DocumentEntry) entry, recipient);
}
}
//after all properties are set -> add recipient to msg object
msg.addRecipient(recipient);
}
示例2: test
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
@Override
public boolean test(Entry entry) {
String entryName = entry.getName();
if (!SummaryInformation.DEFAULT_STREAM_NAME.equals(entryName)) {
return true;
}
if (!(entry instanceof DocumentEntry)) {
return true;
}
DocumentEntry dsiEntry = (DocumentEntry) entry;
sanitizeSummaryInformation(session, dsiEntry);
return true;
}
示例3: test1
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
@Test
void test1() {
// Test an invalid stream, should be ignored
Entry entry = mock(Entry.class);
doReturn("\005RandomString").when(entry).getName();
assertTrue(instance.test(entry));
verify(instance, never()).sanitizeSummaryInformation(eq(session), (DocumentEntry) any());
// Test a valid stream name, but wrong type (should be ignored)
reset(entry);
doReturn(SummaryInformation.DEFAULT_STREAM_NAME).when(entry).getName();
assertTrue(instance.test(entry));
verify(instance, never()).sanitizeSummaryInformation(eq(session), (DocumentEntry) any());
reset(instance, entry);
// Test a valid SummaryInformation name
DocumentEntry docEntry = mock(DocumentEntry.class);
doReturn(SummaryInformation.DEFAULT_STREAM_NAME).when(docEntry).getName();
doNothing().when(instance).sanitizeSummaryInformation(session, docEntry);
assertTrue(instance.test(docEntry));
verify(instance, atLeastOnce()).sanitizeSummaryInformation(session, docEntry);
}
示例4: readContent
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
@Override
protected String readContent(final VFSLeaf leaf) throws IOException, DocumentException {
BufferedInputStream bis = null;
final StringBuilder sb = new StringBuilder();
try {
bis = new BufferedInputStream(leaf.getInputStream());
final POIFSFileSystem filesystem = new POIFSFileSystem(bis);
final Iterator<?> entries = filesystem.getRoot().getEntries();
while (entries.hasNext()) {
final Entry entry = (Entry) entries.next();
final String name = entry.getName();
if (!(entry instanceof DocumentEntry)) {
// Skip directory entries
} else if ("WordDocument".equals(name)) {
collectWordDocument(filesystem, sb);
}
}
return sb.toString();
} catch (final Exception e) {
throw new DocumentException(e.getMessage());
} finally {
if (bis != null) {
bis.close();
}
}
}
示例5: initTableStream
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
/**
* Initializes the table stream
*
* @throws IOException
*/
private void initTableStream() throws IOException
{
String tablename = null;
if(_fib.isFWhichTblStm())
{
tablename="1Table";
}
else
{
tablename="0Table";
}
DocumentEntry tableEntry = (DocumentEntry)_filesystem.getRoot().getEntry(tablename);
//load the table stream into a buffer
int size = tableEntry.getSize();
_tableBuffer = new byte[size];
_filesystem.createDocumentInputStream(tablename).read(_tableBuffer);
}
示例6: checkDirectoryDocumentEntry
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
/**
* Parses a directory document entry which can either be a simple entry or
* a stream that has to be split up into multiple document entries again.
* The parsed information is put into the {@link OutlookMessage} object.
*
* @param de The current node in the .msg file.
* @param msg The resulting {@link OutlookMessage} object.
* @throws IOException Thrown if the .msg file could not be parsed.
*/
private void checkDirectoryDocumentEntry(final DocumentEntry de, final OutlookMessage msg)
throws IOException {
if (de.getName().startsWith(PROPS_KEY)) {
//TODO: parse properties stream
final List<DocumentEntry> deList = getDocumentEntriesFromPropertiesStream(de);
for (final DocumentEntry deFromProps : deList) {
final OutlookMessageProperty msgProp = getMessagePropertyFromDocumentEntry(deFromProps);
msg.setProperty(msgProp);
}
} else {
msg.setProperty(getMessagePropertyFromDocumentEntry(de));
}
}
示例7: checkRecipientDocumentEntry
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
/**
* Parses a recipient document entry which can either be a simple entry or
* a stream that has to be split up into multiple document entries again.
* The parsed information is put into the {@link OutlookRecipient} object.
*
* @param de The current node in the .msg file.
* @param recipient The resulting {@link OutlookRecipient} object.
* @throws IOException Thrown if the .msg file could not be parsed.
*/
private void checkRecipientDocumentEntry(final DocumentEntry de, final OutlookRecipient recipient)
throws IOException {
if (de.getName().startsWith(PROPS_KEY)) {
//TODO: parse properties stream
final List<DocumentEntry> deList = getDocumentEntriesFromPropertiesStream(de);
for (final DocumentEntry deFromProps : deList) {
final OutlookMessageProperty msgProp = getMessagePropertyFromDocumentEntry(deFromProps);
recipient.setProperty(msgProp);
}
} else {
recipient.setProperty(getMessagePropertyFromDocumentEntry(de));
}
}
示例8: getMessagePropertyFromDocumentEntry
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
/**
* Reads a property from a document entry and puts it's type and data to a {@link OutlookMessageProperty} object.
*
* @param de The {@link DocumentEntry} to be read.
* @return An object holding the type and data of the read property.
* @throws IOException In case the property could not be parsed.
*/
private OutlookMessageProperty getMessagePropertyFromDocumentEntry(final DocumentEntry de)
throws IOException {
// analyze the document entry
// (i.e., get class and data type)
final OutlookFieldInformation info = analyzeDocumentEntry(de);
// create a Java object from the data provided
// by the input stream. depending on the field
// information, either a String or a byte[] will
// be returned. other datatypes are not yet supported
final Object data = getData(de, info);
LOGGER.trace(" Document data: {}", data);
return new OutlookMessageProperty(info.getClazz(), data, de.getSize());
}
示例9: analyzeDocumentEntry
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
/**
* Analyzes the {@link DocumentEntry} and returns
* a {@link OutlookFieldInformation} object containing the
* class (the field name, so to say) and type of
* the entry.
*
* @param de The {@link DocumentEntry} that should be examined.
* @return A {@link OutlookFieldInformation} object containing class and type of the document entry or, if the entry is not an interesting field, an empty
* {@link OutlookFieldInformation} object containing {@link OutlookFieldInformation#UNKNOWN} class and type.
*/
private OutlookFieldInformation analyzeDocumentEntry(final DocumentEntry de) {
final String name = de.getName();
// we are only interested in document entries
// with names starting with __substg1.
LOGGER.trace("Document entry: {}", name);
if (name.startsWith(PROPERTY_STREAM_PREFIX)) {
final String clazz;
final String type;
final int mapiType;
try {
final String val = name.substring(PROPERTY_STREAM_PREFIX.length()).toLowerCase();
// the first 4 digits of the remainder
// defines the field class (or field name)
// and the last 4 digits indicate the
// data type.
clazz = val.substring(0, 4);
type = val.substring(4);
LOGGER.trace(" Found document entry: class={}, type={}", clazz, type);
mapiType = Integer.parseInt(type, 16);
} catch (final RuntimeException re) {
LOGGER.error("Could not parse directory entry {}", name, re);
return new OutlookFieldInformation();
}
return new OutlookFieldInformation(clazz, mapiType);
} else {
LOGGER.trace("Ignoring entry with name {}", name);
}
// we are not interested in the field
// and return an empty OutlookFieldInformation object
return new OutlookFieldInformation();
}
示例10: parseAttachment
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
/**
* Creates an {@link OutlookAttachment} object based on
* the given directory entry. The entry may either
* point to an attached file or to an
* attached .msg file, which will be added
* as a {@link OutlookMsgAttachment} object instead.
*
* @param dir The directory entry containing the attachment document entry and some other document entries describing the attachment (name, extension, mime
* type, ...)
* @param msg The {@link OutlookMessage} object that this attachment should be added to.
* @throws IOException Thrown if the attachment could not be parsed/read.
*/
private void parseAttachment(final DirectoryEntry dir, final OutlookMessage msg)
throws IOException {
final OutlookFileAttachment attachment = new OutlookFileAttachment();
// iterate through all document entries
for (final Iterator<?> iter = dir.getEntries(); iter.hasNext(); ) {
final Entry entry = (Entry) iter.next();
if (entry.isDocumentEntry()) {
// the document entry may contain information about the attachment
final DocumentEntry de = (DocumentEntry) entry;
final OutlookMessageProperty msgProp = getMessagePropertyFromDocumentEntry(de);
// we provide the class and data of the document entry to the attachment.
// The attachment implementation has to know the semantics of the field names
attachment.setProperty(msgProp);
} else {
// a directory within the attachment directory entry means that a .msg file is attached at this point.
// we recursively parse this .msg file and add it as a OutlookMsgAttachment object to the current OutlookMessage object.
final OutlookMessage attachmentMsg = new OutlookMessage();
final OutlookMsgAttachment msgAttachment = new OutlookMsgAttachment(attachmentMsg);
msg.addAttachment(msgAttachment);
checkDirectoryEntry((DirectoryEntry) entry, attachmentMsg);
}
}
// only if there was really an attachment, we add this object to the OutlookMessage object
if (attachment.getSize() > -1) {
msg.addAttachment(attachment);
}
}
示例11: test
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
@Override
public boolean test(Entry entry) {
String entryName = entry.getName();
if (!isObject(entryName)) {
return true;
}
LOGGER.info("Found Compound Objects, removing them.");
StringBuilder infos = new StringBuilder();
if (entry instanceof DirectoryEntry) {
Set<String> entryNames = ((DirectoryEntry) entry).getEntryNames();
LOGGER.trace("Compound Objects' entries: {}", entryNames);
infos.append("Entries: ").append(entryNames);
} else if (entry instanceof DocumentEntry) {
int size = ((DocumentEntry) entry).getSize();
infos.append("Size: ").append(size);
}
Threat threat = threat()
.type(ThreatType.EXTERNAL_CONTENT)
.severity(ThreatSeverity.HIGH)
.action(ThreatAction.REMOVE)
.location(entryName)
.details(infos.toString())
.build();
session.recordThreat(threat);
return false;
}
示例12: sanitizeSummaryInformation
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
protected void sanitizeSummaryInformation(BleachSession session, DocumentEntry dsiEntry) {
try (DocumentInputStream dis = new DocumentInputStream(dsiEntry)) {
PropertySet ps = new PropertySet(dis);
// Useful for debugging purposes
// LOGGER.debug("PropertySet sections: {}", ps.getSections());
SummaryInformation dsi = new SummaryInformation(ps);
sanitizeSummaryInformation(session, dsi);
} catch (NoPropertySetStreamException | UnexpectedPropertySetTypeException | MarkUnsupportedException | IOException e) {
LOGGER.error("An error occured while trying to sanitize the document entry", e);
}
}
示例13: test
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
@Override
public boolean test(Entry entry) {
String entryName = entry.getName();
// Matches _VBA_PROJECT_CUR, VBA, ... :)
if (!isMacro(entryName)) {
return true;
}
LOGGER.info("Found Macros, removing them.");
StringBuilder infos = new StringBuilder();
if (entry instanceof DirectoryEntry) {
Set<String> entryNames = ((DirectoryEntry) entry).getEntryNames();
LOGGER.trace("Macros' entries: {}", entryNames);
infos.append("Entries: ").append(entryNames);
} else if (entry instanceof DocumentEntry) {
int size = ((DocumentEntry) entry).getSize();
infos.append("Size: ").append(size);
}
Threat threat = threat()
.type(ThreatType.ACTIVE_CONTENT)
.severity(ThreatSeverity.EXTREME)
.action(ThreatAction.REMOVE)
.location(entryName)
.details(infos.toString())
.build();
session.recordThreat(threat);
return false;
}
示例14: createWorkbookInputStream
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
/**
* returns a {@link BlockStoreInputStream} that exposes all workbook sectors in their correct order
*
* @param is XLS InputStream
* @return {@link BlockStoreInputStream} that wraps the workbook's stream
*
* @throws IOException if the data doesn't contain a proper MS-CFB header
* @throws OldExcelFormatException if the file is too old to be supported
*/
static InputStream createWorkbookInputStream(final XlsInputStream is) throws IOException {
final XlsReader xlsReader = new XlsReader(is);
DocumentEntry workBookEntry = xlsReader.getWorkbookEntry();
DocumentNode workbookNode = (DocumentNode) workBookEntry;
// use proper blockStore
final boolean useMiniStore = workbookNode.getSize() < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE;
final BlockStore blockStore = useMiniStore ? xlsReader.miniStore : xlsReader.difats;
return new BlockStoreInputStream(is, blockStore, workbookNode.getProperty().getStartBlock());
}
示例15: writeWordFile
import org.apache.poi.poifs.filesystem.DocumentEntry; //导入依赖的package包/类
public static boolean writeWordFile(String content,String filename,String path,String examPaperName) throws IOException{
String head = "<html><div style=\"text-align: center\"><span style=\"font-size: 28px\"><span style=\"font-family: 黑体\">" + examPaperName +
"<br /> <br /> </span></span></div>";
String tail = "</html>";
content = head + content + tail;
content = exampaper_formater(content);
ByteArrayInputStream bais = null;
FileOutputStream ostream = null;
try{
if (!"".equals(path)){
File fileDir = new File(path);
if(!fileDir.exists())
fileDir.mkdirs();
if (fileDir.exists()) {
String fileName = filename;
byte b[] = content.getBytes("GBK");
bais = new ByteArrayInputStream(b);
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.getRoot();
DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
ostream = new FileOutputStream(path+ fileName);
poifs.writeFilesystem(ostream);
bais.close();
ostream.close();
}
}
}catch(IOException e){
bais.close();
ostream.close();
e.printStackTrace();
throw e;
}
return true;
}