cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Portier <...@outerthought.org>
Subject Re: AW: AW: AW: AW: [Woody] Binding problem for missing elements in source file
Date Mon, 22 Dec 2003 16:11:46 GMT
oh blast,
sorry for being so bone-headed, but I really needed your example here...
you refer to the document-order of the node!

so not just about the creation of the new node, but creating it at a 
very specific place....

only way out (for now) seems to be to get into writing your own custom 
DOMfactory that knows about your specific document
(see over at o.a.c.util and register that on the JXPAthContext before 
handing it over to the binding using some javascript that looks like this:)

example snatched from a recent posting on cocoon-dev:
see http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=107062994517119&w=2

> in the flow, don't load/save the 
> DOM directly, but through a JXPathContext as follows;
> 
>   var doc = readDocument(url);
>   var bindingCtx = createBindingContext(doc);
>   form.load(bindingCtx);
>   form.showForm("pipeline");
>   form.save(bindingCtx);
> 
> And here's the createBindingContext function:
> 
> function createBindingContext(document) {
>    // Create a JXPath context on the document.
>    var xpathContext = 
> Packages.org.apache.commons.jxpath.JXPathContext.newContext(document);

you should replace this by instantiating your own implementation of the 
Factory interface for jxpath (see here: 
http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/AbstractFactory.html)

you should find some hints for doing this in the current implementation 
of the generic (but simply adding at the end) DOMFactory implementation 
over at:
http://cvs.apache.org/viewcvs.cgi/cocoon-2.1/src/java/org/apache/cocoon/util/jxpath/DOMFactory.java?rev=1.1&view=auto


in case you get tempted in doing the generic implementation for any 
possible DTD, then be sure to send in the patch :-)

>    // Set it to lenient
>    xpathContext.setLenient(true);
>    // Add the necessary factory create elements and attributes as needed 
> on non-existing paths
>    xpathContext.setFactory(new 
> Packages.org.apache.cocoon.util.jxpath.DOMFactory());
>    return xpathContext;
> }


HTH,
-marc=





Markus Heussen wrote:

