Java Doc for CmsEncoder.java in  » Content-Management-System » opencms » org » opencms » i18n » 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 » Content Management System » opencms » org.opencms.i18n 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.opencms.i18n.CmsEncoder

CmsEncoder
final public class CmsEncoder (Code)
The OpenCms CmsEncoder class provides static methods to decode and encode data.

The methods in this class are substitutes for java.net.URLEncoder.encode() and java.net.URLDecoder.decode(). Use the methods from this class in all OpenCms core classes to ensure the encoding is always handled the same way.

The de- and encoding uses the same coding mechanism as JavaScript, special characters are replaced with %hex where hex is a two digit hex number.

Note: On the client side (browser) instead of using corresponding escape and unescape JavaScript functions, better use encodeURIComponent and decodeURIComponent functions which are work properly with unicode characters. These functions are supported in IE 5.5+ and NS 6+ only.


author:
   Alexander Kandzior
version:
   $Revision: 1.25 $
since:
   6.0.0



Field Summary
final public static  StringENCODING_ISO_8859_1
     Constant for the standard ISO-8859-1 encoding.
final public static  StringENCODING_US_ASCII
     Constant for the standard US-ASCII encoding.
final public static  StringENCODING_UTF_8
     Constant for the standard UTF-8 encoding.

Default encoding for JavaScript decodeUriComponent methods is UTF-8 by w3c standard.



Method Summary
public static  StringadjustHtmlEncoding(String input, String encoding)
     Adjusts the given String by making sure all characters that can be displayed in the given charset are contained as chars, whereas all other non-displayable characters are converted to HTML entities.

Just calls CmsEncoder.decodeHtmlEntities(String,String) first and feeds the result to CmsEncoder.encodeHtmlEntities(String,String) .

public static  byte[]changeEncoding(byte[] input, String oldEncoding, String newEncoding)
    
public static  StringcreateString(byte[] bytes, String encoding)
    
public static  Stringdecode(String source)
    
public static  Stringdecode(String source, String encoding)
     This method is a substitute for URLDecoder.decode(). Use this in all OpenCms core classes to ensure the encoding is always handled the same way.

In case you don't know what encoding to use, set the value of the encoding parameter to null.

public static  StringdecodeHtmlEntities(String input, String encoding)
    
public static  StringdecodeParameter(String input)
    
public static  Stringencode(String source)
    
public static  Stringencode(String source, String encoding)
     This method is a substitute for URLEncoder.encode(). Use this in all OpenCms core classes to ensure the encoding is always handled the same way.

In case you don't know what encoding to use, set the value of the encoding parameter to null.

public static  StringencodeHtmlEntities(String input, String encoding)
    
public static  StringencodeJavaEntities(String input, String encoding)
    
public static  StringencodeParameter(String input)
     Encodes a string used as parameter in an uri in a way independent of other encodings/decodings applied later.

Used to ensure that GET parameters are not wrecked by wrong or incompatible configuration settings.

public static  Stringescape(String source, String encoding)
     Encodes a String in a way that is compatible with the JavaScript escape function.
public static  StringescapeHtml(String source)
    
public static  StringescapeNonAscii(String source)
    
public static  StringescapeWBlanks(String source, String encoding)
     Encodes a String in a way that is compatible with the JavaScript escape function.
public static  StringescapeXml(String source)
    
public static  StringescapeXml(String source, boolean doubleEscape)
    
public static  StringlookupEncoding(String encoding, String fallback)
     Checks if a given encoding name is actually supported, and if so resolves it to it's canonical name, if not it returns the given fallback value.

Charsets have a set of aliases.

public static  StringredecodeUriComponent(String input)
     Re-decodes a String that has not been correctly decoded and thus has scrambled character bytes.

This is an equivalent to the JavaScript "decodeURIComponent" function.

public static  Stringunescape(String source, String encoding)
    

Field Detail
ENCODING_ISO_8859_1
final public static String ENCODING_ISO_8859_1(Code)
Constant for the standard ISO-8859-1 encoding.



ENCODING_US_ASCII
final public static String ENCODING_US_ASCII(Code)
Constant for the standard US-ASCII encoding.



