KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > publisher > serverimpl > requestmodel > PerformQueryRequest


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.publisher.serverimpl.requestmodel;
17
18 import org.xml.sax.ContentHandler JavaDoc;
19 import org.outerj.daisy.repository.query.QueryManager;
20 import org.outerj.daisy.repository.query.EvaluationContext;
21 import org.outerj.daisy.publisher.serverimpl.StripDocumentHandler;
22 import org.outerj.daisy.publisher.serverimpl.DummyLexicalHandler;
23 import org.outerx.daisy.x10.SearchResultDocument;
24
25 import java.util.Locale JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
28
29 public class PerformQueryRequest implements Request {
30     private final String JavaDoc query;
31     private final String JavaDoc extraConditions;
32
33     public PerformQueryRequest(String JavaDoc query, String JavaDoc extraConditions) {
34         this.query = query;
35         this.extraConditions = extraConditions;
36     }
37
38     public void process(ContentHandler JavaDoc contentHandler, PublisherContext publisherContext) throws Exception JavaDoc {
39         QueryManager queryManager = publisherContext.getRepository().getQueryManager();
40         Locale JavaDoc locale = publisherContext.getLocale();
41
42         EvaluationContext evaluationContext = new EvaluationContext();
43         if (publisherContext.hasDocument())
44             evaluationContext.setContextDocument(publisherContext.getDocument(), publisherContext.getVersion());
45
46         Map JavaDoc queryOptions = null;
47         if (publisherContext.getVersionMode() == PublisherVersionMode.LAST) {
48             queryOptions = new HashMap JavaDoc(3);
49             queryOptions.put("search_last_version", "true");
50         }
51
52         SearchResultDocument searchResultDocument =
53                 queryManager.performQuery(query, extraConditions, queryOptions, locale, evaluationContext);
54
55         searchResultDocument.save(new StripDocumentHandler(contentHandler), new DummyLexicalHandler());
56     }
57 }
58
Popular Tags