In the default package for convenience -- MaxVoelkel
Please note that this is extremely insecure; anyone with write access to the pages can read ANY page that the web server is able to read. NEVER install this on a public Wiki system. --JanneJalkanen
package com.ecyrd.jspwiki.plugin;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Map;
import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.TranslatorReader;
/**
* Displays a text block in TT and with WikiWords enabled.
* <P>
* <B>Parameters</B>
* <UL>
* <LI>filename - The name of the text fle to be formatted.
* </UL>
*/
public class LinkedCodePlugin implements WikiPlugin {
public static final String PARAM_NAME = "filename";
public String execute(WikiContext context, Map params)
throws PluginException {
// Parse parameters.
String filename = "";
if ((filename = (String) params.get(PARAM_NAME)) == null)
return "Please tell me: filename=???";
// We should now have a code-string.
//
File f = new File(filename);
try {
BufferedReader r = new BufferedReader(new FileReader(f));
String s = r.readLine();
StringBuffer sb = new StringBuffer();
while(s != null)
{
// escape HTML-Tags
String clean = s.replaceAll( "<", "<");
clean = clean.replaceAll( ">", ">");
// make every line in TT
sb.append("{{"+ clean + "}}\\\\");
sb.append("\n");
s = r.readLine();
}
String wikirendered =
context.getEngine().textToHTML( context, sb.toString() );
return wikirendered;
} catch (FileNotFoundException e) {
return "File "+filename+" not found.";
} catch (IOException e) {
return "Error reading "+filename;
}
}
}