Source Code Cross Referenced for AbstractReferralPlugin.java in  » Portal » Open-Portal » 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 » Portal » Open Portal » 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) 2001-2005 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 org.apache.log4j.Logger;
023:
024:        import com.ecyrd.jspwiki.*;
025:        import java.util.*;
026:        import java.io.StringReader;
027:        import java.io.IOException;
028:
029:        /**
030:         *  This is a base class for all plugins using referral things.
031:         *
032:         *  <p>Parameters:<br>
033:         *  maxwidth: maximum width of generated links<br>
034:         *  separator: separator between generated links (wikitext)<br>
035:         *  after: output after the link
036:         *  before: output before the link
037:         *  @author Janne Jalkanen
038:         */
039:        public abstract class AbstractReferralPlugin implements  WikiPlugin {
040:            private static Logger log = Logger
041:                    .getLogger(AbstractReferralPlugin.class);
042:
043:            public static final int ALL_ITEMS = -1;
044:            public static final String PARAM_MAXWIDTH = "maxwidth";
045:            public static final String PARAM_SEPARATOR = "separator";
046:            public static final String PARAM_AFTER = "after";
047:            public static final String PARAM_BEFORE = "before";
048:
049:            protected int m_maxwidth = Integer.MAX_VALUE;
050:            protected String m_before = ""; // null not blank
051:            protected String m_separator = ""; // null not blank 
052:            protected String m_after = "\\\\";
053:
054:            protected WikiEngine m_engine;
055:
056:            public static final String ALL_WIKIS = "*";
057:            public static final String PARAM_WIKI = "wiki";
058:            protected String m_wiki = null;
059:
060:            /**
061:             *  Used to initialize some things.  All plugins must call this first.
062:             *
063:             *  @since 1.6.4
064:             */
065:            public void initialize(WikiContext context, Map params)
066:                    throws PluginException {
067:                m_engine = context.getEngine();
068:                m_maxwidth = TextUtil.parseIntParameter((String) params
069:                        .get(PARAM_MAXWIDTH), Integer.MAX_VALUE);
070:                if (m_maxwidth < 0)
071:                    m_maxwidth = 0;
072:
073:                String s = (String) params.get(PARAM_SEPARATOR);
074:
075:                if (s != null) {
076:                    m_separator = s;
077:                    // pre-2.1.145 there was a separator at the end of the list
078:                    // if they set the parameters, we use the new format of 
079:                    // before Item1 after separator before Item2 after separator before Item3 after
080:                    m_after = "";
081:                }
082:
083:                s = (String) params.get(PARAM_BEFORE);
084:
085:                if (s != null) {
086:                    m_before = s;
087:                }
088:
089:                s = (String) params.get(PARAM_AFTER);
090:
091:                if (s != null) {
092:                    m_after = s;
093:                }
094:
095:                s = (String) params.get(PARAM_WIKI);
096:
097:                if (s != null) {
098:                    m_wiki = s;
099:                }
100:
101:                // log.debug( "Requested maximum width is "+m_maxwidth );
102:            }
103:
104:            /**
105:             *  Makes WikiText from a Collection.
106:             *
107:             *  @param links Collection to make into WikiText.
108:             *  @param separator Separator string to use.
109:             *  @param numItems How many items to show.
110:             */
111:            protected String wikitizeCollection(Collection links,
112:                    String separator, int numItems) {
113:                if (links == null || links.isEmpty())
114:                    return ("");
115:
116:                StringBuffer output = new StringBuffer();
117:
118:                Iterator it = links.iterator();
119:                int count = 0;
120:
121:                //
122:                //  The output will be B Item[1] A S B Item[2] A S B Item[3] A
123:                //
124:                while (it.hasNext()
125:                        && ((count < numItems) || (numItems == ALL_ITEMS))) {
126:                    String value = (String) it.next();
127:
128:                    if (count > 0) {
129:                        output.append(m_after);
130:                        output.append(m_separator);
131:                    }
132:
133:                    output.append(m_before);
134:
135:                    // Make a Wiki markup link. See TranslatorReader.
136:                    output.append("[" + m_engine.beautifyTitle(value) + "]");
137:                    count++;
138:                }
139:
140:                // 
141:                //  Output final item - if there have been none, no "after" is printed
142:                //
143:                if (count > 0)
144:                    output.append(m_after);
145:
146:                return (output.toString());
147:            }
148:
149:            /**
150:             *  Makes HTML with common parameters.
151:             *
152:             *  @since 1.6.4
153:             */
154:            protected String makeHTML(WikiContext context, String wikitext) {
155:                String result = "";
156:                TranslatorReader in = null;
157:
158:                try {
159:                    in = new TranslatorReader(context, new StringReader(
160:                            wikitext));
161:                    in.addLinkTransmutator(new CutMutator(m_maxwidth));
162:                    in.enableImageInlining(false);
163:
164:                    result = FileUtil.readContents(in);
165:                } catch (IOException e) {
166:                    log.error("Failed to convert page data to HTML", e);
167:                } finally {
168:                    try {
169:                        if (in != null)
170:                            in.close();
171:                    } catch (Exception e) {
172:                        log.fatal("Closing failed", e);
173:                    }
174:                }
175:
176:                return result;
177:            }
178:
179:            /**
180:             *  A simple class that just cuts a String to a maximum
181:             *  length, adding three dots after the cutpoint.
182:             */
183:            private class CutMutator implements  StringTransmutator {
184:                private int m_length;
185:
186:                public CutMutator(int length) {
187:                    m_length = length;
188:                }
189:
190:                public String mutate(WikiContext context, String text) {
191:                    if (text.length() > m_length) {
192:                        return text.substring(0, m_length) + "...";
193:                    }
194:
195:                    return text;
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.