Archive for December, 2008
ServletException root cause
by Frank Kim on Dec.30, 2008, under Java SE
Java’s Throwable class defines the getCause() method for accessing the cause of the exception. This method returns a Throwable object which itself could have a cause. By traversing down this chain you can find the root cause of an exception.
However for some unknown reason in ServletException the getRootCause() method was added. Therefore when trying to determine the root cause of an exception in a J2EE environment one has to check what type of exception you have. I do this in the following code.
/**
* Logs all the nested exceptions for the specified exception.
*
* @param ex the exception
*/
protected void logNestedExceptions(Throwable ex) {
int count = 1;
Throwable cause = getCause(ex);
while (cause != null) {
logger.error("Nested Exception " + count, cause);
cause = getCause(cause);
count++;
}
}
/**
* Gets the cause of the exception.
*
* @param ex the exception
* @return the cause
*/
protected Throwable getCause(Throwable ex) {
Throwable cause;
if (ex instanceof ServletException) {
ServletException sex = (ServletException) ex;
cause = sex.getRootCause();
}
else {
cause = ex.getCause();
}
return cause;
}
Finally you need to configure web.xml to use your SiteMap servlet.
<servlet> <servlet-name>sitemap</servlet-name> <servlet-class>com.betweengo.servlet.SiteMap</servlet-class> </servlet> <servlet-mapping> <servlet-name>sitemap</servlet-name> <url-pattern>/sitemap.xml</url-pattern> </servlet-mapping>
Perforce Review
by Frank Kim on Dec.30, 2008, under Perforce
You can have Perforce alert you about changes to sections of the depot.
To do this using the Perforce GUI.
- Go to User -> Edit <your name>…
- Add the branches in the Reviews section that you want to monitor. For example:
//depot/main/.../pom.xml //depot/main/com/betweengo/foo/... //depot/proj/.../bar/...
Thanks to fellow developer Bill Crook for the tip.
Update: Michael Delaney, Perforce guru, pointed out that this works only if a P4Review daemon is running which it is not by default.
Extracting Text From PDF Files
by Frank Kim on Dec.23, 2008, under Adobe
From the Mac Tricks and Tips blog I saw this interesting article, Extracting Text From PDF Files.
- Open Automator, found in Applications > Utilities
- In Automator drag out “Get Selected Finder Items”, then “Extract PDF Text”. I recommend changing the output option to Rich Text.
- Save the file. Either as an application or a file.
- Test. Drag a PDF file onto the Automator file and let it do its work, after a short time you will have a text file with the extracted text.