I will need a bit more guidance on how to set the value of the field to "new
Packages.java.util.Date()". As there appears to be a few locations that
relate to saving the form and I have only little Java experience. My binding
file is:

---
cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
function form2xml(form) {
    var documentURI = cocoon.parameters["documentURI"];
    var document = loadDocument(documentURI);
    form.load(document);
    form.showForm("form-display-pipeline");
    form.
    form.save(document);
    saveDocument(document, documentURI);
    cocoon.sendPage("form-success-pipeline");
}
function loadDocument(uri) {
    var parser = null;
    var source = null;
    var resolver = null;
    try {
        parser =
cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
        resolver =
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.RO
LE);
        source = resolver.resolveURI(uri);
        var is = new
Packages.org.xml.sax.InputSource(source.getInputStream());
        is.setSystemId(source.getURI());
        return parser.parseDocument(is);
    } finally {
        if (source != null)
            resolver.release(source);
        cocoon.releaseComponent(parser);
        cocoon.releaseComponent(resolver);
    }
}
function saveDocument(document, uri) {
    var source = null;
    var resolver = null;
    var outputStream = null;
    try {
        resolver =
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.RO
LE);
        source = resolver.resolveURI(uri);

        var tf =
Packages.javax.xml.transform.TransformerFactory.newInstance();

        if (source instanceof
Packages.org.apache.excalibur.source.ModifiableSource
            &&
tf.getFeature(Packages.javax.xml.transform.sax.SAXTransformerFactory.FEATURE
)) {

            outputStream = source.getOutputStream();
            var transformerHandler = tf.newTransformerHandler();
            var transformer = transformerHandler.getTransformer();
 
transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.INDENT
, "true");
 
transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.METHOD
, "xml");
            transformerHandler.setResult(new
Packages.javax.xml.transform.stream.StreamResult(outputStream));

            var streamer = new
Packages.org.apache.cocoon.xml.dom.DOMStreamer(transformerHandler);
            streamer.stream(document);
        } else {
            throw new Packages.org.apache.cocoon.ProcessingException("Cannot
write to source " + uri);
        }
    } finally {
        if (source != null)
            resolver.release(source);
        cocoon.releaseComponent(resolver);
        if (outputStream != null) {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (error) {
                cocoon.log.error("Could not flush/close outputstream: " +
error);
            }
        }
    }
}
---





-----Original Message-----
From: Joerg Heinicke [mailto:[EMAIL PROTECTED] 
Sent: Saturday, 15 January 2005 11:23 PM
To: [email protected]
Subject: Re: Adding date and time to a xml file

On 15.01.2005 14:28, lincoln wrote:

> I have a form that once submitted will append data to the end of an XML
> file. I also need to append the date and time that this data was added.
eg:
> <root>
>   <data>
>     <dateTime>Thur...</dateTime>
>     <x>...</x>
>     <y>...</y>
>     <z>..</z>
>   </data>
>   <data>
>     <dateTime>Fri...</dateTime>
>     <x>...</x>
>     <y>...</y>
>     <z>..</z>
>   </data>
>   <data>
>     <dateTime>Sat...</dateTime>
>     <x>...</x>
>     <y>...</y>
>     <z>..</z>
>   </data>
>   ...
> </root>
> 
> My code is based on the xml binding sample block and am trying to add this

I guess you mean CForms?

> XSP code to get the date and time (works in isolation):
> <xsp:page xmlns:xsp="http://apache.org/xsp";> 
>       <date><xsp:expr>new Date()</xsp:expr></date> 
> </xsp:page>
> I have heard you can generate a date in the sitemap.xmap somehow, is that
> true and is it a better approach?
> 
> If I do use XSP then I can't see how this binds to the xml file, at a
guess
> I believe I would need to modify the sitemap somehow.

Don't use XSP at all. Add a fd:output with datatype date to your form 
definition, but not into the template. Immediately before saving the 
form set the value of the field to "new Packages.java.util.Date()".

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to