* Jonas Lundberg:
> That might work, but it is not a good solution for me, although
> it might work in other cases. My xqueries are very complex. But
> this can't end here, can it? Is there really no way of returning
> XML in a parameter from a flowscript in Cocoon?
Sitemap parameters are Strings, not Objects. You cannot pass a
DOM. However you can execute an XQuery without the
XQueryGenerator, Java snippet follows:
public static Node executeXQuery(Collection collection, Source
inputSource, Map variables, Logger logger) throws XMLDBException {
XQueryService service = (XQueryService) collection.getService(
"XQueryService", "1.0");
service.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
if (variables != null) {
if (logger != null) logger.debug("Executing " +
inputSource.getURI() + " with variables " + variables);
Iterator it = variables.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
service.declareVariable((String)entry.getKey(),
entry.getValue());
}
} else {
if (logger != null) logger.debug("Executing " +
inputSource.getURI());
}
ResourceSet result = service.execute(new
CocoonSource(inputSource, true));
if (result == null) {
if (logger != null) logger.error("null result after
executing XQuery!");
return null; // a DOM Node cannot be null so null can
be used safely for signaling errors
}
if (result.getSize() == 0) {
if (logger != null) logger.error("empty XML result
after executing XQuery!");
return null; // a DOM Node cannot be null so null can
be used safely for signaling errors
}
XMLResource resource = (XMLResource) result.getResource(0);
return resource.getContentAsDOM();
}
But I think the best solution in order to save directly an XML
document in the XML database is to use the XMLDBSource with
saveDocumentToSource("xmldb:exist://localhost:8080/exist/xmlrpc/db/file.xml",
document),
FlowScript snippet follows:
/*
* Save XML document to source.
* Parameters :
* outputMode : the desired output mode : 'html', 'xml', or 'text'
* Defaults to "xml"
*/
function saveDocumentToSource(source, document, outputMode ) {
var tf = Packages.javax.xml.transform.TransformerFactory.newInstance();
var outputStream = null;
// If no mode is specified, we use XML
if(! outputMode) {
outputMode = 'xml';
}
try {
if (source instanceof
Packages.org.apache.excalibur.source.ModifiableSource
&&
tf.getFeature(Packages.javax.xml.transform.sax.SAXTransformerFactory.FEATURE)) {
outputStream = source.getOutputStream();
var transformer = tf.newTransformer();
transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.INDENT,
"yes");
transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.METHOD,
outputMode);
transformer.transform(
new Packages.javax.xml.transform.dom.DOMSource(document),
new
Packages.javax.xml.transform.stream.StreamResult(outputStream));
} else {
throw new
Packages.org.apache.cocoon.ProcessingException("Cannot write to source " + uri);
}
} finally {
if (outputStream != null) {
outputStream.flush();
outputStream.close();
}
}
}
Best regards,
--
Jean-Baptiste Quenot
Systèmes d'Information
ANYWARE TECHNOLOGIES
Tel : +33 (0)5 61 00 52 90
Fax : +33 (0)5 61 00 51 46
http://www.anyware-tech.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]