Source Code Cross Referenced for Image.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » plugin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.plugin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:            JSPWiki - a JSP-based WikiWiki clone.
003:
004:            Copyright (C) 2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006:            This program is free software; you can redistribute it and/or modify
007:            it under the terms of the GNU Lesser General Public License as published by
008:            the Free Software Foundation; either version 2.1 of the License, or
009:            (at your option) any later version.
010:
011:            This program is distributed in the hope that it will be useful,
012:            but WITHOUT ANY WARRANTY; without even the implied warranty of
013:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:            GNU Lesser General Public License for more details.
015:
016:            You should have received a copy of the GNU Lesser General Public License
017:            along with this program; if not, write to the Free Software
018:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:        package com.ecyrd.jspwiki.plugin;
021:
022:        import java.util.*;
023:        import com.ecyrd.jspwiki.*;
024:        import com.ecyrd.jspwiki.attachment.AttachmentManager;
025:        import com.ecyrd.jspwiki.attachment.Attachment;
026:        import com.ecyrd.jspwiki.providers.ProviderException;
027:
028:        /**
029:         *  Provides an image plugin for better control than is possible with
030:         *  a simple image inclusion.
031:         *
032:         *  @author Janne Jalkanen
033:         *  @since 2.1.4.
034:         */
035:        // FIXME: It is not yet possible to do wiki internal links.  In order to
036:        //        do this cleanly, a TranslatorReader revamp is needed.
037:        public class Image implements  WikiPlugin {
038:            public static final String PARAM_SRC = "src";
039:            public static final String PARAM_ALIGN = "align";
040:            public static final String PARAM_HEIGHT = "height";
041:            public static final String PARAM_WIDTH = "width";
042:            public static final String PARAM_ALT = "alt";
043:            public static final String PARAM_CAPTION = "caption";
044:            public static final String PARAM_LINK = "link";
045:            public static final String PARAM_TARGET = "target";
046:            public static final String PARAM_STYLE = "style";
047:            public static final String PARAM_CLASS = "class";
048:            //    public static final String PARAM_MAP      = "map";
049:            public static final String PARAM_BORDER = "border";
050:
051:            /**
052:             *  This method is used to clean away things like quotation marks which
053:             *  a malicious user could use to stop processing and insert javascript.
054:             */
055:            private static final String getCleanParameter(Map params,
056:                    String paramId) {
057:                return TextUtil.replaceEntities((String) params.get(paramId));
058:            }
059:
060:            public String execute(WikiContext context, Map params)
061:                    throws PluginException {
062:                WikiEngine engine = context.getEngine();
063:                String src = getCleanParameter(params, PARAM_SRC);
064:                String align = getCleanParameter(params, PARAM_ALIGN);
065:                String ht = getCleanParameter(params, PARAM_HEIGHT);
066:                String wt = getCleanParameter(params, PARAM_WIDTH);
067:                String alt = getCleanParameter(params, PARAM_ALT);
068:                String caption = getCleanParameter(params, PARAM_CAPTION);
069:                String link = getCleanParameter(params, PARAM_LINK);
070:                String target = getCleanParameter(params, PARAM_TARGET);
071:                String style = getCleanParameter(params, PARAM_STYLE);
072:                String cssclass = getCleanParameter(params, PARAM_CLASS);
073:                // String map     = getCleanParameter( params, PARAM_MAP );
074:                String border = getCleanParameter(params, PARAM_BORDER);
075:
076:                if (src == null) {
077:                    throw new PluginException(
078:                            "Parameter 'src' is required for Image plugin");
079:                }
080:
081:                if (cssclass == null)
082:                    cssclass = "imageplugin";
083:
084:                if (target != null && !validTargetValue(target)) {
085:                    target = null; // not a valid value so ignore
086:                }
087:
088:                try {
089:                    AttachmentManager mgr = engine.getAttachmentManager();
090:                    Attachment att = mgr.getAttachmentInfo(context, src);
091:
092:                    if (att != null) {
093:                        src = context.getURL(WikiContext.ATTACH, att.getName());
094:                    }
095:                } catch (ProviderException e) {
096:                    throw new PluginException("Attachment info failed: "
097:                            + e.getMessage());
098:                }
099:
100:                StringBuffer result = new StringBuffer();
101:
102:                result.append("<table border=\"0\" class=\"" + cssclass + "\"");
103:                //if( align != null ) result.append(" align=\""+align+"\"");
104:                //if( style != null ) result.append(" style=\""+style+"\"");
105:
106:                //
107:                //  Do some magic to make sure centering also work on FireFox
108:                //
109:                if (style != null) {
110:                    result.append(" style=\"" + style);
111:
112:                    // Make sure that we add a ";" to the end of the style string
113:                    if (result.charAt(result.length() - 1) != ';')
114:                        result.append(";");
115:
116:                    if (align != null && align.equals("center")) {
117:                        result
118:                                .append(" margin-left: auto; margin-right: auto;");
119:                    }
120:
121:                    result.append("\"");
122:                } else {
123:                    if (align != null && align.equals("center"))
124:                        result
125:                                .append(" style=\"margin-left: auto; margin-right: auto;\"");
126:                }
127:
128:                if (align != null && !(align.equals("center")))
129:                    result.append(" align=\"" + align + "\"");
130:
131:                result.append(">\n");
132:
133:                if (caption != null) {
134:                    result.append("<caption align=bottom>"
135:                            + TextUtil.replaceEntities(caption)
136:                            + "</caption>\n");
137:                }
138:
139:                result.append("<tr><td>");
140:
141:                if (link != null) {
142:                    result.append("<a href=\"" + link + "\"");
143:                    if (target != null) {
144:                        result.append(" target=\"" + target + "\"");
145:                    }
146:                    result.append(">");
147:                }
148:
149:                result.append("<img src=\"" + src + "\"");
150:
151:                if (ht != null)
152:                    result.append(" height=\"" + ht + "\"");
153:                if (wt != null)
154:                    result.append(" width=\"" + wt + "\"");
155:                if (alt != null)
156:                    result.append(" alt=\"" + alt + "\"");
157:                if (border != null)
158:                    result.append(" border=\"" + border + "\"");
159:                // if( map != null )    result.append(" map=\""+map+"\"");
160:
161:                result.append(" />");
162:                if (link != null)
163:                    result.append("</a>");
164:                result.append("</td></tr>\n");
165:
166:                result.append("</table>\n");
167:
168:                return result.toString();
169:            }
170:
171:            private boolean validTargetValue(String s) {
172:                if (s.equals("_blank") || s.equals("_self")
173:                        || s.equals("_parent") || s.equals("_top")) {
174:                    return true;
175:                } else if (s.length() > 0) // check [a-zA-z]
176:                {
177:                    char c = s.charAt(0);
178:                    return Character.isLowerCase(c) || Character.isUpperCase(c);
179:                }
180:                return false;
181:            }
182:
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.