ENCODING_UTF_8
final public static String ENCODING_UTF_8(Code)
Constant for the standard UTF-8 encoding.

Default encoding for JavaScript decodeUriComponent methods is UTF-8 by w3c standard.






Method Detail
adjustHtmlEncoding
public static String adjustHtmlEncoding(String input, String encoding)(Code)
Adjusts the given String by making sure all characters that can be displayed in the given charset are contained as chars, whereas all other non-displayable characters are converted to HTML entities.

Just calls CmsEncoder.decodeHtmlEntities(String,String) first and feeds the result to CmsEncoder.encodeHtmlEntities(String,String) .


Parameters:
  input - the input to adjust the HTML encoding for
Parameters:
  encoding - the charset to encode the result with\ the input with the decoded/encoded HTML entities




changeEncoding
public static byte[] changeEncoding(byte[] input, String oldEncoding, String newEncoding)(Code)
Changes the encoding of a byte array that represents a String.


Parameters:
  input - the byte array to convert
Parameters:
  oldEncoding - the current encoding of the byte array
Parameters:
  newEncoding - the new encoding of the byte array the byte array encoded in the new encoding




createString
public static String createString(byte[] bytes, String encoding)(Code)
Creates a String out of a byte array with the specified encoding, falling back to the system default in case the encoding name is not valid.

Use this method as a replacement for new String(byte[], encoding) to avoid possible encoding problems.


Parameters:
  bytes - the bytes to decode
Parameters:
  encoding - the encoding scheme to use for decoding the bytes the bytes decoded to a String




decode
public static String decode(String source)(Code)
Decodes a String using UTF-8 encoding, which is the standard for http data transmission with GET ant POST requests.


Parameters:
  source - the String to decode String the decoded source String




decode
public static String decode(String source, String encoding)(Code)
This method is a substitute for URLDecoder.decode(). Use this in all OpenCms core classes to ensure the encoding is always handled the same way.

In case you don't know what encoding to use, set the value of the encoding parameter to null. This method will then default to UTF-8 encoding, which is probably the right one.


Parameters:
  source - The string to decode
Parameters:
  encoding - The encoding to use (if null, the system default is used) The decoded source String




decodeHtmlEntities
public static String decodeHtmlEntities(String input, String encoding)(Code)
Decodes HTML entity references like € that are contained in the String to a regular character, but only if that character is contained in the given encodings charset.


Parameters:
  input - the input to decode the HTML entities in
Parameters:
  encoding - the charset to decode the input for the input with the decoded HTML entities
See Also:   CmsEncoder.encodeHtmlEntities(String,String)




decodeParameter
public static String decodeParameter(String input)(Code)
Decodes a string used as parameter in an uri in a way independent of other encodings/decodings applied before.


Parameters:
  input - the encoded parameter string the decoded parameter string
See Also:   CmsEncoder.encodeParameter(String)




encode
public static String encode(String source)(Code)
Encodes a String using UTF-8 encoding, which is the standard for http data transmission with GET ant POST requests.


Parameters:
  source - the String to encode String the encoded source String




encode
public static String encode(String source, String encoding)(Code)
This method is a substitute for URLEncoder.encode(). Use this in all OpenCms core classes to ensure the encoding is always handled the same way.

In case you don't know what encoding to use, set the value of the encoding parameter to null. This method will then default to UTF-8 encoding, which is probably the right one.


Parameters:
  source - the String to encode
Parameters:
  encoding - the encoding to use (if null, the system default is used) the encoded source String




encodeHtmlEntities
public static String encodeHtmlEntities(String input, String encoding)(Code)
Encodes all characters that are contained in the String which can not displayed in the given encodings charset with HTML entity references like €.

This is required since a Java String is internally always stored as Unicode, meaning it can contain almost every character, but the HTML charset used might not support all such characters.


Parameters:
  input - the input to encode for HTML
Parameters:
  encoding - the charset to encode the result with the input with the encoded HTML entities
See Also:   CmsEncoder.decodeHtmlEntities(String,String)




encodeJavaEntities
public static String encodeJavaEntities(String input, String encoding)(Code)
Encodes all characters that are contained in the String which can not displayed in the given encodings charset with Java escaping like \u20ac.

