Java Doc for StringUtils.java in  » Net » openfire » org » jivesoftware » 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 » Net » openfire » org.jivesoftware.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.jivesoftware.util.StringUtils

StringUtils
public class StringUtils (Code)
Utility class to peform common String manipulation algorithms.




Method Summary
public static  Stringabbreviate(String str, int maxWidth)
     Abbreviates a string to a specified length and then adds an ellipsis if the input is greater than the maxWidth.
public static  StringchopAtWord(String string, int length)
     Intelligently chops a String at a word boundary (whitespace) that occurs at the specified index in the argument or before.
public static  StringcollectionToString(Collection<String> collection)
     Returns a collection of Strings as a comma-delimitted list of strings.
public static  StringdateToMillis(Date date)
     Formats a Date as a fifteen character long String made up of the Date's padded millisecond value.
public static  byte[]decodeBase64(String data)
     Decodes a base64 String.
Parameters:
  data - a base64 encoded String to decode.
public static  byte[]decodeHex(String hex)
     Turns a hex encoded string into a byte array.
public static  StringencodeBase64(String data)
     Encodes a String as a base64 String.
Parameters:
  data - a String to encode.
public static  StringencodeBase64(byte[] data)
     Encodes a byte array into a base64 String.
Parameters:
  data - a byte array to encode.
public static  StringencodeHex(byte[] bytes)
     Turns an array of bytes into a String representing each byte as an unsigned hex number.
public static  StringescapeForSQL(String string)
     Escapes all necessary characters in the String so that it can be used in SQL
Parameters:
  string - the string to escape.
public static  StringescapeForXML(String string)
     Escapes all necessary characters in the String so that it can be used in an XML doc.
Parameters:
  string - the string to escape.
