RE: BText and Unicode-encoded characters
Timo H Jarvinen <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <[email protected]> |
Hello Christian! The "ugly" option below has a problem:
operator + cannot be applied to
org.enhydra.barracuda.core.comp.BText,org.enhydra.barracuda.core.comp.BText
The ugly option would be enough for me if it works. If there is no other
option than testing the BTextBuffer component, I can do it.
Timo
http://www.vtt.fi/
At 08:37 12.2.2003 -0500, Christian Cryder wrote:
>Hey Timo! One more thought...
>
>Another option which might actually be more elegant would be to do the same
>thing I discussed in my previous email, but to actually create a new
>BTextBuffer component. So you would just do something like this:
>
> BTextBuffer btb = new BTextBuffer(vc);
> btb.appendMarkup("<span>");
> btb.appendText("\u03a3\u03c5\u03bd");
> btb.appendMarkup("</span>");
> return btb;
>
>This component would then delegate to Btext objects accordingly, but it
>would all be behind the scenes. Obviously, adding a new component would
>require a little work in the barracuda.core packages, but I'd be willing to
>write this if you'd be willing to help test it. I can certainly think of
>places something like this might prove useful...
>
>Let me know what you think...
>
>Christian
>----------------------------------------------
>Christian Cryder [[email protected]]
>Internet Architect, ATMReports.com
>Barracuda - http://barracudamvc.org
>----------------------------------------------
>"Coffee? I could quit anytime, just not today"
>
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]]On Behalf Of Christian Cryder
> > Sent: Wednesday, February 12, 2003 8:21 AM
> > To: [email protected]
> > Subject: RE: [Barracuda] BText and Unicode-encoded characters
> >
> >
> > Another option, albeit somewhat ugly, would be to do inline your
> > BTexts like
> > this:
> >
> > //CDATA
> > BText btext1 = new BText("<span>");
> > btext1.setDefaultViewContext(vc);
> > btext1.setAllowMarkupInText(true);
> >
> > //encoded text
> > BText btext2 = new BText("\u03a3\u03c5\u03bd");
> > btext3.setDefaultViewContext(vc);
> > btext2.setAllowMarkupInText(false);
> >
> > //more CDATA
> > BText btext3 = new BText("</span>");
> > btext3.setDefaultViewContext(vc);
> > btext3.setAllowMarkupInText(true);
> >
> > //the final text component that combines them
> > BText btext4 = new BText(btext1 + btext2 + btext3);
> > btext4.setAllowMarkupInText(true);
> > return btext4;
> >
> > Now obviously, this is a bit of a pain, but I'm pretty sure this
> > will work.
> > The setDefaultViewContext(vc) is necessary so that when you call the
> > components' toString() method down in the contructor of btext4, they will
> > properly render.
> >
> > You could probably abstract it a bit using helper/utility methods to get
> > your implementation down to a couple lines of code...
> >
> > return getText((getText("<span>", vc, true) +
> > getText("\u03a3\u03c5\u03bd", vc, false) +
> > getText("</span>", vc, true)), vc, true);
> >
> > public static BText getText(String text, ViewContext vc, boolean
> > allowMarkup) {
> > BText btext = new BText(text);
> > btext.setDefaultViewContext(vc);
> > btext.setAllowMarkupInText(allowMarkup);
> > return btext;
> > }
> >
> > Let me know if any of this doesn't make sense...
> >
> > Christian
> > ----------------------------------------------
> > Christian Cryder [[email protected]]
> > Internet Architect, ATMReports.com
> > Barracuda - http://barracudamvc.org
> > ----------------------------------------------
> > "Coffee? I could quit anytime, just not today"
> >
> > > -----Original Message-----
> > > From: [email protected]
> > > [mailto:[email protected]]On Behalf Of Richard Kunze
> > > Sent: Wednesday, February 12, 2003 6:37 AM
> > > To: [email protected]
> > > Subject: Re: [Barracuda] BText and Unicode-encoded characters
> > >
> > >
> > > On Wednesday 12 February 2003 09:41, Timo H Jarvinen wrote:
> > > > When setAllowMarkupInText(false), it works. Unfortunately, we
> > are using
> > > > BText to add content with arbitrary markup to the page. This kind of
> > > > content would be difficult to render using standard Barracuda
> > > components.
> > > > Therefore, we really need setAllowMarkupInText(true).
> > > >
> > > > Shawn Wilson wrote:
> > > > Okay so that's one point. Now, it sounds like Timo wants
> > something like
> > > > "\u03a3\u03c5" to translate into the HTML entities of "Συ".
> > > >
> > > > That's exactly what I would like to have.
> > >
> > > Sounds a bit like you want to eat your cake and keep it too :-)
> > >
> > > As I've said in a previous mail, a CDATA section (which doesn't
> > > exist in HTML
> > > so XMLC can recycle it for that purpose) in the DOM tells the XMLC HTML
> > > renderer to output that particular DOM node as is, without
> > > applying the usual
> > > automatic escapes. On the one hand, this means that "<" and ">" aren't
> > > escaped to "<" and ">", which allows you to put markup in a CDATA
> > > section. On the other hand, it means that characters that can't
> > > be displayed
> > > in the character set used for output aren't escaped to the
> > > corresponding HTML
> > > entities.
> > >
> > > To get it working nonetheless, you've got three (well, two
> > > realistic and one
> > > that's probably not going to work :-) options:
> > >
> > > - Don't use allowMarkupInText(true), but instead parse your
> > > markup snippets
> > > into small DOM trees and insert those into the page
> > > - Escape the offending characters by hand.
> > > org.enhydra.xml.io.HTMLEntities
> > > provides a couple of convenience methods for converting
> > > characters to named
> > > entities, and you can get the code for converting characters to numeric
> > > entities from org.enhydra.xml.io.HTMLFormatter.writeCharacter().
> > > - Make sure all browsers accessing your application accept UTF-8
> > > as transport
> > > encoding (most modern browsers do, but must be configured to do
> > > so), and tell
> > > Barracuda to use UTF-8 for sending HTML pages.
> > >
> > > Hope this helps,
> > >
> > > Richard
> > >
> > > --
> > > Richard Kunze
> > >
> > > [ t]ivano Software, Bahnhofstr. 18, 63263 Neu-Isenburg
> > > Tel.: +49 6102 80 99 07 - 0, Fax.: +49 6102 80 99 07 - 1
> > > http://www.tivano.de, [email protected]
> > >
> >
> > _______________________________________________
> > Barracuda mailing list
> > [email protected]
> > http://barracudamvc.org/lists/listinfo/barracuda
>
>_______________________________________________
>Barracuda mailing list
>[email protected]
>http://barracudamvc.org/lists/listinfo/barracuda