KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > publisher > serverimpl > docpreparation > QueryIncludeProcessor


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.docpreparation;
17
18 import org.xml.sax.SAXException JavaDoc;
19 import org.xml.sax.ContentHandler JavaDoc;
20 import org.xml.sax.helpers.AttributesImpl JavaDoc;
21 import org.outerj.daisy.repository.VariantKey;
22 import org.outerj.daisy.repository.query.EvaluationContext;
23 import org.outerj.daisy.publisher.serverimpl.requestmodel.PublisherVersionMode;
24
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 /**
29  * This ContentHandler executes queries and inserts include
30  * instructions for the documents in the resultset (rather
31  * then including the resultset itself).
32  */

33 public class QueryIncludeProcessor extends QueriesProcessor {
34     public QueryIncludeProcessor(ContentHandler JavaDoc consumer, ContentProcessor owner) {
35         super(consumer, owner);
36     }
37
38     protected String JavaDoc getSensitiveClass() {
39         return "query-and-include";
40     }
41
42     protected void executeQuery(String JavaDoc query) throws SAXException JavaDoc {
43         VariantKey[] result = null;
44         try {
45             EvaluationContext evaluationContext = new EvaluationContext();
46             evaluationContext.setContextDocument(owner.getDocument(), owner.getVersion());
47             result = queryManager.performQueryReturnKeys(query, null, getQueryOptions(), locale, evaluationContext);
48         } catch (Exception JavaDoc e) {
49             outputFailedQueryMessage(e, query);
50         }
51
52         if (result != null) {
53             // output include instructions for each query result
54
for (int i = 0; i < result.length; i++) {
55                 AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
56                 attrs.addAttribute("", "class", "class", "CDATA", "include");
57                 consumer.startElement("", "pre", "pre", attrs);
58                 VariantKey key = result[i];
59                 String JavaDoc url = "daisy:" + String.valueOf(key.getDocumentId()) + "@" + String.valueOf(key.getBranchId()) + ":" + String.valueOf(key.getLanguageId());
60                 characters(url.toCharArray(), 0, url.length());
61                 consumer.endElement("", "pre", "pre");
62             }
63         }
64     }
65 }
66
Popular Tags