/* Copyright 2004 Mario Ivankovits mario@ops.co.at Licensed 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 org.stringfellow.jspwiki; import java.net.URLEncoder; import java.util.Map; import com.ecyrd.jspwiki.TextUtil; import com.ecyrd.jspwiki.WikiContext; import com.ecyrd.jspwiki.WikiEngine; import com.ecyrd.jspwiki.attachment.Attachment; import com.ecyrd.jspwiki.attachment.AttachmentManager; import com.ecyrd.jspwiki.plugin.PluginException; import com.ecyrd.jspwiki.plugin.WikiPlugin; import com.ecyrd.jspwiki.providers.ProviderException; /** * Provides an image plugin for better control than is possible with * a simple image inclusion. * Allows server-side image resize * * @author Mario Ivankovits * * Additions: * @author Christoph Sauer * if no link is provided, it will be linked to the original picture. * By doing this you get an default "enlarge" option, simply by clicking on the image */ // FIXME: It is not yet possible to do wiki internal links. In order to // do this cleanly, a TranslatorReader revamp is needed. public class ImageX implements WikiPlugin { public static final String PARAM_SRC = "src"; public static final String PARAM_IMAGE_SERVLET = "image_servlet"; public static final String PARAM_TYPE = "type"; public static final String PARAM_ROTATE = "rotate"; 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_MAP = "map"; 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 imageServlet = getCleanParameter(params, PARAM_IMAGE_SERVLET); String src = getCleanParameter(params, PARAM_SRC); String type = getCleanParameter(params, PARAM_TYPE); String rotate = getCleanParameter(params, PARAM_ROTATE); String align = getCleanParameter(params, PARAM_ALIGN); String ht = getCleanParameter(params, PARAM_HEIGHT); String wt = getCleanParameter(params, PARAM_WIDTH); String alt = getCleanParameter(params, PARAM_ALT); 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 map = getCleanParameter( params, PARAM_MAP ); String border = getCleanParameter(params, PARAM_BORDER); String att_name = null; if (src == null) { throw new PluginException("Parameter 'src' is required for Image plugin"); } if (cssclass == null) { cssclass = "imageplugin"; } try { AttachmentManager mgr = engine.getAttachmentManager(); Attachment att = mgr.getAttachmentInfo(context, src); if (att != null) { src = engine.getAttachmentURL(att.getName()); att_name = 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("\n"); result.append("
" + TextUtil.replaceEntities(caption) + "
"); //csauer: if no link is provided, it will be linked to the original picture //by doing this you get an default "enlarge" option, simply by clicking on the image if (link == null) { link = src; } if (link != null) { result.append(""); } result.append("\"""); if (link != null) { result.append(""); } result.append("
\n"); return result.toString(); } }