org.apache.poi.hpsf.DocumentSummaryInformation Java Examples

The following examples show how to use org.apache.poi.hpsf.DocumentSummaryInformation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WordUtil.java    From javatech with Creative Commons Attribution Share Alike 4.0 International 7 votes vote down vote up
public static void setDocProperties(String filename) throws IOException {
    System.out.println("filename = [" + filename + "]");
    FileInputStream fis = new FileInputStream(new File(filename));
    HWPFDocument doc = new HWPFDocument(fis);

    SummaryInformation summaryInformation = doc.getSummaryInformation();
    summaryInformation.setAuthor("张鹏");
    summaryInformation.setLastAuthor("张鹏");
    DocumentSummaryInformation documentSummaryInformation = doc.getDocumentSummaryInformation();
    documentSummaryInformation.setCompany("张鹏");
    documentSummaryInformation.setDocumentVersion("1");

    FileOutputStream fos = new FileOutputStream(new File(filename));
    doc.write(fos);

    fos.close();
    doc.close();
    fis.close();
}
 
Example #2
Source File: HPSFPropertiesExtractor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example #3
Source File: POIDocument.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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() {
    if (initialized) {
        return;
    }
    DocumentSummaryInformation dsi = readPropertySet(DocumentSummaryInformation.class, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
    if (dsi != null) {
        dsInf = dsi;
    }
    SummaryInformation si = readPropertySet(SummaryInformation.class, SummaryInformation.DEFAULT_STREAM_NAME);
    if (si != null) {
        sInf = si;
    }

    // Mark the fact that we've now loaded up the properties
    initialized = true;
}
 
Example #4
Source File: ExportEventsImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void makeDocInfo ( final HSSFWorkbook workbook )
{
    workbook.createInformationProperties ();

    final DocumentSummaryInformation dsi = workbook.getDocumentSummaryInformation ();
    dsi.setCompany ( "Eclipse SCADA Project" );

    final CustomProperties cp = new CustomProperties ();
    cp.put ( "Eclipse SCADA Export Version", Activator.getDefault ().getBundle ().getVersion ().toString () );
    dsi.setCustomProperties ( cp );
}
 
Example #5
Source File: POIDocument.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fetch the Document Summary Information of the document
 * 
 * @return The Document Summary Information or null 
 *      if it could not be read for this document.
 */
public DocumentSummaryInformation getDocumentSummaryInformation() {
    if(!initialized) {
        readProperties();
    }
    return dsInf;
}
 
Example #6
Source File: HSSFWorkbook.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** Writes the workbook out to a brand new, empty POIFS */
private void write(NPOIFSFileSystem fs) throws IOException {
    // For tracking what we've written out, used if we're
    //  going to be preserving nodes
    List<String> excepts = new ArrayList<String>(1);

    // Write out the Workbook stream
    fs.createDocument(new ByteArrayInputStream(getBytes()), "Workbook");

    // Write out our HPFS properties, if we have them
    writeProperties(fs, excepts);
    
    if (preserveNodes) {
        // Don't write out the old Workbook, we'll be doing our new one
        // If the file had an "incorrect" name for the workbook stream,
        // don't write the old one as we'll use the correct name shortly
        excepts.addAll(Arrays.asList(WORKBOOK_DIR_ENTRY_NAMES));

        // summary information has been already written via writeProperties and might go in a
        // different stream, if the file is cryptoapi encrypted
        excepts.addAll(Arrays.asList(
            DocumentSummaryInformation.DEFAULT_STREAM_NAME,
            SummaryInformation.DEFAULT_STREAM_NAME,
            getEncryptedPropertyStreamName()
        ));

        // Copy over all the other nodes to our new poifs
        EntryUtils.copyNodes(
                new FilteringDirectoryNode(getDirectory(), excepts)
                , new FilteringDirectoryNode(fs.getRoot(), excepts)
                );

        // YK: preserve StorageClsid, it is important for embedded workbooks,
        // see Bugzilla 47920
        fs.getRoot().setStorageClsid(getDirectory().getStorageClsid());
    }
}
 
Example #7
Source File: POIDocument.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Writes out the standard Document Information Properties (HPSF)
 * @param outFS the NPOIFSFileSystem to write the properties into
 * @param writtenEntries a list of POIFS entries to add the property names too
 * 
 * @throws IOException if an error when writing to the 
 *      {@link NPOIFSFileSystem} occurs
 */
protected void writeProperties(NPOIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
    EncryptionInfo ei = getEncryptionInfo();
    final boolean encryptProps = (ei != null && ei.isDocPropsEncrypted());
    NPOIFSFileSystem fs = (encryptProps) ? new NPOIFSFileSystem() : outFS;
    
    SummaryInformation si = getSummaryInformation();
    if (si != null) {
        writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME, si, fs);
        if(writtenEntries != null) {
            writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME);
        }
    }
    DocumentSummaryInformation dsi = getDocumentSummaryInformation();
    if (dsi != null) {
        writePropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME, dsi, fs);
        if(writtenEntries != null) {
            writtenEntries.add(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
        }
    }

    if (!encryptProps) {
        return;
    }

    // create empty document summary
    dsi = PropertySetFactory.newDocumentSummaryInformation();
    writePropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME, dsi, outFS);
    // remove summary, if previously available
    if (outFS.getRoot().hasEntry(SummaryInformation.DEFAULT_STREAM_NAME)) {
        outFS.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
    }
    Encryptor encGen = ei.getEncryptor();
    if (!(encGen instanceof CryptoAPIEncryptor)) {
        throw new EncryptedDocumentException("Using "+ei.getEncryptionMode()+" encryption. Only CryptoAPI encryption supports encrypted property sets!");
    }
    CryptoAPIEncryptor enc = (CryptoAPIEncryptor)encGen;
    try {
        enc.setSummaryEntries(outFS.getRoot(), getEncryptedPropertyStreamName(), fs);
    } catch (GeneralSecurityException e) {
        throw new IOException(e);
    } finally {
        fs.close();
    }
}
 
