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

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

/*
* 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: SetDocumentMeta.java 595817 2007-11-16 20:49:03Z vgritsenko $
*/

package org.apache.xindice.server.rpc.messages;

import org.apache.xindice.core.Collection;
import org.apache.xindice.core.meta.MetaData;
import org.apache.xindice.server.rpc.RPCDefaultMessage;
import org.apache.xindice.xml.TextWriter;
import org.apache.xindice.xml.dom.DOMParser;
import org.apache.xindice.xml.dom.DocumentImpl;

import org.w3c.dom.Document;

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

/**
* XML-RPC message to set the meta data associated with a document
*
* @author <a href="mailto:dviner@apache.org">Dave Viner</a>
* @version $Revision: 595817 $, $Date: 2007-11-16 15:49:03 -0500 (Fri, 16 Nov 2007) $
*/
public class SetDocumentMeta extends RPCDefaultMessage {

    /**
     * Set the MetaData object for the requested document.
     *
     * This method expects the Map to contain the name of the collection
     * in the RPCDefaultMessage.COLLECTION key, the name of the document in
     * the RPCDefaultMessage.NAME key, and the XML for the new MetaData
     * object in the RPCDefaultMessage.META key.  It will return an XML
     * representation of the newly created MetaData object associated with this
     * document. The XML will be stored in the RPCDefaultMessage.RESULT key.
     *
     * @param message the parameters passed to the xmlrpc method.
     * @return Map containing XML of the newly created MetaData object.
     */
    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);
        }
        if (!message.containsKey(META)) {
            throw new Exception(MISSING_META_PARAM);
        }

        Collection col = getCollection((String) message.get(COLLECTION));
        if (!col.isMetaEnabled()) {
            // meta information is not enabled !
            throw new Exception(MISSING_META_CONFIGURATION);
        }

        // Read and store sent meta data
        MetaData meta = new MetaData();
        Document doc = DOMParser.toDocument((String) message.get(META));
        meta.streamFromXML(doc.getDocumentElement());

        String docname = (String) message.get(NAME);
        col.setDocumentMeta(docname, meta);

        // Retreive stored meta data and sent back
        meta = col.getDocumentMeta(docname);
        doc = new DocumentImpl();
        meta.streamToXML(doc, true);

        Map result = new HashMap(3);
        result.put(RESULT, TextWriter.toString(doc));
        return result;
    }
}
TOP

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

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.