1 16 package org.apache.cocoon.components.source.impl; 17 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.util.Iterator ; 21 22 import org.apache.avalon.excalibur.pool.Recyclable; 23 import org.apache.cocoon.ProcessingException; 24 import org.apache.cocoon.ResourceNotFoundException; 25 import org.apache.cocoon.environment.ModifiableSource; 26 import org.apache.excalibur.source.Source; 27 import org.apache.excalibur.source.SourceException; 28 import org.apache.excalibur.source.SourceNotFoundException; 29 import org.apache.excalibur.source.SourceValidity; 30 import org.apache.excalibur.source.impl.validity.TimeStampValidity; 31 import org.apache.excalibur.xml.sax.XMLizable; 32 import org.xml.sax.ContentHandler ; 33 import org.xml.sax.SAXException ; 34 35 42 public final class CocoonToAvalonSource 43 implements Source, XMLizable, Recyclable { 44 45 46 protected org.apache.cocoon.environment.Source source; 47 48 49 protected String protocol; 50 51 54 public CocoonToAvalonSource( 55 String location, 56 org.apache.cocoon.environment.Source source) { 57 this.source = source; 58 int pos = location.indexOf(':'); 59 this.protocol = location.substring(0, pos); 60 } 61 62 65 public String getScheme() { 66 return this.protocol; 67 } 68 69 72 public boolean exists() { 73 try { 74 this.getInputStream(); 75 return true; 76 } catch (Exception local) { 77 return false; 78 } 79 } 80 81 84 public InputStream getInputStream() throws IOException , SourceException { 85 try { 86 return this.source.getInputStream(); 87 } catch (ResourceNotFoundException rnfe) { 88 throw new SourceNotFoundException("Source not found.", rnfe); 89 } catch (ProcessingException pe) { 90 throw new SourceException("ProcessingException", pe); 91 } 92 } 93 94 97 public String getURI() { 98 return this.source.getSystemId(); 99 } 100 101 107 public SourceValidity getValidity() { 108 if (this.source.getLastModified() > 0) { 109 return new TimeStampValidity(this.source.getLastModified()); 110 } 111 return null; 112 } 113 114 118 public void refresh() { 119 if (this.source instanceof ModifiableSource) { 120 ((ModifiableSource) this.source).refresh(); 121 } 122 } 123 124 129 public String getMimeType() { 130 return null; 131 } 132 133 136 public void toSAX(ContentHandler contentHandler) throws SAXException { 137 this.source.toSAX(contentHandler); 138 } 139 140 143 public void recycle() { 144 this.source.recycle(); 145 } 146 147 151 public long getContentLength() { 152 return this.source.getContentLength(); 153 } 154 155 159 public long getLastModified() { 160 return this.source.getLastModified(); 161 } 162 163 168 public String getParameter(String name) { 169 return null; 170 } 171 172 177 public long getParameterAsLong(String name) { 178 return 0; 179 } 180 181 186 public Iterator getParameterNames() { 187 return java.util.Collections.EMPTY_LIST.iterator(); 188 } 189 190 } 191 | Popular Tags |