List of usage examples for org.apache.poi.hpsf PropertySet PropertySet
public PropertySet(PropertySet ps)
From source file:com.oneis.graphics.ThumbnailFinder.java
License:Mozilla Public License
/** * Try and get a thumbnail from an old Microsoft Office document *///from w ww.j a v a 2 s . c o m private void findFromOldMSOffice() { try { File poiFilesystem = new File(inFilename); // Open the POI filesystem. InputStream is = new FileInputStream(poiFilesystem); POIFSFileSystem poifs = new POIFSFileSystem(is); is.close(); // Read the summary information. DirectoryEntry dir = poifs.getRoot(); DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(siEntry); PropertySet ps = new PropertySet(dis); dis.close(); SummaryInformation si = new SummaryInformation(ps); if (si != null) { byte[] thumbnailData = si.getThumbnail(); if (thumbnailData != null) { Thumbnail thumbnail = new Thumbnail(thumbnailData); byte[] wmf = thumbnail.getThumbnailAsWMF(); // Got something! thumbnailDimensions = tryWMFFormat(new ByteArrayInputStream(wmf), outFilename, outFormat, maxDimension); } } } catch (Exception e) { logIgnoredException("ThumbnailFinder Apache POI file reading failed", e); } }
From source file:com.pnf.plugin.ole.parser.StreamReader.java
License:Apache License
private List<INode> readSummaryInfoStream(ByteBuffer stream) { List<INode> roots = new LinkedList<>(); String propType = "Property"; try {/*from w ww . ja v a 2 s . c om*/ SummaryInformation sInfo = new SummaryInformation(new PropertySet(stream.array())); StreamEntry cInfo = new StreamEntry("Creation Information"); cInfo.addChild(new StreamEntry("Application Name", propType, sInfo.getApplicationName())); cInfo.addChild(new StreamEntry("Creation", "Time", sInfo.getCreateDateTime() != null ? sInfo.getCreateDateTime().toString() : null)); cInfo.addChild(new StreamEntry("Author", propType, sInfo.getAuthor())); cInfo.addChild(new StreamEntry("Last Author", propType, sInfo.getLastAuthor())); cInfo.addChild(new StreamEntry("Template", propType, sInfo.getTemplate())); roots.add(cInfo); propType = "Time"; StreamEntry timeInfo = new StreamEntry("Times"); timeInfo.addChild(new StreamEntry("Total Edit Time", propType, String.valueOf(sInfo.getEditTime()))); timeInfo.addChild(new StreamEntry("Last Saved", propType, sInfo.getLastSaveDateTime() != null ? sInfo.getLastSaveDateTime().toString() : null)); timeInfo.addChild(new StreamEntry("Last Printed", propType, sInfo.getLastPrinted() != null ? sInfo.getLastPrinted().toString() : null)); roots.add(timeInfo); propType = "Misc"; StreamEntry misc = new StreamEntry("Miscellaneous"); misc.addChild(new StreamEntry("OS Version", "int", String.valueOf(sInfo.getOSVersion()))); misc.addChild(new StreamEntry("Revision Number", "int", sInfo.getRevNumber())); misc.addChild(new StreamEntry("Page Count", "int", String.valueOf(sInfo.getPageCount()))); misc.addChild(new StreamEntry("Word Count", "int", String.valueOf(sInfo.getWordCount()))); int secVal = sInfo.getSecurity(); String security = null; if (!sInfo.wasNull()) { // Set description according to POI documentation switch (secVal) { case 0: security = "No security"; break; case 1: security = "Password protected"; break; case 2: security = "Read-only recommended"; break; case 4: security = "Read-only enforced"; break; case 8: security = "Locked for annotations"; break; default: break; } security += " (code " + secVal + ")"; } else { security = "Field not set"; } misc.addChild(new StreamEntry("Document Security", "int", security)); misc.addChild(new StreamEntry("Subject", propType, sInfo.getSubject())); misc.addChild(new StreamEntry("Keywords", propType, sInfo.getKeywords())); roots.add(misc); } catch (Throwable t) { addMessage("Attempted to read " + SUMM_INFO + " stream but no property sets were found.", null, Message.CORRUPT); } return roots; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ConfigureXLS.java
License:Open Source License
/** * @param poifs/*from w w w. j a v a 2 s. c om*/ * @returns the DocumentSummaryInformation for poifs, or null if no DocumentSummaryInformation is found. */ protected DocumentSummaryInformation getDocSummary(final POIFSFileSystem poifs) { DirectoryEntry dir = poifs.getRoot(); DocumentSummaryInformation result = null; try { DocumentEntry dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(dsiEntry); PropertySet ps = new PropertySet(dis); dis.close(); result = new DocumentSummaryInformation(ps); } catch (FileNotFoundException ex) { // There is no document summary information. result = null; } /* * just returning null if anything weird happens. If there is a problem with the xls file, * something else will probably blow up later. */ catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex); log.debug(ex); result = null; } catch (NoPropertySetStreamException ex) { //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex); log.debug(ex); result = null; } catch (MarkUnsupportedException ex) { //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex); log.debug(ex); result = null; } catch (UnexpectedPropertySetTypeException ex) { //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex); log.debug(ex); result = null; } catch (IllegalPropertySetDataException ex) { //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex); log.debug(ex); result = null; } return result; }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static String getSummaryData(String filename, String key) { String value = null;/*from www . j a v a2 s.c o m*/ FileInputStream stream = null; try { stream = new FileInputStream(new File(filename)); POIFSFileSystem poifs = null; try { poifs = new POIFSFileSystem(stream); } catch (Exception e) { stream.close(); return getPOISummaryData(filename, key); } DirectoryEntry dir = poifs.getRoot(); DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); if (siEntry != null) { DocumentInputStream dis = new DocumentInputStream(siEntry); PropertySet ps = new PropertySet(dis); SummaryInformation si = new SummaryInformation(ps); if (key.compareTo(SUMMARY_DATA_AUTHOR) == 0) { value = si.getAuthor(); } else if (key.compareTo(SUMMARY_DATA_KEYWORDS) == 0) { value = si.getKeywords(); } else if (key.compareTo(SUMMARY_DATA_TITLE) == 0) { value = si.getTitle(); } else if (key.compareTo(SUMMARY_DATA_SUBJECT) == 0) { value = si.getSubject(); } } } catch (Exception ex) { ex.getStackTrace(); } finally { try { stream.close(); } catch (Exception ex) { ex.printStackTrace(); } } return value; }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static String getAuthor(File file) { String author = null;//from w w w . j a v a 2 s .c o m try { FileInputStream stream = new FileInputStream(file); POIFSFileSystem poifs = null; try { poifs = new POIFSFileSystem(stream); } catch (Exception e) { stream.close(); return getCreator(file); } DirectoryEntry dir = null; try { dir = poifs.getRoot(); } catch (Exception ex) { System.out.println("DirectoryEntry is NULL???"); return null; } DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); if (siEntry != null) { DocumentInputStream dis = new DocumentInputStream(siEntry); PropertySet ps = new PropertySet(dis); SummaryInformation si = new SummaryInformation(ps); author = si.getAuthor(); } stream.close(); } catch (Exception ex) { ex.getStackTrace(); } return author; }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static void setAuthor(String filename, String author) { try {/*from www .j a va 2 s. c o m*/ FileInputStream stream = new FileInputStream(new File(filename)); POIFSFileSystem poifs = new POIFSFileSystem(stream); DirectoryEntry dir = poifs.getRoot(); System.out.println("SummaryInformation.DEFAULT_STREAM_NAME: " + SummaryInformation.DEFAULT_STREAM_NAME); DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(siEntry); PropertySet ps = new PropertySet(dis); SummaryInformation si = new SummaryInformation(ps); System.out.println("SummaryInformation setAuthor: " + author); si.setAuthor(author); OutputStream outStream = null; outStream = new FileOutputStream(new File(filename)); byte[] buffer = new byte[1024]; int length; while ((length = stream.read(buffer)) > 0) { outStream.write(buffer, 0, length); } outStream.close(); stream.close(); } catch (Exception ex) { ex.getStackTrace(); } }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static void setAuthor(File file, String author) { try {//from w ww . j a v a 2s . c o m FileInputStream stream = new FileInputStream(file); POIFSFileSystem poifs = null; try { poifs = new POIFSFileSystem(stream); } catch (Exception e) { stream.close(); setCreator(file, author); return; } DirectoryEntry dir = poifs.getRoot(); DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); if (siEntry != null) { DocumentInputStream dis = new DocumentInputStream(siEntry); PropertySet ps = new PropertySet(dis); SummaryInformation si = new SummaryInformation(ps); si.setAuthor(author); } stream.close(); } catch (Exception ex) { ex.getStackTrace(); } }
From source file:mj.ocraptor.extraction.tika.parser.microsoft.SummaryExtractor.java
License:Apache License
private void parseSummaryEntryIfExists(DirectoryNode root, String entryName) throws IOException, TikaException { try {/* w w w.j a va 2 s .co m*/ DocumentEntry entry = (DocumentEntry) root.getEntry(entryName); PropertySet properties = new PropertySet(new DocumentInputStream(entry)); if (properties.isSummaryInformation()) { parse(new SummaryInformation(properties)); } if (properties.isDocumentSummaryInformation()) { parse(new DocumentSummaryInformation(properties)); } } catch (FileNotFoundException e) { // entry does not exist, just skip it } catch (NoPropertySetStreamException e) { // no property stream, just skip it } catch (UnexpectedPropertySetTypeException e) { throw new TikaException("Unexpected HPSF document", e); } catch (MarkUnsupportedException e) { throw new TikaException("Invalid DocumentInputStream", e); } catch (Exception e) { LOGGER.warn("Ignoring unexpected exception while parsing summary entry " + entryName, e); } }
From source file:net.sf.mpxj.mpp.ProjectPropertiesReader.java
License:Open Source License
/** * The main entry point for processing project properties. * /*from www. ja va2s . c o m*/ * @param file parent project file * @param props properties data * @param rootDir Root of the POI file system. */ public void process(ProjectFile file, Props props, DirectoryEntry rootDir) throws MPXJException { try { //MPPUtility.fileDump("c:\\temp\\props.txt", props.toString().getBytes()); ProjectProperties ph = file.getProjectProperties(); ph.setStartDate(props.getTimestamp(Props.PROJECT_START_DATE)); ph.setFinishDate(props.getTimestamp(Props.PROJECT_FINISH_DATE)); ph.setScheduleFrom(ScheduleFrom.getInstance(1 - props.getShort(Props.SCHEDULE_FROM))); ph.setDefaultCalendarName(props.getUnicodeString(Props.DEFAULT_CALENDAR_NAME)); ph.setDefaultStartTime(props.getTime(Props.START_TIME)); ph.setDefaultEndTime(props.getTime(Props.END_TIME)); ph.setStatusDate(props.getTimestamp(Props.STATUS_DATE)); ph.setHyperlinkBase(props.getUnicodeString(Props.HYPERLINK_BASE)); //ph.setDefaultDurationIsFixed(); ph.setDefaultDurationUnits(MPPUtility.getDurationTimeUnits(props.getShort(Props.DURATION_UNITS))); ph.setMinutesPerDay(Integer.valueOf(props.getInt(Props.MINUTES_PER_DAY))); ph.setMinutesPerWeek(Integer.valueOf(props.getInt(Props.MINUTES_PER_WEEK))); ph.setDefaultOvertimeRate(new Rate(props.getDouble(Props.OVERTIME_RATE), TimeUnit.HOURS)); ph.setDefaultStandardRate(new Rate(props.getDouble(Props.STANDARD_RATE), TimeUnit.HOURS)); ph.setDefaultWorkUnits(MPPUtility.getWorkTimeUnits(props.getShort(Props.WORK_UNITS))); ph.setSplitInProgressTasks(props.getBoolean(Props.SPLIT_TASKS)); ph.setUpdatingTaskStatusUpdatesResourceStatus(props.getBoolean(Props.TASK_UPDATES_RESOURCE)); ph.setCurrencyDigits(Integer.valueOf(props.getShort(Props.CURRENCY_DIGITS))); ph.setCurrencySymbol(props.getUnicodeString(Props.CURRENCY_SYMBOL)); ph.setCurrencyCode(props.getUnicodeString(Props.CURRENCY_CODE)); //ph.setDecimalSeparator(); ph.setSymbolPosition(MPPUtility.getSymbolPosition(props.getShort(Props.CURRENCY_PLACEMENT))); //ph.setThousandsSeparator(); ph.setWeekStartDay(Day.getInstance(props.getShort(Props.WEEK_START_DAY) + 1)); ph.setFiscalYearStartMonth(Integer.valueOf(props.getShort(Props.FISCAL_YEAR_START_MONTH))); ph.setFiscalYearStart(props.getShort(Props.FISCAL_YEAR_START) == 1); ph.setDaysPerMonth(Integer.valueOf(props.getShort(Props.DAYS_PER_MONTH))); ph.setEditableActualCosts(props.getBoolean(Props.EDITABLE_ACTUAL_COSTS)); ph.setHonorConstraints(!props.getBoolean(Props.HONOR_CONSTRAINTS)); PropertySet ps = new PropertySet(new DocumentInputStream( ((DocumentEntry) rootDir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)))); SummaryInformation summaryInformation = new SummaryInformation(ps); ph.setProjectTitle(summaryInformation.getTitle()); ph.setSubject(summaryInformation.getSubject()); ph.setAuthor(summaryInformation.getAuthor()); ph.setKeywords(summaryInformation.getKeywords()); ph.setComments(summaryInformation.getComments()); ph.setTemplate(summaryInformation.getTemplate()); ph.setLastAuthor(summaryInformation.getLastAuthor()); ph.setRevision(NumberHelper.parseInteger(summaryInformation.getRevNumber())); ph.setCreationDate(summaryInformation.getCreateDateTime()); ph.setLastSaved(summaryInformation.getLastSaveDateTime()); ph.setShortApplicationName(summaryInformation.getApplicationName()); ph.setEditingTime(Integer.valueOf((int) summaryInformation.getEditTime())); ph.setLastPrinted(summaryInformation.getLastPrinted()); ps = new PropertySet(new DocumentInputStream( ((DocumentEntry) rootDir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)))); ExtendedDocumentSummaryInformation documentSummaryInformation = new ExtendedDocumentSummaryInformation( ps); ph.setCategory(documentSummaryInformation.getCategory()); ph.setPresentationFormat(documentSummaryInformation.getPresentationFormat()); ph.setManager(documentSummaryInformation.getManager()); ph.setCompany(documentSummaryInformation.getCompany()); ph.setContentType(documentSummaryInformation.getContentType()); ph.setContentStatus(documentSummaryInformation.getContentStatus()); ph.setLanguage(documentSummaryInformation.getLanguage()); ph.setDocumentVersion(documentSummaryInformation.getDocumentVersion()); Map<String, Object> customPropertiesMap = new HashMap<String, Object>(); CustomProperties customProperties = documentSummaryInformation.getCustomProperties(); if (customProperties != null) { for (CustomProperty property : customProperties.values()) { customPropertiesMap.put(property.getName(), property.getValue()); } } ph.setCustomProperties(customPropertiesMap); ph.setCalculateMultipleCriticalPaths(props.getBoolean(Props.CALCULATE_MULTIPLE_CRITICAL_PATHS)); ph.setBaselineDate(props.getTimestamp(Props.BASELINE_DATE)); ph.setBaselineDate(1, props.getTimestamp(Props.BASELINE1_DATE)); ph.setBaselineDate(2, props.getTimestamp(Props.BASELINE2_DATE)); ph.setBaselineDate(3, props.getTimestamp(Props.BASELINE3_DATE)); ph.setBaselineDate(4, props.getTimestamp(Props.BASELINE4_DATE)); ph.setBaselineDate(5, props.getTimestamp(Props.BASELINE5_DATE)); ph.setBaselineDate(6, props.getTimestamp(Props.BASELINE6_DATE)); ph.setBaselineDate(7, props.getTimestamp(Props.BASELINE7_DATE)); ph.setBaselineDate(8, props.getTimestamp(Props.BASELINE8_DATE)); ph.setBaselineDate(9, props.getTimestamp(Props.BASELINE9_DATE)); ph.setBaselineDate(10, props.getTimestamp(Props.BASELINE10_DATE)); } catch (Exception ex) { throw new MPXJException(MPXJException.READ_ERROR, ex); } }
From source file:net.sf.mpxj.mpp.SummaryInformation.java
License:Open Source License
/** * Constructor./* ww w . j a v a 2s . c o m*/ * * @param rootDir root of the POI file system * @throws MPXJException */ public SummaryInformation(DirectoryEntry rootDir) throws MPXJException { try { PropertySet ps = new PropertySet( new DocumentInputStream(((DocumentEntry) rootDir.getEntry("\005SummaryInformation")))); HashMap<Integer, Object> map = getPropertyMap(ps); m_projectTitle = (String) map.get(PROJECT_TITLE); m_subject = (String) map.get(SUBJECT); m_author = (String) map.get(AUTHOR); m_keywords = (String) map.get(KEYWORDS); m_comments = (String) map.get(COMMENTS); m_revision = NumberUtility.parseInteger((String) map.get(REVISION_NUMBER)); m_creationDate = (Date) map.get(CREATION_DATE); m_lastSaved = (Date) map.get(LAST_SAVED); ps = new PropertySet( new DocumentInputStream(((DocumentEntry) rootDir.getEntry("\005DocumentSummaryInformation")))); map = getPropertyMap(ps); m_category = (String) map.get(CATEGORY); m_company = (String) map.get(COMPANY); m_manager = (String) map.get(MANAGER); m_documentSummaryInformation = map; } catch (Exception ex) { throw new MPXJException(MPXJException.READ_ERROR, ex); } }