This was added to the McKessonApsWikiPlugins, perhaps it might be useful in the stock distribution with the rest of the form based stuff.



package com.mckessonaps.jspwiki.plugin.formdebug;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;

import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.forms.FormElement;
import com.ecyrd.jspwiki.forms.FormHandler;
import com.ecyrd.jspwiki.forms.FormInfo;
import com.ecyrd.jspwiki.plugin.PluginException;
import com.ecyrd.jspwiki.plugin.WikiPlugin;


/**
 * Hopefully this will help debug Wiki form problems.
 */
public class FormDebugHandler implements WikiPlugin, FormHandler
{

	public String execute(WikiContext context, Map params) throws PluginException
	{
		StringBuffer buffer = new StringBuffer();
		buffer
		.append("<div style='font-size: 90%; margin: 10px; padding: 5px; border-style:inset; background: #F0F0F0;'>");
		buffer.append("<H1>FormDebugHandler</H1>");
		debug(params, buffer, "<H2>Plugin Parameters...</H2>");
		debug(context, buffer);
		buffer.append("</div>");

		return buffer.toString();
	}

	private void debug(Map params, StringBuffer buffer, String banner)
	{
		buffer.append(banner);

		TreeMap sortedParams = new TreeMap(params);
		for (Iterator iter = sortedParams.entrySet().iterator(); iter.hasNext();)
		{
			Map.Entry entry = (Map.Entry) iter.next();
			String key = (String) entry.getKey();
			String value = (String) entry.getValue();
			buffer.append(key + " = " + value + "<br />");
		}
	}

	private void debug(WikiContext context, StringBuffer buffer)
	{
		buffer.append("<H2>WikiContext...</H2>");


		buffer.append("getCurrentUser() =" + context.getCurrentUser() + "<br />");
		buffer.append("getRequestContext() =" + context.getRequestContext() + "<br />");

		FormInfo info = (FormInfo) context.getVariable(FormElement.FORM_VALUES_CARRIER);
		debug(info, buffer);

	}

	private void debug(FormInfo info, StringBuffer buffer)
	{
		buffer.append("<H3>FormInfo...</H3>");

		buffer.append("getAction() = " + info.getAction() + "<br />");
		buffer.append("getError() = " + info.getError() + "<br />");
		buffer.append("getHandler() = " + info.getHandler() + "<br />");
		buffer.append("getName() = " + info.getName() + "<br />");
		buffer.append("getResult() = " + info.getResult() + "<br />");
		buffer.append("getStatus() = " + info.getStatus() + "<br />");

		debug(info.getSubmission(), buffer, "<H4>Submission map...</H4>");
	}

}


ContributedFormHandlers

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-5) was last changed on 20-Feb-2010 11:52 by 164.67.235.79