Source Code Cross Referenced for LinkExtender.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:        /**
002:         * Controls generation of external links based on the linking.properties file at the bottom
003:         * of the classpath.
004:         *
005:         * The file controls how link syntax is hyperlinked
006:         * Syntax: prefix=mylink
007:         * mylink can include the keyword expansion ${url} to add the suffix of the link
008:         * if you want to have the external link open in a new frame, or in a different frame,
009:         * a key of the form "prefix.target" can be specified, e.g.:
010:         *
011:         * c2=http://c2.com/cgi/wiki?${url}
012:         * c2.target=#blank
013:         *
014:         * @author garethc
015:         * 8/11/2002 08:53:38
016:         */package vqwiki.lex;
017:
018:        import org.apache.log4j.Logger;
019:        import vqwiki.Environment;
020:
021:        import java.io.IOException;
022:        import java.util.Properties;
023:
024:        public class LinkExtender {
025:
026:            private static final Logger logger = Logger
027:                    .getLogger(LinkExtender.class);
028:            private static final String LINKING_PROPERTIES_FILE = "/linking.properties";
029:            public static final String URL_KEYWORD = "${url}";
030:            private static Properties linkingProperties;
031:
032:            /**
033:             * Use the prefix to produce a hyperlink based on entries in the linking.properties file
034:             *
035:             * @param prefix the prefix
036:             * @param url    the parameter as given by the user
037:             * @param text
038:             * @return
039:             * @throws Exception
040:             */
041:            public static String generateLink(String prefix, String url,
042:                    String text) throws Exception {
043:                return generateLink(prefix, url, text, false);
044:            }
045:
046:            /**
047:             * Use the prefix to produce a hyperlink based on entries in the linking.properties file
048:             *
049:             * @param prefix the prefix
050:             * @param url    the parameter as given by the user
051:             * @param text
052:             * @param onlyExternalLinks true if there are only external links converted, false otherwise.
053:             * @return HTML representation of this link.
054:             * @throws Exception
055:             */
056:            public static String generateLink(String prefix, String url,
057:                    String text, boolean onlyExternalLinks) throws Exception {
058:                logger.debug("generating link for prefix=" + prefix + ",url="
059:                        + url);
060:                String displayName = null;
061:                int displayNameDelimLocation = url.indexOf('|');
062:                if (displayNameDelimLocation >= 0) {
063:                    displayName = url.substring(displayNameDelimLocation + 1);
064:                    url = url.substring(0, displayNameDelimLocation);
065:                }
066:                Properties linkingProperties = getLinkingProperties();
067:                String expansion = linkingProperties.getProperty(prefix);
068:                if (expansion == null) {
069:                    logger.info("no expansion found for link extension: "
070:                            + prefix);
071:                    return "<span class=\"extendlinkproblem\">" + text
072:                            + "</span>";
073:                }
074:                while (true) {
075:                    int urlLocation = expansion.indexOf(URL_KEYWORD);
076:                    if (urlLocation >= 0) {
077:                        StringBuffer buffer = new StringBuffer();
078:                        buffer.append(expansion.substring(0, urlLocation));
079:                        buffer.append(url);
080:                        buffer.append(expansion.substring(urlLocation
081:                                + URL_KEYWORD.length(), expansion.length()));
082:                        expansion = buffer.toString();
083:                    } else {
084:                        break;
085:                    }
086:                }
087:                String target = linkingProperties.getProperty(prefix
088:                        + ".target");
089:                StringBuffer buffer = new StringBuffer();
090:                if (expansion.startsWith("http") || expansion.startsWith("ftp")
091:                        || expansion.startsWith("mailto")
092:                        || expansion.startsWith("news")
093:                        || expansion.startsWith("telnet")
094:                        || expansion.startsWith("file")) {
095:                    buffer.append("<a class=\"externallink\" href=\"");
096:                } else {
097:                    if (onlyExternalLinks) {
098:                        if (displayName == null) {
099:                            String showPrefix = linkingProperties
100:                                    .getProperty(prefix + ".showprefix");
101:                            if (showPrefix != null
102:                                    && showPrefix.equals("false")) {
103:                                return url;
104:                            } else {
105:                                return text;
106:                            }
107:                        } else {
108:                            return displayName;
109:                        }
110:                    }
111:                    buffer.append("<a href=\"");
112:                }
113:                buffer.append(expansion);
114:                buffer.append("\" ");
115:                if (target != null) {
116:                    buffer.append("target=\"");
117:                    buffer.append(target);
118:                    buffer.append("\"");
119:                }
120:                buffer.append(">");
121:                if (displayName == null) {
122:                    String showPrefix = linkingProperties.getProperty(prefix
123:                            + ".showprefix");
124:                    if (showPrefix != null && showPrefix.equals("false")) {
125:                        buffer.append(url);
126:                    } else {
127:                        buffer.append(text);
128:                    }
129:                } else {
130:                    buffer.append(displayName);
131:                }
132:                buffer.append("</a>");
133:                return buffer.toString();
134:            }
135:
136:            private static Properties getLinkingProperties() throws IOException {
137:                if (linkingProperties == null) {
138:                    linkingProperties = new Properties();
139:                    linkingProperties.load(Environment.getInstance()
140:                            .getResourceAsStream(LINKING_PROPERTIES_FILE));
141:                }
142:                return linkingProperties;
143:            }
144:
145:            /**
146:             * Produce a link that doesn't use the prefix: scheme but can have a linking.properties entry
147:             * hyperlinks.target=...
148:             *
149:             * @param destination
150:             * @return
151:             */
152:            public static String generateNonExpandedLink(String destination)
153:                    throws IOException {
154:                StringBuffer buffer = new StringBuffer();
155:                if (destination.startsWith("http")
156:                        || destination.startsWith("ftp")
157:                        || destination.startsWith("mailto")
158:                        || destination.startsWith("news")
159:                        || destination.startsWith("telnet")
160:                        || destination.startsWith("file")) {
161:                    buffer.append("<a class=\"externallink\" href=\"");
162:                } else {
163:                    buffer.append("<a href=\"");
164:                }
165:                buffer.append(destination);
166:                buffer.append("\" ");
167:                String target = getLinkingProperties().getProperty(
168:                        "hyperlinks.target");
169:                if (target != null) {
170:                    buffer.append("target=\"");
171:                    buffer.append(target);
172:                    buffer.append("\"");
173:                }
174:                buffer.append(">");
175:                buffer.append(destination);
176:                buffer.append("</a>");
177:                return buffer.toString();
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.