cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Josema Alonso" <jos...@simbiosystems.com>
Subject Re: XMLForm Xindice Howto added to Wiki [please, att. Ivelin]
Date Mon, 27 Jan 2003 12:55:39 GMT
Hello again,

Ivelin, I have coded the changes and finally got it working.
The part I don't like too much is where I need to get the model in order to
add the document to the DB. Until that part everything seems to fit quite
nicely.
Remember I got the model stored in a XMLDocumentContainer and now I need the
whole model in a DOM Node or XML String in order to add it to Xindice.

This is what I did:
/**
* Add the document to the database
*/
public void addDocument() throws Exception {
  try {
    //add the document to the database
    XindiceManager xi = new XindiceManager();
    //needs the DocumentRoot of the container
    xi.add(xindiceSubCol,
((Document)(((XMLDocumentContainer)(getForm().getModel())).getValue())).getD
ocumentElement(), null);
  }
  catch (Exception e) {
    getLogger().error("DOM Document could not be created", e);
    throw e;
  }
}

Yeah, what a casting experience! ;-)
Maybe I'm missing somehting and there's an easier way in order to get what I
need...

I prefer to send thi to the list for review by you or anybody else and then
I'll update the Wiki howto. Once reviewed and finished maybe this will be a
candidate for the official how-to docs, what do you think?

Thanks for your help, I'm learning a lot.



----- Original Message -----
From: "Ivelin Ivanov" <ivelin@apache.org>
To: <cocoon-users@xml.apache.org>
Sent: Sunday, January 26, 2003 3:24 AM
Subject: Re: XMLForm Xindice Howto added to Wiki [please, att. Ivelin]


> >
> > > 3) Override the getForm() method in the action
> > Wouldn't it be enough to override the getFormModel() method?
>
> Yes. Your code looks good.
>
> > Something like this:
> >   protected Object getFormModel() {
> >  //to load the XML model
> >  Container DOMModel = null;
> >  Source modelSrc = null;
> >    //this parameter holds the name of the xml file with the empty XML
> > structure
> >     String modelFileName = getParameters().getParameter("xmlform-model",
> > null);
> >     if(modelFileName==null) return null;
> >     try {
> >      modelSrc = getSourceResolver().resolveURI(modelFileName);
> >   DOMModel = new XMLDocumentContainer(new
> > StreamSource(modelSrc.getInputStream()));
> >         return DOMModel;
> >       }
> >       catch ( Exception e) {
> >         throw new CascadingRuntimeException( " Failed instantiating form
> > model ", e );
> >       }
> >       finally {
> >         getSourceResolver().release(modelSrc);
> >       }
> >   }
> >
> > > 4) Use the JXPath DOMContainer to load the xml file(constant)
> > I have used XMLDocumentContainer. I see there's a DocumentContainer but
> only
> > present in JXPath 1.1 alpha and the jar file is still not included in
> > Cocoon, so I used the soon to be deprecated mentioned.
> > Btw, how could I extract a DOMNode from the root or an XML String so I
> could
> > store the whole structure afterwards? I see in 1.1alpha I could do
> something
> > like 'DocumentContainer.MODEL_DOM' but I guess in 1.0 I should get a
> > JXPathContext and search for the root node so I can get the String I
need.
> > Am I right?
>
> Absolutely. On all counts.
>
> >
> > > 5) Use the DOMContainer object as the Form model
> > Ok. But where should I store it? In a separate file like the ArtistBean
I
> > got before?
> > Or maybe would be enough to declare it and initialize it in the
getForm()
> or
> > getFormModel() method?
>
> Should do.
>
> >
> > > 6) When you need to reference a node in the model, instead of using
the
> > DOM
> > > API, you can directly use XPath,
> > > like this: getForm().getValue("/@id")
> > At this stage I can only see the form and when trying to access the
model
> I
> > get the following exception: 'Cannot setValue of an object that is not
> some
> > other object's property/child'
>
> I am not sure why that is. Look at the source of the XMLFormTransformer
and
> see how it uses the Form.getValue() to access properties referenced via
> "ref" attributes in an XMLForm source document.
>
> >
> > Sorry about all the questions but this is totally new for me and it is
not
> > easy.
>
> Not a problem at all. I have been looking for a good XML data model & db
> example for a long time.
> You are getting up to speed very fast.
>
>
>
> Cheers,
>
>
> Ivelin
>
>
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
> For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>
>
>



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

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


Mime
View raw message