Re: BText containing markup and unicode escape sequences

Jacob Kjome <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Note that setAllowMarkupInText(true) simply means that the content of the 
BText will passed into the document via a CDATA section.  All rules of 
CDATA sections apply here.  This is somewhat of a hack, but necessary for 
some situations.  The problem with it is that you must be diligent in 
making sure you are passing in valid markup, otherwise you end up with an 
non well formed document.

One workaround might be to create a Text node in which you pass in the 
special chars.  Then grab the value of that text node to mix in with the 
markup such as....

Node node = 
document.createTextNode("\u03a3\u03bf\u03c5\u03b7\u03b4\u03b9\u03ba\u03ac");
BText b = new BText();
b.setAllowMarkupInText(true);
b.setText("<b>"+node.getNodeValue()+"</b>");

Then again, you could also create a node for the <b> tag, append the text 
node as a child of that, and pass the node back rather than a BText.  In 
fact, this might be a better idea to do since it guarantees you well formed 
markup.  I would reserve setAllowMarkupInText(true) for times when you 
can't very well control the text you are passing back such as markup+text 
stored in the database.  In the current case, you know what your markup and 
text are, so you should probably just deal with them in the DOM rather that 
messing with the hacky CDATA section.

Just a thought.... BText might be enhanced to allow appended text where 
each appended piece of markup/text is treated individually for using a 
CDATA section or not.  That allow developers to continue to use BText and 
not have to resort to dealing with the underlying DOM interfaces that BText 
was meant to shield them from.


Jake

At 03:50 PM 12/22/2003 +0200, you wrote:
>Hello!
>
>I'm returning a BText containig some markup and unicode escape sequences 
>(greek chars). If I setAllowMarkupInText(false) the greek text is 
>displayed correctly but the markup is of course changed to &lt; etc...
>Since I have to include some markup I setAllowMarkupInText(true), but now 
>the greek char are all displayed as questionmarks.
>
>Have anybody had the same problem? I would really appreciate any hints on 
>how to get around this problem!
>
>
>simple example:
>
>public Object getItem(String key) {
>
>BText b = new BText();
>b.setAllowMarkupInText(true); 
>b.setText("<b>\u03a3\u03bf\u03c5\u03b7\u03b4\u03b9\u03ba\u03ac</b>");
>return b;
>
>}
>
>
>
>Regards,
>Magnus
>
>_______________________________________________
>Barracuda mailing list
>[email protected]
>http://barracudamvc.org/lists/listinfo/barracuda
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.