cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oceatoon <t.katelb...@systheo.com>
Subject Re:(Solved) save XML document to disk?
Date Mon, 04 Apr 2005 11:41:09 GMT
My Apologies for these auto responded questions 
I guess it fills up the list with questions and answers ;)
Regards

//saves document to the uri
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(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); 
             } 
         } 
     } 
 } 

<posté comme article et comme courrier>

oceatoon wrote:

> Hi cocooners
> 
> I'm using loadDocument(path2myxml) to act on an xml file in my flow.
> Before going into a new dev I was wondering if there allready existed a
> "savedocument(document , path)" or document.save() function, that saves
> back to disk the applied modifications. I found saveXML in the
> sessionContext, but can't use it in the FLow.
> 
> var document = loadDocument("path/labels_multi.xml");
> ---XML modfications---
> document.save();
> 
> Thanks for the thoughts
> Tibor



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


Mime
View raw message