vgritsenko 2003/12/23 18:48:52
Modified: java/src/org/apache/xindice/client/xmldb/xmlrpc CollectionImpl.java java/src/org/apache/xindice/server/rpc/messages GetDocument.java Added: java/src/org/apache/xindice/server/rpc/messages GetResource.java Log: Implement getResource method (and GetResource command) as it works in embed mode: add Binary resource support Revision Changes Path 1.38 +14 -10 xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java Index: CollectionImpl.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- CollectionImpl.java 23 Dec 2003 12:22:46 -0000 1.37 +++ CollectionImpl.java 24 Dec 2003 02:48:52 -0000 1.38 @@ -64,6 +64,7 @@ import org.apache.xindice.client.xmldb.ResourceSetImpl; import org.apache.xindice.client.xmldb.XindiceCollection; import org.apache.xindice.client.xmldb.resources.XMLResourceImpl; +import org.apache.xindice.client.xmldb.resources.BinaryResourceImpl; import org.apache.xindice.core.FaultCodes; import org.apache.xindice.core.meta.MetaData; import org.apache.xindice.server.rpc.RPCDefaultMessage; @@ -225,22 +226,22 @@ checkOpen(); try { - Hashtable params = new Hashtable(); params.put(RPCDefaultMessage.COLLECTION, collPath); params.put(RPCDefaultMessage.NAME, id); params.put(RPCDefaultMessage.COMPRESSED, "true"); - Object result = runRemoteCommand("GetDocument", params); - /* - * If we get a Hashtable back then the result is compressed. - */ + Object result = runRemoteCommand("GetResource", params); + + // If we get a Hashtable back then the result is compressed. if (result instanceof Hashtable) { Hashtable compressed = (Hashtable) result; SymbolDeserializer symbolDeserial = new SymbolDeserializer(); return new XMLResourceImpl(id, id, this, symbolDeserial.getSymbols(compressed), (byte[]) compressed.get("document")); + } else if (result instanceof byte[]) { + return new BinaryResourceImpl(id, this, (byte[]) result); } else { - return new XMLResourceImpl(id, (String) result, this); + return new XMLResourceImpl(id, this, (String) result); } } catch (Exception e) { @@ -304,8 +305,11 @@ params.put(RPCDefaultMessage.DOCUMENT, res.getContent()); String name = (String) runRemoteCommand("InsertDocument", params); - // TODO: BinaryResource - ((XMLResourceImpl) res).setId(name); + if (res instanceof XMLResource) { + ((XMLResourceImpl) res).setId(name); + } else { + ((BinaryResourceImpl) res).setId(name); + } } catch (XMLDBException x) { 1.7 +6 -52 xml-xindice/java/src/org/apache/xindice/server/rpc/messages/GetDocument.java Index: GetDocument.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/server/rpc/messages/GetDocument.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- GetDocument.java 9 Aug 2003 21:19:53 -0000 1.6 +++ GetDocument.java 24 Dec 2003 02:48:52 -0000 1.7 @@ -71,61 +71,15 @@ import java.util.Hashtable; /** - * + * @deprecated Replaced by [EMAIL PROTECTED] GetResource} * @version CVS $Revision$, $Date$ */ -public class GetDocument extends RPCDefaultMessage { +public class GetDocument extends GetResource { private static final Log log = LogFactory.getLog(GetDocument.class); public Hashtable execute(Hashtable message) throws Exception { - SymbolSerializer symbolSerializer = null; - - if (!message.containsKey(COLLECTION)) { - throw new Exception(MISSING_COLLECTION_PARAM); - } - - if (!message.containsKey(NAME)) { - throw new Exception(MISSING_NAME_PARAM); - } - - Collection col = getCollection((String) message.get(COLLECTION)); - - Document doc = col.getDocument(message.get(NAME)); - if (doc == null) { - throw new Exception(API_NAME + ": Document not found " + - (String) message.get(NAME)); - } - - Hashtable result = new Hashtable(); - if (message.containsKey(COMPRESSED)) { - try { - symbolSerializer = new SymbolSerializer(col.getSymbols()); - } catch (Exception e) { - // It's ok (in theory) for a Collection to have no symbol table - if (log.isWarnEnabled()) { - log.warn("ignored exception", e); - } - } - - long timestamp = 1; - /* Time stamp is an optimization and longs are causing problems with XML-RPC - so we'll try to get everything working without them. - if ( ! message.containsKey(TIMESTAMP) ) { - throw new Exception(MISSING_TIMESTAMP_PARAM); - } - - int timestamp = ((Integer) message.get("timestamp")).intValue();*/ - if (/*( timestamp != -1) &&*/ (symbolSerializer != null)) { - result.put(RESULT, - symbolSerializer.convertFromDocument(doc, timestamp)); - } else { - result.put(RESULT, TextWriter.toString(doc)); - } - } else { - result.put(RESULT, TextWriter.toString(doc)); - } - - return result; + log.warn("Please use GetResource instead. GetResource supports same as GetDocument, plus binary resources"); + return super.execute(message); } } 1.1 xml-xindice/java/src/org/apache/xindice/server/rpc/messages/GetResource.java Index: GetResource.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xindice" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999-2001, The dbXML * Group, L.L.C., http://www.dbxmlgroup.com. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * CVS $Id: GetResource.java,v 1.1 2003/12/24 02:48:52 vgritsenko Exp $ */ package org.apache.xindice.server.rpc.messages; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.xindice.core.Collection; import org.apache.xindice.server.rpc.RPCDefaultMessage; import org.apache.xindice.util.SymbolSerializer; import org.apache.xindice.xml.TextWriter; import org.w3c.dom.Document; import java.util.Hashtable; /** * * @version CVS $Revision: 1.1 $, $Date: 2003/12/24 02:48:52 $ */ public class GetResource extends RPCDefaultMessage { private static final Log log = LogFactory.getLog(GetResource.class); public Hashtable execute(Hashtable message) throws Exception { if (!message.containsKey(COLLECTION)) { throw new Exception(MISSING_COLLECTION_PARAM); } if (!message.containsKey(NAME)) { throw new Exception(MISSING_NAME_PARAM); } Collection col = getCollection((String) message.get(COLLECTION)); Object obj = col.getEntry(message.get(NAME)); if (obj == null) { throw new Exception(API_NAME + ": Document not found " + (String) message.get(NAME)); } Hashtable result = new Hashtable(); if (obj instanceof byte[]) { // Binary resource result.put(RESULT, obj); } else if (message.containsKey(COMPRESSED)) { SymbolSerializer symbolSerializer = null; try { symbolSerializer = new SymbolSerializer(col.getSymbols()); } catch (Exception e) { // It's ok (in theory) for a Collection to have no symbol table if (log.isWarnEnabled()) { log.warn("ignored exception", e); } } long timestamp = 1; /* TODO: Timestamp optimization. Longs are causing problems with XML-RPC so we'll try to get everything working without them. if (!message.containsKey(TIMESTAMP)) { throw new Exception(MISSING_TIMESTAMP_PARAM); } int timestamp = ((Integer) message.get("timestamp")).intValue(); */ Document doc = (Document)obj; if (/*( timestamp != -1) &&*/ (symbolSerializer != null)) { result.put(RESULT, symbolSerializer.convertFromDocument(doc, timestamp)); } else { result.put(RESULT, TextWriter.toString(doc)); } } else { Document doc = (Document)obj; result.put(RESULT, TextWriter.toString(doc)); } return result; } }