Package org.apache.xindice.server.rpc.messages

Source Code of org.apache.xindice.server.rpc.messages.GetResource

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: GetResource.java 595817 2007-11-16 20:49:03Z vgritsenko $
*/

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.core.data.Entry;
import org.apache.xindice.server.rpc.RPCDefaultMessage;
import org.apache.xindice.util.SymbolSerializer;
import org.apache.xindice.xml.TextWriter;
import org.apache.xindice.xml.dom.CompressedDocument;

import org.w3c.dom.Document;

import java.util.HashMap;
import java.util.Map;

/**
*
* @version $Revision: 595817 $, $Date: 2007-11-16 15:49:03 -0500 (Fri, 16 Nov 2007) $
*/
public class GetResource extends RPCDefaultMessage {

    private static final Log log = LogFactory.getLog(GetResource.class);

    public Map execute(Map 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));
        Entry obj = col.getEntry(message.get(NAME));

        Map result = new HashMap(3);
        if (obj == null) {
            // Return empty result

        } else if (obj.getEntryType() == Entry.BINARY) {
            // Binary resource
            result.put(RESULT, obj.getValue());

        } else if (message.containsKey(COMPRESSED)) {
            // Compressed XML resource
            SymbolSerializer symbolSerializer = new SymbolSerializer(col.getSymbols());

            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 might be compressed (with bytes) or not. In a latter case, convert to string.
            Document doc = (Document) obj.getValue();
            if (/*( timestamp != -1) &&*/ ((CompressedDocument) doc).getDataBytes() != null) {
                result.put(RESULT, symbolSerializer.convertFromDocument(doc, timestamp));
            } else {
                result.put(RESULT, TextWriter.toString(doc));
            }

        } else {
            // XML resource
            Document doc = (Document) obj.getValue();
            result.put(RESULT, TextWriter.toString(doc));
        }

        return result;
    }
}
TOP

Related Classes of org.apache.xindice.server.rpc.messages.GetResource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.