KickJava   Java API By Example, From Geeks To Geeks.

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


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.outerj.daisy.xmlutil.SaxBuffer;
19 import org.outerj.daisy.publisher.serverimpl.PublisherImpl;
20 import org.outerj.daisy.repository.VariantKey;
21 import org.xml.sax.ContentHandler JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23 import org.xml.sax.helpers.AttributesImpl JavaDoc;
24
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 /**
30  * An object containing a 'prepared' copy of a document and of all
31  * the documents it includes, 'prepared' meaning that it includes
32  * the content of HTML parts, with queries executed, includes processed, ...
33  */

34 public class PreparedDocuments {
35     private List JavaDoc preparedDocuments = new ArrayList JavaDoc();
36     private final VariantKey navigationDoc;
37     private final String JavaDoc pubReqSet;
38
39     public PreparedDocuments(VariantKey navigationDoc, String JavaDoc pubReqSet) {
40         this.navigationDoc = navigationDoc;
41         this.pubReqSet = pubReqSet;
42     }
43
44     public PreparedDocument getNewPreparedDocument(VariantKey document) {
45         int id = preparedDocuments.size() + 1;
46         PreparedDocument preparedDocument = new PreparedDocument(new SaxBuffer(), id, document);
47         preparedDocuments.add(preparedDocument);
48         return preparedDocument;
49     }
50
51     public static class PreparedDocument {
52         private VariantKey documentKey;
53         private SaxBuffer saxBuffer;
54         private int id;
55
56         public PreparedDocument(SaxBuffer saxBuffer, int id, VariantKey documentKey) {
57             this.saxBuffer = saxBuffer;
58             this.id = id;
59             this.documentKey = documentKey;
60         }
61
62         public SaxBuffer getSaxBuffer() {
63             return saxBuffer;
64         }
65
66         public int getId() {
67             return id;
68         }
69
70         public VariantKey getDocumentKey() {
71             return documentKey;
72         }
73     }
74
75     public void generateSax(ContentHandler JavaDoc contentHandler, boolean applyDocumentSpecificStyling) throws SAXException JavaDoc {
76         AttributesImpl JavaDoc rootAttrs = new AttributesImpl JavaDoc();
77         rootAttrs.addAttribute("", "applyDocumentTypeStyling", "applyDocumentTypeStyling", "CDATA", String.valueOf(applyDocumentSpecificStyling));
78         contentHandler.startElement(PublisherImpl.NAMESPACE, "preparedDocuments", "p:preparedDocuments", rootAttrs);
79
80         Iterator JavaDoc documentsIt = preparedDocuments.iterator();
81         while (documentsIt.hasNext()) {
82             PreparedDocument preparedDocument = (PreparedDocument)documentsIt.next();
83             AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
84             attrs.addAttribute("", "id", "id", "CDATA", String.valueOf(preparedDocument.getId()));
85             VariantKey documentKey = preparedDocument.getDocumentKey();
86             attrs.addAttribute("", "documentId", "documentId", "CDATA", String.valueOf(documentKey.getDocumentId()));
87             attrs.addAttribute("", "branchId", "branchId", "CDATA", String.valueOf(documentKey.getBranchId()));
88             attrs.addAttribute("", "languageId", "languageId", "CDATA", String.valueOf(documentKey.getLanguageId()));
89
90             contentHandler.startElement(PublisherImpl.NAMESPACE, "preparedDocument", "p:preparedDocument", attrs);
91             preparedDocument.getSaxBuffer().toSAX(contentHandler);
92             contentHandler.endElement(PublisherImpl.NAMESPACE, "preparedDocument", "p:preparedDocument");
93         }
94
95         contentHandler.endElement(PublisherImpl.NAMESPACE, "preparedDocuments", "p:preparedDocuments");
96     }
97
98     public VariantKey getNavigationDoc() {
99         return navigationDoc;
100     }
101
102     public String JavaDoc getPubReqSet() {
103         return pubReqSet;
104     }
105 }
106
Popular Tags