Error: Circular reference - you can't include a page in itself!";
}
}
else
{
previousIncludes = new ArrayList();
}
previousIncludes.add( page.getName() );
context.setVariable( ATTR_RECURSE, previousIncludes );
/**
* We want inclusion to occur within the context of
* its own page, because we need the links to be correct.
*/
WikiContext includedContext = (WikiContext) context.clone();
includedContext.setPage( page );
String pageData = engine.getPureText( page );
String moreLink = "";
if( section != -1 )
{
try
{
pageData = TextUtil.getSection( pageData, section );
}
catch( IllegalArgumentException e )
{
throw new PluginException( e.getMessage() );
}
}
if( pageData.length() > maxlen )
{
pageData = pageData.substring( 0, maxlen )+" ...";
moreLink = "More...
";
}
// Perform search replace according to the parameters
// search1 to searchN and replace1 to replaceN
int r = 0;
Object nextReplace = null;
Object nextSearch;
do{
r++;
nextSearch = params.get( PARAM_SEARCH+r );
if(nextSearch == null )
nextSearch = "%"+r+"$";
nextReplace = params.get( PARAM_REPLACE+r );
if(nextReplace != null){
pageData = pageData.replace((String)nextSearch, (String)nextReplace);
}
}while( nextReplace != null );
// --------------------------------------------------------
res.append("");
res.append( engine.textToHTML( includedContext, pageData ) );
res.append( moreLink );
res.append("
");
//
// Remove the name from the stack; we're now done with this.
//
previousIncludes.remove( page.getName() );
context.setVariable( ATTR_RECURSE, previousIncludes );
}
else
{
if( defaultstr != null )
{
res.append( defaultstr );
}
else
{
res.append("There is no page called '"+includedPage+"'. Would you like to ");
res.append("create it?");
}
}
}
else
{
res.append("");
res.append("You have to define a page!");
res.append("");
}
return res.toString();
}
}