...
The parser is invoked using a W3CWidgetFactory object. This has a number of configuration properties that can be set, and these are described at the bottom of this page. While most of these are optional, to use the factory to parse .wgt files you MUST supply a valid output directory into which the Factory will unpack the widget.
For example, a simple program to unpack a .wgt file, and write the name of the widget to the console looks like this:
Code Block | ||||
---|---|---|---|---|
| ||||
public static void main(String[] args) { File out = new File("out"); File zipFile = new File("in/butterfly.wgt"); W3CWidgetFactory fac = new W3CWidgetFactory(); fac.setOutputDirectory(out.getAbsolutePath()); fac.setLocalPath("/out"); try { W3CWidget widget = fac.parse(zipFile); System.out.println(widget.getLocalName("en")); } catch (BadWidgetZipFileException e) { e.printStackTrace(); } catch (BadManifestException e) { e.printStackTrace(); } } |
Localized elements
Many of the elements of a W3CWidget object are localized; these elements all implement the ILocalizedElement interface. These elements can be processed using the LocalizationUtils class, which has methods to process these elements based on lists of preferred locales. E.g., to extract the single most preferred Name element for the "fr" locale:
Code Block |
---|
INameEntity[] names = widget.getNames().toArray(new INameEntity[fNamesList.size()]);
String[] locales = new String[]{"fr"};
INameEntity name = (INameEntity)LocalizationUtils.getLocalizedElement(names, locales);
|
LocalizationUtils uses icu4j to process elements using appropriate fallback strategies based on language variants and extensionsTo 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 reference
...