Wednesday, September 9, 2009, 10:38:59 PM, YR Chen wrote:
[snip]
> Sorry, I meant ${node.@@markup}. Following the source in FreeMarker 2.3.15:
[snip]
> That function only encodes '<' and '&'.
And since that outputs markup (never attribute values), escaping '>'
is indeed not needed. (Actually, I just realized, there is a bug there
that you didn't run into: it should still escape "]]>"-s.)
[snip]
> I haven't read the XML spec closely, so this might just be a parser
> bug, but I had the javax.xml.xpath XML parser die on me with a
> serialized XML string like this: "<formula>x > 3</formula>".
Huh? What kind of XML parser is that which doesn't respect the basic
rules of XML? Sounds like it's time to trash it...
[snip]
> Well FreeMarker does have the capability of treating template markup as data:
>
> [#assign markup]
> <breadcrumb>foo</breadcrumb>
> <breadcrumb>bar</breadcrumb>
> [/#assign]
In this example it just treated the XML as plain text...
> So it's not that big of a step to want to treat that data as XML:
>
> [#list xml(markup).breadcrumb as breadcrumb]
> ${breadcrumb.@@nested_markup}
> [/#list]
Well, the example before this didn't put me closer to the solution...
anyway, surely this xml(...) thing doable. I wonder if Jonathan
planned to add something like this in 2.4.
[snip]
>>> As an aside, when looking through the FreeMarker code base, I get the feeling
>>> that either this was designed in the very early ages of Java
>>
>> It's J2SE 1.2 compatible...
>>
>>> and is constrained from being modernized for legacy reasons, or it
>>> suffers from a serious case of "not-invented-here" syndrome.
>
>> What cases of that exactly you have seen?
[snip]
>
> For example, the mismatch between TemplateModel objects and Java
> collections. I understand the need for an object wrapper, but I
> don't get why we need things like TemplateHashModel for Maps or
> TemplateSequenceModel for Lists - why couldn't the Map or List
> interfaces be used directly here?
I guess because they are way too complex to implement (if you want to
implement a custom wrapper class), they don't require that items are
TemplateModel-s (sure, you could extend the interface with
getTemplateModel or like, but then you again had to wrap HashMap-s and
like, so...), and they don't support multi-type values (like in
FreeMarker you can have a value that is a hash and a sequence and a
string at once; this is something the XML wrapper happens to use
extensively). (Actually, the List and Map interfaces are not
compatible, because the size() method of them clashes, so you couldn't
even have a list+map type, which is really a loss... it's so often
useful.) (Not to mention, that as an FM 1.x legacy, hashes only accept
String keys... because, back then they only meant to be collections of
variables, and variable names are strings.)
Anyway, I often wonder wether the whole intrusive-object-wrapping
business bought as much advantage than it caused headache... Surely
Attila or someone else will stand up pointing to powerful features
that wouldn't be possible without it, but then maybe X users use
those, and 10*X users suffer because of the difficulties in the more
common scenarios... (Also I'm not at all sure there is not another
way, like instead of replacing the Java type-system extending it.
Somehow... um. Anyway, most certainly such things won't happen in
FreeMarker, due to backward-compatibility... maybe in a next-gen
template engine we make.)
> It's also doesn't handle Sets well - the default object wrapper
> wraps it in a TemplateSequenceModel, even though it doesn't have an
> indexing method, via an internal ArrayList. FreeMarker should've
> just used the collection interfaces (including Iterator) and throw
> UnsupportedOperationException on methods that cause mutation.
There the rationale was, I guess, that the template author is not
supposed to know the difference between a Set and a List... and the
template should not work or fail due to changes in the data-model like
that. Actually, FTL doesn't even have sets in its type system. It's
like it doesn't have double, int, long, etc., just number. It has a
simpler type system than Java has.
> Also, I had to implement my own ObjectWrapper to get around memory
> and performance issues involved with copying collections backed by a
> DB. Copying a collection into an ArrayList defeats the whole purpose
> of lazily populated collections or proxy collections.
What wrapper are you using? Because unfortunately,
DefaultObjectWrapper has some problems... it's there mostly because
it's backward-compatible. I'm certain plain BeansWrapper wouldn't
screw that data-base thing you are talking about. Whenever I used
FreeMarker, among the first things used to be "wrapper = new
BeansWrapper(); wrapper.setSimpleMapWrapper(true);
config.setObjectWrapper(wrapper);".
> Regards, Yuh-Ruey Chen
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.
http://p.sf.net/sfu/bobj-july_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel