Package org.xhtmlrenderer.util
Class GeneralUtil
java.lang.Object
org.xhtmlrenderer.util.GeneralUtil
Description of the Class
- Author:
- Patrick Wright
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DecimalFormat
Used to format an Object's hashcode into a 0-padded 10 char String, e.g. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Given an Object instance, returns just the classname with no packagestatic String
classNameOnly
(String cname) Given a String classname, returns just the classname with no packagestatic void
Dumps an exception to the console, only the last 5 lines of the stack trace.static final String
escapeHTML
(String s) Converts any special characters into their corresponding HTML entities , for example < to <.static URL
getURLFromClasspath
(Object obj, String resource) static StringBuffer
htmlEscapeSpace
(String uri) static String
static boolean
isMacOSX()
static void
static InputStream
openStreamFromClasspath
(Object obj, String resource) Description of the Methodstatic String
Description of the Methodstatic int
Parses an integer from a string using less restrictive rules about which characters we won't accept.static String
trackBack
(int cnt) Returns a String tracking the last n method calls, from oldest to most recent.static void
writeStringToFile
(String content, String encoding, String fileName)
-
Field Details
-
PADDED_HASH_FORMAT
Used to format an Object's hashcode into a 0-padded 10 char String, e.g. for 24993066 returns "0024993066"
-
-
Constructor Details
-
GeneralUtil
public GeneralUtil()
-
-
Method Details
-
openStreamFromClasspath
Description of the Method- Parameters:
obj
- PARAMresource
- PARAM- Returns:
- Returns
-
getURLFromClasspath
-
dumpShortException
Dumps an exception to the console, only the last 5 lines of the stack trace.- Parameters:
ex
- PARAM
-
trackBack
Returns a String tracking the last n method calls, from oldest to most recent. You can use this as a simple tracing mechanism to find out the calls that got to where you execute thetrackBack()
call from. Example:// called from Box.calcBorders(), line 639 String tback = GeneralUtil.trackBack(6); System.out.println(tback);
producesBoxing.layoutChildren(ln 204) BlockBoxing.layoutContent(ln 81) Boxing.layout(ln 72) Boxing.layout(ln 133) Box.totalLeftPadding(ln 306) Box.calcBorders(ln 639)
ThetrackBack()
method itself is always excluded from the dump. Note the output may not be useful if HotSpot has been optimizing the code.- Parameters:
cnt
- How far back in the call tree to go; if call tree is smaller, will be limited to call tree.- Returns:
- see desc
-
classNameOnly
Given an Object instance, returns just the classname with no package- Parameters:
o
- PARAM- Returns:
- Returns
-
classNameOnly
Given a String classname, returns just the classname with no package- Parameters:
cname
- PARAM- Returns:
- Returns
-
paddedHashCode
Description of the Method- Parameters:
o
- PARAM- Returns:
- Returns
-
isMacOSX
public static boolean isMacOSX() -
htmlEscapeSpace
-
inputStreamToString
- Throws:
IOException
-
main
-
writeStringToFile
public static void writeStringToFile(String content, String encoding, String fileName) throws IOException, UnsupportedEncodingException -
parseIntRelaxed
Parses an integer from a string using less restrictive rules about which characters we won't accept. This scavenges the supplied string for any numeric character, while dropping all others.- Parameters:
s
- The string to parse- Returns:
- The number represented by the passed string, or 0 if the string is null, empty, white-space only, contains only non-numeric characters, or simply evaluates to 0 after parsing (e.g. "0")
-
escapeHTML
Converts any special characters into their corresponding HTML entities , for example < to <. This is done using a character by character test, so you may consider other approaches for large documents. Make sure you declare the entities that might appear in this replacement, e.g. the latin-1 entities This method was taken from a code-samples website, written and hosted by Real Gagnon, at http://www.rgagnon.com/javadetails/java-0306.html.- Parameters:
s
- The String which may contain characters to escape.- Returns:
- The string with the characters as HTML entities.
-