From: Wolfgang M. M. <wol...@us...> - 2004-09-20 18:00:59
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xmlrpc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27729/src/org/exist/xmlrpc Modified Files: QueryResult.java RpcConnection.java Log Message: Added support to set output properties via XQuery pragma to xmlrpc, XQueryGenerator and REST interface. Index: QueryResult.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmlrpc/QueryResult.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** QueryResult.java 29 Jan 2004 15:06:44 -0000 1.3 --- QueryResult.java 20 Sep 2004 18:00:48 -0000 1.4 *************** *** 1,16 **** package org.exist.xmlrpc; import org.exist.xquery.value.Sequence; public class QueryResult { ! long queryTime = 0; ! Sequence result; ! long timestamp = 0; ! public QueryResult(Sequence result) { ! this(result, 0); } ! public QueryResult(Sequence result, long queryTime) { this.result = result; this.queryTime = queryTime; --- 1,20 ---- package org.exist.xmlrpc; + import org.exist.xquery.XQueryContext; import org.exist.xquery.value.Sequence; public class QueryResult { ! ! protected long queryTime = 0; ! protected Sequence result; ! protected XQueryContext context; ! protected long timestamp = 0; ! public QueryResult(XQueryContext context, Sequence result) { ! this(context, result, 0); } ! public QueryResult(XQueryContext context, Sequence result, long queryTime) { ! this.context = context; this.result = result; this.queryTime = queryTime; Index: RpcConnection.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xmlrpc/RpcConnection.java,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** RpcConnection.java 16 Sep 2004 12:33:44 -0000 1.72 --- RpcConnection.java 20 Sep 2004 18:00:48 -0000 1.73 *************** *** 81,84 **** --- 81,85 ---- import org.exist.xquery.CompiledXQuery; import org.exist.xquery.PathExpr; + import org.exist.xquery.Pragma; import org.exist.xquery.XPathException; import org.exist.xquery.XQuery; *************** *** 215,219 **** } ! protected Sequence doQuery(User user, DBBroker broker, String xpath, DocumentSet docs, NodeSet contextSet, Hashtable parameters) throws Exception { --- 216,220 ---- } ! protected QueryResult doQuery(User user, DBBroker broker, String xpath, DocumentSet docs, NodeSet contextSet, Hashtable parameters) throws Exception { *************** *** 254,262 **** if(compiled == null) compiled = xquery.compile(context, source); try { long start = System.currentTimeMillis(); Sequence result = xquery.execute(compiled, contextSet); LOG.info("query took " + (System.currentTimeMillis() - start) + "ms."); ! return result; } finally { pool.returnCompiledXQuery(source, compiled); --- 255,264 ---- if(compiled == null) compiled = xquery.compile(context, source); + checkPragmas(context, parameters); try { long start = System.currentTimeMillis(); Sequence result = xquery.execute(compiled, contextSet); LOG.info("query took " + (System.currentTimeMillis() - start) + "ms."); ! return new QueryResult(context, result); } finally { pool.returnCompiledXQuery(source, compiled); *************** *** 264,279 **** } public int executeQuery(User user, String xpath, Hashtable parameters) throws Exception { long startTime = System.currentTimeMillis(); - LOG.debug("query: " + xpath); DBBroker broker = null; try { broker = brokerPool.get(user); ! Sequence resultValue = doQuery(user, broker, xpath, null, null, parameters); ! QueryResult qr = new QueryResult(resultValue, (System ! .currentTimeMillis() - startTime)); ! connectionPool.resultSets.put(qr.hashCode(), qr); ! return qr.hashCode(); } finally { brokerPool.release(broker); --- 266,300 ---- } + /** + * 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, Hashtable parameters) 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]); + parameters.put(pair[0], pair[1]); + } + } + public int executeQuery(User user, String xpath, Hashtable parameters) throws Exception { long startTime = System.currentTimeMillis(); DBBroker broker = null; try { broker = brokerPool.get(user); ! QueryResult result = doQuery(user, broker, xpath, null, null, parameters); ! result.queryTime = System.currentTimeMillis() - startTime; ! connectionPool.resultSets.put(result.hashCode(), result); ! return result.hashCode(); } finally { brokerPool.release(broker); *************** *** 1172,1182 **** try { broker = brokerPool.get(user); ! Sequence resultSeq = doQuery(user, broker, xpath, null, null, parameters); ! if (resultSeq == null) return "<?xml version=\"1.0\"?>\n" + "<exist:result xmlns:exist=\"http://exist.sourceforge.net/NS/exist\" " + "hitCount=\"0\"/>"; ! result = printAll(broker, resultSeq, howmany, start, parameters, (System.currentTimeMillis() - startTime)); } finally { --- 1193,1203 ---- try { broker = brokerPool.get(user); ! QueryResult qr = doQuery(user, broker, xpath, null, null, parameters); ! if (qr == null) return "<?xml version=\"1.0\"?>\n" + "<exist:result xmlns:exist=\"http://exist.sourceforge.net/NS/exist\" " + "hitCount=\"0\"/>"; ! result = printAll(broker, qr.result, howmany, start, parameters, (System.currentTimeMillis() - startTime)); } finally { *************** *** 1195,1198 **** --- 1216,1220 ---- NodeSet nodes = null; DocumentSet docs = null; + QueryResult queryResult; Sequence resultSeq = null; DBBroker broker = null; *************** *** 1213,1219 **** docs.add(node.getDocument()); } ! resultSeq = doQuery(user, broker, xpath, docs, nodes, parameters); ! if (resultSeq == null) return ret; LOG.debug("found " + resultSeq.getLength()); --- 1235,1242 ---- docs.add(node.getDocument()); } ! queryResult = doQuery(user, broker, xpath, docs, nodes, parameters); ! if (queryResult == null) return ret; + resultSeq = queryResult.result; LOG.debug("found " + resultSeq.getLength()); *************** *** 1257,1264 **** brokerPool.release(broker); } ! QueryResult qr = new QueryResult(resultSeq, ! (System.currentTimeMillis() - startTime)); ! connectionPool.resultSets.put(qr.hashCode(), qr); ! ret.put("id", new Integer(qr.hashCode())); ret.put("results", result); return ret; --- 1280,1287 ---- brokerPool.release(broker); } ! queryResult.result = resultSeq; ! queryResult.queryTime = (System.currentTimeMillis() - startTime); ! connectionPool.resultSets.put(queryResult.hashCode(), queryResult); ! ret.put("id", new Integer(queryResult.hashCode())); ret.put("results", result); return ret; *************** *** 1371,1374 **** --- 1394,1398 ---- Serializer serializer = broker.getSerializer(); serializer.reset(); + checkPragmas(qr.context, parameters); serializer.setProperties(parameters); return serializer.serialize(nodeValue); *************** *** 1390,1394 **** throw new EXistException("result set unknown or timed out"); qr.timestamp = System.currentTimeMillis(); ! Serializer serializer = broker.getSerializer(); serializer.reset(); --- 1414,1418 ---- throw new EXistException("result set unknown or timed out"); qr.timestamp = System.currentTimeMillis(); ! checkPragmas(qr.context, parameters); Serializer serializer = broker.getSerializer(); serializer.reset(); *************** *** 1688,1695 **** try { broker = brokerPool.get(user); ! Sequence resultSeq = doQuery(user, broker, xpath, null, null, null); ! if (resultSeq == null) return new Hashtable(); ! NodeList resultSet = (NodeList) resultSeq; HashMap map = new HashMap(); HashMap doctypes = new HashMap(); --- 1712,1719 ---- try { broker = brokerPool.get(user); ! QueryResult qr = doQuery(user, broker, xpath, null, null, null); ! if (qr == null) return new Hashtable(); ! NodeList resultSet = (NodeList) qr.result; HashMap map = new HashMap(); HashMap doctypes = new HashMap(); |