cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc Salvetti" <salvetti.m...@gmail.com>
Subject Saving a file from the cocoon webapp
Date Mon, 09 Jun 2008 10:27:32 GMT
Hello,

I'm having a file permission problem with my webapp, and it seems to be due
to the app overwriting the saved file rather than saving it. After the file
is saved, the group have changed to "nobody", which creates problems in my
case.

I'm using a function that was fond in the cocoon examples and I'd like to
change it so that it preserve the group but I haven't found what to do by
looking at the api.

This is the function I'm using to save files :

function saveDocument(document, uri) {
    var source = null;
    var resolver = null;
    var outputStream = null;
    try {
        resolver =
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
        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("encoding", "UTF-8");
            transformer.setOutputProperty("{
http://xml.apache.org/xslt}indent-amount", "4");
            transformer.setOutputProperty("{
http://xml.apache.org/xalan}indent-amount", "4");

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.setNormalizeNamespaces(false);
            //try
            streamer.stream(document);
            //catch
            //in case of exception, writing of the data should be canceled
to avoid partial writing
            //if source.canCancel()
            //source.cancel();
            //else ??
        } 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);
            }
        }
    }
}


Any help would be greatly appreciated

Marc

Mime
View raw message