com.powerml
Class PresentationParser

java.lang.Object
  extended bycom.powerml.PresentationParser

public class PresentationParser
extends java.lang.Object

Instances of this class are used to parse Microsoft PowerPoint presentations. The parsed information can be accessed in several ways. Use the various to...() methods for this.

Example: parse the file presentation.ppt and output parsed data as formatted XML to the console:

PresentationParser parser = new PresentationParser(new FileInputStream("presentation.ppt"));
parser.toFormattedXml(System.out);


Constructor Summary
PresentationParser(java.io.InputStream inputStream)
          Creates a new PresentationParser instance.
 
Method Summary
 Presentation getPresentation()
          Returns the parsed presentation.
 void setPurgeStrings(boolean purgeStrings)
          By default, before generating XML from parsed data, the contained text is cleaned of control characters which would render the resulting XML document invalid.
 void setRoundPrecision(int roundPrecision)
           Sets the rounding precision for floating point values in XML.
 void setSchemaLocation(java.lang.String schemaLocation)
           This method allows to specify the PowerML schema location.
 void toCompressedXml(java.io.OutputStream outputStream)
          This method transforms the parsed presentation data to ZLIB compressed XML and writes it to a stream.
 org.dom4j.Document toDom4JDocument()
          Transforms the parsed presentation data to a dom4j document (see the dom4j site for further details).
 void toFormattedXml(java.io.OutputStream outputStream)
          Transforms the parsed presentation data to formatted XML.
 org.w3c.dom.Document toW3CDocument()
          Transforms the parsed presentation data to a W3C XML document.
 void toXml(java.io.OutputStream outputStream)
          Transforms the parsed presentation data to (unformatted) XML which is written to an output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PresentationParser

public PresentationParser(java.io.InputStream inputStream)
Creates a new PresentationParser instance. The actual file parsing is started when invoking one of the to...() methods.

Parameters:
inputStream - stream containing a PowerPoint file
Method Detail

getPresentation

public Presentation getPresentation()
                             throws java.io.IOException,
                                    InvalidFormatException
Returns the parsed presentation.

Returns:
parsed presentation
Throws:
java.io.IOException - if an I/O error occured
InvalidFormatException - if the PowerPoint file is not valid

setPurgeStrings

public void setPurgeStrings(boolean purgeStrings)
By default, before generating XML from parsed data, the contained text is cleaned of control characters which would render the resulting XML document invalid. This method can change this behaviour, in order to retain control characters and parse the resulting XML document with a custom parser.

Parameters:
purgeStrings - specifies whether to clean strings of control characters or not

setRoundPrecision

public void setRoundPrecision(int roundPrecision)

Sets the rounding precision for floating point values in XML. Specify the number of digits after the decimal point. Invoke this method before one of the to...() methods. Note that trailing zeros are truncated, e.g. 1.8796 rounded with a precision of 3 is 1.88 and not 1.880.

The default is 6.

Parameters:
roundPrecision - rounding precision for FP numbers

setSchemaLocation

public void setSchemaLocation(java.lang.String schemaLocation)

This method allows to specify the PowerML schema location. This can be useful in case you want to validate the generated XML against a local copy of the PowerML schema for increased performance.

If you specify a null schema location, the generated XML lacks any reference to the PowerML schema. If this method is omitted, the XML will contain a reference to http://www.powerml.com/schema/powerml.xsd.

Parameters:
schemaLocation - location of the schema file

toCompressedXml

public void toCompressedXml(java.io.OutputStream outputStream)
                     throws java.io.IOException,
                            InvalidFormatException
This method transforms the parsed presentation data to ZLIB compressed XML and writes it to a stream. Use java.util.zip.InflaterInputStream for decompression.

Parameters:
outputStream - target output stream
Throws:
java.io.IOException - if an I/O error occured
InvalidFormatException - if the PowerPoint file is not valid

toDom4JDocument

public org.dom4j.Document toDom4JDocument()
                                   throws java.io.IOException,
                                          InvalidFormatException
Transforms the parsed presentation data to a dom4j document (see the dom4j site for further details).

Returns:
dom4j document containing presentation data
Throws:
java.io.IOException - if an I/O error occured
InvalidFormatException - if the PowerPoint file is not valid

toFormattedXml

public void toFormattedXml(java.io.OutputStream outputStream)
                    throws java.io.IOException,
                           InvalidFormatException
Transforms the parsed presentation data to formatted XML. Line breaks are preserved.

Parameters:
outputStream - the target output stream
Throws:
java.io.IOException - if an I/O error occured
InvalidFormatException - if the PowerPoint file is not valid

toW3CDocument

public org.w3c.dom.Document toW3CDocument()
                                   throws java.io.IOException,
                                          InvalidFormatException,
                                          org.dom4j.DocumentException
Transforms the parsed presentation data to a W3C XML document.

Returns:
W3C document containing parsed data
Throws:
java.io.IOException - if an I/O error occured
InvalidFormatException - if the PowerPoint file is not valid
org.dom4j.DocumentException - if conversion to W3C document failed

toXml

public void toXml(java.io.OutputStream outputStream)
           throws java.io.IOException,
                  InvalidFormatException
Transforms the parsed presentation data to (unformatted) XML which is written to an output stream. Line breaks are preserved.

Parameters:
outputStream - target output stream
Throws:
java.io.IOException - if an I/O error occured
InvalidFormatException - if the PowerPoint file is not valid


© 2004-2005 Ralf Terdic. All rights reserved.
www.powerml.com