Source Code Cross Referenced for ResponseUtils.java in  » GIS » GeoServer » org » geoserver » ows » util » 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 » GIS » GeoServer » org.geoserver.ows.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
002:         * This code is licensed under the GPL 2.0 license, availible at the root
003:         * application directory.
004:         */
005:        package org.geoserver.ows.util;
006:
007:        import java.io.IOException;
008:        import java.io.Writer;
009:
010:        /**
011:         * Utility class performing operations related to http respones.
012:         *
013:         * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
014:         *
015:         */
016:        public class ResponseUtils {
017:            /**
018:             * Parses the passed string, and encodes the special characters (used in
019:             * xml for special purposes) with the appropriate codes. e.g. '<' is
020:             * changed to '&lt;'
021:             *
022:             * @param inData The string to encode into xml.
023:             *
024:             * @return the encoded string. Returns null, if null is passed as argument
025:             *
026:             */
027:            public static String encodeXML(String inData) {
028:                //return null, if null is passed as argument
029:                if (inData == null) {
030:                    return null;
031:                }
032:
033:                //if no special characters, just return
034:                //(for optimization. Though may be an overhead, but for most of the
035:                //strings, this will save time)
036:                if ((inData.indexOf('&') == -1) && (inData.indexOf('<') == -1)
037:                        && (inData.indexOf('>') == -1)
038:                        && (inData.indexOf('\'') == -1)
039:                        && (inData.indexOf('\"') == -1)) {
040:                    return inData;
041:                }
042:
043:                //get the length of input String
044:                int length = inData.length();
045:
046:                //create a StringBuffer of double the size (size is just for guidance
047:                //so as to reduce increase-capacity operations. The actual size of
048:                //the resulting string may be even greater than we specified, but is
049:                //extremely rare)
050:                StringBuffer buffer = new StringBuffer(2 * length);
051:
052:                char charToCompare;
053:
054:                //iterate over the input String
055:                for (int i = 0; i < length; i++) {
056:                    charToCompare = inData.charAt(i);
057:
058:                    //if the ith character is special character, replace by code
059:                    if (charToCompare == '&') {
060:                        buffer.append("&amp;");
061:                    } else if (charToCompare == '<') {
062:                        buffer.append("&lt;");
063:                    } else if (charToCompare == '>') {
064:                        buffer.append("&gt;");
065:                    } else if (charToCompare == '\"') {
066:                        buffer.append("&quot;");
067:                    } else if (charToCompare == '\'') {
068:                        buffer.append("&apos;");
069:                    } else {
070:                        buffer.append(charToCompare);
071:                    }
072:                }
073:
074:                //return the encoded string
075:                return buffer.toString();
076:            }
077:
078:            /**
079:             * Writes <CODE>string</CODE> into writer, escaping &, ', ", <, and >
080:             * with the XML excape strings.
081:             */
082:            public static void writeEscapedString(Writer writer, String string)
083:                    throws IOException {
084:                for (int i = 0; i < string.length(); i++) {
085:                    char c = string.charAt(i);
086:
087:                    if (c == '<') {
088:                        writer.write("&lt;");
089:                    } else if (c == '>') {
090:                        writer.write("&gt;");
091:                    } else if (c == '&') {
092:                        writer.write("&amp;");
093:                    } else if (c == '\'') {
094:                        writer.write("&apos;");
095:                    } else if (c == '"') {
096:                        writer.write("&quot;");
097:                    } else {
098:                        writer.write(c);
099:                    }
100:                }
101:            }
102:
103:            /**
104:             * Appends a query string to a url.
105:             * <p>
106:             * This method checks <code>url</code> to see if the appended query string requires a '?' or
107:             * '&' to be prepended.
108:             * </p>
109:             *
110:             * @param url The base url.
111:             * @param queryString The query string to be appended, should not contain the '?' character.
112:             *
113:             * @return A full url with the query string appended.
114:             * 
115:             * TODO: remove this and replace with Requetss.appendQueryString
116:             */
117:            public static String appendQueryString(String url,
118:                    String queryString) {
119:                if (url.endsWith("?") || url.endsWith("&")) {
120:                    return url + queryString;
121:                }
122:
123:                if (url.indexOf('?') != -1) {
124:                    return url + "&" + queryString;
125:                }
126:
127:                return url + "?" + queryString;
128:            }
129:
130:            /**
131:             * Strips the query string off a request url.
132:             *
133:             * @param url The url.
134:             *
135:             * @return The original minus the query string.
136:             */
137:            public static String stripQueryString(String url) {
138:                int index = url.indexOf('?');
139:
140:                if (index == -1) {
141:                    return url;
142:                }
143:
144:                return url.substring(0, index);
145:            }
146:
147:            /**
148:             * Appends a path tpo a url.
149:             * <p>
150:             * This method checks <code>url</code> to see if the appended path requires a '/' to be
151:             * prepended.
152:             * </p>
153:             * @param url The base url.
154:             * @param path The path to be appended to the url.
155:             *
156:             * @return The full url with the path appended.
157:             * TODO: remove this and replace with Requetss.appendContextPath
158:             */
159:            public static String appendPath(String url, String path) {
160:                if (path.startsWith("/")) {
161:                    path = path.substring(1);
162:                }
163:
164:                return url.endsWith("/") ? (url + path) : (url + "/" + path);
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.