|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SetDocumentMeta.java | 50% | 80% | 100% | 72.4% |
|
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: SetDocumentMeta.java 595817 2007-11-16 20:49:03Z vgritsenko $ | |
18 | */ | |
19 | ||
20 | package org.apache.xindice.server.rpc.messages; | |
21 | ||
22 | import org.apache.xindice.core.Collection; | |
23 | import org.apache.xindice.core.meta.MetaData; | |
24 | import org.apache.xindice.server.rpc.RPCDefaultMessage; | |
25 | import org.apache.xindice.xml.TextWriter; | |
26 | import org.apache.xindice.xml.dom.DOMParser; | |
27 | import org.apache.xindice.xml.dom.DocumentImpl; | |
28 | ||
29 | import org.w3c.dom.Document; | |
30 | ||
31 | import java.util.HashMap; | |
32 | import java.util.Map; | |
33 | ||
34 | /** | |
35 | * XML-RPC message to set the meta data associated with a document | |
36 | * | |
37 | * @author <a href="mailto:dviner@apache.org">Dave Viner</a> | |
38 | * @version $Revision: 595817 $, $Date: 2007-11-16 20:49:03 +0000 (Fri, 16 Nov 2007) $ | |
39 | */ | |
40 | public class SetDocumentMeta extends RPCDefaultMessage { | |
41 | ||
42 | /** | |
43 | * Set the MetaData object for the requested document. | |
44 | * | |
45 | * This method expects the Map to contain the name of the collection | |
46 | * in the RPCDefaultMessage.COLLECTION key, the name of the document in | |
47 | * the RPCDefaultMessage.NAME key, and the XML for the new MetaData | |
48 | * object in the RPCDefaultMessage.META key. It will return an XML | |
49 | * representation of the newly created MetaData object associated with this | |
50 | * document. The XML will be stored in the RPCDefaultMessage.RESULT key. | |
51 | * | |
52 | * @param message the parameters passed to the xmlrpc method. | |
53 | * @return Map containing XML of the newly created MetaData object. | |
54 | */ | |
55 | 4 | public Map execute(Map message) throws Exception { |
56 | ||
57 | 4 | if (!message.containsKey(COLLECTION)) { |
58 | 0 | throw new Exception(MISSING_COLLECTION_PARAM); |
59 | } | |
60 | 4 | if (!message.containsKey(NAME)) { |
61 | 0 | throw new Exception(MISSING_NAME_PARAM); |
62 | } | |
63 | 4 | if (!message.containsKey(META)) { |
64 | 0 | throw new Exception(MISSING_META_PARAM); |
65 | } | |
66 | ||
67 | 4 | Collection col = getCollection((String) message.get(COLLECTION)); |
68 | 4 | if (!col.isMetaEnabled()) { |
69 | // meta information is not enabled ! | |
70 | 0 | throw new Exception(MISSING_META_CONFIGURATION); |
71 | } | |
72 | ||
73 | // Read and store sent meta data | |
74 | 4 | MetaData meta = new MetaData(); |
75 | 4 | Document doc = DOMParser.toDocument((String) message.get(META)); |
76 | 4 | meta.streamFromXML(doc.getDocumentElement()); |
77 | ||
78 | 4 | String docname = (String) message.get(NAME); |
79 | 4 | col.setDocumentMeta(docname, meta); |
80 | ||
81 | // Retreive stored meta data and sent back | |
82 | 4 | meta = col.getDocumentMeta(docname); |
83 | 4 | doc = new DocumentImpl(); |
84 | 4 | meta.streamToXML(doc, true); |
85 | ||
86 | 4 | Map result = new HashMap(3); |
87 | 4 | result.put(RESULT, TextWriter.toString(doc)); |
88 | 4 | return result; |
89 | } | |
90 | } |
|