KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > importer > DefaultContentHandler


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.importer;
18
19 import java.io.InputStream JavaDoc;
20
21 import org.alfresco.util.ParameterCheck;
22 import org.xml.sax.Attributes JavaDoc;
23 import org.xml.sax.ErrorHandler JavaDoc;
24 import org.xml.sax.Locator JavaDoc;
25 import org.xml.sax.SAXException JavaDoc;
26 import org.xml.sax.SAXParseException JavaDoc;
27
28
29 /**
30  * Default Import Content Handler
31  *
32  * Responsible for interacting with an Alfresco Importer.
33  */

34 public class DefaultContentHandler
35     implements ImportContentHandler, ErrorHandler JavaDoc
36 {
37     private ImportContentHandler targetHandler = null;
38     private Importer importer = null;
39
40     
41     /**
42      * Construct
43      *
44      * @param targetHandler
45      */

46     public DefaultContentHandler(ImportContentHandler targetHandler)
47     {
48         ParameterCheck.mandatory("targetHandler", targetHandler);
49         this.targetHandler = targetHandler;
50     }
51
52     /*
53      * (non-Javadoc)
54      * @see org.alfresco.repo.importer.ImportContentHandler#setImporter(org.alfresco.repo.importer.Importer)
55      */

56     public void setImporter(Importer importer)
57     {
58         this.importer = importer;
59         this.targetHandler.setImporter(importer);
60     }
61
62     /*
63      * (non-Javadoc)
64      * @see org.alfresco.repo.importer.ImportContentHandler#importStream(java.lang.String)
65      */

66     public InputStream JavaDoc importStream(String JavaDoc content)
67     {
68         return targetHandler.importStream(content);
69     }
70     
71     /*
72      * (non-Javadoc)
73      * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
74      */

75     public void setDocumentLocator(Locator JavaDoc locator)
76     {
77         targetHandler.setDocumentLocator(locator);
78     }
79
80     /*
81      * (non-Javadoc)
82      * @see org.xml.sax.ContentHandler#startDocument()
83      */

84     public void startDocument() throws SAXException JavaDoc
85     {
86         importer.start();
87         targetHandler.startDocument();
88     }
89
90     /*
91      * (non-Javadoc)
92      * @see org.xml.sax.ContentHandler#endDocument()
93      */

94     public void endDocument() throws SAXException JavaDoc
95     {
96         try
97         {
98             targetHandler.endDocument();
99         }
100         finally
101         {
102             importer.end();
103         }
104     }
105
106     /*
107      * (non-Javadoc)
108      * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
109      */

110     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri) throws SAXException JavaDoc
111     {
112         targetHandler.startPrefixMapping(prefix, uri);
113     }
114
115     /*
116      * (non-Javadoc)
117      * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
118      */

119     public void endPrefixMapping(String JavaDoc prefix) throws SAXException JavaDoc
120     {
121         targetHandler.endPrefixMapping(prefix);
122     }
123
124     /*
125      * (non-Javadoc)
126      * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
127      */

128     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts) throws SAXException JavaDoc
129     {
130         targetHandler.startElement(uri, localName, qName, atts);
131     }
132
133     /*
134      * (non-Javadoc)
135      * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
136      */

137     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc
138     {
139         targetHandler.endElement(uri, localName, qName);
140     }
141
142     /*
143      * (non-Javadoc)
144      * @see org.xml.sax.ContentHandler#characters(char[], int, int)
145      */

146     public void characters(char[] ch, int start, int length) throws SAXException JavaDoc
147     {
148         targetHandler.characters(ch, start, length);
149     }
150
151     /*
152      * (non-Javadoc)
153      * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
154      */

155     public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException JavaDoc
156     {
157         targetHandler.ignorableWhitespace(ch, start, length);
158     }
159
160     /*
161      * (non-Javadoc)
162      * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
163      */

164     public void processingInstruction(String JavaDoc target, String JavaDoc data) throws SAXException JavaDoc
165     {
166         targetHandler.processingInstruction(target, data);
167     }
168
169     /*
170      * (non-Javadoc)
171      * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
172      */

173     public void skippedEntity(String JavaDoc name) throws SAXException JavaDoc
174     {
175         targetHandler.skippedEntity(name);
176     }
177
178     /*
179      * (non-Javadoc)
180      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
181      */

182     public void error(SAXParseException JavaDoc exception) throws SAXException JavaDoc
183     {
184         try
185         {
186             targetHandler.error(exception);
187         }
188         finally
189         {
190             importer.error(exception);
191         }
192     }
193
194     /*
195      * (non-Javadoc)
196      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
197      */

198     public void fatalError(SAXParseException JavaDoc exception) throws SAXException JavaDoc
199     {
200         try
201         {
202             targetHandler.error(exception);
203         }
204         finally
205         {
206             importer.error(exception);
207         }
208     }
209
210     /*
211      * (non-Javadoc)
212      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
213      */

214     public void warning(SAXParseException JavaDoc exception) throws SAXException JavaDoc
215     {
216         targetHandler.warning(exception);
217     }
218
219 }
220
Popular Tags