RE: Re: BText containing markup and unicode escape sequences

"Christian Cryder" <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Hey Jake,

Good question, and I'm sending my response to both you and the list since
other people may be interested in chiming in as well.

> I was thinking about how we might make it easier on users of BText when
> they have markup they don't want to have parsed by the DOM, but do have
> some text that needs to be parsed.  Having to use the use the work around
> below is kind of annoying, especially since components are supposed to
> shield users from the DOM.  I was trying to figure out a way to
> allow users to append text to a BText and allow them to specify whether to
> allowMarkupInText for each individual string they append.
> However, I'm not sure how to implement this cleanly.

I had actually given this some thought a while back, and the idea I came up
with was to create a BTextBuffer component (where BTextBuffer relates to
BText the way StringBuffer relates to String). The basic idea would be to
create a component that simply allows you to append on a whole bunch of
individual BTexts...then you could control the allowMarkupInText on each
"segment" individually. The renderer wouldn't be that hard to build - it'd
basically just find the right spot in the DOM to bind the whole component
to, and then create an individual node for each contained BText and bind
them all to that - so the actual rendering would stay located in BText.

So that's the general thought I was kicking around a while back, but I never
got around to implementing it. I'd be curious to hear what others think...

Christian
----------------------------------------------
Christian Cryder
Internet Architect, ATMReports.com
Project Chair, BarracudaMVC - http://barracudamvc.org
----------------------------------------------
"Coffee? I could quit anytime, just not today"


> -----Original Message-----
> From: Jacob Kjome [mailto:[email protected]]
> Sent: Sunday, December 28, 2003 10:46 AM
> To: Christian Cryder
> Subject: Fwd: Re: [Barracuda] BText containing markup and unicode escape
> sequences
>
>
> Hi Christian,
>
> I was thinking about how we might make it easier on users of BText when
> they have markup they don't want to have parsed by the DOM, but do have
> some text that needs to be parsed.  Having to use the use the work around
> below is kind of annoying, especially since components are supposed to
> shield users from the DOM.  I was trying to figure out a way to
> allow users
> to append text to a BText and allow them to specify whether to
> allowMarkupInText for each individual string they append.
> However, I'm not
> sure how to implement this cleanly.  Should it be implemented at
> all?  Since rendering is done in a separate render class, we'd have to
> create a new publicly accessible method to access an object which
> holds not
> only the string data, but also the corresponding info of whether a
> particular part of the string should be added as a Text node or a
> CDATASecition.
>
> Do you think this is worth doing?  New methods I envision would be
> something like...
>
> prependText(String text);
> prependText(String text, boolean allowMarkupInText);
> appendText(String text);
> appendText(String text, boolean allowMarkupInText);
> get[ObjectThatTracksTheObjectText]();
>
> Obviously, I'm not sure what that last one should be named so
> we'd have to
> come up with something appropriate.  And for the *pendText() methods, the
> ones without a boolean argument would just call the applicable
> one with the
> boolean argument with a default of "false".
>
> Let me know if you think this is something that should be done or if we
> should just keep things the way they are and discourage users from using
> allowMarkupInText in the first place and say that they should use
> the work
> around I stated below if they really want to mix CDATA section
> behavior and
> normal Text node behavior.
>
> Jake
>
>
> >To: [email protected]
> >Subject: Re: [Barracuda] BText containing markup and unicode escape
> >   sequences
> >
> >
> >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\u03
> ba\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
> >
> >_______________________________________________
> >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.