Simple Parser Example

Using Maven

Here we show you how to set-up a little demo project under linux in which the parser is used as a library component. The application realized in this demo will parse a page given in MediaWiki’s Wikitext and render the page as HTML.

To get started make sure you have Apache Maven installed (we tested using Maven 2.2.1 and 3.0 together with OpenJDK 1.6.0_20 and _22).

We bundled the demo as a Maven archetype (a kind of project template). To create a project from such an archetype issue the following command:

$ mvn archetype:generate \
    -DarchetypeGroupId=org.sweble.wikitext \
    -DarchetypeArtifactId=swc-example \
    -DarchetypeVersion=1.0.0 \
    -DarchetypeRepository=http://mojo.informatik.uni-erlangen.de/nexus/content/repositories/public

If you want to experiment with the 2.0.0 alpha version of sweble, use the following incantation:

$ mvn archetype:generate \
    -DarchetypeGroupId=org.sweble.wikitext \
    -DarchetypeArtifactId=swc-example-basic-archetype \
    -DarchetypeVersion=2.0.0-alpha-3-SNAPSHOT \
    -DarchetypeRepository=http://mojo.informatik.uni-erlangen.de/nexus/content/repositories/public

Next you will be asked to enter some information. For our demo project, please enter:

Define value for property 'groupId': : com.example
Define value for property 'artifactId': : parser-test
Define value for property 'version': 1.0-SNAPSHOT:          (just hit return)
Define value for property 'package': com.example:           (just hit return)

You will be asked to confirm the configuration. Enter “Y”.

Maven will now generate a project from the swc-example archetype in directory parser-test/. To compile the project and generate a .jar library do the following:

$ cd parser-test/
$ mvn package

If you are doing this for the first time a lot of libraries have to be pulled in which can take quite some time. Afterwards, we can test our application. First we need a page in Wikitext to test the application with. Please copy the following text and paste it into a file called “Simple_Page.wikitext” (mind the ‘_’!) which must be located in the parser-test/ directory:

== Simple Page ==

Hi! This is a '''simple page'''. If everything works as expected this page will be
* encoding validated
* preprocessed
* parsed
* postprocessed
* and finally rendered as HTML.

However, template expansion will not be performed.

Good Luck!

Now type in the following command:

$ java -jar target/parser-test-1.0-SNAPSHOT.jar Simple_Page

(Don’t add ‘.wikitext’ to the name of the page!)

If everything goes well there should be a Simple_Page.html file in the parser-test/ directory which you can view with the browser of your choice.

And that’s it. Have fun browsing the code!

Using a Jar with Dependencies

For those unfamiliar with Maven there is also the possibility of downloading a .zip file which contains the demo project, Eclipse project files and the swc-engine library. First download the .zip archive.

swc-example-basic.zip

Extract the archive and start Eclipse. Now go to:

  • File
  • Import…
  • General -> Existing Projects into Workspace -> Next
  • Enter the path to the swc-example-basic directory (either Browse or enter manually and then Refresh)
  • Finish

You have now imported the Eclipse project swc-example-basic into your Eclipse workspace and can start playing with it.

Leave a Reply

Your email address will not be published. Required fields are marked *