1 16 package org.apache.cocoon.components.source.impl; 17 18 import org.apache.avalon.framework.component.ComponentManager; 19 import org.apache.cocoon.ProcessingException; 20 import org.apache.cocoon.components.source.SourceUtil; 21 import org.apache.cocoon.environment.Environment; 22 import org.apache.cocoon.environment.ModifiableSource; 23 import org.apache.excalibur.source.Source; 24 import org.apache.excalibur.source.SourceException; 25 import org.apache.excalibur.source.SourceResolver; 26 import org.xml.sax.ContentHandler ; 27 import org.xml.sax.InputSource ; 28 import org.xml.sax.SAXException ; 29 30 import java.io.IOException ; 31 import java.io.InputStream ; 32 33 42 public final class AvalonToCocoonSource 43 implements ModifiableSource { 44 45 46 protected Source source; 47 48 49 protected SourceResolver resolver; 50 51 52 protected Environment environment; 53 54 55 protected ComponentManager manager; 56 57 60 public AvalonToCocoonSource(Source source, 61 SourceResolver resolver, 62 Environment environment, 63 ComponentManager manager) { 64 this.source = source; 65 this.resolver = resolver; 66 this.environment = environment; 67 this.manager = manager; 68 } 69 70 74 public long getLastModified() { 75 return this.source.getLastModified(); 76 } 77 78 82 public long getContentLength() { 83 return this.source.getContentLength(); 84 } 85 86 89 public InputStream getInputStream() 90 throws ProcessingException, IOException { 91 try { 92 return this.source.getInputStream(); 93 } catch (SourceException e) { 94 throw SourceUtil.handle(e); 95 } 96 } 97 98 106 public InputSource getInputSource() 107 throws ProcessingException, IOException { 108 try { 109 InputSource newObject = new InputSource (this.source.getInputStream()); 110 newObject.setSystemId(this.getSystemId()); 111 return newObject; 112 } catch (SourceException se) { 113 throw SourceUtil.handle(se); 114 } 115 } 116 117 120 public String getSystemId() { 121 return this.source.getURI(); 122 } 123 124 public void recycle() { 125 this.resolver.release(this.source); 126 this.source = null; 127 this.environment = null; 128 } 129 130 public void refresh() { 131 this.source.refresh(); 132 } 133 134 139 public void toSAX(ContentHandler handler) 140 throws SAXException { 141 try { 142 SourceUtil.parse(this.manager, this.source, handler); 143 } catch (ProcessingException pe) { 144 throw new SAXException ("ProcessingException during streaming.", pe); 145 } catch (IOException ioe) { 146 throw new SAXException ("IOException during streaming.", ioe); 147 } 148 } 149 150 } 151 | Popular Tags |