-
the Pavlov site
-

PDFPDF version

Writing A Velocity Pluglet

About This Document

One of the big improvements in Pavlov 1.1 is the leveraging of the Apache Jakarta Project's Velocity Template Engine to create templated Pluglets and Skins. This document describes how to write a Velocity Feedback Pluglet for Pavlov.

Step 1: Find The VelocityPluglet Directory

Let's assume you already have Pavlov 1.1B1 or later installed. Find the directory it was installed in. Now, there will be a subdirectory called pluglets and its subdirectory of pluglets/velocity. In the 1.1BX release, there are two subdirectories here called aliengrades and navylife. Every subdirectory of pluglets/velocity is scanned at startup for a file named index.vm. Those with a valid index.vm are accepted and added to the Feedback Menu in Pavlov. So, for example, on my machine, I have

/home/haus/pup/pluglets/velocity/aliengrades/index.vm
/home/haus/pup/pluglets/velocity/navylife/index.vm
    

let's take a look at one of these.

Step 2: Look at an Example

We open up the file pluglets/velocity/aliengrades/index.vm and see something like this:

01   <HTML>
02   <HEAD></HEAD>
03   <BODY BGCOLOR="black">
04 
05   <TABLE HEIGHT="223" WIDTH="304">
06   <TR>
07   <TD HEIGHT="223" WIDTH="304">
08   #set ( $right = $ANSWER_EVENT.getNumberOfCorrectAnswers() )
09   #set ( $tot= $ANSWER_EVENT.getNumberOfAnswers() )
10   #set ( $perc  = 100 * $right/$tot )
11
12   #if ( !$perc )
13     #set ($img ="logo.jpg")
14   #elseif ( $perc < 59 )
15     #set ($img ="f.jpg")
...stuff deleted...
16   #else 
17      #set ($img ="aplus.jpg")
18   #end
19   <IMG SRC ="$BASE_URL$img">
20   </TD>
21   </TR>
22   </TABLE>
23
24   </BODY>
25   </HTML>

     

Let's make a few observations:

Note
Java doesn't like some META tags, and it hates bad HTML. If you have problems debugging a VelocityPluglet, try to remove META tags and simplify the HTML.

Step 3: Use Advanced Velocity Features

The best source for information on advanced Velocity features is at Apache Jakarta Project's Velocity Site. There are some neat tricks on display there.

Step 4: Get More Information From Pavlov

Pavlov passes a great deal of information to your template using the AnswerEvent class. You can get information from the AnswerEvent by using it's methods. A few examples:

$ANSWER_EVENT.getQuestionData().getPercentage() Percentage of correct answers over whole user history
$ANSWER_EVENT.getUser().getName() User's login name.
$ANSWER_EVENT.getBookData().getTitle() Title of book in use
$ANSWER_EVENT.getChapterData().getStrategy().getName() Name of the question selection strategy in use
$ANSWER_EVENT.getChapterData().getQuizCollectionData().numQuizzes Number of quizzes this user has taken on this chapter
$ANSWER_EVENT.getChapterData().getQuizCollectionData().totalAsked Number of questions this user has answered over all quizzes on this chapter

The point here is not to list all the possible types of information you can glean from the system, but to illustrate that there is a lot to choose from.

Step 5: Publish

When you get a feedback pluglet that you like, send it to the Pavlov project. We'll need copyright information and have to filter out obscenities, but other than that, we'll be happy to make your pluglet available. That way, others can not only use your pluglet, but learn from it as well!