Writing Event Notification classes

Another way to extend ViewsFlash's capabilities is by adding code of your own which will be executed at key events.

1. Study the source code provided, and refer to its documentation in the section below.

Base Class Purpose
PublishNotifier Called on Publishing events
VoteNotifier Called when a valid vote is cast
RequestNotifier   Called after an HttpServletRequest is received and parsed.

2. Compile your code and move the .class file to the .../ViewsFlash/WEB-INF/com/cogix/vwf directory, and restart your application server. For complete instructions, click here.

3. Add the indicated viewsflash servlet configuration parameter to the viewsflash.properties file. For example: publishnotifierextension=PublishNotifierExtension

4. Restart your application server.

5. Use logging statements to debug. Look for them in the ViewsFlash Administrator log in the Administrator page, or in viewsflash.log file in the viewsflash data directory. The classes include init() and destroy() methods, useful for logging and initializing.

PublishNotifier

ViewsFlash often needs to integrate into an authoring system. Using this extension, your Java code can notify the authoring system, or any other application, when a poll or survey is scheduled for publication. It can also take action right after it is actually published. With this information, the publishing system can move files from staging to production servers, for example.

Write your class starting with this skeleton code for PublishNotifierExtension.java. Compile the class as specified above. Use the following viewsflash servlet parameter to indicate the name of your class:
publishnotifierextension=com.cogix.vwf.PublishNotifierExtension

com.cogix.vwf.PublishNotifierExtension methods:

void onPublishChange ( File pollfile, File resultsfile, String spotname, String pollid, Date open, Date close, Spot spot, definition def, Poll pol, ThisCall thiscall )

This event happens when the Submit button on the Publish page the ViewsFlash accepts the changes, showing Changes accepted in the browser. At this moment, you have the most current information on a poll or survey's schedule.

Parameter Meaning
spotname The place name
pollid The Poll ID
open / close Date when the poll or survey opens / closes (can be in the past or future, can be null if undefined)
pollfile / resultsfile Where the HTML created for the voting form or the response page are. Note that at the time of this event, these files may not exist or may be outdated. If you need their content, use OnPublishOpen.
spot /def / pol These objects are useful in advanced applications. Examine the code for examples of their use.
thiscall This object provides access to environmental objects such as the request and response objects. Examine the code for examples of its use.

void onPublishOpen ( File pollfile, File resultsfile, String spotname, String pollid, Spot spot, definition def, Poll pol)

This event happens at the designated Start Publication time, when a poll or survey opens, and its HTML form and response page are written to disk. Sometimes it is called once, for the poll page, and again for the results page; it can also be called once for both. Check carefully for null parameters.

Parameter Meaning
spotname The place name
pollid The Poll ID
pollfile / resultsfile Where the HTML created for the voting form or the response page are. If you wanted to send the files to a staging server using ftp, you could do it here. Either of these can be null.
Spot /def / pol as above
   

void onPublishClose ( File pollfile, File resultsfile, String spotname, String pollid, Spot spot, definition def, Poll pol)

When the poll or survey is closed, this method may be called, but there is no guarantee that it will be called. Its arguments are the same arguments as OnPublishOpen.


Void onPublishExtra ( File resultsfile, String spotname, String pollid, Spot spot, definition def, Poll pol)

This event happens when an Extra report is scheduled for publication, after its HTML is written. Check carefully for null parameters.

Parameter Meaning
spotname The place name
pollid The Poll ID
pollfile Where the HTML created for the finished report page is. Can be null.
Spot /def / pol as above
   

VoteNotifier

Some applications call for tracking where or when people have voted. Using this extension, your Java code can notify another application after a valid vote has been received. To validate a vote, use the Validation classes instead.

Write your class starting with this skeleton code for SampleVoteNotifierExtension.java. Compile the class as specified above. Use the following viewsflash servlet parameter to indicate the name of your class:
votenotifierextension=com.cogix.vwf.SampleVoteNotifierExtension

com.cogix.vwf.SampleVoteNotifierExtension methods:

void onVote ( Poll pol, ThisCall thiscall)

This event happens when a valid vote or survey is received.

Parameter Meaning
pol The Poll object. Use pol.pollid() to get the poll's ID.
thiscall This object provides access to environmental objects such as the request and response objects. Examine the code for examples of its use.
void onUpdate ( Poll pol, ThisCall thiscall)

This event happens when a valid vote or survey is updated. This requires that the Security page settings allow only one response that can be revised after completion.

Parameter Meaning
pol The Poll object. Use pol.pollid() to get the poll's ID.
thiscall This object provides access to environmental objects such as the request and response objects. Examine the code for examples of its use.

 

RequestNotifier

This extension implements the Request Authentication method for authenticating visitors in the Security page. When running inside an application server, it is common for the servlet context or the request attributes to contain useful information, such as a authenticated User ID. The onRequest method allows for retrieving the information and putting in a place where it can be used by ViewsFlash earlier.

void onRequest ( ThisCall thiscall)

This event happens right after the HttpServletRequest is parsed. This method is expected to set two servlet request attributes using HttpServletRequest.setAttribute (name,value). The two attributes have preset names: RequestNotifier.RequestNotifierTransient and RequestNotifier.RequestNotifierId. Set RequestNotifierTransient to "1" if the user ID is not a permanent one. Set RequestNotifierId to the unique UserID.

The information set in these two request attributes is used by the "Use Request Authentication" option in the Security page.

Parameter Meaning
thiscall This object provides access to environmental objects such as the request and response objects. Examine the code for examples of its use.

 

Next: Extensible Authentication