/* <> Namespace JSPWiki plugin Dirk Frederickx Jun 2005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package brushed.jspwiki.namespaceplugin; import org.apache.log4j.Logger; import com.ecyrd.jspwiki.*; import com.ecyrd.jspwiki.plugin.*; import java.util.*; /** * Breaks a pagename into pieces, based on the namespace delimiter * *

Parameters

* * * @author Dirk Frederickx */ public class Namespace extends AbstractReferralPlugin { public static final String PARAM_PAGE = "page"; public static final String PARAM_DELIMITER = "delimiter"; public static final String PARAM_CONCAT = "concat"; public static final String PARAM_STYLE = "style"; public String execute( WikiContext context, Map params ) throws PluginException { m_engine = context.getEngine(); //use m_engine from parent bugfix StringBuffer m_result = new StringBuffer(); WikiPage page = context.getPage(); if( page == null ) return ""; // parse parameters String name = (String)params.get( PARAM_PAGE ); if( name == null ) name = page.getName() ; String delimiter = (String)params.get( PARAM_DELIMITER ); if( delimiter == null ) delimiter = "." ; String concat = (String)params.get( PARAM_CONCAT ); if( concat == null ) concat = " " + delimiter + " "; String style = (String)params.get( PARAM_STYLE ); if( style == null ) { style = "namespace"; } else { style = "(" + style + ")"; } // do the job m_result.append("%%" + style + " \n"); StringBuffer nn = new StringBuffer(); StringTokenizer st = new StringTokenizer( name, delimiter ); while( st.hasMoreTokens() ) { if( nn.length() != 0 ) { nn.append(delimiter) ; m_result.append( concat ) ; } String ss = st.nextToken(); nn.append( ss ); m_result.append( '[' ); m_result.append( ss ); m_result.append( '|' ); m_result.append( nn ); m_result.append( ']' ); } m_result.append ("\n%%\n" ) ; return makeHTML( context, m_result.toString() ); } }