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


001:        package vqwiki.utils;
002:
003:        import vqwiki.WikiBase;
004:        import vqwiki.Environment;
005:
006:        import javax.servlet.http.HttpServletRequest;
007:        import java.net.URLDecoder;
008:        import java.net.URLEncoder;
009:        import java.text.DecimalFormat;
010:        import java.io.UnsupportedEncodingException;
011:
012:        import org.apache.log4j.Logger;
013:
014:        /*
015:         Very Quick Wiki - WikiWikiWeb clone
016:         Copyright (C) 2001-2002 Gareth Cronin
017:
018:         This program is free software; you can redistribute it and/or modify
019:         it under the terms of the latest version of the GNU Lesser General
020:         Public License as published by the Free Software Foundation;
021:
022:         This program is distributed in the hope that it will be useful,
023:         but WITHOUT ANY WARRANTY; without even the implied warranty of
024:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025:         GNU Lesser General Public License for more details.
026:
027:         You should have received a copy of the GNU Lesser General Public License
028:         along with this program (gpl.txt); if not, write to the Free Software
029:         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
030:         */
031:
032:        public class JSPUtils {
033:
034:            /** Logger */
035:            public static final Logger logger = Logger
036:                    .getLogger(JSPUtils.class);
037:            protected static DecimalFormat decFormat = new DecimalFormat("0.00");
038:
039:            /**
040:             *
041:             */
042:            public JSPUtils() {
043:            }
044:
045:            /**
046:             * This caused problems - encoding without a charset is not well-defined
047:             * behaviour, so we'll look for a default encoding. (coljac)
048:             */
049:            public static String encodeURL(String url) {
050:                try {
051:                    if (Environment.getInstance().getForceEncoding() != null) {
052:                        return URLEncoder.encode(url, Environment.getInstance()
053:                                .getForceEncoding());
054:                    } else {
055:                        return url;
056:                    }
057:                } catch (UnsupportedEncodingException e) {
058:                    e.printStackTrace();
059:                    return url;
060:                }
061:            }
062:
063:            /**
064:             *
065:             */
066:            public static String encodeURL(String url, String charset) {
067:                try {
068:                    return URLEncoder.encode(url, charset);
069:                } catch (java.io.UnsupportedEncodingException ex) {
070:                    logger.error("unknown char set: " + charset, ex);
071:                    return null;
072:                }
073:            }
074:
075:            /**
076:             *
077:             */
078:            public static String decodeURL(String url) {
079:                try {
080:                    return URLDecoder.decode(url, Environment.getInstance()
081:                            .getStringSetting(
082:                                    Environment.PROPERTY_FILE_ENCODING));
083:                } catch (UnsupportedEncodingException e) {
084:                    logger.error("unknown char set in environment", e);
085:                    try {
086:                        return URLDecoder.decode(url, "UTF-8");
087:                    } catch (UnsupportedEncodingException e1) {
088:                        logger.fatal("unknown charset in catch-method: ", e1);
089:                        return null;
090:                    }
091:                }
092:            }
093:
094:            /**
095:             *
096:             */
097:            public static String decodeURL(String url, String charset) {
098:                try {
099:                    return URLDecoder.decode(url, charset);
100:                } catch (java.io.UnsupportedEncodingException ex) {
101:                    logger.error("unknown char set: " + charset, ex);
102:                    return null;
103:                }
104:            }
105:
106:            /**
107:             *
108:             */
109:            public static String decimalFormat(double number) {
110:                return decFormat.format(number);
111:            }
112:
113:            /**
114:             *
115:             */
116:            public static String convertToHTML(char character) {
117:                switch (character) {
118:                case ('<'):
119:                    return "&lt";
120:                case ('>'):
121:                    return "&gt";
122:                case ('&'):
123:                    return "&amp";
124:                }
125:                return String.valueOf(character);
126:            }
127:
128:            /**
129:             *
130:             */
131:            public static boolean containsSpecial(String text) {
132:                if (text.indexOf('<') >= 0) {
133:                    return true;
134:                } else if (text.indexOf('>') >= 0) {
135:                    return true;
136:                } else if (text.indexOf('&') >= 0) {
137:                    return true;
138:                }
139:                return false;
140:            }
141:
142:            /**
143:             * Create the root path for a specific WIKI without the server name.
144:             * This is useful for local redirection or local URL's (relative URL's to the server).
145:             * @param request The HttpServletRequest
146:             * @param virtualWiki The name of the current virtual Wiki
147:             * @return the root path for this viki
148:             */
149:            public static String createLocalRootPath(
150:                    HttpServletRequest request, String virtualWiki) {
151:                String contextPath = "";
152:                contextPath += request.getContextPath();
153:                if (virtualWiki == null || virtualWiki.length() < 1) {
154:                    virtualWiki = WikiBase.DEFAULT_VWIKI;
155:                }
156:                return contextPath + "/" + virtualWiki + "/";
157:            }
158:
159:            /**
160:             * Create the root path for a specific WIKI with a specific server
161:             * @param request The HttpServletRequest
162:             * @param virtualWiki The name of the current virtual Wiki
163:             * @param server the specific server given for the path.
164:             *               If it is set to "null" or an empty string, it will take
165:             *               the servername from the given request.
166:             * @return the root path for this viki
167:             */
168:            public static String createRootPath(HttpServletRequest request,
169:                    String virtualWiki, String server) {
170:                String contextPath = "";
171:                String contextScheme = request.getScheme();
172:
173:                if (server == null || server.trim().equals("")) {
174:                    contextPath = contextScheme + "://"
175:                            + request.getServerName();
176:                } else {
177:                    contextPath = contextScheme + "://" + server;
178:                }
179:                if ((contextScheme.equals("http") && request.getServerPort() != 80)
180:                        || (contextScheme.equals("https") && request
181:                                .getServerPort() != 443)) {
182:                    contextPath += ":" + request.getServerPort();
183:                }
184:                contextPath += request.getContextPath();
185:                if (virtualWiki == null || virtualWiki.length() < 1) {
186:                    virtualWiki = WikiBase.DEFAULT_VWIKI;
187:                }
188:                return contextPath + "/" + virtualWiki + "/";
189:            }
190:
191:            /**
192:             *
193:             */
194:            public static String createRedirectURL(HttpServletRequest request,
195:                    String url) {
196:                String rootPath = JSPUtils.createLocalRootPath(request,
197:                        (String) request.getAttribute("virtualWiki"));
198:                StringBuffer buffer = new StringBuffer();
199:                buffer.append(rootPath);
200:                buffer.append(url);
201:                return buffer.toString();
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.