KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
20 import org.outerj.daisy.publisher.serverimpl.docpreparation.PreparedDocuments;
21 import org.outerj.daisy.publisher.serverimpl.PublisherImpl;
22 import org.outerj.daisy.publisher.serverimpl.StripDocumentHandler;
23 import org.outerj.daisy.publisher.PublisherException;
24
25 public class PreparedDocumentsRequest implements Request {
26     private final VariantKey navigationDoc;
27     private final boolean applyDocumentSpecificStyling;
28     private final String JavaDoc pubReqSet;
29
30     /**
31      *
32      * @param navigationDoc allowed to be null
33      */

34     public PreparedDocumentsRequest(VariantKey navigationDoc,
35             boolean applyDocumentSpecificStyling, String JavaDoc pubReqSet) {
36         this.navigationDoc = navigationDoc;
37         this.applyDocumentSpecificStyling = applyDocumentSpecificStyling;
38         this.pubReqSet = pubReqSet;
39     }
40
41     public void process(ContentHandler JavaDoc contentHandler, PublisherContext publisherContext) throws Exception JavaDoc {
42         Document document = publisherContext.getDocument();
43         Version version = publisherContext.getVersion();
44         if (version != null) {
45             if (publisherContext.searchRecursivePrepDocs(document.getId(), document.getBranchId(), document.getLanguageId(), pubReqSet)) {
46                 throw new PublisherException("Detected recursive p:preparedDocuments call on same document variant using the same publishe request set. Document variant: "
47                         + document.getVariantKey() + ", publisher request set: " + pubReqSet);
48             }
49             PreparedDocuments preparedDocuments = new PreparedDocuments(navigationDoc, pubReqSet);
50             PublisherImpl publisher = publisherContext.getPublisher();
51             PublisherContextImpl childPublisherContext = new PublisherContextImpl(publisherContext);
52             childPublisherContext.setPreparedDocuments(preparedDocuments);
53             childPublisherContext.setContentProcessor(null); // for the case where we have nested preparedDocuments calls
54

55             PreparedDocuments.PreparedDocument preparedDocument = preparedDocuments.getNewPreparedDocument(document.getVariantKey());
56             publisher.performRequest(pubReqSet, document, version, childPublisherContext, new StripDocumentHandler(preparedDocument.getSaxBuffer()));
57
58             preparedDocuments.generateSax(contentHandler, applyDocumentSpecificStyling);
59         }
60     }
61 }
62
Popular Tags