Source Code Cross Referenced for MediaWikiUtil.java in  » Wiki-Engine » VeryQuickWiki » vqwiki » lex » 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 » VeryQuickWiki » vqwiki.lex 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package vqwiki.lex;
002:
003:        import java.net.URLEncoder;
004:        import java.util.Hashtable;
005:        import java.util.Stack;
006:        import org.apache.log4j.Logger;
007:        import vqwiki.Environment;
008:        import vqwiki.WikiBase;
009:        import vqwiki.servlets.WikiServlet;
010:        import vqwiki.utils.JSPUtils;
011:        import vqwiki.utils.Utilities;
012:
013:        /**
014:         * Utility methods used with the Mediawiki lexers.
015:         *
016:         * @author Ryan Holliday
017:         */
018:        public class MediaWikiUtil {
019:
020:            private static Logger logger = Logger.getLogger(MediaWikiUtil.class
021:                    .getName());
022:
023:            /**
024:             * Given a String that represents a Wiki HTML link (a URL with an optional
025:             * link text that is enclosed in brackets), return a formatted HTML anchor tag.
026:             *
027:             * @param raw The raw Wiki syntax that is to be converted into an HTML link.
028:             * @return A formatted HTML link for the Wiki syntax.
029:             */
030:            protected static String buildHtmlLink(String raw) {
031:                if (raw == null || raw.length() <= 2) {
032:                    // no link, display the raw text
033:                    return raw;
034:                }
035:                // strip the first and last brackets
036:                String link = raw.substring(1, raw.length() - 1).trim();
037:                return buildHtmlLinkRaw(link);
038:            }
039:
040:            /**
041:             * Given a String that represents a raw HTML link (a URL link that is
042:             * not enclosed in brackets), return a formatted HTML anchor tag.
043:             *
044:             * @param raw The raw HTML link that is to be converted into an HTML link.
045:             * @return A formatted HTML link.
046:             */
047:            protected static String buildHtmlLinkRaw(String raw) {
048:                if (raw == null)
049:                    return raw;
050:                String link = raw.trim();
051:                if (link.length() <= 0) {
052:                    // no link to display
053:                    return raw;
054:                }
055:                // search for link text (space followed by text)
056:                String punctuation = Utilities.extractTrailingPunctuation(link);
057:                String text = "";
058:                int pos = link.indexOf(' ');
059:                if (pos == -1) {
060:                    pos = link.indexOf('\t');
061:                }
062:                if (pos > 0) {
063:                    text = link.substring(pos + 1).trim();
064:                    link = link.substring(0, pos).trim();
065:                    punctuation = "";
066:                } else {
067:                    link = link.substring(0,
068:                            link.length() - punctuation.length()).trim();
069:                    text = link;
070:                }
071:                String html = linkHtml(link, text, punctuation);
072:                return (html != null) ? html : raw;
073:            }
074:
075:            /**
076:             *
077:             */
078:            protected static String buildWikiLink(String raw, String virtualWiki) {
079:                if (raw == null || raw.length() <= 4) {
080:                    // no topic, display the raw text
081:                    return raw;
082:                }
083:                // strip the first and last brackets
084:                String topic = raw.substring(2, raw.length() - 2).trim();
085:                if (topic.length() <= 0) {
086:                    // empty brackets, no topic to display
087:                    return raw;
088:                }
089:                // search for topic text ("|" followed by text)
090:                String text = topic.trim();
091:                int pos = topic.indexOf('|');
092:                if (pos > 0) {
093:                    text = topic.substring(pos + 1).trim();
094:                    topic = topic.substring(0, pos).trim();
095:                }
096:                String url = "Wiki?" + JSPUtils.encodeURL(topic);
097:                if (!exists(topic, virtualWiki)) {
098:                    url = "Wiki?topic=" + JSPUtils.encodeURL(topic)
099:                            + "&action=" + WikiServlet.ACTION_EDIT;
100:                    return "<a class=\"newtopic\" title=\"" + topic
101:                            + "\" href=\"" + url + "\">" + text + "</a>";
102:                }
103:                return "<a title=\"" + topic + "\" href=\"" + url + "\">"
104:                        + text + "</a>";
105:            }
106:
107:            /**
108:             *
109:             */
110:            public static String escapeHtml(String html) {
111:                if (html == null)
112:                    return html;
113:                StringBuffer escaped = new StringBuffer();
114:                for (int i = 0; i < html.length(); i++) {
115:                    if (html.charAt(i) == '<') {
116:                        escaped.append("&lt;");
117:                    } else if (html.charAt(i) == '>') {
118:                        escaped.append("&gt;");
119:                    } else {
120:                        escaped.append(html.charAt(i));
121:                    }
122:                }
123:                return escaped.toString();
124:            }
125:
126:            /**
127:             *
128:             */
129:            protected static boolean exists(String topic, String virtualWiki) {
130:                // FIXME - this causes a database query for every topic in the page,
131:                // which is very inefficient
132:                try {
133:                    return WikiBase.getInstance().exists(virtualWiki, topic);
134:                } catch (Exception e) {
135:                    logger.error(e);
136:                }
137:                return false;
138:            }
139:
140:            /**
141:             *
142:             */
143:            protected static String linkHtml(String link, String text,
144:                    String punctuation) {
145:                String html = null;
146:                String linkLower = link.toLowerCase();
147:                if (linkLower.startsWith("http://")) {
148:                    html = "<a class=\"externallink\" rel=\"nofollow\" title=\""
149:                            + link
150:                            + "\" href=\""
151:                            + link
152:                            + "\">"
153:                            + text
154:                            + "</a>" + punctuation;
155:                } else if (linkLower.startsWith("https://")) {
156:                    text += "&hArr;";
157:                    html = "<a class=\"externallink\" rel=\"nofollow\" title=\""
158:                            + link
159:                            + "\" href=\""
160:                            + link
161:                            + "\">"
162:                            + text
163:                            + "</a>" + punctuation;
164:                } else if (linkLower.startsWith("ftp://")) {
165:                    text += "&hArr;";
166:                    html = "<a class=\"externallink\" rel=\"nofollow\" title=\""
167:                            + link
168:                            + "\" href=\""
169:                            + link
170:                            + "\">"
171:                            + text
172:                            + "</a>" + punctuation;
173:                } else if (linkLower.startsWith("mailto://")) {
174:                    text += "&hArr;";
175:                    html = "<a class=\"externallink\" rel=\"nofollow\" title=\""
176:                            + link
177:                            + "\" href=\""
178:                            + link
179:                            + "\">"
180:                            + text
181:                            + "</a>" + punctuation;
182:                } else if (linkLower.startsWith("news://")) {
183:                    text += "&hArr;";
184:                    html = "<a class=\"externallink\" rel=\"nofollow\" title=\""
185:                            + link
186:                            + "\" href=\""
187:                            + link
188:                            + "\">"
189:                            + text
190:                            + "</a>" + punctuation;
191:                } else if (linkLower.startsWith("telnet://")) {
192:                    text += "&hArr;";
193:                    html = "<a class=\"externallink\" rel=\"nofollow\" title=\""
194:                            + link
195:                            + "\" href=\""
196:                            + link
197:                            + "\">"
198:                            + text
199:                            + "</a>" + punctuation;
200:                } else if (linkLower.startsWith("file://")) {
201:                    text += "&hArr;";
202:                    html = "<a class=\"externallink\" rel=\"nofollow\" title=\""
203:                            + link
204:                            + "\" href=\""
205:                            + link
206:                            + "\">"
207:                            + text
208:                            + "</a>" + punctuation;
209:                }
210:                return html;
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.