package com.ecyrd.jspwiki.plugin.i3g;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import com.ecyrd.jspwiki.ReferenceManager;
import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.WikiEngine;
import com.ecyrd.jspwiki.WikiPage;
import com.ecyrd.jspwiki.plugin.PluginException;
import com.ecyrd.jspwiki.plugin.WikiPlugin;
public class WikiMap implements WikiPlugin{
private ReferenceManager ref;
private WikiEngine engine;
private Vector references, pages;
public String execute(WikiContext context, Map params) throws PluginException {
engine = context.getEngine();
ref=engine.getReferenceManager();
String width="300", height="300", ownwindow="off",
recursiondepth="10" ,zoom="50", locality="1",
debugMode="off", ip;
int allpages=0;
String startpage=context.getPage().getName();
allpages=engine.getPageCount();
ip = context.getHttpRequest().getRemoteAddr();
try{
if(PluginUtil.getParameter(params, "startpage")!=null)startpage=PluginUtil.getParameter(params, "startpage");
}
catch(Exception e){}
try{
if(PluginUtil.getParameter(params, "width")!=null) width=PluginUtil.getParameter(params, "width");
}
catch(Exception e){}
try{
if(PluginUtil.getParameter(params, "height")!=null)height=PluginUtil.getParameter(params, "height");
}
catch(Exception e){}
try{
if(PluginUtil.getParameter(params, "ownwindow")!=null)ownwindow=PluginUtil.getParameter(params, "ownwindow");
}
catch(Exception e){}
try{
if(PluginUtil.getParameter(params, "recursiondepth")!=null) recursiondepth=PluginUtil.getParameter(params, "recursiondepth");
}
catch(Exception e){}
try{
if(PluginUtil.getParameter(params, "zoom")!=null)zoom=PluginUtil.getParameter(params, "zoom");
}
catch(Exception e){}
try{
if(PluginUtil.getParameter(params, "locality")!=null)locality=PluginUtil.getParameter(params, "locality");
}
catch(Exception e){}
try{
if(PluginUtil.getParameter(params, "debugMode")!=null)debugMode=PluginUtil.getParameter(params, "debugMode");
}
catch(Exception e){}
try{
pages = new Vector();
references = new Vector();
setupWikiStructureTO(startpage,pages,references, 0);
}
catch (Exception e) {return "Please reload this page!";}
try {
return " "+
"";
} catch (Exception e) {
throw new PluginException(e.getMessage());
}
}
//**without Servlet
public String[] linksTO(String pagename)
{
String backText;
String[] test;
try{
backText="";
Collection linksto = engine.getPageManager().getAllPages();
Iterator iter = linksto.iterator();
while(iter.hasNext())
{
WikiPage holder = (WikiPage) iter.next();
Collection colholder = ref.findReferrers(holder.getName());
if (colholder!=null&&colholder.contains(pagename))
{
backText=backText+","+holder.getName();
}
}
if(backText!="")
{
test=backText.substring(1,backText.length()).split(",");
return test;
}
}
catch (Exception e){}
return null;
}
public void setupWikiStructureTO(String startPage, Vector pages, Vector references, int rekDepth ) {
//Pout.print("setupWikiStructureTO");
String[] strPages = linksTO(startPage);
System.out.println("add "+startPage);
pages.add(startPage);
if(strPages==null||rekDepth>=1000)
return;
for(int i=0; i