Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > help needed with jtidy HTML encode/decode please

Reply
Thread Tools

help needed with jtidy HTML encode/decode please

 
 
Andrew
Guest
Posts: n/a
 
      08-11-2009
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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-11-2009
On Tue, 11 Aug 2009 02:30:40 -0700 (PDT), Andrew
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>I need to convert a String so that international characters are
>replaced with their HTML escaped equivalents.


see http://mindprod.com/products1.html#ENTITIES
--
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.
 
Reply With Quote
 
 
 
 
Andrew
Guest
Posts: n/a
 
      08-11-2009
On 11 Aug, 10:35, Roedy Green <(E-Mail Removed)>
wrote:
> On Tue, 11 Aug 2009 02:30:40 -0700 (PDT), Andrew
> <(E-Mail Removed)> wrote, quoted or indirectly quoted
> someone who said :
>
> >I need to convert a String so that international characters are
> >replaced with their HTML escaped equivalents.

>
> seehttp://mindprod.com/products1.html#ENTITIES
> --
> Roedy Green Canadian Mind Productshttp://mindprod.com


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?

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-11-2009
On Tue, 11 Aug 2009 08:16:23 -0700 (PDT), Andrew
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>> seehttp://mindprod.com/products1.html#ENTITIES
>> --
>> Roedy Green Canadian Mind Productshttp://mindprod.com

>
>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.
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      08-12-2009
Andrew wrote:
> 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
 
Reply With Quote
 
Andrew
Guest
Posts: n/a
 
      08-12-2009
On 12 Aug, 03:48, Arne Vajh°j <(E-Mail Removed)> wrote:
> Andrew wrote:
> > 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


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...capeUtils.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

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      08-22-2009
Andrew wrote:
> On 12 Aug, 03:48, Arne Vajh°j <(E-Mail Removed)> wrote:
>> Andrew wrote:
>>> 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.

>
> 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.

> I found another solution, in Apache
> commons. See http://commons.apache.org/lang/api-2...capeUtils.html.


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting HTML to XHTML (JTidy,OpenXML,Xerces) anupamjain@gmail.com Java 9 03-24-2006 01:35 PM
A Jtidy and XHTML question mike Java 2 09-24-2004 07:16 PM
Is there a better parser (writen in java) than Jtidy? mike Java 1 09-11-2004 12:35 PM
how to enhance the jtidy performance?!......any idea mike Java 0 08-17-2004 04:37 PM
USE OF JTIDY SYSTEM!! mike Java 0 05-05-2004 03:49 PM



Advertisments