This can be used to escape values used in Java property files.


Parameters:
  input - the input to encode for Java
Parameters:
  encoding - the charset to encode the result with the input with the encoded Java entities




encodeParameter
public static String encodeParameter(String input)(Code)
Encodes a string used as parameter in an uri in a way independent of other encodings/decodings applied later.

Used to ensure that GET parameters are not wrecked by wrong or incompatible configuration settings. In order to ensure this, the String is first encoded with html entities for any character that cannot encoded in US-ASCII; additionally, the plus sign is also encoded to avoid problems with the white-space replacer. Finally, the entity prefix is replaced with characters not used as delimiters in urls.


Parameters:
  input - the parameter string the encoded parameter string




escape
public static String escape(String source, String encoding)(Code)
Encodes a String in a way that is compatible with the JavaScript escape function.
Parameters:
  source - The text to be encoded
Parameters:
  encoding - the encoding type The JavaScript escaped string



escapeHtml
public static String escapeHtml(String source)(Code)
Escapes special characters in a HTML-String with their number-based entity representation, for example & becomes &.

A character num is replaced if
((ch != 32) && ((ch > 122) || (ch < 48) || (ch == 60) || (ch == 62)))


Parameters:
  source - the String to escape String the escaped String
See Also:   CmsEncoder.escapeXml(String)




escapeNonAscii
public static String escapeNonAscii(String source)(Code)
Escapes non ASCII characters in a HTML-String with their number-based entity representation, for example & becomes &#38;.

A character num is replaced if
(ch > 255)


Parameters:
  source - the String to escape String the escaped String
See Also:   CmsEncoder.escapeXml(String)




escapeWBlanks
public static String escapeWBlanks(String source, String encoding)(Code)
Encodes a String in a way that is compatible with the JavaScript escape function. Multiple blanks are encoded _multiply _with %20.


Parameters:
  source - The text to be encoded
Parameters:
  encoding - the encoding type The JavaScript escaped string




escapeXml
public static String escapeXml(String source)(Code)
Escapes a String so it may be printed as text content or attribute value in a HTML page or an XML file.

This method replaces the following characters in a String:

  • < with &lt;
  • > with &gt;
  • & with &amp;
  • " with &quot;


Parameters:
  source - the string to escape the escaped string
See Also:   CmsEncoder.escapeHtml(String)




escapeXml
public static String escapeXml(String source, boolean doubleEscape)(Code)
Escapes a String so it may be printed as text content or attribute value in a HTML page or an XML file.

This method replaces the following characters in a String:

  • < with &lt;
  • > with &gt;
  • & with &amp;
  • " with &quot;


Parameters:
  source - the string to escape
Parameters:
  doubleEscape - if false, all entities that already are escaped are left untouched the escaped string
See Also:   CmsEncoder.escapeHtml(String)




lookupEncoding
public static String lookupEncoding(String encoding, String fallback)(Code)
Checks if a given encoding name is actually supported, and if so resolves it to it's canonical name, if not it returns the given fallback value.

Charsets have a set of aliases. For example, valid aliases for "UTF-8" are "UTF8", "utf-8" or "utf8". This method resolves any given valid charset name to it's "canonical" form, so that simple String comparison can be used when checking charset names internally later.

Please see http://www.iana.org/assignments/character-sets for a list of valid charset alias names.


Parameters:
  encoding - the encoding to check and resolve
Parameters:
  fallback - the fallback encoding scheme the resolved encoding name, or the fallback value




redecodeUriComponent
public static String redecodeUriComponent(String input)(Code)
Re-decodes a String that has not been correctly decoded and thus has scrambled character bytes.

This is an equivalent to the JavaScript "decodeURIComponent" function. It converts from the default "UTF-8" to the currently selected system encoding.


Parameters:
  input - the String to convert String the converted String




unescape
public static String unescape(String source, String encoding)(Code)
Decodes a String in a way that is compatible with the JavaScript unescape function.


Parameters:
  source - The String to be decoded
Parameters:
  encoding - the encoding type The JavaScript unescaped String




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.