KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > taglib > core > SourceTag


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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.apache.cocoon.taglib.core;
17
18 import org.apache.cocoon.ProcessingException;
19 import org.apache.cocoon.components.source.SourceUtil;
20 import org.apache.cocoon.taglib.XMLProducerTagSupport;
21 import org.apache.cocoon.xml.EmbeddedXMLPipe;
22
23 import org.apache.excalibur.source.Source;
24
25 import org.xml.sax.SAXException JavaDoc;
26
27 /**
28  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
29  * @version CVS $Id: SourceTag.java 53976 2004-10-07 14:21:36Z vgritsenko $
30  */

31 public class SourceTag extends XMLProducerTagSupport {
32     private String JavaDoc src;
33
34     public void setSrc(String JavaDoc src) {
35         this.src = src;
36     }
37
38     /*
39      * @see Tag#doEndTag(String, String, String)
40      */

41     public int doEndTag(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName)
42     throws SAXException JavaDoc {
43         Source source = null;
44         try {
45             source = resolver.resolveURI(src);
46             SourceUtil.toSAX(source, new EmbeddedXMLPipe(this.xmlConsumer));
47         } catch (SAXException JavaDoc e) {
48             throw e;
49         } catch (Exception JavaDoc e) {
50             if (e instanceof ProcessingException) {
51                 ProcessingException pe = (ProcessingException) e;
52                 Throwable JavaDoc t = pe.getCause();
53                 if (t != null && t instanceof SAXException JavaDoc)
54                     throw (SAXException JavaDoc) t;
55             }
56             throw new SAXException JavaDoc(e.getMessage(), e);
57         } finally {
58             if (source != null) {
59                 resolver.release(source);
60             }
61         }
62         return EVAL_PAGE;
63     }
64
65     /*
66      * @see Recyclable#recycle()
67      */

68     public void recycle() {
69         this.src = null;
70         super.recycle();
71     }
72 }
73
Popular Tags