Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents...
Hide

Project Zero Developer’s Guide

Concepts and components
Basic concepts overview
Event processing
Writing Java handlers
Writing Groovy handlers
Firing events
Global Context
Global Context reference
Application directory layout
Virtualized directories
Assemble
PHP
Features and configuration
Configuration
Debugging
Dependencies
Packaging
Application classpath
Logging and tracing
RESTful resources
RESTful documentation
File serving
Response rendering
Validators and validation
HTTP error handling
Calling a remote resource
Using the Connection API
Sending an email using EmailConnection
Configuring destinations
Configuring protocols
Configuring connection handlers
Creating a connection handler
Creating a custom protocol transport
Simple logging connection handlers
Protocol reference
Client programming with Dojo
Runtime options
Deployment modifications
HTTP configuration
SSL configuration
Proxy configuration
Extending the CLI
Security considerations
Authentication
OpenID authentication
Extending security
Security tokens
CSRF prevention support
Extending token support
Leveraging TAI
User service
File based user service
LDAP user service
Extending user service
Security Utilities
Leveraging XOREncoder
Extensions
Atom support
RSS support
JSON support
XMLEncoder
REST to SOAP extension
URIUtils
Developer Web tools
Database setup tools
Configuring data access
Common query patterns
Advanced query patterns
Update patterns
Local database transactions
Extending data access
Configuration vendor differences
PHP data access
Resource model
Configuring ZRM
Resource model declaration
Programmatic model API
HTTP REST API
A ZRM mini tutorial
Active content filtering support
Default filters
Custom filters
Runtime management
Management commands
Zero socket opener
Other extension modules
Amazon E-commerce service
Flickr service
WeatherZero forecast service
Wikipedia service
Reference
Zero command line interface
JavaDoc - Public API
JavaDoc - Public SPI
JavaDoc - All Classes

 

Wikipedia service

This extension provides an easy way to retrieve a Wikipedia entry from Wikipedia. It uses the mediawiki Special:Export service to export an article, stores it on disk (cache), and produces a usable HTML block from the entry.

Adding zero.services.wikipedia to your project

To use the Wikipedia extension, add it to your project. You can do this with the Project Zero tooling by editing your config/ivy.xml file. Add the zero.services.wikipedia library to your dependencies. If you do not have the library installed, it is downloaded automatically when you save the ivy.xml file or the next time your resolve your project.

Requesting a Wikipedia entry

To perform a request, use the following REST API:

http://localhost:8080/resources/wikipedia/{wikiword}

In this example, {wikiword} is substituted with the name of the Wikipedia entry you want to retrieve.

The Wikipedia API

The Wikipedia service provides a Wikipedia class that can be called directly from Groovy, PHP, or Java code. The following example retrieves the Wikipedia entry in HTML:
getWikiHtml(String wikiWord, boolean truncate)
getWikiHtml(String wikiWord, String language, boolean truncate)

In this example, if truncate is true then the entry is truncated. If language is specified it should be a language code, for example en for English.

The following example retrieves the Wikipedia entry in HTML, as in the previous example, but this API should be used since the entry is retrieved from a local cache, if possible.

getWikiHtmlCache(String wikiWord, boolean truncate)
getWikiHtmlCache(String wikiWord, String language, boolean truncate)

In this example, if truncate is true, then the entry is truncated. If language is specified it should be a language code, for example en for English.

The following example retrieves the Wikipedia entry in Mediawiki markup:

getWikiMarkup(String wikiWord)
getWikiMarkup(String wikiWord, String language)

The following example truncates a given HTML block and places the truncatedMessage message at the end of the block.

truncateHtml(String html, String truncatedMessage)

Tweaking the Wikipedia API

There are several constants defined in the Wikipedia class that can be modified to tweak the behavior of the API, as shown in the following example.

   public static final String DEFAULT_WIKIPEDIA_LANGUAGE = "en";
   public static final String NOT_FOUND_MESSAGE = ": was not found.";
   public static final String AMBIGUOS_MESSAGE = "This disambiguation page lists articles associated with the same title.";
   
   //These settings are applied when requesting truncated text
   public static final int TRUNCATE_MIN_CHARS = 512;
   public static final int TRUNCATE_MAX_PARAS = 4;
   public static final String TRUNCATED_LINK_TEXT = "More...";
   
   //These settings are not related to truncation
   public static final boolean REMOVE_IMAGES = false;
   public static final boolean REMOVE_TABLES = false;
   public static final boolean USE_IMAGE_THUMBNAILS = true;
   
   //These directories will contain the data cached from Wikipedia
   public static final String WIKIPEDIA_DIR = "wikipedia";
   public static final String WIKIIMAGES_DIR = "wikiImages";
   
   //This setting is used by the getWikiHtmlCache
   public static long CACHE_MAX_AGE = 1 * 60 * 60 * 1000; // = 1 hour

Additional resources

r4 - 08 Feb 2008 - 15:02:13 - paynel
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site