tags:

views:

1497

answers:

3

I'm trying to use the StringEscapeUtils.escapeXML() function from org.apache.commons.lang...

There are two versions of that function, one which expects (Writer, String) and one which just expects (String)....

http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html#escapeXml(java.lang.String)

I'm trying to use the version that just expects the String parameter without the Writer, but Java is complaining that I've not given it a Writer.

How do I use this in my program so that I don't need a Writer?

String escXml = StringEscapeUtils.escapeXml(attr.get());
xml = xml.concat("<"+attr.getID()+">"+escXml+"</"+attr.getID()+">");

I've also tried just doing it inline in the string itself.

xml = xml.concat("<"+attr.getID()+">"+StringEscapeUtils.escapeXml(attr.get())+"</"+attr.getID()+">");

Both of these attempts have given me the error about it expecting the Writer though. Can anyone help me with this?

Thanks, Matt

A: 

What exactly is the compiler error message?

is it possible that you're using a different version of the commons library that does not have the 1-parameter method?

Michael Borgwardt
A: 

I've pasted the error below. This is in some JSP and Jetty is what is throwing the error.

I copied the commons-lang-2.4.jar file into Jetty so I think I'm using the right one. Perhaps not?

Caused by:

org.apache.jasper.JasperException: PWC6033: Unable to compile class for JSP

PWC6197: An error occurred at line: 9 in the jsp file: /zimlet/_dev/edu_wiu_directory/ldap.jsp PWC6199: Generated servlet error: The method escapeXml(Writer, String) in the type StringEscapeUtils is not applicable for the arguments (Object)

at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:107) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:280) at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:347) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:400) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:477) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:371) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093) at com.zimbra.cs.zimlet.ZimletFilter.doFilter(ZimletFilter.java:202) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.mortbay.servlet.UserAgentFilter.doFilter(UserAgentFilter.java:81) at org.mortbay.servlet.GzipFilter.doFilter(GzipFilter.java:132) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:716) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:406) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139) at org.mortbay.jetty.handler.rewrite.RewriteHandler.handle(RewriteHandler.java:350) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139) at org.mortbay.jetty.Server.handle(Server.java:313) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396) at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)

Matt
As matt b said, you pass to the method an Object, not an String. Try attr.get().toString(). And, please don't use an answer, if you react to answers, modify your question.
Mnementh
Thanks...that's what I needed. Sorry about posting my response in an answer...Matt
Matt
+5  A: 

The error message is telling you that you are passing an Object into the method, not a String.

If you are sure that the Object is a String, then you'll need to cast it to a String first.

If this doesn't work, please post the actual code that is giving you trouble.

matt b