KickJava   Java API By Example, From Geeks To Geeks.

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


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.ContentHandler JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20 import org.xml.sax.Locator JavaDoc;
21 import org.xml.sax.Attributes JavaDoc;
22 import org.outerj.daisy.repository.Document;
23 import org.outerj.daisy.repository.Version;
24 import org.outerj.daisy.publisher.serverimpl.requestmodel.PublisherContext;
25
26 /**
27  * Processes special instructions in the content, such as queries
28  * and includes.
29  *
30  * <p>A ContentProcessor can be instantiated recursively by the
31  * IncludeProcessor: if the IncludeProcessor includes some content,
32  * it will create a new ContentProcessor and push the content
33  * through that ContentProcessor. ContentProcessors have a reference
34  * to their parent processor so that recursive includes can be
35  * detected.
36  *
37  * <p>From Daisy 1.5, this has been updated to perform a new publisher
38  * request for each included document.
39  *
40  * <pre>
41  * +--ContentProcessor---------------------------------------------+
42  * | +--------------+ +---------------------+ +----------------+ |
43  * | |QueryProcessor|->|QueryIncludeProcessor|->|IncludeProcessor| |
44  * | +--------------+ +---------------------+ +-------+--------+ |
45  * +----------------------------------------------------|----------+
46  * +____________________________________________|
47  * |
48  * +-------|-------------------------------------------------------+
49  * | +-----v--------+ +---------------------+ +----------------+ |
50  * | |QueryProcessor|->|QueryIncludeProcessor|->|IncludeProcessor| |
51  * | +--------------+ +---------------------+ +-------+--------+ |
52  * +----------------------------------------------------|----------+
53  * |
54  * v
55  * and so on
56  * </pre>
57  *
58  */

59 public class ContentProcessor implements ContentHandler JavaDoc {
60     private Document document;
61     private Version version;
62
63     private ContentHandler JavaDoc pipe;
64     private ContentProcessor parent;
65
66     private IncludesProcessor includesProcessor;
67     private PublisherContext publisherContext;
68     private PreparationPipe preparationPipe;
69
70     /**
71      * @param document the document whose data is being processed through this pipe
72      * @param version the version whose data is being processed through this pipe
73      * @param parent optional, can be null
74      */

75     public ContentProcessor(Document document, Version version, ContentHandler JavaDoc consumer, PreparationPipe preparationPipe,
76             PublisherContext publisherContext, ContentProcessor parent) {
77         this.document = document;
78         this.version = version;
79         this.includesProcessor = new IncludesProcessor(document, consumer, this);
80         this.preparationPipe = preparationPipe;
81         this.publisherContext = publisherContext;
82         this.parent = parent;
83         this.pipe = new QueriesProcessor(new QueryIncludeProcessor(includesProcessor, this), this);
84     }
85
86     public ContentProcessor getParent() {
87         return parent;
88     }
89
90     public void setParent(ContentProcessor parent) {
91         this.parent = parent;
92     }
93
94     public IncludesProcessor getIncludesProcessor() {
95         return includesProcessor;
96     }
97
98     public PublisherContext getPublisherContext() {
99         return publisherContext;
100     }
101
102     public PreparationPipe getPreparationPipe() {
103         return preparationPipe;
104     }
105
106     public Document getDocument() {
107         return document;
108     }
109
110     public Version getVersion() {
111         return version;
112     }
113
114     public void endDocument() throws SAXException JavaDoc {
115         pipe.endDocument();
116     }
117
118     public void startDocument () throws SAXException JavaDoc {
119         pipe.startDocument();
120     }
121
122     public void characters (char ch[], int start, int length) throws SAXException JavaDoc {
123         pipe.characters(ch, start, length);
124     }
125
126     public void ignorableWhitespace (char ch[], int start, int length) throws SAXException JavaDoc {
127         pipe.ignorableWhitespace(ch, start, length);
128     }
129
130     public void endPrefixMapping (String JavaDoc prefix) throws SAXException JavaDoc {
131         pipe.endPrefixMapping(prefix);
132     }
133
134     public void skippedEntity (String JavaDoc name) throws SAXException JavaDoc {
135         pipe.skippedEntity(name);
136     }
137
138     public void setDocumentLocator (Locator JavaDoc locator) {
139         pipe.setDocumentLocator(locator);
140     }
141
142     public void processingInstruction (String JavaDoc target, String JavaDoc data) throws SAXException JavaDoc {
143         pipe.processingInstruction(target, data);
144     }
145
146     public void startPrefixMapping (String JavaDoc prefix, String JavaDoc uri) throws SAXException JavaDoc {
147         pipe.startPrefixMapping(prefix, uri);
148     }
149
150     public void endElement (String JavaDoc namespaceURI, String JavaDoc localName,
151                             String JavaDoc qName) throws SAXException JavaDoc {
152         pipe.endElement(namespaceURI, localName, qName);
153     }
154
155     public void startElement (String JavaDoc namespaceURI, String JavaDoc localName,
156                               String JavaDoc qName, Attributes JavaDoc atts) throws SAXException JavaDoc {
157         pipe.startElement(namespaceURI, localName, qName, atts);
158     }
159 }
160
Popular Tags