Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 89   Methods: 1
NCLOC: 45   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
GetResource.java 64.3% 77.3% 100% 73%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: GetResource.java 712565 2008-11-09 21:52:26Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.server.rpc.messages;
 21   
 22    import org.apache.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24    import org.apache.xindice.core.Collection;
 25    import org.apache.xindice.core.data.Entry;
 26    import org.apache.xindice.server.rpc.RPCDefaultMessage;
 27    import org.apache.xindice.util.SymbolSerializer;
 28    import org.apache.xindice.xml.TextWriter;
 29    import org.apache.xindice.xml.dom.CompressedDocument;
 30   
 31    import org.w3c.dom.Document;
 32   
 33    import java.util.HashMap;
 34    import java.util.Map;
 35   
 36    /**
 37    *
 38    * @version $Revision: 712565 $, $Date: 2008-11-09 21:52:26 +0000 (Sun, 09 Nov 2008) $
 39    */
 40    public class GetResource extends RPCDefaultMessage {
 41   
 42  176 public Map execute(Map message) throws Exception {
 43  176 if (!message.containsKey(COLLECTION)) {
 44  0 throw new Exception(MISSING_COLLECTION_PARAM);
 45    }
 46   
 47  176 if (!message.containsKey(NAME)) {
 48  0 throw new Exception(MISSING_NAME_PARAM);
 49    }
 50   
 51  176 Collection col = getCollection((String) message.get(COLLECTION));
 52  176 Entry obj = col.getEntry(message.get(NAME));
 53   
 54  176 Map result = new HashMap(3);
 55  176 if (obj == null) {
 56    // Return empty result
 57   
 58  171 } else if (obj.getEntryType() == Entry.BINARY) {
 59    // Binary resource
 60  2 result.put(RESULT, obj.getValue());
 61   
 62  169 } else if (message.containsKey(COMPRESSED)) {
 63    // Compressed XML resource
 64   
 65    // Document might be compressed (with bytes) or not. In a latter case, send a string.
 66  169 CompressedDocument doc = (CompressedDocument) obj.getValue();
 67  169 if (doc.getDataBytes() != null) {
 68  169 SymbolSerializer symbolSerializer = new SymbolSerializer(col.getSymbols());
 69   
 70    // Get client's symbol table timestamp
 71  169 long timestamp = 0;
 72  169 if (message.containsKey(TIMESTAMP)) {
 73  169 timestamp = Long.parseLong((String) message.get("timestamp"));
 74    }
 75   
 76  169 result.put(RESULT, symbolSerializer.serialize(doc, timestamp));
 77    } else {
 78  0 result.put(RESULT, TextWriter.toString(doc));
 79    }
 80   
 81    } else {
 82    // Uncompressed XML resource
 83  0 Document doc = (Document) obj.getValue();
 84  0 result.put(RESULT, TextWriter.toString(doc));
 85    }
 86   
 87  176 return result;
 88    }
 89    }