From: Wolfgang M. M. <wol...@us...> - 2004-09-20 18:00:59
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/http In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27729/src/org/exist/http Modified Files: RESTServer.java Log Message: Added support to set output properties via XQuery pragma to xmlrpc, XQueryGenerator and REST interface. Index: RESTServer.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/http/RESTServer.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** RESTServer.java 20 Sep 2004 10:23:19 -0000 1.19 --- RESTServer.java 20 Sep 2004 18:00:48 -0000 1.20 *************** *** 60,63 **** --- 60,64 ---- import org.exist.util.serializer.SAXSerializerPool; import org.exist.xquery.CompiledXQuery; + import org.exist.xquery.Pragma; import org.exist.xquery.XPathException; import org.exist.xquery.XQuery; *************** *** 451,457 **** context = compiled.getContext(); context.setStaticallyKnownDocuments(docs); ! if(compiled == null) compiled = xquery.compile(context, source); try { long startTime = System.currentTimeMillis(); --- 452,459 ---- context = compiled.getContext(); context.setStaticallyKnownDocuments(docs); ! if(compiled == null) compiled = xquery.compile(context, source); + checkPragmas(context, outputProperties); try { long startTime = System.currentTimeMillis(); *************** *** 471,474 **** --- 473,497 ---- } + /** + * Check if the XQuery contains pragmas that define serialization settings. + * If yes, copy the corresponding settings to the current set of output properties. + * + * @param context + */ + protected void checkPragmas(XQueryContext context, Properties properties) throws XPathException { + Pragma pragma = context.getPragma(Pragma.SERIALIZE_QNAME); + if(pragma == null) + return; + String[] contents = pragma.tokenizeContents(); + for(int i = 0; i < contents.length; i++) { + String[] pair = Pragma.parseKeyValuePair(contents[i]); + if(pair == null) + throw new XPathException("Unknown parameter found in " + pragma.getQName().toString() + + ": '" + contents[i] + "'"); + LOG.debug("Setting serialization property from pragma: " + pair[0] + " = " + pair[1]); + properties.setProperty(pair[0], pair[1]); + } + } + protected String printCollection(DBBroker broker, Collection collection) { SAXSerializer serializer = null; |