package orc.jspwiki;

import java.util.Map;

import com.ecyrd.jspwiki.TextUtil;
import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.plugin.PluginException;
import com.ecyrd.jspwiki.plugin.WikiPlugin;

public class Orc implements WikiPlugin {
	private final static String HAS_ORC = "orc.jspwiki.HAS_ORC";
	public String execute(WikiContext ctx, Map props) throws PluginException {
		String baseURL = (String)props.get("baseURL");
		if (baseURL == null) baseURL = "/orchard/";
		StringBuilder out = new StringBuilder();
		if (ctx.getVariable(HAS_ORC) == null) {
			// add required css and js files
			ctx.setVariable(HAS_ORC, true);
			out.append("<script src=\"" +
					baseURL + "orc.js\" " +
					"type=\"text/javascript\"></script>\n");
			out.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" +
					baseURL + "orc.css\" media=\"screen\"/>");
		}
		String tag = "pre";
		String editable = (String)props.get("editable");
		if (editable != null && !editable.equals("false")) {
			tag = "textarea";
		}
		String height = (String)props.get("height");
		String body = (String)props.get("_body");
		if (body != null) {
			body = TextUtil.replaceEntities(body);
			out.append("<"+tag+" class=\"orc\"");
			if (height != null) {
				out.append(" style=\"height: " + height + "\"");
			}
			out.append(">");
			out.append(body.trim());
			out.append("</"+tag+">");
		}
		return out.toString();
	}
}

@@ -205,16 +205,686 @@
 lugin;%0A%0A
+/**%0A * This is a plugin for JSPWiki which enables syntax like this:%0A * %3Cpre%3E%0A * %5B%7Borc%0A * %0A * -- your program here%0A * %7D%5D%0A * %3C/pre%3E%0A * %0A * %3Cp%3EThis plugin supports the properties:%0A * %3Cul%3E%0A * %3Cli%3Erunnable: if %22false%22, program is not runnable.%0A * %3Cli%3Eeditable: if %22true%22, program is editable.%0A * %3Cli%3Eheight: a CSS height (e.g. %22100px%22). If this is not given, the box will be just big enough to contain the existing program text.%0A * %3Cli%3EbaseURL: URL path to Orchard installation (defaults to %22/orchard/%22)%0A * %3C/ul%3E%0A * %0A * %3Cp%3ETo install, %22ant jar%22, place the resulting jar in the WEB-INF/lib directory of jspwiki, and restart your servlet container.%0A * %0A * @author quark%0A *%0A */%0A
 public c
@@ -1734,16 +1734,67 @@
 ight%22);%0A
+%09%09String runnable = (String)props.get(%22runnable%22);%0A
 %09%09String
@@ -1893,16 +1893,16 @@
 (body);%0A
-
 %09%09%09out.a
@@ -1928,16 +1928,123 @@
 ss=%5C%22orc
+%22);%0A%09%09%09if (runnable != null && runnable.equals(%22false%22)) %7B%0A%09%09%09%09out.append(%22-snippet%22);%0A%09%09%09%7D%0A%09%09%09out.append(%22
 %5C%22%22);%0A%09%09

Add runnable=false option for code snippets.