vgritsenko 02/02/01 07:01:33 Modified: src/java/org/apache/cocoon/transformation FragmentExtractorTransformer.java Log: Make constants final; prevent (possible in future) reconfiguration bugs Revision Changes Path 1.7 +47 -45 xml-cocoon2/src/java/org/apache/cocoon/transformation/FragmentExtractorTransformer.java Index: FragmentExtractorTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/FragmentExtractorTransformer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- FragmentExtractorTransformer.java 31 Jan 2002 11:16:11 -0000 1.6 +++ FragmentExtractorTransformer.java 1 Feb 2002 15:01:33 -0000 1.7 @@ -17,6 +17,7 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.parameters.Parameters; + import org.apache.cocoon.ProcessingException; import org.apache.cocoon.caching.CacheValidity; import org.apache.cocoon.caching.Cacheable; @@ -26,6 +27,7 @@ import org.apache.cocoon.generation.FragmentExtractorGenerator; import org.apache.cocoon.xml.dom.DOMBuilder; import org.apache.cocoon.xml.dom.DOMFactory; + import org.w3c.dom.Document; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -37,13 +39,14 @@ import java.util.Map; -/** The transformation half of the FragmentExtractor. - * This transformer sieves an incoming stream of xml +/** + * The transformation half of the FragmentExtractor. + * This transformer sieves an incoming stream of xml * and replaces fragments with an xlink locator pointing to the fragments. * <p> * The extracted fragments are idendified by their element name and namespace URI. * The default is to extract SVG images ("svg" elements in namespace - * "http://www.w3.org/2000/svg"), but this can be overriden in the configuration : + * "http://www.w3.org/2000/svg"), but this can be overriden in the configuration: * <pre> * <extract-uri>http://my/namespace/uri</extract-uri> * <extract-element>my-element</extract-element> @@ -53,19 +56,22 @@ * and the associated generator are very likely to fail on a clustered server.</b> * * @author <a href="mailto:[EMAIL PROTECTED]">Paul Russell</a> - * @version CVS $Revision: 1.6 $ $Date: 2002/01/31 11:16:11 $ + * @version CVS $Revision: 1.7 $ $Date: 2002/02/01 15:01:33 $ */ public class FragmentExtractorTransformer extends AbstractTransformer implements Composable, Disposable, Cacheable, Poolable, Configurable { - private String extractURI = "http://www.w3.org/2000/svg"; - private String extractElement = "svg"; + private static final String EXTRACT_URI_NAME = "extract-uri"; + private static final String EXTRACT_ELEMENT_NAME = "extract-element"; + + private static final String EXTRACT_URI = "http://www.w3.org/2000/svg"; + private static final String EXTRACT_ELEMENT = "svg"; - private final static String EXTRACT_URI_NAME = "extract-uri"; - private final static String EXTRACT_ELEMENT_NAME = "extract-element"; + private static final String FE_URI = "http://apache.org/cocoon/fragmentextractor/2.0"; + private static final String XLINK_URI = "http://www.w3c.org/1999/xlink"; - private static String FE_URI = "http://apache.org/cocoon/fragmentextractor/2.0"; - private static String XLINK_URI = "http://www.w3c.org/1999/xlink"; + private String extractURI; + private String extractElement; private static String generatorClass = "org.apache.cocoon.generation.FragmentExtractorGenerator"; @@ -87,16 +93,13 @@ this.documentFactory = (DOMFactory) this.manager.lookup(Parser.ROLE); } - /** + /** * Configure this transformer. */ - public void configure( Configuration conf ) - throws ConfigurationException { - if ( conf != null ) { - - this.extractURI = conf.getChild(EXTRACT_URI_NAME).getValue(this.extractURI); - this.extractElement = conf.getChild(EXTRACT_ELEMENT_NAME).getValue(this.extractElement); - + public void configure(Configuration conf) throws ConfigurationException { + if (conf != null) { + this.extractURI = conf.getChild(EXTRACT_URI_NAME).getValue(EXTRACT_URI); + this.extractElement = conf.getChild(EXTRACT_ELEMENT_NAME).getValue(EXTRACT_ELEMENT); if (getLogger().isDebugEnabled()) { getLogger().debug("Extraction URI is " + this.extractURI); getLogger().debug("Extraction element is " + this.extractElement); @@ -104,8 +107,7 @@ } } - /** Setup the transformer. - */ + /** Setup the transformer. */ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException { extractLevel = 0; @@ -136,16 +138,14 @@ /** * Receive notification of the beginning of a document. */ - public void startDocument() - throws SAXException { + public void startDocument() throws SAXException { super.startDocument(); } /** * Receive notification of the end of a document. */ - public void endDocument() - throws SAXException { + public void endDocument() throws SAXException { super.endDocument(); } @@ -157,7 +157,7 @@ */ public void startPrefixMapping(String prefix, String uri) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.startPrefixMapping(prefix,uri); prefixMap.put(prefix,uri); } else { @@ -172,7 +172,7 @@ */ public void endPrefixMapping(String prefix) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.endPrefixMapping(prefix); prefixMap.remove(prefix); } else { @@ -195,7 +195,7 @@ */ public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException { - if ( this.extractURI.equals(uri) && this.extractElement.equals(loc) ) { + if (this.extractURI.equals(uri) && this.extractElement.equals(loc)) { extractLevel++; fragmentID++; getLogger().debug("FragmentExtractorTransformer extractLevel now " + extractLevel + "."); @@ -204,7 +204,7 @@ this.currentBuilder = new DOMBuilder(documentFactory); this.currentBuilder.startDocument(); Iterator itt = prefixMap.entrySet().iterator(); - while ( itt.hasNext() ) { + while (itt.hasNext()) { Map.Entry entry = (Map.Entry)itt.next(); this.currentBuilder.startPrefixMapping( (String)entry.getKey(), @@ -213,7 +213,7 @@ } } - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.startElement(uri,loc,raw,a); } else { this.currentBuilder.startElement(uri,loc,raw,a); @@ -234,18 +234,18 @@ */ public void endElement(String uri, String loc, String raw) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.endElement(uri,loc,raw); } else { this.currentBuilder.endElement(uri,loc,raw); - if ( this.extractURI.equals(uri) && this.extractElement.equals(loc) ) { + if (this.extractURI.equals(uri) && this.extractElement.equals(loc)) { extractLevel--; getLogger().debug("FragmentExtractorTransformer extractLevel now " + extractLevel + "."); - if ( extractLevel == 0 ) { + if (extractLevel == 0) { // finish building the DOM. remove existing prefix mappings. Iterator itt = prefixMap.entrySet().iterator(); - while ( itt.hasNext() ) { + while (itt.hasNext()) { Map.Entry entry = (Map.Entry) itt.next(); this.currentBuilder.endPrefixMapping( (String)entry.getKey() @@ -258,7 +258,7 @@ getLogger().debug("FragmentExtractorTransformer stored document " + id + "."); // Insert ref. - super.startPrefixMapping("fe",FE_URI); + super.startPrefixMapping("fe", FE_URI); AttributesImpl atts = new AttributesImpl(); atts.addAttribute(null,"fragment-id","fragment-id","CDATA",id); super.startElement(FE_URI,"fragment","fe:fragment",atts); @@ -278,7 +278,7 @@ */ public void characters(char c[], int start, int len) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.characters(c,start,len); } else { this.currentBuilder.characters(c,start,len); @@ -294,7 +294,7 @@ */ public void ignorableWhitespace(char c[], int start, int len) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.ignorableWhitespace(c,start,len); } else { this.currentBuilder.ignorableWhitespace(c,start,len); @@ -310,7 +310,7 @@ */ public void processingInstruction(String target, String data) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.processingInstruction(target,data); } else { this.currentBuilder.processingInstruction(target,data); @@ -325,7 +325,7 @@ */ public void skippedEntity(String name) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.skippedEntity(name); } else { this.currentBuilder.skippedEntity(name); @@ -343,7 +343,7 @@ */ public void startDTD(String name, String publicId, String systemId) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.startDTD(name,publicId,systemId); } else { throw new SAXException( @@ -357,7 +357,7 @@ */ public void endDTD() throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.endDTD(); } else { throw new SAXException( @@ -374,7 +374,7 @@ */ public void startEntity(String name) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.startEntity(name); } else { this.currentBuilder.startEntity(name); @@ -388,7 +388,7 @@ */ public void endEntity(String name) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.endEntity(name); } else { this.currentBuilder.endEntity(name); @@ -400,7 +400,7 @@ */ public void startCDATA() throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.startCDATA(); } else { this.currentBuilder.startCDATA(); @@ -412,7 +412,7 @@ */ public void endCDATA() throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.endCDATA(); } else { this.currentBuilder.endCDATA(); @@ -428,7 +428,7 @@ */ public void comment(char ch[], int start, int len) throws SAXException { - if ( extractLevel == 0 ) { + if (extractLevel == 0) { super.comment(ch,start,len); } else { this.currentBuilder.comment(ch,start,len); @@ -441,5 +441,7 @@ public void dispose() { if(this.documentFactory!=null) this.manager.release((Component) this.documentFactory); this.documentFactory = null; + + this.manager = null; } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]