FileDocCategorySizeDatePackage
WriteAuthorAndTitle.javaAPI DocApache Poi 3.0.118039Mon Jan 01 12:39:42 GMT 2007org.apache.poi.hpsf.examples

WriteAuthorAndTitle

public class WriteAuthorAndTitle extends Object

This class is a sample application which shows how to write or modify the author and title property of an OLE 2 document. This could be done in two different ways:

  • The first approach is to open the OLE 2 file as a POI filesystem (see class {@link POIFSFileSystem}), read the summary information property set (see classes {@link SummaryInformation} and {@link PropertySet}), write the author and title properties into it and write the property set back into the POI filesystem.

  • The second approach does not modify the original POI filesystem, but instead creates a new one. All documents from the original POIFS are copied to the destination POIFS, except for the summary information stream. The latter is modified by setting the author and title property before writing it to the destination POIFS. It there are several summary information streams in the original POIFS - e.g. in subordinate directories - they are modified just the same.

This sample application takes the second approach. It expects the name of the existing POI filesystem's name as its first command-line parameter and the name of the output POIFS as the second command-line argument. The program then works as described above: It copies nearly all documents unmodified from the input POI filesystem to the output POI filesystem. If it encounters a summary information stream it reads its properties. Then it sets the "author" and "title" properties to new values and writes the modified summary information stream into the output file.

Further explanations can be found in the HPSF HOW-TO.

author
Rainer Klute <klute@rainer-klute.de>
version
$Id: WriteAuthorAndTitle.java 489730 2006-12-22 19:18:16Z bayard $
since
2003-09-01

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

Runs the example program.

param
args Command-line arguments. The first command-line argument must be the name of a POI filesystem to read.
throws
IOException if any I/O exception occurs.

        /* Check whether we have exactly two command-line arguments. */
        if (args.length != 2)
        {
            System.err.println("Usage: " + WriteAuthorAndTitle.class.getName() +
                               " originPOIFS destinationPOIFS");
            System.exit(1);
        }
        
        /* Read the names of the origin and destination POI filesystems. */
        final String srcName = args[0];
        final String dstName = args[1];

        /* Read the origin POIFS using the eventing API. The real work is done
         * in the class ModifySICopyTheRest which is registered here as a
         * POIFSReader. */
        final POIFSReader r = new POIFSReader();
        final ModifySICopyTheRest msrl = new ModifySICopyTheRest(dstName);
        r.registerListener(msrl);
        r.read(new FileInputStream(srcName));
        
        /* Write the new POIFS to disk. */
        msrl.close();