bloritsch 01/06/08 07:13:22 Modified: src/org/apache/cocoon/sitemap Tag: cocoon_20_branch AbstractSitemap.java ContentAggregator.java ErrorNotifier.java Handler.java LinkTranslator.java Manager.java SitemapComponentSelector.java XSLTFactoryLoader.java Log: Code Cleanup: remove unnecessary imports, fix some loop declarations, etc. Revision Changes Path No revision No revision 1.4.2.3 +54 -25 xml-cocoon2/src/org/apache/cocoon/sitemap/AbstractSitemap.java Index: AbstractSitemap.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/AbstractSitemap.java,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.3 diff -u -r1.4.2.2 -r1.4.2.3 --- AbstractSitemap.java 2001/06/07 21:13:40 1.4.2.2 +++ AbstractSitemap.java 2001/06/08 14:13:17 1.4.2.3 @@ -7,7 +7,6 @@ *****************************************************************************/ package org.apache.cocoon.sitemap; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -18,7 +17,6 @@ import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; -import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.configuration.Configurable; @@ -29,28 +27,23 @@ import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.avalon.framework.thread.ThreadSafe; -import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.Processor; import org.apache.cocoon.Roles; import org.apache.cocoon.components.classloader.RepositoryClassLoader; import org.apache.cocoon.components.pipeline.EventPipeline; import org.apache.cocoon.components.pipeline.StreamPipeline; import org.apache.cocoon.components.url.URLFactory; import org.apache.cocoon.environment.Environment; -import org.apache.cocoon.environment.Request; import org.apache.cocoon.util.ClassUtils; import org.apache.avalon.excalibur.component.ExcaliburComponentManager; import org.apache.avalon.excalibur.component.ExcaliburComponentSelector; import org.apache.avalon.excalibur.component.RoleManager; import org.apache.avalon.excalibur.component.DefaultRoleManager; -import org.apache.log.Hierarchy; -import org.xml.sax.SAXException; /** * Base class for generated <code>Sitemap</code> classes * * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> - * @version CVS $Revision: 1.4.2.2 $ $Date: 2001/06/07 21:13:40 $ + * @version CVS $Revision: 1.4.2.3 $ $Date: 2001/06/08 14:13:17 $ */ public abstract class AbstractSitemap extends AbstractLoggable implements Sitemap, Disposable, ThreadSafe { private Context context; @@ -178,7 +171,7 @@ */ public void load_component(int type, Object hint, String classURL, Configuration configuration, String mime_type) throws Exception { - Class clazz; + Class clazz = null; //FIXME(GP): Is it true that a class name containing a colon should be an URL? if (classURL.indexOf(':') > 1) { URL url = urlFactory.getURL(classURL); @@ -229,9 +222,10 @@ getLogger().error ("cannot read class byte stream", ioe); } list.add(b); - b = new byte [(list.size()-1) * BYTE_ARRAY_SIZE + last]; + int listSize = list.size(); + b = new byte [(listSize-1) * BYTE_ARRAY_SIZE + last]; int i; - for (i = 0; i < list.size()-1; i++) { + for (i = 0; i < listSize-1; i++) { System.arraycopy(list.get(i), 0, b, i * BYTE_ARRAY_SIZE, BYTE_ARRAY_SIZE); } System.arraycopy(list.get(i), 0, b, i * BYTE_ARRAY_SIZE, last); @@ -244,8 +238,10 @@ */ protected String substitute (List list, String expr) throws PatternException, NumberFormatException { - if (expr == null) + if (expr == null) { return null; + } + StringBuffer result = new StringBuffer(); String s = null; int j = 0; @@ -258,22 +254,32 @@ while (ii <= expr.length() && (i = expr.indexOf('{', ii)) != -1) { result.append(expr.substring(ii, i)); j = expr.indexOf('}', i); - if (j < i) + if (j < i) { throw new PatternException ("invalid expression in \""+expr+"\""); + } + ii = j+1; - if (j == -1) + if (j == -1) { throw new PatternException ("invalid expression in URL "+expr); + } + k = list.size() - 1; s = expr.substring (i+1,j); - for (l = -1; (l = s.indexOf("../",l+1)) != -1; k--); + + l = -1; + + while ((l = s.indexOf("../",l+1)) != -1) { + k--; + } + m = s.lastIndexOf('/'); if (m == -1) { result.append((String)((Map)list.get(k)).get(s)); } else { result.append((String)((Map)list.get(k)).get(s.substring(m+1))); } - getLogger().debug("substitute evaluated value for " + (m == -1 ? s : s.substring(m+1)) - + " as " + (String)((Map)list.get(k)).get(m == -1 ? s : s.substring(m+1))); + getLogger().debug("substitute evaluated value for " + ((m == -1) ? s : s.substring(m+1)) + + " as " + (String)((Map)list.get(k)).get((m == -1) ? s : s.substring(m+1))); } if (ii < expr.length()) { result.append(expr.substring(ii)); @@ -330,13 +336,36 @@ * dispose */ public void dispose() { - if (this.urlFactory!=null) manager.release((Component)this.urlFactory); - if (this.generators!=null) manager.release((Component)this.generators); - if (this.transformers!=null) manager.release((Component)this.transformers); - if (this.serializers!=null) manager.release((Component)this.serializers); - if (this.readers!=null) manager.release((Component)this.readers); - if (this.actions!=null) manager.release((Component)this.actions); - if (this.matchers!=null) manager.release((Component)this.matchers); - if (this.selectors!=null) manager.release((Component)this.selectors); + if (this.urlFactory!=null) { + manager.release((Component)this.urlFactory); + } + + if (this.generators!=null) { + manager.release((Component)this.generators); + } + + if (this.transformers!=null) { + manager.release((Component)this.transformers); + } + + if (this.serializers!=null) { + manager.release((Component)this.serializers); + } + + if (this.readers!=null) { + manager.release((Component)this.readers); + } + + if (this.actions!=null) { + manager.release((Component)this.actions); + } + + if (this.matchers!=null) { + manager.release((Component)this.matchers); + } + + if (this.selectors!=null) { + manager.release((Component)this.selectors); + } } } 1.5.2.1 +8 -4 xml-cocoon2/src/org/apache/cocoon/sitemap/ContentAggregator.java Index: ContentAggregator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/ContentAggregator.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- ContentAggregator.java 2001/05/31 17:38:51 1.5 +++ ContentAggregator.java 2001/06/08 14:13:17 1.5.2.1 @@ -42,7 +42,7 @@ /** * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> - * @version CVS $Id: ContentAggregator.java,v 1.5 2001/05/31 17:38:51 bloritsch Exp $ + * @version CVS $Id: ContentAggregator.java,v 1.5.2.1 2001/06/08 14:13:17 bloritsch Exp $ */ public class ContentAggregator extends ContentHandlerWrapper @@ -257,13 +257,17 @@ EventPipeline ep = (EventPipeline)this.partEventPipelines.get(i); if(ep instanceof CacheableEventPipeline){ Map map = ((CacheableEventPipeline)ep).generateValidity(environment); - if(map == null) + if(map == null) { return null; - for(Iterator j=map.values().iterator(); j.hasNext();){ + } + + Iterator j = map.values().iterator(); + + while(j.hasNext()) { CacheValidity epv = (CacheValidity)j.next(); v.add(epv); } - }else{ + } else { return null; } } 1.2.2.1 +1 -4 xml-cocoon2/src/org/apache/cocoon/sitemap/ErrorNotifier.java Index: ErrorNotifier.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/ErrorNotifier.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- ErrorNotifier.java 2001/05/10 21:17:02 1.2 +++ ErrorNotifier.java 2001/06/08 14:13:18 1.2.2.1 @@ -7,13 +7,10 @@ *****************************************************************************/ package org.apache.cocoon.sitemap; -import java.util.Enumeration; -import java.util.Hashtable; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.cocoon.Notification; import org.apache.cocoon.Notifier; import org.apache.cocoon.generation.ComposerGenerator; -import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; /** @@ -22,7 +19,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> * @created 31 July 2000 - * @version CVS $Revision: 1.2 $ $Date: 2001/05/10 21:17:02 $ + * @version CVS $Revision: 1.2.2.1 $ $Date: 2001/06/08 14:13:18 $ */ public class ErrorNotifier extends ComposerGenerator implements Recyclable { 1.9.2.2 +12 -10 xml-cocoon2/src/org/apache/cocoon/sitemap/Handler.java Index: Handler.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/Handler.java,v retrieving revision 1.9.2.1 retrieving revision 1.9.2.2 diff -u -r1.9.2.1 -r1.9.2.2 --- Handler.java 2001/06/06 17:13:16 1.9.2.1 +++ Handler.java 2001/06/08 14:13:18 1.9.2.2 @@ -7,10 +7,7 @@ *****************************************************************************/ package org.apache.cocoon.sitemap; -import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URL; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentManager; @@ -34,8 +31,6 @@ import org.apache.cocoon.environment.FactoryURLResolver; import org.apache.cocoon.environment.URLResolver; import org.apache.cocoon.environment.Source; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; /** * Handles the manageing and stating of one <code>Sitemap</code> @@ -43,7 +38,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Revision: 1.9.2.1 $ $Date: 2001/06/06 17:13:16 $ + * @version CVS $Revision: 1.9.2.2 $ $Date: 2001/06/08 14:13:18 $ */ public class Handler extends AbstractLoggable implements Runnable, Configurable, Composable, Contextualizable, Processor, Disposable { @@ -204,7 +199,7 @@ /** Generate the Sitemap class */ public void run() { - Sitemap smap; + Sitemap smap = null; String markupLanguage = "sitemap"; String programmingLanguage = "java"; @@ -246,7 +241,10 @@ this.exception = (Exception) t; } } finally { - if(programGenerator != null) this.manager.release(programGenerator); + if(programGenerator != null) { + this.manager.release(programGenerator); + } + this.regeneration = null; this.environment = null; this.isRegenerationRunning = false; @@ -254,8 +252,9 @@ } public void throwEventualException() throws Exception { - if (this.exception != null) + if (this.exception != null) { throw new ProcessingException("Exception in Handler",this.exception); + } } public Exception getException() { @@ -266,7 +265,10 @@ * dispose */ public void dispose() { - if(urlFactory != null) manager.release((Component)urlFactory); + if(urlFactory != null) { + manager.release((Component)urlFactory); + } + this.urlResolver = null; } } 1.2.2.1 +1 -3 xml-cocoon2/src/org/apache/cocoon/sitemap/LinkTranslator.java Index: LinkTranslator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/LinkTranslator.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- LinkTranslator.java 2001/05/22 14:45:31 1.2 +++ LinkTranslator.java 2001/06/08 14:13:18 1.2.2.1 @@ -8,21 +8,19 @@ package org.apache.cocoon.sitemap; import java.io.IOException; -import java.io.PrintStream; import java.util.Map; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.Constants; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.transformation.Transformer; -import org.apache.cocoon.util.NetUtils; import org.apache.cocoon.xml.xlink.ExtendedXLinkPipe; import org.xml.sax.Attributes; import org.xml.sax.SAXException; /** * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Revision: 1.2 $ $Date: 2001/05/22 14:45:31 $ + * @version CVS $Revision: 1.2.2.1 $ $Date: 2001/06/08 14:13:18 $ */ public class LinkTranslator extends ExtendedXLinkPipe implements Transformer { 1.2.2.2 +13 -13 xml-cocoon2/src/org/apache/cocoon/sitemap/Manager.java Index: Manager.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/Manager.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- Manager.java 2001/06/06 17:13:18 1.2.2.1 +++ Manager.java 2001/06/08 14:13:19 1.2.2.2 @@ -7,9 +7,6 @@ *****************************************************************************/ package org.apache.cocoon.sitemap; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.MalformedURLException; import java.util.HashMap; import java.util.Iterator; import org.apache.avalon.framework.component.Component; @@ -23,14 +20,11 @@ import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.avalon.excalibur.component.RoleManager; -import org.apache.cocoon.Constants; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.pipeline.EventPipeline; import org.apache.cocoon.components.pipeline.StreamPipeline; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.sitemap.Handler; -import org.apache.cocoon.sitemap.XSLTFactoryLoader; -import org.xml.sax.SAXException; /** * This class manages all sub <code>Sitemap</code>s of a <code>Sitemap</code> @@ -38,7 +32,7 @@ * checking regeneration of the sub <code>Sitemap</code> * * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> - * @version CVS $Revision: 1.2.2.1 $ $Date: 2001/06/06 17:13:18 $ + * @version CVS $Revision: 1.2.2.2 $ $Date: 2001/06/08 14:13:19 $ */ public class Manager extends AbstractLoggable implements Component, Configurable, Composable, Contextualizable, ThreadSafe { @@ -142,12 +136,17 @@ return false; } - /** make sure the uri_prefix ends with a slash */ + /** + * make sure the uri_prefix ends with a slash + * + * NOTE: Together 5 marks this as unused. If verified, we need to remove it. + */ private String getPrefix (String uri_prefix) { - if (uri_prefix.length() > 0) - return (uri_prefix.charAt(uri_prefix.length() - 1) == '/' ? uri_prefix : uri_prefix + "/"); - else + if (uri_prefix.length() > 0) { + return ((uri_prefix.charAt(uri_prefix.length() - 1) == '/') ? uri_prefix : uri_prefix + "/"); + } else { return uri_prefix; + } } private Handler getHandler(final Environment environment, @@ -162,7 +161,7 @@ if (check_reload && sitemapHandler.hasChanged() && !sitemapHandler.isRegenerating()) { - if (reload_asynchron == true) { + if (reload_asynchron) { sitemapHandler.regenerateAsynchronously(environment); } else { sitemapHandler.regenerate(environment); @@ -186,7 +185,8 @@ private void setupProcessing (Environment environment, Handler sitemapHandler, String uri_prefix, String source) throws Exception { environment.changeContext(uri_prefix, source); - if (! sitemapHandler.available()) + if (! sitemapHandler.available()) { throw new ProcessingException("The sitemap handler's sitemap is not available.", sitemapHandler.getException()); + } } } 1.2.2.2 +2 -2 xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapComponentSelector.java Index: SitemapComponentSelector.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapComponentSelector.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- SitemapComponentSelector.java 2001/06/06 17:13:19 1.2.2.1 +++ SitemapComponentSelector.java 2001/06/08 14:13:19 1.2.2.2 @@ -20,10 +20,10 @@ /** Default component manager for Cocoon's sitemap components. * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> - * @version CVS $Id: SitemapComponentSelector.java,v 1.2.2.1 2001/06/06 17:13:19 bloritsch Exp $ + * @version CVS $Id: SitemapComponentSelector.java,v 1.2.2.2 2001/06/08 14:13:19 bloritsch Exp $ */ public class SitemapComponentSelector extends ExcaliburComponentSelector { - HashMap mime_types; + private HashMap mime_types; /** The conctructors (same as the Avalon ComponentManager) */ 1.2.2.1 +16 -7 xml-cocoon2/src/org/apache/cocoon/sitemap/XSLTFactoryLoader.java Index: XSLTFactoryLoader.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/XSLTFactoryLoader.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- XSLTFactoryLoader.java 2001/05/18 20:50:12 1.2 +++ XSLTFactoryLoader.java 2001/06/08 14:13:19 1.2.2.1 @@ -25,7 +25,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> - * @version CVS $Revision: 1.2 $ $Date: 2001/05/18 20:50:12 $ + * @version CVS $Revision: 1.2.2.1 $ $Date: 2001/06/08 14:13:19 $ */ public class XSLTFactoryLoader { @@ -36,11 +36,14 @@ public String getClassSource(String className, String prefix, String pattern, NodeList conf) throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception { Object factory = obj.get(className); - if (factory == null) factory = ClassUtils.newInstance(className); + if (factory == null) { + factory = ClassUtils.newInstance(className); + } + obj.put(className, factory); if (factory instanceof Loggable) { - ((Loggable)factory).setLogger(this.log); + ((Loggable)factory).setLogger(XSLTFactoryLoader.log); } if (factory instanceof CodeFactory) { return ((CodeFactory) factory).generateClassSource(prefix, pattern, conf); @@ -59,11 +62,14 @@ public String getParameterSource(String className, NodeList conf) throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception { Object factory = obj.get(className); - if (factory == null) factory = ClassUtils.newInstance(className); + if (factory == null) { + factory = ClassUtils.newInstance(className); + } + obj.put (className, factory); if (factory instanceof Loggable) { - ((Loggable)factory).setLogger(this.log); + ((Loggable)factory).setLogger(XSLTFactoryLoader.log); } if (factory instanceof CodeFactory) { return ((CodeFactory) factory).generateParameterSource(conf); @@ -76,11 +82,14 @@ public String getMethodSource(String className, NodeList conf) throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception { Object factory = obj.get(className); - if (factory == null) factory = ClassUtils.newInstance(className); + if (factory == null) { + factory = ClassUtils.newInstance(className); + } + obj.put (className, factory); if (factory instanceof Loggable) { - ((Loggable)factory).setLogger(this.log); + ((Loggable)factory).setLogger(XSLTFactoryLoader.log); } if (factory instanceof CodeFactory) { return ((CodeFactory) factory).generateMethodSource(conf); ---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]