> 
>>-----Ursprüngliche Nachricht-----
>>Von: Marc Portier
>>Gesendet: Montag, 22. Dezember 2003 12:41
>>An: users@cocoon.apache.org
>>Betreff: Re: AW: AW: AW: [Woody] Binding problem for missing elements in
>>source file
>>
>>
>>
>>
>>Markus Heussen wrote:
>>
>>
>>>Many thanks to you, now everything works fine :-)
>>>
>>
>>yeah, we get there *eventually*
>>
>>
>>>But two questions I still have:
>>>
>>>1. Is it possible to control the position where nodes will be
>>
>>created within
>>
>>>a context? Sometimes this is necessary if the xml schema defines the
>>>sequence of nodes.
>>>
>>
>>could you be more specific?
>>
>>naieve first thought: the @path attribute of the wb:context has
>>precisely this purpose
>>
>>(given your previous questions and remarks that sounds like a too
>>simplistic answer though)
>>
> 
> 
> My source file contains something like this:
> ...
> <v:Person Rolle="Versicherungsnehmer">
> 	<v:Anrede Schlüssel="1"/>
> 	<!-- here a v:Titel node is missing -->
> 	<v:Vorname>firstname</v:Vorname>
> 	<v:Name>name</v:Name>
> 	<v:Anschrift>
> 		<v:Straße>street</v:Straße>
> 		<v:Plz>12345</v:Plz>
> 		<v:Ort>location</v:Ort>
> 	</v:Anschrift>
> 	<v:Geschlecht Schlüssel="1"/>
> 	<v:Geburtsdatum>0000-00-00</v:Geburtsdatum>
> 	<v:Familienstand Schlüssel="1"/>
> 	<v:Staatsangehörigkeit>D</v:Staatsangehörigkeit>
> 	...
> </v:Person>
> ...
> 
> 
> And here is my binding:
> ...
> <wb:context path="v:Partner/*[@Rolle='Versicherungsnehmer'][1]">
> 	<wb:value id="vn_anrede" path="v:Anrede/@Schlüssel" lenient="true"/>
> 	<wb:value id="vn_titel" path="v:Titel" lenient="true"/>
> 	<wb:value id="vn_vorname" path="v:Vorname" lenient="true"/>
> 	<wb:value id="vn_name" path="v:Name"/>
> 	<wb:value id="vn_namenszusatz" path="v:Namenszusatz" lenient="true"/>
> 	<wb:context path="v:Anschrift">
> 		<wb:value id="vn_strasse" path="v:Straße" lenient="true"/>
> 		<wb:value id="vn_plz" path="v:Plz"/>
> 		<wb:value id="vn_ort" path="v:Ort"/>
> 	</wb:context>
> 	...
> </wb:context>
> ...
> 
> 
> After submission the v:Titel node is recognized as missing and will be
> created as the last node of the context. So my result looks like this:
> 
> ...
> <v:Person Rolle="Versicherungsnehmer">
> 	<v:Anrede Schlüssel="1"/>
> 	<!-- here the v:Titel node has to be
> created --><!--<v:Titel>Dr.</v:Titel>-->
> 	<v:Vorname>firstname</v:Vorname>
> 	<v:Name>name</v:Name>
> 	<v:Anschrift>
> 		<v:Straße>street</v:Straße>
> 		<v:Plz>12345</v:Plz>
> 		<v:Ort>location</v:Ort>
> 	</v:Anschrift>
> 	<v:Geschlecht Schlüssel="1"/>
> 	<v:Geburtsdatum>0000-00-00</v:Geburtsdatum>
> 	<v:Familienstand Schlüssel="1"/>
> 	<v:Staatsangehörigkeit>D</v:Staatsangehörigkeit>
> 	...
> 	<!-- here the node was created --><v:Titel>Dr.</v:Titel>
> </v:Person>
> ...
> 
> 
> But the W3C schema not allows this position for this node because the
> sequence of the nodes has to be like this:
> 
> ...
> <v:Person Rolle="Versicherungsnehmer">
> 	<v:Anrede Schlüssel="1"/>
> 	<v:Titel>Dr.</v:Titel>
> 	<v:Vorname>firstname</v:Vorname>
> 	<v:Name>name</v:Name>
> 	<v:Anschrift>
> 		<v:Straße>street</v:Straße>
> 		<v:Plz>12345</v:Plz>
> 		<v:Ort>location</v:Ort>
> 	</v:Anschrift>
> 	<v:Geschlecht Schlüssel="1"/>
> 	<v:Geburtsdatum>0000-00-00</v:Geburtsdatum>
> 	<v:Familienstand Schlüssel="1"/>
> 	<v:Staatsangehörigkeit>D</v:Staatsangehörigkeit>
> 	...
> </v:Person>
> ...
> 
> 
> Is there a way woody supports this? A workaround can be a transformation of
> the result message that constructs the xml document that is valid against
> the schema. But that's not my favor :-(
> 
> Thank you for your help!
> 
> Markus
> 
> 
> 
>>>2. If the input of a date form field is for example "31.02.2004" after
>>>submission this value is automatically set to "02.03.2004". How
>>
>>can I change
>>
>>>this behavior? Is there a attribute I can set in the woody binding or
>>>definition file to get the behavior like using the "setLenient(false)"
>>>method of the class SimpleDateFormat?
>>>
>>
>>not yet, see other thread where you originally posted this...
>>
>>
>>>Thanks for helping me!
>>>
>>
>>de nada,
>>
>>-marc=
>>
>>
>>>Greetings, Markus
>>>
>>>
>>>
>>>>-----Ursprüngliche Nachricht-----
>>>>Von: Marc Portier
>>>>Gesendet: Samstag, 20. Dezember 2003 16:08
>>>>An: users@cocoon.apache.org
>>>>Betreff: Re: AW: AW: [Woody] Binding problem for missing elements in
>>>>source file
>>>>
>>>>
>>>>Yo, all.
>>>>
>>>>answer is in the combination of using
>>>>- @lenient (for surviving reads from paths that don't exist yet)
>>>>- and the o.a.c.util.jxpath.DOMFactory (for creating new paths on the
>>>>target XML)
>>>>
>>>>for some mysterious reason one of my commits messed up the auto-registry
>>>>of that factory on Nodes, fixed now.
>>>>
>>>>regards,
>>>>-marc=
>>>>
>>>>
>>>>
>>>>Markus Heussen wrote:
>>>>
>>>>
>>>>
>>>>>>-----Ursprüngliche Nachricht-----
>>>>>>Von: Upayavira [mailto:uv@upaya.co.uk]
>>>>>>Gesendet: Donnerstag, 18. Dezember 2003 12:12
>>>>>>An: users@cocoon.apache.org
>>>>>>Betreff: Re: AW: [Woody] Binding problem for missing elements
>>
>>in source
>>
>>>>>>file
>>>>>>
>>>>>>
>>>>>>Markus Heussen wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>-----Ursprungliche Nachricht-----
>>>>>>>Von: Upayavira
>>>>>>>Gesendet: Mittwoch, 17. Dezember 2003 16:49
>>>>>>>An: users@cocoon.apache.org
>>>>>>>Betreff: Re: [Woody] Binding problem for missing elements in
>>>>
>>>>source file
>>>>
>>>>
>>>>>>>Markus Heussen wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>Hi all.
>>>>>>>>>
>>>>>>>>>I'm new to the Woody framework but till now it works fine
>>>>
>>>>for me. But I
>>>>
>>>>
>>>>>>>have
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>one problem I don't know how to solve at best :-(
>>>>>>>>>
>>>>>>>>>I get the following exception when I submit the form:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>org.apache.cocoon.woody.binding.BindingException: Problem
>>>>
>>>>binding field
>>>>
>>>>
>>>>>>>>>vn_titel (parent = "") to xpath v:Titel (context xpath
=
>>>>>>>>>"/soap-env:Envelope[1]/soap-env:Body[1]/v:Versicherung[1]/v:Par
>>>>>>
>>>>>>tner[1]/v:P
>>>>>>
>>>>>>
>>>>>>
>>>>>>>er
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>son[1]")
>>>>>>>>>
>>>>>>>>>org.apache.commons.jxpath.JXPathException: No value for
>>>>
>>>>xpath: v:Titel
>>>>
>>>>
>>>>>>>>>The field is defined in the form definition file and a
>>>>
>>>>binding is also
>>>>
>>>>
>>>>>>>>>defined in the woody binding file. But in one case there
is no
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>>corresponding
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>XML tag in my source file. In other case there is one.
I
>>>>
>>>>have to create
>>>>
>>>>
>>>>>>>the
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>>element if it is missing. So how can I manage this
>>
>>situation at best?
>>
>>>>>>>>>Who can point me to the right direction?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>Not sure if I'm right here, but I think you need 'lenient'
>>>>
>>>>jxpath within
>>>>
>>>>
>>>>>>>>binding - this means that, if jxpath doesn't find a node,
it
>>>>
>>>>ignores it,
>>>>
>>>>
>>>>>>>>rather than causing an exception.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>But this is not exactly what I have to do. If there is no node
>>>>>>
>>>>>>in the source
>>>>>>
>>>>>>
>>>>>>
>>>>>>>file I have to create this node before the binding saves it
>>
>>back to the
>>
>>>>>>>source. How can I manage this at best? I have no experience in
>>>>
>>>>using the
>>>>
>>>>
>>>>>>>woody framework. When I set @readonly to true within the
>>>>
>>>>binding I get no
>>>>
>>>>
>>>>>>>exceptions because there is no saving process. But in fact I
>>>>
>>>>have to save
>>>>
>>>>
>>>>>>>it. I tried something around <wb:insert-node/> but it didn't
work :-(
>>>>>>><wb:delete-node/> does what I expected.
>>>>>>>
>>>>>>>Anyone there who can give me a hint? I really need this feature.
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>I'm no expert either, and I've never used binding. I am talking about
>>>>>>'lenient' not 'readonly' or 'direction'. It was committed
>>
>>into CVS this
>>
>>>>>>morning, here's a snippet from the status.xml file:
>>>>>>
>>>>>> <action dev="MPO" type="add" >
>>>>>>   Changed semantics on the cforms binding. Added a @direction
>>>>>>(which replaces
>>>>>>   the @read-only) and a @lenient attribute on all binding
>>>>>>implementations in
>>>>>>   the pool.
>>>>>> </action>
>>>>>>
>>>>>>
>>>>>>Still don't know if this is what you're after.
>>>>>>
>>>>>>Regards,  Upayavira
>>>>>
>>>>>
>>>>>I spend some time learning more about this lenient thing and
>>>>
>>>>meanwhile I use
>>>>
>>>>
>>>>>a current developer version (about two hours old) for my application.
>>>>>
>>>>>But still it doesn't work :-( Maybe somebody can explain what I'm doing
>>>>>wrong. I have something like this:
>>>>>
>>>>>
>>>>>woody binding:
>>>>><wb:value id="vn_titel" path="v:Titel" lenient="true"/>
>>>>>
>>>>>
>>>>>woody field:
>>>>><wd:field id="vn_titel" required="false">
>>>>>	<wd:label>Titel</wd:label>
>>>>>	<wd:datatype base="string"/>
>>>>></wd:field>
>>>>>
>>>>>
>>>>>On submit I get the following exception:
>>>>>
>>>>>org.apache.commons.jxpath.JXPathException: Exception trying to
>>>>
>>>>create xpath
>>>>
>>>>
>>>>>v:Titel; Factory is not set on the JXPathContext - cannot create path:
>>>>>
>>>>
>>>>/soap-env:Envelope[1]/soap-env:Body[1]/v:Versicherung[1]/v:Partner
>>>>[1]/v:Pers
>>>>
>>>>
>>>>>on[1]
>>>>>
>>>>>Though it was recognized that the v:Titel node is not present
>>>>
>>>>in my source
>>>>
>>>>
>>>>>file. But what's my mistake? I also tried to set the lenient
>>>>
>>>>attribute on
>>>>
>>>>
>>>>>the parent context element but I still get the exception.
>>>>>
>>>>>I need your help because this feature is very basic for me.
>>>>>
>>>>>Thanks for your help.
>>>>>
>>>>>Markus
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>>Markus
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>There has been discussion on the dev list about adding this
over the
>>>>>>>>last couple of days. I'm not sure if it is in CVS Cocoon yet,
but I
>>>>>>>>suspect it will be within a day or so.
>>>>>>>>
>>>>>>>>Regards, Upayavira
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>Thanks for your help, Markus.
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>---------------------------------------------------------------------
>>>>>>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>>>>>>For additional commands, e-mail: users-help@cocoon.apache.org
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>>>>>For additional commands, e-mail: users-help@cocoon.apache.org
>>>>>
>>>>>
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>>>>For additional commands, e-mail: users-help@cocoon.apache.org
>>>>>
>>>>
>>>>--
>>>>Marc Portier                            http://outerthought.org/
>>>>Outerthought - Open Source, Java & XML Competence Support Center
>>>>Read my weblog at                http://blogs.cocoondev.org/mpo/
>>>>mpo@outerthought.org                              mpo@apache.org
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>>>For additional commands, e-mail: users-help@cocoon.apache.org
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>>For additional commands, e-mail: users-help@cocoon.apache.org
>>>
>>
>>--
>>Marc Portier                            http://outerthought.org/
>>Outerthought - Open Source, Java & XML Competence Support Center
>>Read my weblog at                http://blogs.cocoondev.org/mpo/
>>mpo@outerthought.org                              mpo@apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at                http://blogs.cocoondev.org/mpo/
mpo@outerthought.org                              mpo@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message