1 16 package org.apache.cocoon.generation; 17 18 import org.apache.avalon.framework.parameters.Parameters; 19 import org.apache.cocoon.ProcessingException; 20 import org.apache.cocoon.caching.CacheableProcessingComponent; 21 import org.apache.cocoon.components.source.SourceUtil; 22 import org.apache.cocoon.environment.SourceResolver; 23 import org.apache.excalibur.source.Source; 24 import org.apache.excalibur.source.SourceException; 25 import org.apache.excalibur.source.SourceValidity; 26 import org.xml.sax.SAXException ; 27 28 import java.io.IOException ; 29 import java.io.Serializable ; 30 import java.util.Map ; 31 32 51 public class FileGenerator extends ServiceableGenerator 52 implements CacheableProcessingComponent { 53 54 55 protected Source inputSource; 56 57 61 public void recycle() { 62 if (null != this.inputSource) { 63 super.resolver.release(this.inputSource); 64 this.inputSource = null; 65 } 66 super.recycle(); 67 } 68 69 73 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) 74 throws ProcessingException, SAXException , IOException { 75 76 super.setup(resolver, objectModel, src, par); 77 try { 78 this.inputSource = super.resolver.resolveURI(src); 79 } catch (SourceException se) { 80 throw SourceUtil.handle("Error during resolving of '" + src + "'.", se); 81 } 82 } 83 84 90 public Serializable getKey() { 91 return this.inputSource.getURI(); 92 } 93 94 100 public SourceValidity getValidity() { 101 return this.inputSource.getValidity(); 102 } 103 104 107 public void generate() 108 throws IOException , SAXException , ProcessingException { 109 110 try { 111 if (getLogger().isDebugEnabled()) { 112 getLogger().debug("Source " + super.source + 113 " resolved to " + this.inputSource.getURI()); 114 } 115 SourceUtil.parse(this.manager, this.inputSource, super.xmlConsumer); 116 } catch (SAXException e) { 117 SourceUtil.handleSAXException(this.inputSource.getURI(), e); 118 } 119 } 120 } 121 | Popular Tags |