public static  StringescapeHTMLTags(String in)
     This method takes a string which may contain HTML tags (ie, <b>, <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences.
public static  StringgetElapsedTime(long delta)
     Returns a textual representation for the time that has elapsed.
Parameters:
  delta - the elapsed time.
public static  Stringhash(String data)
     Hashes a String using the Md5 algorithm and returns the result as a String of hexadecimal numbers.
public static  Stringhash(String data, String algorithm)
     Hashes a String using the specified algorithm and returns the result as a String of hexadecimal numbers.
public static  Stringhash(byte[] bytes, String algorithm)
     Hashes a byte array using the specified algorithm and returns the result as a String of hexadecimal numbers.
public static  StringrandomString(int length)
     Returns a random String of numbers and letters (lower and upper case) of the specified length.
public static  Stringreplace(String string, String oldString, String newString)
     Replaces all instances of oldString with newString in string.
Parameters:
  string - the String to search to perform replacements on.
Parameters:
  oldString - the String that should be replaced by newString.
Parameters:
  newString - the String that will replace all instances of oldString.
public static  Stringreplace(String line, String oldString, String newString, int[] count)
     Replaces all instances of oldString with newString in line. The count Integer is updated with number of replaces.
Parameters:
  line - the String to search to perform replacements on.
Parameters:
  oldString - the String that should be replaced by newString.
Parameters:
  newString - the String that will replace all instances of oldString.
public static  StringreplaceIgnoreCase(String line, String oldString, String newString)
     Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case.
public static  StringreplaceIgnoreCase(String line, String oldString, String newString, int[] count)
     Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case. The count paramater is set to the number of replaces performed.
Parameters:
  line - the String to search to perform replacements on
Parameters:
  oldString - the String that should be replaced by newString
Parameters:
  newString - the String that will replace all instances of oldString
Parameters:
  count - a value that will be updated with the number of replacesperformed.
public static  Collection<String>stringToCollection(String string)
     Returns a comma-delimitted list of Strings as a Collection.
public static  StringstripTags(String in)
     This method takes a string and strips out all tags except
tags while still leaving the tag body intact.
Parameters:
  in - the text to be converted.
public static  String[]toLowerCaseWordArray(String text)
     Converts a line of text into an array of lower case words using a BreakIterator.wordInstance().

This method is under the Jive Open Source Software License and was written by Mark Imbriaco.

public static  StringunescapeFromXML(String string)
     Unescapes the String by converting XML escape sequences back into normal characters.
Parameters:
  string - the string to unescape.
public static  StringwordWrap(String input, int width, Locale locale)
     Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner.
public static  StringzeroPadString(String string, int length)
     Pads the supplied String with 0's to the specified length and returns the result as a new String.



Method Detail
abbreviate
public static String abbreviate(String str, int maxWidth)(Code)
Abbreviates a string to a specified length and then adds an ellipsis if the input is greater than the maxWidth. Example input:
 user1@jivesoftware.com/home
 
and a maximum length of 20 characters, the abbreviate method will return:
 user1@jivesoftware.c...
 

Parameters:
  str - the String to abbreviate.
Parameters:
  maxWidth - the maximum size of the string, minus the ellipsis. the abbreviated String, or null if the string was null.



chopAtWord
public static String chopAtWord(String string, int length)(Code)
Intelligently chops a String at a word boundary (whitespace) that occurs at the specified index in the argument or before. However, if there is a newline character before length, the String will be chopped there. If no newline or whitespace is found in string up to the index length, the String will chopped at length.

For example, chopAtWord("This is a nice String", 10) will return "This is a" which is the first word boundary less than or equal to 10 characters into the original String.
Parameters:
  string - the String to chop.
Parameters:
  length - the index in string to start looking for awhitespace boundary at. a substring of string whose length is less than orequal to length, and that is chopped at whitespace.




collectionToString
public static String collectionToString(Collection<String> collection)(Code)
Returns a collection of Strings as a comma-delimitted list of strings. a String representing the Collection.



dateToMillis
public static String dateToMillis(Date date)(Code)
Formats a Date as a fifteen character long String made up of the Date's padded millisecond value. a Date encoded as a String.



decodeBase64
public static byte[] decodeBase64(String data)(Code)
Decodes a base64 String.
Parameters:
  data - a base64 encoded String to decode. the decoded String.



decodeHex
public static byte[] decodeHex(String hex)(Code)
Turns a hex encoded string into a byte array. It is specifically meant to "reverse" the toHex(byte[]) method.
Parameters:
  hex - a hex encoded String to transform into a byte array. a byte array representing the hex String[



encodeBase64
public static String encodeBase64(String data)(Code)
Encodes a String as a base64 String.
Parameters:
  data - a String to encode. a base64 encoded String.



encodeBase64
public static String encodeBase64(byte[] data)(Code)
Encodes a byte array into a base64 String.
Parameters:
  data - a byte array to encode. a base64 encode String.



encodeHex
public static String encodeHex(byte[] bytes)(Code)
Turns an array of bytes into a String representing each byte as an unsigned hex number.

Method by Santeri Paavolainen, Helsinki Finland 1996
(c) Santeri Paavolainen, Helsinki Finland 1996
Distributed under LGPL.
Parameters:
  bytes - an array of bytes to convert to a hex-string generated hex string




escapeForSQL
public static String escapeForSQL(String string)(Code)
Escapes all necessary characters in the String so that it can be used in SQL
Parameters:
  string - the string to escape. the string with appropriate characters escaped.



escapeForXML
public static String escapeForXML(String string)(Code)
Escapes all necessary characters in the String so that it can be used in an XML doc.
Parameters:
  string - the string to escape. the string with appropriate characters escaped.



escapeHTMLTags
public static String escapeHTMLTags(String in)(Code)
This method takes a string which may contain HTML tags (ie, <b>, <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences. It will also replace LF with <br>.
Parameters:
  in - the text to be converted. the input string with the characters '<' and '>' replacedwith their HTML escape sequences.



getElapsedTime
public static String getElapsedTime(long delta)(Code)
Returns a textual representation for the time that has elapsed.
Parameters:
  delta - the elapsed time. textual representation for the time that has elapsed.



hash
public static String hash(String data)(Code)
Hashes a String using the Md5 algorithm and returns the result as a String of hexadecimal numbers. This method is synchronized to avoid excessive MessageDigest object creation. If calling this method becomes a bottleneck in your code, you may wish to maintain a pool of MessageDigest objects instead of using this method.

A hash is a one-way function -- that is, given an input, an output is easily computed. However, given the output, the input is almost impossible to compute. This is useful for passwords since we can store the hash and a hacker will then have a very hard time determining the original password.

In Jive, every time a user logs in, we simply take their plain text password, compute the hash, and compare the generated hash to the stored hash. Since it is almost impossible that two passwords will generate the same hash, we know if the user gave us the correct password or not. The only negative to this system is that password recovery is basically impossible. Therefore, a reset password method is used instead.
Parameters:
  data - the String to compute the hash of. a hashed version of the passed-in String




hash
public static String hash(String data, String algorithm)(Code)
Hashes a String using the specified algorithm and returns the result as a String of hexadecimal numbers. This method is synchronized to avoid excessive MessageDigest object creation. If calling this method becomes a bottleneck in your code, you may wish to maintain a pool of MessageDigest objects instead of using this method.

A hash is a one-way function -- that is, given an input, an output is easily computed. However, given the output, the input is almost impossible to compute. This is useful for passwords since we can store the hash and a hacker will then have a very hard time determining the original password.

In Jive, every time a user logs in, we simply take their plain text password, compute the hash, and compare the generated hash to the stored hash. Since it is almost impossible that two passwords will generate the same hash, we know if the user gave us the correct password or not. The only negative to this system is that password recovery is basically impossible. Therefore, a reset password method is used instead.
Parameters:
  data - the String to compute the hash of.
Parameters:
  algorithm - the name of the algorithm requested. a hashed version of the passed-in String




hash
public static String hash(byte[] bytes, String algorithm)(Code)
Hashes a byte array using the specified algorithm and returns the result as a String of hexadecimal numbers. This method is synchronized to avoid excessive MessageDigest object creation. If calling this method becomes a bottleneck in your code, you may wish to maintain a pool of MessageDigest objects instead of using this method.

A hash is a one-way function -- that is, given an input, an output is easily computed. However, given the output, the input is almost impossible to compute. This is useful for passwords since we can store the hash and a hacker will then have a very hard time determining the original password.

In Jive, every time a user logs in, we simply take their plain text password, compute the hash, and compare the generated hash to the stored hash. Since it is almost impossible that two passwords will generate the same hash, we know if the user gave us the correct password or not. The only negative to this system is that password recovery is basically impossible. Therefore, a reset password method is used instead.
Parameters:
  bytes - the byte array to compute the hash of.
Parameters:
  algorithm - the name of the algorithm requested. a hashed version of the passed-in String




randomString
public static String randomString(int length)(Code)
Returns a random String of numbers and letters (lower and upper case) of the specified length. The method uses the Random class that is built-in to Java which is suitable for low to medium grade security uses. This means that the output is only pseudo random, i.e., each number is mathematically generated so is not truly random.

The specified length must be at least one. If not, the method will return null.
Parameters:
  length - the desired length of the random String to return. a random String of numbers and letters of the specified length.




replace
public static String replace(String string, String oldString, String newString)(Code)
Replaces all instances of oldString with newString in string.
Parameters:
  string - the String to search to perform replacements on.
Parameters:
  oldString - the String that should be replaced by newString.
Parameters:
  newString - the String that will replace all instances of oldString. a String will all instances of oldString replaced by newString.



replace
public static String replace(String line, String oldString, String newString, int[] count)(Code)
Replaces all instances of oldString with newString in line. The count Integer is updated with number of replaces.
Parameters:
  line - the String to search to perform replacements on.
Parameters:
  oldString - the String that should be replaced by newString.
Parameters:
  newString - the String that will replace all instances of oldString. a String will all instances of oldString replaced by newString.



replaceIgnoreCase
public static String replaceIgnoreCase(String line, String oldString, String newString)(Code)
Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case.
Parameters:
  line - the String to search to perform replacements on
Parameters:
  oldString - the String that should be replaced by newString
Parameters:
  newString - the String that will replace all instances of oldString a String will all instances of oldString replaced by newString



replaceIgnoreCase
public static String replaceIgnoreCase(String line, String oldString, String newString, int[] count)(Code)
Replaces all instances of oldString with newString in line with the added feature that matches of newString in oldString ignore case. The count paramater is set to the number of replaces performed.
Parameters:
  line - the String to search to perform replacements on
Parameters:
  oldString - the String that should be replaced by newString
Parameters:
  newString - the String that will replace all instances of oldString
Parameters:
  count - a value that will be updated with the number of replacesperformed. a String will all instances of oldString replaced by newString



stringToCollection
public static Collection<String> stringToCollection(String string)(Code)
Returns a comma-delimitted list of Strings as a Collection. a Collection representing the String.



stripTags
public static String stripTags(String in)(Code)
This method takes a string and strips out all tags except
tags while still leaving the tag body intact.
Parameters:
  in - the text to be converted. the input string with all tags removed.



toLowerCaseWordArray
public static String[] toLowerCaseWordArray(String text)(Code)
Converts a line of text into an array of lower case words using a BreakIterator.wordInstance().

This method is under the Jive Open Source Software License and was written by Mark Imbriaco.
Parameters:
  text - a String of text to convert into an array of words text broken up into an array of words.




unescapeFromXML
public static String unescapeFromXML(String string)(Code)
Unescapes the String by converting XML escape sequences back into normal characters.
Parameters:
  string - the string to unescape. the string with appropriate characters unescaped.



wordWrap
public static String wordWrap(String input, int width, Locale locale)(Code)
Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner. If the width specified is less than 5 or greater than the input Strings length the string will be returned as is.

Please note that this method can be lossy - trailing spaces on wrapped lines may be trimmed.
Parameters:
  input - the String to reformat.
Parameters:
  width - the maximum length of any one line. a new String with reformatted as needed.




zeroPadString
public static String zeroPadString(String string, int length)(Code)
Pads the supplied String with 0's to the specified length and returns the result as a new String. For example, if the initial String is "9999" and the desired length is 8, the result would be "00009999". This type of padding is useful for creating numerical values that need to be stored and sorted as character data. Note: the current implementation of this method allows for a maximum length of 64.
Parameters:
  string - the original String to pad.
Parameters:
  length - the desired length of the new padded String. a new String padded with the required number of 0's.



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.