01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.taglib.core;
18:
19: import org.apache.cocoon.ProcessingException;
20: import org.apache.cocoon.components.source.SourceUtil;
21: import org.apache.cocoon.taglib.XMLProducerTagSupport;
22: import org.apache.cocoon.xml.EmbeddedXMLPipe;
23:
24: import org.apache.excalibur.source.Source;
25:
26: import org.xml.sax.SAXException;
27:
28: /**
29: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
30: * @version CVS $Id: SourceTag.java 433543 2006-08-22 06:22:54Z crossley $
31: */
32: public class SourceTag extends XMLProducerTagSupport {
33: private String src;
34:
35: public void setSrc(String src) {
36: this .src = src;
37: }
38:
39: /*
40: * @see Tag#doEndTag(String, String, String)
41: */
42: public int doEndTag(String namespaceURI, String localName,
43: String qName) throws SAXException {
44: Source source = null;
45: try {
46: source = resolver.resolveURI(src);
47: SourceUtil.toSAX(source, new EmbeddedXMLPipe(
48: this .xmlConsumer));
49: } catch (SAXException e) {
50: throw e;
51: } catch (Exception e) {
52: if (e instanceof ProcessingException) {
53: ProcessingException pe = (ProcessingException) e;
54: Throwable t = pe.getCause();
55: if (t != null && t instanceof SAXException)
56: throw (SAXException) t;
57: }
58: throw new SAXException(e.getMessage(), e);
59: } finally {
60: if (source != null) {
61: resolver.release(source);
62: }
63: }
64: return EVAL_PAGE;
65: }
66:
67: /*
68: * @see Recyclable#recycle()
69: */
70: public void recycle() {
71: this.src = null;
72: super.recycle();
73: }
74: }
|