KickJava   Java API By Example, From Geeks To Geeks.

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


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.repository.*;
22
23 import java.util.Map JavaDoc;
24 import java.util.HashMap JavaDoc;
25
26 public class ForEachRequest implements Request {
27     private final String JavaDoc query;
28     private final boolean useLastVersion;
29     private final DocumentRequest documentRequest;
30
31     public ForEachRequest(String JavaDoc query, boolean useLastVersion, DocumentRequest documentRequest) {
32         this.query = query;
33         this.useLastVersion = useLastVersion;
34         this.documentRequest = documentRequest;
35     }
36
37     public void process(ContentHandler JavaDoc contentHandler, PublisherContext publisherContext) throws Exception JavaDoc {
38         EvaluationContext evaluationContext = new EvaluationContext();
39         if (publisherContext.hasDocument())
40             evaluationContext.setContextDocument(publisherContext.getDocument(), publisherContext.getVersion());
41         QueryManager queryManager = publisherContext.getRepository().getQueryManager();
42
43         Map JavaDoc queryOptions = null;
44         if (publisherContext.getVersionMode() == PublisherVersionMode.LAST) {
45             queryOptions = new HashMap JavaDoc(3);
46             queryOptions.put("search_last_version", "true");
47         }
48         
49         VariantKey[] keys = queryManager.performQueryReturnKeys(query, null, queryOptions, publisherContext.getLocale(), evaluationContext);
50
51         for (int i = 0; i < keys.length; i++) {
52             VariantKey currentKey = keys[i];
53             PublisherContextImpl childPublisherContext = new PublisherContextImpl(publisherContext);
54             childPublisherContext.setDocumentVariant(currentKey.getDocumentId(), currentKey.getBranchId(), currentKey.getLanguageId());
55             childPublisherContext.setVersionId(useLastVersion ? -2 : -3);
56             documentRequest.process(contentHandler, childPublisherContext);
57         }
58     }
59 }
60
Popular Tags