help needed with jtidy HTML encode/decode please

A

Andrew

Hello,

I need to convert a String so that international characters are
replaced with their HTML escaped equivalents. I have heard that jtidy
on sourceforge might be able to do this but the documentation is sadly
lacking. Even generating fresh javadoc info from the source I am
finding it tricky to work out what exactly I need and even if this is
library will do the trick. Has anyone here used jtidy to do this
please?

Regards,

Andrew Marlow
 
A

Andrew

seehttp://mindprod.com/products1.html#ENTITIES

Thanks, this looks like it might be what I need. I could not find the
ant build.xml or maven pom though. How do I build it?
 
R

Roedy Green

Thanks, this looks like it might be what I need. I could not find the
ant build.xml or maven pom though. How do I build it?

see com/mindprod/entities/rebuild.xml

build.xml is the one I use that prepares the distributable too.

The class files are all included, so you should not need to build.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"You can have quality software, or you can have pointer arithmetic; but you cannot have both at the same time."
~ Bertrand Meyer (born: 1950 age: 59) 1989, creator of design by contract and the Eiffel language.
 
A

Arne Vajhøj

Andrew said:
I need to convert a String so that international characters are
replaced with their HTML escaped equivalents. I have heard that jtidy
on sourceforge might be able to do this but the documentation is sadly
lacking. Even generating fresh javadoc info from the source I am
finding it tricky to work out what exactly I need and even if this is
library will do the trick. Has anyone here used jtidy to do this
please?

Surprisingly this functionality is missing in standard
Java library.

I am sure that you can find third party libraries with it.

But is is worth bothering? One for loop and one if else
should take around 2 minutes to write.

Arne
 
A

Andrew

Surprisingly this functionality is missing in standard
Java library.

I am sure that you can find third party libraries with it.

But is is worth bothering? One for loop and one if else
should take around 2 minutes to write.

Arne

I am sure Roedy's implementation is more than a for loop and and if
stmt. I think it needs to be more. I found another solution, in Apache
commons. See http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/StringEscapeUtils.html.
IMO it goes to show that this problem does come up from time to time
and apache commons has the answer.

Regards,

Andrew Marlow
 
A

Arne Vajhøj

Andrew said:
I am sure Roedy's implementation is more than a for loop and and if
stmt.
Possible.

I think it needs to be more.

If you are happy with the numeric code then no. If you want to support
names then you need an extra if statement and Map with the names in.

The core of the escape is:

public void escape(Writer writer, String str) throws IOException {
int len = str.length();
for (int i = 0; i < len; i++) {
char c = str.charAt(i);
String entityName = this.entityName(c);
if (entityName == null) {
if (c > 0x7F) {
writer.write("&#");
writer.write(Integer.toString(c, 10));
writer.write(';');
} else {
writer.write(c);
}
} else {
writer.write('&');
writer.write(entityName);
writer.write(';');
}
}
}
IMO it goes to show that this problem does come up from time to time
and apache commons has the answer.

If you only need this feature then commons lang is overkill.

If you need multiple features, then commons lang is a good
pick.

Most Jakarta libs are pretty good.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top