You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Vincent Hennebert <vi...@anyware-tech.com> on 2007/12/14 11:55:32 UTC
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Hi Andreas,
> Author: adelmelle
> Date: Thu Dec 13 06:43:08 2007
> New Revision: 603926
>
> URL: http://svn.apache.org/viewvc?rev=603926&view=rev
> Log:
> Minor tweaks:
> * only add text to a fo:wrapper if it is not a direct flow-descendant
> * error if an fo:wrapper that is a direct flow-descendant contains inline-level children
>
> Modified:
> xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
>
> + /* Check if the fo:wrapper is a child of an fo:flow or
> fo:static-content
> + * (or a descendant in nested fo:wrapper sequence, the first of which
> + * is a child of an fo:flow or fo:static-content */
> + FONode ancestor = this.parent;
> + while (!(ancestor instanceof Flow)
> + && ancestor instanceof Wrapper) {
Might be wrong, but isn’t that the very same as:
while (!(ancestor instanceof Wrapper))
?
<snip/>
> protected void validateChildNode(Locator loc, String nsURI,
> String localName) throws ValidationException {
> @@ -58,9 +74,30 @@
> "(#PCDATA|%inline;|%block;)");
> }
> } else if (isBlockOrInlineItem(nsURI, localName)) {
> + if (isFlowChild
> + && isInlineItem(nsURI, localName)
> + && !isNeutralItem(nsURI, localName)) {
> + invalidChildError(loc, nsURI, localName,
> + "fo:" + localName + " not allowed as child of an fo:wrapper "
> + + "that is a child of an fo:flow or fo:static-content");
> + }
> blockOrInlineItemFound = true;
> } else {
> invalidChildError(loc, nsURI, localName);
And regarding the validation, wouldn’t it be safer to call the
validateChildNode of the nearest non-wrapper ancestor? That way this
class would really keep neutral, and we wouldn’t have to worry about the
implementation of new FO elements.
My 2 cents,
Vincent
--
Vincent Hennebert Anyware Technologies
http://people.apache.org/~vhennebert http://www.anyware-tech.com
Apache FOP Committer FOP Development/Consulting
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Posted by Andreas L Delmelle <a_...@pandora.be>.
On Dec 14, 2007, at 12:49, Andreas L Delmelle wrote:
Slight correction:
> On Dec 14, 2007, at 11:55, Vincent Hennebert wrote:
>
>> Hi Andreas,
>>
>>> + while (!(ancestor instanceof Flow)
>>> + && ancestor instanceof Wrapper) {
>>
>> Might be wrong, but isn’t that the very same as:
>> while (!(ancestor instanceof Wrapper))
>> ?
> <snip />
> Your version will run indefinitely, unless there is a Wrapper
> somewhere in the ancestry...
Your version will throw a NullPointerException:
when ancestor becomes the Root,
ancestor.getParent() will return null,
'ancestor instanceof Wrapper' will still return false, so the loop
will be entered one more time,
and then ancestor.getParent() will throw a NPE.
Cheers
Andreas
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Posted by Andreas L Delmelle <a_...@pandora.be>.
On Dec 16, 2007, at 09:03, Andreas L Delmelle wrote:
> On Dec 15, 2007, at 10:24, Andreas L Delmelle wrote:
>
> Come to think of it, maybe the cleanest way is:
>
> * add the following to FONode:
>
> public static void validateChildNode(FONode thisNode, Locator...)
> throws ValidationException {
> thisNode.validateChildNode(...);
> }
Sorry, meant 'protected static'. A subclass in a subpackage does have
access to its superclass' protected static methods.
Cheers
Andreas
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Posted by Andreas L Delmelle <a_...@pandora.be>.
On Dec 15, 2007, at 10:24, Andreas L Delmelle wrote:
> <snip />
>>>
>>> Options:
>>> * increase the general visibility to public (not sure why this
>>> would be
>>> desirable; unless there's any other compelling reasons to do so, I'd
>>> rather not...)
>>
>> Yeah, we’re hitting a limitation of Java here. Basically we’re
>> missing
>> a keyword allowing classes of a sub-package to access the method.
>> Making
>> it public with a proper comment is still the less ugly way to do
>> in my
>> opinion.
>
> I'll go for this one, then.
Come to think of it, maybe the cleanest way is:
* add the following to FONode:
public static void validateChildNode(FONode thisNode, Locator...)
throws ValidationException {
thisNode.validateChildNode(...);
}
* the instance method itself can remain protected, but Wrapper could
get it to do something like:
FONode.validateChildNode(getParent(), locator, nsURI, localName);
Cheers
Andreas
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Posted by Andreas L Delmelle <a_...@pandora.be>.
On Dec 14, 2007, at 16:05, Vincent Hennebert wrote:
<snip />
> But the test inside the loop is not necessary, since it will
> automatically be performed at the end of the loop (more precisely:
> before starting the next iteration). If ancestor is a Flow, then
> ancestor is not a Wrapper, then the while loop will stop there. So the
> following should be enough:
> while (ancestor instanceof Wrapper) {
> ancestor = ancestor.getParent();
> }
> // Once we get here we have !(ancestor instanceof Wrapper)
Raaah!! My table is glass, so I think I'll skip the head-banging part
for now... ;-)
You're right. I'll correct it.
>>
>> Options:
>> * increase the general visibility to public (not sure why this
>> would be
>> desirable; unless there's any other compelling reasons to do so, I'd
>> rather not...)
>
> Yeah, we’re hitting a limitation of Java here. Basically we’re missing
> a keyword allowing classes of a sub-package to access the method.
> Making
> it public with a proper comment is still the less ugly way to do in my
> opinion.
I'll go for this one, then. Although it struck me that there is
something awkward about the validateChildNode() method.
The question that triggered this: What if I wanted to implement an
extension element that is a valid child to an fo:wrapper?
IIC, I would need to alter the hardcoded validateChildNode() in
Wrapper.java to get FOP to not throw a ValidationException...
Maybe we need different validateChildFONode() and
validateChildExtensionNode() methods.
The first can be completely hardcoded for all I care (only changes
when the recommendation changes), while the second one uses a sort of
Map that can be extended by the users.
Cheers
Andreas
>
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Posted by Vincent Hennebert <vi...@anyware-tech.com>.
Andreas L Delmelle wrote:
> On Dec 14, 2007, at 13:07, Vincent Hennebert wrote:
>
>> Andreas L Delmelle wrote:
>>> On Dec 14, 2007, at 11:55, Vincent Hennebert wrote:
>>>
>>>> Hi Andreas,
>>>>
>>>>> + while (!(ancestor instanceof Flow)
>>>>> + && ancestor instanceof Wrapper) {
>>
>> Sorry, I meant:
>> while (ancestor instanceof Wrapper)
>> The original loop will stop when:
>> ancestor instanceof Flow || !(ancestor instanceof Wrapper)
>> which is equivalent to simply
>> !(ancestor instanceof Wrapper)
>> So I think the loop may be simplified.
>
> Still not convinced...
> The loop should end either if the ancestor is not a Wrapper (a Block,
> Inline, whatever) or if the ancestor is a Flow (this is implicitly
> covered by the previous, but this makes sure we stop at the Flow and do
> not climb further to the PageSequence and the Root)
But as you said this is already covered by the previous test! In other
words: the loop should end either if the ancestor is not a Wrapper (a
Block, Inline, whatever), or if the ancestor is not a Wrapper (a
Flow...).
> Doing this with a simple check is impossible, IIC. You would at least
> need something like:
>
> while (!(ancestor instanceof Wrapper)) {
> ancestor = ancestor.getParent();
> if (ancestor instanceof Flow) {
> break;
> }
> }
But the test inside the loop is not necessary, since it will
automatically be performed at the end of the loop (more precisely:
before starting the next iteration). If ancestor is a Flow, then
ancestor is not a Wrapper, then the while loop will stop there. So the
following should be enough:
while (ancestor instanceof Wrapper) {
ancestor = ancestor.getParent();
}
// Once we get here we have !(ancestor instanceof Wrapper)
That’s simply the way the while loop works. Had you used a repeat loop
(do...while in Java), this would have been another question.
... Unless I’ve completely missed something.
<snip/>
> Just bumped into one obstacle:
> validateChildNode() is a protected member of FONode, and as such, each
> subclass in the fo.flow package has access only its own version...
>
> Options:
> * increase the general visibility to public (not sure why this would be
> desirable; unless there's any other compelling reasons to do so, I'd
> rather not...)
Yeah, we’re hitting a limitation of Java here. Basically we’re missing
a keyword allowing classes of a sub-package to access the method. Making
it public with a proper comment is still the less ugly way to do in my
opinion.
> * implement the exception rule for Wrapper in a default implementation
> in FObj, which would allow delegating to the parent for any neutral
> items. FObj does have access to its parent's validateChildNode()
Well we rather not clutter up FObj with a method that only applies to
Wrapper. Were it useful to many subclasses, why not, but that’s not the
case here. I don’t think FOP will ever implement the other neutral FOs
(related to dynamic content) that might have a use of it.
Vincent
-- Vincent Hennebert Anyware Technologies
http://people.apache.org/~vhennebert http://www.anyware-tech.com
Apache FOP Committer FOP Development/Consulting
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Posted by Andreas L Delmelle <a_...@pandora.be>.
On Dec 14, 2007, at 13:07, Vincent Hennebert wrote:
> Andreas L Delmelle wrote:
>> On Dec 14, 2007, at 11:55, Vincent Hennebert wrote:
>>
>>> Hi Andreas,
>>>
>>>> + while (!(ancestor instanceof Flow)
>>>> + && ancestor instanceof Wrapper) {
>>>
>>> Might be wrong, but isn’t that the very same as:
>>> while (!(ancestor instanceof Wrapper))
>>> ?
>
> rhaaaa! (Hitting my head against the table several times.)
>
> Sorry, I meant:
> while (ancestor instanceof Wrapper)
> The original loop will stop when:
> ancestor instanceof Flow || !(ancestor instanceof Wrapper)
> which is equivalent to simply
> !(ancestor instanceof Wrapper)
> So I think the loop may be simplified.
Still not convinced...
The loop should end either if the ancestor is not a Wrapper (a Block,
Inline, whatever) or if the ancestor is a Flow (this is implicitly
covered by the previous, but this makes sure we stop at the Flow and
do not climb further to the PageSequence and the Root)
Doing this with a simple check is impossible, IIC. You would at least
need something like:
while (!(ancestor instanceof Wrapper)) {
ancestor = ancestor.getParent();
if (ancestor instanceof Flow) {
break;
}
}
which would simply move the additional condition into a separate if-
block.
>>> And regarding the validation, wouldn’t it be safer to call the
>>> validateChildNode of the nearest non-wrapper ancestor? That way this
>>> class would really keep neutral, and we wouldn’t have to worry
>>> about the
>>> implementation of new FO elements.
>>
>> There's an idea, although, strictly speaking the fo:wrapper has
>> its own
>> content-model.
>
> Sure. Wrapper could check for the exceptions it introduces (mainly the
> acceptance of fo:markers as its initial children), and defer to its
> parent element for the rest. Then that wouldn’t even be needed to
> recursively get the nearest non-wrapper ancestor IIC.
>
Just bumped into one obstacle:
validateChildNode() is a protected member of FONode, and as such,
each subclass in the fo.flow package has access only its own version...
Options:
* increase the general visibility to public (not sure why this would
be desirable; unless there's any other compelling reasons to do so,
I'd rather not...)
* implement the exception rule for Wrapper in a default
implementation in FObj, which would allow delegating to the parent
for any neutral items. FObj does have access to its parent's
validateChildNode()
Cheers
Andreas
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Posted by Vincent Hennebert <vi...@anyware-tech.com>.
Andreas L Delmelle wrote:
> On Dec 14, 2007, at 11:55, Vincent Hennebert wrote:
>
>> Hi Andreas,
>>
>>> + while (!(ancestor instanceof Flow)
>>> + && ancestor instanceof Wrapper) {
>>
>> Might be wrong, but isn’t that the very same as:
>> while (!(ancestor instanceof Wrapper))
>> ?
rhaaaa! (Hitting my head against the table several times.)
Sorry, I meant:
while (ancestor instanceof Wrapper)
The original loop will stop when:
ancestor instanceof Flow || !(ancestor instanceof Wrapper)
which is equivalent to simply
!(ancestor instanceof Wrapper)
So I think the loop may be simplified.
<snip/>
>> And regarding the validation, wouldn’t it be safer to call the
>> validateChildNode of the nearest non-wrapper ancestor? That way this
>> class would really keep neutral, and we wouldn’t have to worry about the
>> implementation of new FO elements.
>
> There's an idea, although, strictly speaking the fo:wrapper has its own
> content-model.
Sure. Wrapper could check for the exceptions it introduces (mainly the
acceptance of fo:markers as its initial children), and defer to its
parent element for the rest. Then that wouldn’t even be needed to
recursively get the nearest non-wrapper ancestor IIC.
> But you are right, in that it only disallows parts of that
> content-model, if its parent would not allow them as children...
>
> Going to try this approach, and will get back to you on that.
>
>
> Thanks for the feedback.
>
> Cheers
>
> Andreas
Vincent
--
Vincent Hennebert Anyware Technologies
http://people.apache.org/~vhennebert http://www.anyware-tech.com
Apache FOP Committer FOP Development/Consulting
Re: svn commit: r603926 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Wrapper.java
Posted by Andreas L Delmelle <a_...@pandora.be>.
On Dec 14, 2007, at 11:55, Vincent Hennebert wrote:
> Hi Andreas,
>
>> + while (!(ancestor instanceof Flow)
>> + && ancestor instanceof Wrapper) {
>
> Might be wrong, but isn’t that the very same as:
> while (!(ancestor instanceof Wrapper))
> ?
Not really.
The while-loop continues until
* either it finds an instance of Flow (a fo:flow or fo:static-content),
* or something that is not a Wrapper.
The check immediately below finds out whether we have a Flow, so that
would mean that either the current fo:wrapper is a direct child to an
fo:flow/fo:static-content, or it has no other ancestors than
fo:wrappers, and the last one is a direct child to a Flow.
Your version will run indefinitely, unless there is a Wrapper
somewhere in the ancestry...
The two situations being checked for are:
<fo:flow ...>
...
<fo:wrapper>...
and
<fo:flow ...>
...
<fo:wrapper>
<fo:wrapper>
<fo:wrapper>...etc.
Once there is another type of node in between, the switch isFlowChild
will be false, and everything proceeds as before.
>
> <snip/>
>
>> protected void validateChildNode(Locator loc, String nsURI,
>> String localName) throws ValidationException {
>> @@ -58,9 +74,30 @@
>> "(#PCDATA|%inline;|%block;)");
>> }
>> } else if (isBlockOrInlineItem(nsURI, localName)) {
>> + if (isFlowChild
>> + && isInlineItem(nsURI, localName)
>> + && !isNeutralItem(nsURI, localName)) {
>> + invalidChildError(loc, nsURI, localName,
>> + "fo:" + localName + " not allowed as
>> child of an fo:wrapper "
>> + + "that is a child of an fo:flow or
>> fo:static-content");
>> + }
>> blockOrInlineItemFound = true;
>> } else {
>> invalidChildError(loc, nsURI, localName);
>
> And regarding the validation, wouldn’t it be safer to call the
> validateChildNode of the nearest non-wrapper ancestor? That way this
> class would really keep neutral, and we wouldn’t have to worry
> about the
> implementation of new FO elements.
There's an idea, although, strictly speaking the fo:wrapper has its
own content-model.
But you are right, in that it only disallows parts of that content-
model, if its parent would not allow them as children...
Going to try this approach, and will get back to you on that.
Thanks for the feedback.
Cheers
Andreas