org.apache.wookie.w3c
Class W3CWidgetFactory

java.lang.Object
  extended by org.apache.wookie.w3c.W3CWidgetFactory

public class W3CWidgetFactory
extends java.lang.Object

Factory for parsing W3C Widget packages (.wgt files).

To use the factory you MUST supply a valid output directory into which the Factory will unpack the widget. Other factory properties are optional.

Factory properties:

outputDirectory
The directory where the widget will be saved. The factory will expand the widget archive into this directory, using the widget's identifier to generate a directory name and structure in which to place it
startPageProcessor
An implementation of the IStartPageProcessor interface. Setting this property allows you to inject a class that can pre-process start pages for the widget; for example to inject javascript, tidy up HTML, insert template code etc. If this is not set, no pre-processing is done by the factory.
locales
The supported locales (as BCP47 language-tags) to be processed for the widget. This determines which start files, icons, and other localized elements will be processed and expanded. This is set to "en" by default
encodings
The supported encodings to be processed for the widget. This determines which custom encodings will be allowed for start files. This is set to UTF-8 by default.
localPath
The base URL from which unpacked widgets will be served, e.g. "/myapp/widgets". The URLs of start files will be appended to this base URL to create the widget URL. The default value of this property is "/widgets"
features
The features supported by the implementation; this should be supplied as IRIs e.g. "http://wave.google.com". The features are matched against features requested by the widget; if the widget requires features that are unsupported, an Exception will be thrown when parsing the widget package. The default value of this property is an empty String array.


Constructor Summary
W3CWidgetFactory()
           
 
Method Summary
 java.io.File getUnzippedWidgetDirectory()
           
 W3CWidget parse(java.io.File zipFile)
          Parse a given ZipFile and return a W3CWidget object representing the processed information in the package.
 W3CWidget parse(java.io.File zipFile, java.lang.String defaultIdentifier)
          Parse a given ZipFile and return a W3CWidget object representing the processed information in the package.
 W3CWidget parse(java.net.URL url)
          Parse a widget at a given URL and return a W3CWidget object representing the processed information in the package.
 W3CWidget parse(java.net.URL url, boolean ignoreContentType)
          Parse a widget at a given URL and return a W3CWidget object representing the processed information in the package.
 W3CWidget parse(java.net.URL url, boolean ignoreContentType, java.lang.String defaultIdentifier)
          Parse a widget at a given URL and return a W3CWidget object representing the processed information in the package.
 void setEncodings(java.lang.String[] encodings)
           
 void setFeatures(java.lang.String[] features)
          Set the features to be included when parsing widgets
 void setLocales(java.lang.String[] locales)
          Set the supported locales to be used when parsing widgets
 void setLocalPath(java.lang.String localPath)
          Set the base URL to use
 void setOutputDirectory(java.lang.String outputDirectory)
          Set the directory to use to save widgets.
 void setStartPageProcessor(IStartPageProcessor startPageProcessor)
          Set the start page processor to use when parsing widgets
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

W3CWidgetFactory

public W3CWidgetFactory()
Method Detail

setFeatures

public void setFeatures(java.lang.String[] features)
Set the features to be included when parsing widgets

Parameters:
features -

setOutputDirectory

public void setOutputDirectory(java.lang.String outputDirectory)
                        throws java.io.IOException
Set the directory to use to save widgets.

Parameters:
outputDirectory -
Throws:
java.io.IOException - if the directory does not exist

setStartPageProcessor

public void setStartPageProcessor(IStartPageProcessor startPageProcessor)
Set the start page processor to use when parsing widgets

Parameters:
startPageProcessor -

setLocales

public void setLocales(java.lang.String[] locales)
Set the supported locales to be used when parsing widgets

Parameters:
locales -

setLocalPath

public void setLocalPath(java.lang.String localPath)
Set the base URL to use

Parameters:
localPath -
Throws:
java.lang.Exception

parse

public W3CWidget parse(java.io.File zipFile)
                throws java.lang.Exception,
                       BadWidgetZipFileException,
                       BadManifestException
Parse a given ZipFile and return a W3CWidget object representing the processed information in the package. The widget will be saved in the outputFolder.

Parameters:
zipFile -
Returns:
the widget model
Throws:
BadWidgetZipFileException - if there is a problem with the zip package
BadManifestException - if there is a problem with the config.xml manifest file in the package
java.lang.Exception

parse

public W3CWidget parse(java.io.File zipFile,
                       java.lang.String defaultIdentifier)
                throws java.lang.Exception,
                       BadWidgetZipFileException,
                       BadManifestException
Parse a given ZipFile and return a W3CWidget object representing the processed information in the package. The widget will be saved in the outputFolder.

Parameters:
zipFile -
defaultIdentifier - a default identifier to use if the widget package does not have an identifier
Returns:
the widget model
Throws:
BadWidgetZipFileException - if there is a problem with the zip package
BadManifestException - if there is a problem with the config.xml manifest file in the package
java.lang.Exception

parse

public W3CWidget parse(java.net.URL url)
                throws BadWidgetZipFileException,
                       BadManifestException,
                       InvalidContentTypeException,
                       java.io.IOException,
                       java.lang.Exception
Parse a widget at a given URL and return a W3CWidget object representing the processed information in the package. The widget will be saved in the outputFolder.

Parameters:
url -
Returns:
the widget model
Throws:
BadWidgetZipFileException - if there is a problem with the zip package
BadManifestException - if there is a problem with the config.xml manifest file in the package
InvalidContentTypeException - if the widget has an invalid content type
java.io.IOException - if the widget cannot be downloaded
java.lang.Exception

parse

public W3CWidget parse(java.net.URL url,
                       boolean ignoreContentType)
                throws BadWidgetZipFileException,
                       BadManifestException,
                       InvalidContentTypeException,
                       java.io.IOException,
                       java.lang.Exception
Parse a widget at a given URL and return a W3CWidget object representing the processed information in the package. The widget will be saved in the outputFolder.

Parameters:
url -
ignoreContentType - set to true to instruct the parser to ignore invalid content type exceptions
Returns:
the widget model
Throws:
BadWidgetZipFileException - if there is a problem with the zip package
BadManifestException - if there is a problem with the config.xml manifest file in the package
InvalidContentTypeException - if the widget has an invalid content type
java.io.IOException - if the widget cannot be downloaded
java.lang.Exception

parse

public W3CWidget parse(java.net.URL url,
                       boolean ignoreContentType,
                       java.lang.String defaultIdentifier)
                throws BadWidgetZipFileException,
                       BadManifestException,
                       InvalidContentTypeException,
                       java.io.IOException,
                       java.lang.Exception
Parse a widget at a given URL and return a W3CWidget object representing the processed information in the package. The widget will be saved in the outputFolder.

Parameters:
url -
ignoreContentType - set to true to instruct the parser to ignore invalid content type exceptions
defaultIdentifier - an identifier to use if the downloaded widget has no identifier - for example when updating a widget
Returns:
the widget model
Throws:
BadWidgetZipFileException - if there is a problem with the zip package
BadManifestException - if there is a problem with the config.xml manifest file in the package
InvalidContentTypeException - if the widget has an invalid content type
java.io.IOException - if the widget cannot be downloaded
java.lang.Exception

setEncodings

public void setEncodings(java.lang.String[] encodings)
                  throws java.lang.Exception
Throws:
java.lang.Exception

getUnzippedWidgetDirectory

public java.io.File getUnzippedWidgetDirectory()


2012 Apache Software Foundation.