Java Doc for Encodes.java in  » Ajax » zk » org » zkoss » web » servlet » http » 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 » Ajax » zk » org.zkoss.web.servlet.http 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.zkoss.web.servlet.http.Encodes

Encodes
public class Encodes (Code)
Encoding utilities for servlets.
author:
   tomyeh
See Also:   Https

Inner Class :public static interface URLEncoder


Constructor Summary
protected  Encodes()
    

Method Summary
final public static  StringBufferaddToQueryString(StringBuffer sb, Map params)
     /** Appends a map of parameters (name=value) to a query string. It returns the query string preceding with '?' if any parameter exists, or an empty string if no parameter at all.
final public static  StringBufferaddToQueryString(StringBuffer sb, String name, Object value)
     Appends a parameter (name=value) to a query string. This method automatically detects whether other query is already appended.
final public static  booleancontainsQuery(String str, String name)
     Tests whether a parameter exists in the query string.
final public static  StringencodeURI(String s)
     Does the HTTP encoding for the URI location.
final public static  StringencodeURIComponent(String s)
     Does the HTTP encoding for an URI query parameter. For example, '/' is translated to '%2F'. Both name and value must be encoded seperately.
final public static  StringencodeURL(ServletContext ctx, ServletRequest request, ServletResponse response, String uri)
     Encodes an URL. It resolves "*" contained in URI, if any, to the proper Locale, and the browser code. Refer to Servlets.locate(ServletContextServletRequestStringLocator) for details.
public static  URLEncodergetURLEncoder()
     Returns the URI encoder, or null if no uri encoder.
final public static  StringremoveFromQueryString(String str, String name)
     Remove all name/value pairs of the specified name from a string.
final public static  StringBufferremoveFromQueryString(StringBuffer sb, String name)
     Remove all name/value pairs of the specified name from a string.
final public static  StringsetToQueryString(String str, String name, Object value)
     Sets the parameter (name=value) to a query string. If the name already exists in the query string, it will be removed first. If your name has appeared in the string, it will replace your new value to the query string. Otherwise, it will append the name/value to the new string.
final public static  StringBuffersetToQueryString(StringBuffer sb, String name, Object value)
     Sets the parameter (name=value) to a query string.
final public static  StringsetToQueryString(String str, Map params)
     Sets a map of parameters (name=value) to a query string.
final public static  StringBuffersetToQueryString(StringBuffer sb, Map params)
     Sets a map of parameters (name=value) to a query string.
public static  voidsetURLEncoder(URLEncoder encoder)
     Sets the URI encoder.


Constructor Detail
Encodes
protected Encodes()(Code)




Method Detail
addToQueryString
final public static StringBuffer addToQueryString(StringBuffer sb, Map params) throws UnsupportedEncodingException(Code)
/** Appends a map of parameters (name=value) to a query string. It returns the query string preceding with '?' if any parameter exists, or an empty string if no parameter at all. Thus, you could do

request.getRequestDispatcher(
addToQueryStirng(new StringBuffer(uri), params).toString());

Since RequestDispatcher.include and forward do not allow wrapping the request and response -- see spec and the implementation of both Jetty and Catalina, we have to use this method to pass the parameters.
Parameters:
  params - a map of parameters; format: (String, Object) or(String, Object[]); null is OK




addToQueryString
final public static StringBuffer addToQueryString(StringBuffer sb, String name, Object value) throws UnsupportedEncodingException(Code)
Appends a parameter (name=value) to a query string. This method automatically detects whether other query is already appended. If so, & is used instead of ?.

The query string might contain servlet path and other parts. This method starts the searching from the first '?'. If the query string doesn't contain '?', it is assumed to be a string without query's name/value pairs.
Parameters:
  value - the value. If it is null, only name is appened.If it is an array of objects, multipe pairs of name=value[j] willbe appended.




containsQuery
final public static boolean containsQuery(String str, String name)(Code)
Tests whether a parameter exists in the query string.



encodeURI
final public static String encodeURI(String s) throws UnsupportedEncodingException(Code)
Does the HTTP encoding for the URI location. For example, '%' is translated to '%25'.

Since Encodes.encodeURL(ServletContext,ServletRequest,ServletResponse,String) will invoke this method automatically, you rarely need this method.
Parameters:
  s - the string to encode; null is OK the encoded string or null if s is null
See Also:   Encodes.encodeURIComponent




encodeURIComponent
final public static String encodeURIComponent(String s) throws UnsupportedEncodingException(Code)
Does the HTTP encoding for an URI query parameter. For example, '/' is translated to '%2F'. Both name and value must be encoded seperately. Example, encodeURIComponent(name) + '=' + encodeURIComponent(value).

Since Encodes.encodeURL(ServletContext,ServletRequest,ServletResponse,String) will not invoke this method automatically, you'd better to encode each query parameter by this method or Encodes.addToQueryString(StringBuffer,Map) .
Parameters:
  s - the string to encode; null is OK the encoded string or null if s is null
See Also:   Encodes.addToQueryString(StringBuffer,String,Object)
See Also:   Encodes.encodeURI




encodeURL
final public static String encodeURL(ServletContext ctx, ServletRequest request, ServletResponse response, String uri) throws ServletException(Code)
Encodes an URL. It resolves "*" contained in URI, if any, to the proper Locale, and the browser code. Refer to Servlets.locate(ServletContextServletRequestStringLocator) for details.

In additions, if uri starts with "/", the context path, e.g., /zkdemo, is prefixed. In other words, "/ab/cd" means it is relevant to the servlet context path (say, "/zkdemo").

If uri starts with "~abc/", it means it is relevant to a foreign Web context called /abc. And, it will be converted to "/abc/" first (without prefix request.getContextPath()).

Finally, the uri is encoded by HttpServletResponse.encodeURL.

This method invokes Encodes.encodeURI for any characters before '?'. However, it does NOT encode any character after '?'. Thus, you might hvae to invoke Encodes.encodeURIComponent or Encodes.addToQueryString(StringBuffer,Map) to encode the query parameters.

The URL Prefix and Encoder

In a sophisticated environment, e.g., Reverse Proxy, the encoded URL might have to be prefixed with some special prefix. To do that, you can implement URLEncoder , and then specify it with Encodes.setURLEncoder . When Encodes.encodeURL encodes an URL, it will check any URL encoder is defined (by Encodes.setURLEncoder . If any, it will invoke URLEncoder.encodeURL with the encoded URL to give it the last chance to post-process it, such as inserting a special prefix.
Parameters:
  request - the request; never null
Parameters:
  response - the response; never null
Parameters:
  uri - it must be null, empty or starts with "/". It might contain"*" for current browser code and Locale.
Parameters:
  ctx - the servlet context; used only if "*" is contained in uri
exception:
  IndexOutOfBoundException - if uri is empty
See Also:   org.zkoss.web.servlet.Servlets.locate
See Also:   org.zkoss.web.servlet.Servlets.generateURI




getURLEncoder
public static URLEncoder getURLEncoder()(Code)
Returns the URI encoder, or null if no uri encoder.
since:
   3.0.1
See Also:   Encodes.setURLEncoder
See Also:   Encodes.encodeURL



removeFromQueryString
final public static String removeFromQueryString(String str, String name) throws UnsupportedEncodingException(Code)
Remove all name/value pairs of the specified name from a string.

The query string might contain servlet path and other parts. This method starts the searching from the last '?'. If the query string doesn't contain '?', it is assumed to be a string without query's name/value pairs.
See Also:   Encodes.addToQueryString




removeFromQueryString
final public static StringBuffer removeFromQueryString(StringBuffer sb, String name) throws UnsupportedEncodingException(Code)
Remove all name/value pairs of the specified name from a string.
See Also:   Encodes.addToQueryString



setToQueryString
final public static String setToQueryString(String str, String name, Object value) throws UnsupportedEncodingException(Code)
Sets the parameter (name=value) to a query string. If the name already exists in the query string, it will be removed first. If your name has appeared in the string, it will replace your new value to the query string. Otherwise, it will append the name/value to the new string.

The query string might contain servlet path and other parts. This method starts the searching from the first '?'. If the query string doesn't contain '?', it is assumed to be a string without query's name/value pairs.
Parameters:
  str - The query string like xxx?xxx=xxx&xxx=xxx or null.
Parameters:
  name - The get parameter name.
Parameters:
  value - The value associated with the get parameter name. The new or result query string with your name/value.
See Also:   Encodes.addToQueryString




setToQueryString
final public static StringBuffer setToQueryString(StringBuffer sb, String name, Object value) throws UnsupportedEncodingException(Code)
Sets the parameter (name=value) to a query string. If the name already exists in the query string, it will be removed first.
See Also:   Encodes.addToQueryString



setToQueryString
final public static String setToQueryString(String str, Map params) throws UnsupportedEncodingException(Code)
Sets a map of parameters (name=value) to a query string. If the name already exists in the query string, it will be removed first.
See Also:   Encodes.addToQueryString



setToQueryString
final public static StringBuffer setToQueryString(StringBuffer sb, Map params) throws UnsupportedEncodingException(Code)
Sets a map of parameters (name=value) to a query string. If the name already exists in the query string, it will be removed first.
See Also:   Encodes.addToQueryString



setURLEncoder
public static void setURLEncoder(URLEncoder encoder)(Code)
Sets the URI encoder.

Default: null

The URI encoder is used to post process the encoded URL returned by Encodes.encodeURL .

When Encodes.encodeURL encodes an URL, it will check any URL encoder is defined (by Encodes.setURLEncoder . If any, it will invoke URLEncoder.encodeURL with the encoded URL to give it the last chance to 'manipulate' it.
since:
   3.0.1
See Also:   Encodes.encodeURL




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.