help needed with jtidy HTML encode/decode please

Discussion in 'Java' started by Andrew, Aug 11, 2009.

  1. Andrew

    Andrew Guest

    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
    Andrew, Aug 11, 2009
    #1
    1. Advertising

  2. Andrew

    Roedy Green Guest

    On Tue, 11 Aug 2009 02:30:40 -0700 (PDT), Andrew
    <> 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.
    Roedy Green, Aug 11, 2009
    #2
    1. Advertising

  3. Andrew

    Andrew Guest

    On 11 Aug, 10:35, Roedy Green <>
    wrote:
    > On Tue, 11 Aug 2009 02:30:40 -0700 (PDT), Andrew
    > <> 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?
    Andrew, Aug 11, 2009
    #3
  4. Andrew

    Roedy Green Guest

    On Tue, 11 Aug 2009 08:16:23 -0700 (PDT), Andrew
    <> 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.
    Roedy Green, Aug 11, 2009
    #4
  5. Andrew

    Arne Vajhøj Guest

    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
    Arne Vajhøj, Aug 12, 2009
    #5
  6. Andrew

    Andrew Guest

    On 12 Aug, 03:48, Arne Vajhøj <> 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.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
    Andrew, Aug 12, 2009
    #6
  7. Andrew

    Arne Vajhøj Guest

    Andrew wrote:
    > On 12 Aug, 03:48, Arne Vajhøj <> 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.4/org/apache/commons/lang/StringEscapeUtils.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
    Arne Vajhøj, Aug 23, 2009
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MNQ
    Replies:
    2
    Views:
    642
    Eyck Jentzsch
    May 18, 2004
  2. Harald Kirsch
    Replies:
    2
    Views:
    2,111
    Harald Kirsch
    Aug 28, 2003
  3. Damir Hakimov

    base64.encode and decode not correct

    Damir Hakimov, Aug 16, 2005, in forum: Python
    Replies:
    1
    Views:
    341
  4. Replies:
    7
    Views:
    1,167
  5. Newbie
    Replies:
    4
    Views:
    217
    Newbie
    Jul 31, 2004
Loading...

Share This Page