package com.ecyrd.jspwiki.plugin; import com.ecyrd.jspwiki.WikiContext; import com.ecyrd.jspwiki.WikiPage; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; /** * This simple plugin displays the date and time when the plugin was * last modified. * * Usage: *
* [{INSERT DateModifiedPlugin}]
*
*
* Optional parameter: format - specifies the format to use
* when stringinizing the date.
*
* @author vovan
* @version 1.0
*/
public class DateModifiedPlugin implements WikiPlugin {
/**
* The default date format, a-la CurrentTimePlugin.
*/
public static final String DEFAULT_FORMAT = "HH:mm:ss dd-MMM-yyyy zzzz";
/**
* Executes the plugin and spits out the date as a result.
*
* @param context a WikiContext value
* @param params a Map value
* @return a String value
* @exception PluginException if an error occurs
*/
public String execute(WikiContext context, Map params)
throws PluginException {
//Get the format that we want to use for the date.
String formatString = (String) params.get("format");
//See if the parameter was present.
if(formatString == null) {
formatString = DEFAULT_FORMAT;
}
try {
//Create a formatter for the date:
SimpleDateFormat fmt = new SimpleDateFormat(formatString);
//Get the date when the page was last modified:
Date d = context.getPage().getLastModified();
//Check that the date is actually present:
if (d == null) {
return "Never";
} else {
return fmt.format(d);
}
}
catch(IllegalArgumentException e) {
throw new PluginException("You specified bad format: " + e.getMessage());
}
}
}