in jspwiki-main/src/main/java/org/apache/wiki/plugin/BugReportHandler.java [80:163]
public String execute( final Context context, final Map< String, String > params ) throws PluginException {
final String title = params.get( PARAM_TITLE );
String description = params.get( PARAM_DESCRIPTION );
String version = params.get( PARAM_VERSION );
String submitter = null;
final SimpleDateFormat format = new SimpleDateFormat( DEFAULT_DATEFORMAT );
final ResourceBundle rb = Preferences.getBundle( context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE );
final Principal wup = context.getCurrentUser();
if( wup != null ) {
submitter = wup.getName();
}
if( title == null ) {
throw new PluginException(rb.getString("bugreporthandler.titlerequired"));
}
if( title.isEmpty() ) {
return "";
}
if( description == null ) {
description = "";
}
if( version == null ) {
version = "unknown";
}
final Properties mappings = parseMappings( params.get( PARAM_MAPPINGS ) );
// Start things
try {
final StringWriter str = new StringWriter();
final PrintWriter out = new PrintWriter( str );
final Date d = new Date();
// Outputting of basic data
out.println( "|" + mappings.getProperty(PARAM_TITLE,"Title" ) + "|" + title );
out.println( "|" + mappings.getProperty("date","Date" ) + "|" + format.format( d ) );
out.println( "|" + mappings.getProperty(PARAM_VERSION,"Version" ) + "|" + version );
if( submitter != null ) {
out.println("|"+mappings.getProperty("submitter","Submitter") + "|" + submitter );
}
// Outputting the other parameters added to this.
for( final Map.Entry< String, String > entry : params.entrySet() ) {
if( !( entry.getKey().equals( PARAM_TITLE ) ||
entry.getKey().equals( PARAM_DESCRIPTION ) ||
entry.getKey().equals( PARAM_VERSION ) ||
entry.getKey().equals( PARAM_MAPPINGS ) ||
entry.getKey().equals( PARAM_PAGE ) ||
entry.getKey().startsWith( "_" )
) ) {
// If no mapping has been defined, just ignore it.
final String head = mappings.getProperty( entry.getKey(), entry.getKey() );
if( !head.isEmpty() ) {
out.println( "|" + head + "|" + entry.getValue() );
}
}
}
out.println();
out.println( description );
out.close();
// Now create a new page for this bug report
final String pageName = findNextPage( context, title, TextUtil.replaceEntities(params.get( PARAM_PAGE )) );
final Page newPage = Wiki.contents().page( context.getEngine(), pageName );
final Context newContext = context.clone();
newContext.setPage( newPage );
context.getEngine().getManager( PageManager.class ).saveText( newContext, str.toString() );
final MessageFormat formatter = new MessageFormat("");
formatter.applyPattern( rb.getString("bugreporthandler.new") );
final String[] args = { "<a href=\""+context.getViewURL(pageName)+"\">"+pageName+"</a>" };
return formatter.format( args );
} catch( final RedirectException e ) {
LOG.info("Saving not allowed, reason: '"+e.getMessage()+"', can't redirect to "+e.getRedirect());
throw new PluginException("Saving not allowed, reason: "+e.getMessage());
} catch( final WikiException e ) {
LOG.error( "Unable to save page!", e );
return rb.getString("bugreporthandler.unable" );
}
}