1 16 package org.apache.cocoon.generation; 17 18 import java.io.Serializable ; 19 20 import org.apache.avalon.framework.service.ServiceException; 21 import org.apache.cocoon.ResourceNotFoundException; 22 import org.apache.cocoon.ProcessingException; 23 import org.apache.cocoon.caching.CacheableProcessingComponent; 24 import org.apache.cocoon.components.sax.XMLDeserializer; 25 26 import org.apache.excalibur.source.SourceValidity; 27 import org.apache.excalibur.source.impl.validity.NOPValidity; 28 import org.apache.excalibur.store.Store; 29 30 import org.xml.sax.SAXException ; 31 32 47 public class FragmentExtractorGenerator extends ServiceableGenerator 48 implements CacheableProcessingComponent { 49 50 56 public Serializable getKey() { 57 return this.source; 58 } 59 60 66 public SourceValidity getValidity() { 67 return NOPValidity.SHARED_INSTANCE; 68 } 69 70 public void generate() throws SAXException , ProcessingException { 71 if (getLogger().isDebugEnabled()) { 73 getLogger().debug("Retrieving fragment " + source + "."); 74 } 75 76 Store store = null; 77 XMLDeserializer deserializer = null; 78 Object fragment = null; 79 try { 80 store = (Store) this.manager.lookup(Store.TRANSIENT_STORE); 81 fragment = store.get(source); 82 if (fragment == null) { 83 throw new ResourceNotFoundException("Could not find fragment " + source + " in store"); 84 } 85 86 deserializer = (XMLDeserializer) this.manager.lookup(XMLDeserializer.ROLE); 87 deserializer.setConsumer(this.xmlConsumer); 88 deserializer.deserialize(fragment); 89 90 } catch (ServiceException ce) { 91 if (getLogger().isDebugEnabled()) { 92 getLogger().debug("Could not lookup for component.", ce); 93 } 94 throw new SAXException ("Could not lookup for component.", ce); 95 } finally { 96 this.manager.release(store); 97 this.manager.release(deserializer); 98 } 99 } 100 } 101 | Popular Tags |