Example #8
Source File: SpreadsheetAddInfo.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
public cfData execute( cfSession _session, List<cfData> parameters ) throws cfmRunTimeException {
	if ( parameters.get(0).getDataType() != cfData.CFSTRUCTDATA )
		throwException(_session, "parameter must be of type structure");
	
	cfSpreadSheetData	spreadsheet	= (cfSpreadSheetData)parameters.get(1);
	cfStructData	s	= (cfStructData)parameters.get(0);
	
	Workbook	workbook	= spreadsheet.getWorkBook();
	
	/*
	 * XSSFWorkbook
	 */
	if ( workbook instanceof XSSFWorkbook ){
		XSSFWorkbook xSSFWorkbook = (XSSFWorkbook)workbook;
		
		CoreProperties cP = xSSFWorkbook.getProperties().getCoreProperties();
		
		if ( s.containsKey("author") )
			cP.setCreator( s.getData("author").getString() );
		if ( s.containsKey("category") )
			cP.setCategory( s.getData("category").getString() );
		if ( s.containsKey("subject") )
			cP.setSubjectProperty( s.getData("subject").getString() );
		if ( s.containsKey("title") )
			cP.setTitle( s.getData("title").getString() );
		if ( s.containsKey("revision") )
			cP.setRevision( s.getData("revision").getString() );
		if ( s.containsKey("description") )
			cP.setDescription( s.getData("description").getString() );
		 		
	}else{
		HSSFWorkbook hSSFWorkbook = (HSSFWorkbook)workbook;
		DocumentSummaryInformation dSummary = hSSFWorkbook.getDocumentSummaryInformation();
		
		if ( dSummary == null ){
			hSSFWorkbook.createInformationProperties();
			dSummary = hSSFWorkbook.getDocumentSummaryInformation();
		}
		
		if ( s.containsKey("category") )
			dSummary.setCategory( s.getData("category").getString() );
		if ( s.containsKey("manager") )
			dSummary.setManager( s.getData("manager").getString() );
		if ( s.containsKey("company") )
			dSummary.setCompany( s.getData("company").getString() );

		SummaryInformation sInformation = hSSFWorkbook.getSummaryInformation();
		
		if ( s.containsKey("title") )
			sInformation.setTitle( s.getData("title").getString() );
		if ( s.containsKey("subject") )
			sInformation.setSubject( s.getData("subject").getString() );
		if ( s.containsKey("author") )
			sInformation.setAuthor( s.getData("author").getString() );
		if ( s.containsKey("comments") )
			sInformation.setComments( s.getData("comments").getString() );
		if ( s.containsKey("keywords") )
			sInformation.setKeywords( s.getData("keywords").getString() );
		if ( s.containsKey("lastauthor") )
			sInformation.setLastAuthor( s.getData("lastauthor").getString() );
	}
	
	return cfBooleanData.TRUE;
}
 
Example #9
Source File: EventBasedExcelExtractor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Would return the document information metadata for the document,
 *  if we supported it
 */
public DocumentSummaryInformation getDocSummaryInformation() {
    throw new IllegalStateException("Metadata extraction not supported in streaming mode, please use ExcelExtractor");
}
 
Example #10
Source File: POIOLE2TextExtractor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the document information metadata for the document
 *
    * @return The Document Summary Information or null
    *      if it could not be read for this document.
 */
public DocumentSummaryInformation getDocSummaryInformation() {
	return document.getDocumentSummaryInformation();
}