/* JSPWiki - a JSP-based WikiWiki clone. Copyright (C) 2002 Janne Jalkanen (Janne.Jalkanen@iki.fi) 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 com.ecyrd.jspwiki.plugin; import java.util.*; import com.ecyrd.jspwiki.*; import com.ecyrd.jspwiki.attachment.AttachmentManager; import com.ecyrd.jspwiki.attachment.Attachment; import com.ecyrd.jspwiki.providers.ProviderException; /** * Provides a progress bar plugin (based on the image plugin). * * @author Nascif A. Abousalh-Neto * @since 2.1.4. */ // FIXME: It is not yet possible to do wiki internal links. In order to // do this cleanly, a TranslatorReader revamp is needed. public class ProgressBar implements WikiPlugin { public static final String PARAM_PERCENTAGE= "percentage"; public static final String PARAM_SRC_LEFT = "src_left"; public static final String PARAM_SRC_RIGHT = "src_right"; public static final String PARAM_ALIGN = "align"; public static final String PARAM_HEIGHT = "height"; public static final String PARAM_WIDTH = "width"; public static final String PARAM_ALT = "alt"; public static final String PARAM_CAPTION = "caption"; public static final String PARAM_LINK = "link"; public static final String PARAM_STYLE = "style"; public static final String PARAM_CLASS = "class"; public static final String PARAM_BORDER = "border"; /** * This method is used to clean away things like quotation marks which * a malicious user could use to stop processing and insert javascript. */ private static final String getCleanParameter( Map params, String paramId ) { return TextUtil.replaceEntities( (String) params.get( paramId ) ); } public String execute( WikiContext context, Map params ) throws PluginException { WikiEngine engine = context.getEngine(); String percentage = getCleanParameter( params, PARAM_PERCENTAGE ); String src_left = getCleanParameter( params, PARAM_SRC_LEFT ); String src_right = getCleanParameter( params, PARAM_SRC_RIGHT ); String align = getCleanParameter( params, PARAM_ALIGN ); String ht = getCleanParameter( params, PARAM_HEIGHT ); String wt = getCleanParameter( params, PARAM_WIDTH ); String caption = getCleanParameter( params, PARAM_CAPTION ); String link = getCleanParameter( params, PARAM_LINK ); String style = getCleanParameter( params, PARAM_STYLE ); String cssclass = getCleanParameter( params, PARAM_CLASS ); String border = getCleanParameter( params, PARAM_BORDER ); int leftWidth = 0; int rightWidth = 100; int width = 100; if( ht == null ) { ht = "10"; } if( src_left == null ) { src_left = "images/green.png"; } if( src_right == null ) { src_right = "images/red.png"; } if( wt != null ) { try { width = Integer.parseInt(wt); } catch (NumberFormatException e) { throw new PluginException("Width is not a valid integer"); } } if( percentage != null ) { try { int p = Integer.parseInt(percentage); if (p < 0 || p > 100) { throw new PluginException("Percentage must be an integer between 0 and 100"); } leftWidth = (width * p) / 100; rightWidth = width - leftWidth; } catch (NumberFormatException e) { throw new PluginException("Percentage is not a valid integer"); } } if( cssclass == null ) cssclass = "imageplugin"; try { AttachmentManager mgr = engine.getAttachmentManager(); Attachment att = mgr.getAttachmentInfo( context, src_left ); if( att != null ) { src_left = engine.getAttachmentURL(att.getName()); } att = mgr.getAttachmentInfo( context, src_right ); if( att != null ) { src_right = engine.getAttachmentURL(att.getName()); } } catch( ProviderException e ) { throw new PluginException( "Attachment info failed: "+e.getMessage() ); } StringBuffer result = new StringBuffer(); result.append( "\n" ); if( caption != null ) { result.append("\n"); } result.append( "" ); result.append(""); result.append("\n"); result.append("
"+TextUtil.replaceEntities(caption)+"
" ); //////////////////////////////////////////////////////////////////////////////// //add left image if( link != null ) { result.append(""); } result.append( "\""+Integer.toString(leftWidth)+"%"); if( link != null ) result.append(""); //////////////////////////////////////////////////////////////////////////////// //add right image if( link != null ) { result.append(""); } result.append( "\""+Integer.toString(leftWidth)+"%"); if( link != null ) result.append(""); //////////////////////////////////////////////////////////////////////////////// // close table result.append("
\n"); return result.toString(); } }