You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2011/10/03 15:05:48 UTC

svn commit: r1178402 - /incubator/wookie/site/trunk/content/wookie/docs/developer/parser.mdtext

Author: scottbw
Date: Mon Oct  3 13:05:48 2011
New Revision: 1178402

URL: http://svn.apache.org/viewvc?rev=1178402&view=rev
Log:
Updated doc with maven info, more examples, and some fixes to sample code

Modified:
    incubator/wookie/site/trunk/content/wookie/docs/developer/parser.mdtext

Modified: incubator/wookie/site/trunk/content/wookie/docs/developer/parser.mdtext
URL: http://svn.apache.org/viewvc/incubator/wookie/site/trunk/content/wookie/docs/developer/parser.mdtext?rev=1178402&r1=1178401&r2=1178402&view=diff
==============================================================================
--- incubator/wookie/site/trunk/content/wookie/docs/developer/parser.mdtext (original)
+++ incubator/wookie/site/trunk/content/wookie/docs/developer/parser.mdtext Mon Oct  3 13:05:48 2011
@@ -18,6 +18,18 @@ Notice:    Licensed to the Apache Softwa
 
 The code that Wookie uses to parse and unpack W3C Widgets can also be used in other applications and projects as a standalone library. The parser can be found as a sub-project within the "parser/java/" folder in the main Wookie source tree.
 
+# Using the parser in a Maven project
+
+To use the parser with a Maven project, include the following dependency configuration in your project:
+
+    <dependency>
+     <groupId>org.apache.wookie</groupId>
+     <artifactId>wookie-java-parser</artifactId>
+     <type>jar</type>
+     <scope>compile</scope>
+     <version>0.9.1-incubating-SNAPSHOT</version>
+    </dependency>
+
 # Building the parser
 To build the parser as a standalone .jar, run `ant publish-local` from within the parser folder; the jar will be saved in `parser/dist`. Dependencies are described in the ivy.xml file that can also be found in the `parser/dist` folder.
 
@@ -44,13 +56,21 @@ For example, a simple program to unpack 
 		}
 	}
 
+The W3CWidgetFactory can also download and install widgets directly from a URL as well as locally from the file system:
+
+    W3CWidget widget = fac.parse(new URL("http://foo.com/bar.wgt"));
+
+Note that if the widget does not use the application/widget content-type, you should set "ignore content type" to true:
+
+    W3CWidget widget = fac.parse(new URL("http://foo.com/bar.wgt"), true);    
+
 #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:
 
-     INameEntity[] names = widget.getNames().toArray(new INameEntity[fNamesList.size()]);
+     INameEntity[] names = widget.getNames().toArray(new INameEntity[widget.getNames().size()]);
      String[] locales = new String[]{"fr"};
-	 INameEntity name = (INameEntity)LocalizationUtils.getLocalizedElement(names, locales);
+     INameEntity name = (INameEntity)LocalizationUtils.getLocalizedElement(names, locales,widget.getDefaultLocale());
 
 
 `LocalizationUtils` uses icu4j to process elements using appropriate fallback strategies based on language variants and extensions.