### Eclipse Workspace Patch 1.0 #P JSPWiki-2.8 Index: src/com/nukleos/jspwiki/plugin/InterwikiLinks.java =================================================================== --- src/com/nukleos/jspwiki/plugin/InterwikiLinks.java (revision 0) +++ src/com/nukleos/jspwiki/plugin/InterwikiLinks.java (revision 0) @@ -0,0 +1,207 @@ +/* + InterwikiLinks - a plugin for JSPWiki - a JSP-based WikiWiki clone. + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package com.nukleos.jspwiki.plugin; + +import org.apache.log4j.Logger; +import com.ecyrd.jspwiki.*; +import com.ecyrd.jspwiki.parser.Heading; +import com.ecyrd.jspwiki.parser.HeadingListener; +import com.ecyrd.jspwiki.parser.JSPWikiMarkupParser; +import com.ecyrd.jspwiki.plugin.PluginException; +import com.ecyrd.jspwiki.plugin.WikiPlugin; + +import java.util.*; +import java.io.StringReader; +import java.io.IOException; + +/** + * Provides a list or table of InterWiki links. + *
+ * Parameters: + *
+ *+ * Note that the output of this plugin is placed in an HTML DIV with a class + * 'interwikilinks'; you can use that in your CSS to give the output a distinct + * look. + *
+ * + * + * @author Wouter van daele (devjunkie at nukleos dot com) + * @version 2009-02-22 + */ +public class InterwikiLinks implements WikiPlugin +{ + private static enum OutputTypes + { + TEXT_OUTPUT, U_LIST_OUTPUT, O_LIST_OUTPUT, TABLE_OUTPUT + }; + + private static Logger log = Logger.getLogger( InterwikiLinks.class ); + + /** Parameter name for setting the type. */ + public static final String PARAM_TYPE = "type"; + + /** Parameter name for setting the title. */ + public static final String PARAM_TABLE_TITLE = "tabletitle"; + + /** Parameter name for setting the separator. */ + public static final String PARAM_SEPARATOR = "separator"; + + private OutputTypes default_outputtype = OutputTypes.TEXT_OUTPUT; + + private String default_tableTitle = "Interwiki Links Table"; + + private String default_separator = ", "; + + private String crlf = System.getProperty( "line.separator" ); + + public String execute( WikiContext context, Map params ) throws PluginException + { + try + { + StringBuffer sb = new StringBuffer(); + OutputTypes outputType = default_outputtype; + + // Get parameters, if any + String typeParam = (String) params.get( PARAM_TYPE ); + String tableTitleParam = (String) params.get( PARAM_TABLE_TITLE ); + String separatorParam = (String) params.get( PARAM_SEPARATOR ); + + // Handle default cases + if ( typeParam == null ) + { + outputType = OutputTypes.TEXT_OUTPUT; + } + else if( "TEXT".equals( typeParam.toUpperCase() ) ) + { + outputType = OutputTypes.TEXT_OUTPUT; + } + else if( "ULIST".equals( typeParam.toUpperCase() ) ) + { + outputType = OutputTypes.U_LIST_OUTPUT; + } + else if( "OLIST".equals( typeParam.toUpperCase() ) ) + { + outputType = OutputTypes.O_LIST_OUTPUT; + } + else if( "TABLE".equals( typeParam.toUpperCase() ) ) + { + outputType = OutputTypes.TABLE_OUTPUT; + } + + if( (tableTitleParam == null) || "".equals( tableTitleParam ) ) + { + tableTitleParam = default_tableTitle; + } + + if( (separatorParam == null) || "".equals( separatorParam ) ) + { + separatorParam = default_separator; + } + + // Create output buffer + log.debug( "TITLE: " + tableTitleParam + ", SEPARATOR: " + separatorParam + ", TYPE: " + outputType.name() ); + + sb.append( "| " ); + sb.append( link ); + sb.append( " | " ); + sb.append( context.getEngine().getInterWikiURL( link ) ); + sb.append( " |
Aaaaargh - how is this possible? No output type is defined in this InterwikiLinks plugin call!
" ); + } + + + sb.append( crlf + "