use of org.apache.poi.hpsf.DocumentSummaryInformation in project CodeUtils by boredream.
the class TempUtils method setPPT.
public static void setPPT() {
try {
PowerPointExtractor ppe = new PowerPointExtractor("temp" + File.separator + "office" + File.separator + "ppt2007.ppt");
DocumentSummaryInformation dsi = ppe.getDocSummaryInformation();
DirectoryEntry root = ppe.getRoot();
System.out.println(dsi.getSlideCount());
System.out.println(root.getName());
} catch (Exception e) {
e.printStackTrace();
}
// SlideShow _slideShow = new SlideShow();
// Slide slide = _slideShow.createSlide();
//
// // 创建并置入简单文本
// TextBox _text = new TextBox();
// TextRun _textRun = _text.createTextRun();
// _textRun.setRawText("杜磊米");
// _text.setAnchor(new Rectangle(10,10,100,100));
//
// // 创建并置入带有样式的文本
// AutoShape _autoShape = new AutoShape(ShapeTypes.Rectangle); //设置形状
// TextRun _autoText = _autoShape.createTextRun();
// _autoText.setRawText("杜磊米");
// _autoShape.setAnchor(new Rectangle(200,200,100,100));
// _autoShape.setFillColor(new Color(170,215,255));
// _autoShape.setLineWidth(5.0);
// _autoShape.setLineStyle(Line.LINE_DOUBLE);
//
// // AutoShape 对象可以设置多个不同样式文本
// TextRun _autoText2 = _autoShape.createTextRun();
// RichTextRun _richText = _autoText2.appendText("杜");
// _richText.setFontColor(new Color(255,255,255));
// RichTextRun _richText2 = _autoText2.appendText("磊米");
// _richText2.setFontColor(new Color(255,0,0));
// _richText2.setFontSize(12);
//
// // 将文本对象置入幻灯片
// slide.addShape(_text);
// slide.addShape(_autoShape);
//
//
//
// // 输出文件
// try {
// _slideShow.write(new FileOutputStream("temp\\office\\test.pptx"));
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
use of org.apache.poi.hpsf.DocumentSummaryInformation in project poi by apache.
the class POIDocument method readProperties.
/**
* Find, and create objects for, the standard
* Document Information Properties (HPSF).
* If a given property set is missing or corrupt,
* it will remain null;
*/
protected void readProperties() {
PropertySet ps;
// DocumentSummaryInformation
ps = getPropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
if (ps instanceof DocumentSummaryInformation) {
dsInf = (DocumentSummaryInformation) ps;
} else if (ps != null) {
logger.log(POILogger.WARN, "DocumentSummaryInformation property set came back with wrong class - ", ps.getClass());
} else {
logger.log(POILogger.WARN, "DocumentSummaryInformation property set came back as null");
}
// SummaryInformation
ps = getPropertySet(SummaryInformation.DEFAULT_STREAM_NAME);
if (ps instanceof SummaryInformation) {
sInf = (SummaryInformation) ps;
} else if (ps != null) {
logger.log(POILogger.WARN, "SummaryInformation property set came back with wrong class - ", ps.getClass());
} else {
logger.log(POILogger.WARN, "SummaryInformation property set came back as null");
}
// Mark the fact that we've now loaded up the properties
initialized = true;
}
use of org.apache.poi.hpsf.DocumentSummaryInformation in project poi by apache.
the class HPSFPropertiesExtractor method getDocumentSummaryInformationText.
public String getDocumentSummaryInformationText() {
if (document == null) {
// event based extractor does not have a document
return "";
}
DocumentSummaryInformation dsi = document.getDocumentSummaryInformation();
StringBuilder text = new StringBuilder();
// Normal properties
text.append(getPropertiesText(dsi));
// Now custom ones
CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
if (cps != null) {
for (String key : cps.nameSet()) {
String val = getPropertyValueText(cps.get(key));
text.append(key).append(" = ").append(val).append("\n");
}
}
// All done
return text.toString();
}
use of org.apache.poi.hpsf.DocumentSummaryInformation in project poi by apache.
the class CryptoAPIEncryptor method getSummaryEntries.
/**
* Encrypt the Document-/SummaryInformation and other optionally streams.
* Opposed to other crypto modes, cryptoapi is record based and can't be used
* to stream-encrypt a whole file
*
* @see <a href="http://msdn.microsoft.com/en-us/library/dd943321(v=office.12).aspx">2.3.5.4 RC4 CryptoAPI Encrypted Summary Stream</a>
*/
public OutputStream getSummaryEntries(DirectoryNode dir) throws IOException, GeneralSecurityException {
// NOSONAR
CryptoAPIDocumentOutputStream bos = new CryptoAPIDocumentOutputStream(this);
byte[] buf = new byte[8];
// skip header
bos.write(buf, 0, 8);
String[] entryNames = { SummaryInformation.DEFAULT_STREAM_NAME, DocumentSummaryInformation.DEFAULT_STREAM_NAME };
List<StreamDescriptorEntry> descList = new ArrayList<StreamDescriptorEntry>();
int block = 0;
for (String entryName : entryNames) {
if (!dir.hasEntry(entryName)) {
continue;
}
StreamDescriptorEntry descEntry = new StreamDescriptorEntry();
descEntry.block = block;
descEntry.streamOffset = bos.size();
descEntry.streamName = entryName;
descEntry.flags = StreamDescriptorEntry.flagStream.setValue(0, 1);
descEntry.reserved2 = 0;
bos.setBlock(block);
DocumentInputStream dis = dir.createDocumentInputStream(entryName);
IOUtils.copy(dis, bos);
dis.close();
descEntry.streamSize = bos.size() - descEntry.streamOffset;
descList.add(descEntry);
dir.getEntry(entryName).delete();
block++;
}
int streamDescriptorArrayOffset = bos.size();
bos.setBlock(0);
LittleEndian.putUInt(buf, 0, descList.size());
bos.write(buf, 0, 4);
for (StreamDescriptorEntry sde : descList) {
LittleEndian.putUInt(buf, 0, sde.streamOffset);
bos.write(buf, 0, 4);
LittleEndian.putUInt(buf, 0, sde.streamSize);
bos.write(buf, 0, 4);
LittleEndian.putUShort(buf, 0, sde.block);
bos.write(buf, 0, 2);
LittleEndian.putUByte(buf, 0, (short) sde.streamName.length());
bos.write(buf, 0, 1);
LittleEndian.putUByte(buf, 0, (short) sde.flags);
bos.write(buf, 0, 1);
LittleEndian.putUInt(buf, 0, sde.reserved2);
bos.write(buf, 0, 4);
byte[] nameBytes = StringUtil.getToUnicodeLE(sde.streamName);
bos.write(nameBytes, 0, nameBytes.length);
// null-termination
LittleEndian.putShort(buf, 0, (short) 0);
bos.write(buf, 0, 2);
}
int savedSize = bos.size();
int streamDescriptorArraySize = savedSize - streamDescriptorArrayOffset;
LittleEndian.putUInt(buf, 0, streamDescriptorArrayOffset);
LittleEndian.putUInt(buf, 4, streamDescriptorArraySize);
bos.reset();
bos.setBlock(0);
bos.write(buf, 0, 8);
bos.setSize(savedSize);
dir.createDocument("EncryptedSummary", new ByteArrayInputStream(bos.getBuf(), 0, savedSize));
DocumentSummaryInformation dsi = PropertySetFactory.newDocumentSummaryInformation();
try {
dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
} catch (WritingNotSupportedException e) {
throw new IOException(e);
}
return bos;
}
use of org.apache.poi.hpsf.DocumentSummaryInformation in project poi by apache.
the class TestReadAllFiles method readDocumentSummaryInformation.
/**
* <p>This test method checks whether DocumentSummary information streams
* can be read. This is done by opening all "Test*" files in the 'poifs' directrory
* pointed to by the "POI.testdata.path" system property, trying to extract
* the document summary information stream in the root directory and calling
* its get... methods.</p>
* @throws Exception
*/
@Test
public void readDocumentSummaryInformation() throws Exception {
/* Read a test document <em>doc</em> into a POI filesystem. */
NPOIFSFileSystem poifs = new NPOIFSFileSystem(file, true);
try {
final DirectoryEntry dir = poifs.getRoot();
/*
* If there is a document summry information stream, read it from
* the POI filesystem.
*/
if (dir.hasEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)) {
final DocumentSummaryInformation dsi = TestWriteWellKnown.getDocumentSummaryInformation(poifs);
/* Execute the get... methods. */
dsi.getByteCount();
dsi.getByteOrder();
dsi.getCategory();
dsi.getCompany();
dsi.getCustomProperties();
// FIXME dsi.getDocparts();
// FIXME dsi.getHeadingPair();
dsi.getHiddenCount();
dsi.getLineCount();
dsi.getLinksDirty();
dsi.getManager();
dsi.getMMClipCount();
dsi.getNoteCount();
dsi.getParCount();
dsi.getPresentationFormat();
dsi.getScale();
dsi.getSlideCount();
}
} finally {
poifs.close();
}
}
Aggregations