cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portlet CocoonPortlet.java
Date Wed, 23 Jun 2004 20:09:06 GMT
vgritsenko    2004/06/23 13:09:06

  Modified:    src/java/org/apache/cocoon/servlet CocoonServlet.java
               src/blocks/portal/java/org/apache/cocoon/portlet
                        CocoonPortlet.java
  Log:
  Sync CocoonServlet and CocoonPortlet
  
  Revision  Changes    Path
  1.32      +21 -21    cocoon-2.1/src/java/org/apache/cocoon/servlet/CocoonServlet.java
  
  Index: CocoonServlet.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/servlet/CocoonServlet.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- CocoonServlet.java	23 Jun 2004 19:46:06 -0000	1.31
  +++ CocoonServlet.java	23 Jun 2004 20:09:04 -0000	1.32
  @@ -466,7 +466,7 @@
           }
   
           this.containerEncoding = getInitParameter("container-encoding", "ISO-8859-1");
  -        this.defaultFormEncoding = getInitParameter("form-encoding","ISO-8859-1");
  +        this.defaultFormEncoding = getInitParameter("form-encoding", "ISO-8859-1");
           this.appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, this.defaultFormEncoding);
   
           this.manageExceptions = getInitParameterAsBoolean("manage-exceptions", true);
  @@ -543,7 +543,7 @@
        *
        * @throws ServletException
        */
  -     protected String getClassPath() throws ServletException {
  +    protected String getClassPath() throws ServletException {
           StringBuffer buildClassPath = new StringBuffer();
   
           File root = null;
  @@ -616,7 +616,7 @@
           buildClassPath.append(File.pathSeparatorChar)
                         .append(getExtraClassPath());
           return buildClassPath.toString();
  -     }
  +    }
   
       private File extractLibraries() {
           try {
  @@ -774,13 +774,13 @@
           final Priority logPriority = Priority.getPriorityForName(logLevel);
   
           final CocoonLogFormatter formatter = new CocoonLogFormatter();
  -        formatter.setFormat( "%7.7{priority} %{time}   [%8.8{category}] " +
  -                             "(%{uri}) %{thread}/%{class:short}: %{message}\\n%{throwable}"
);
  -        final ServletOutputLogTarget servTarget = new ServletOutputLogTarget(this.servletContext,
formatter );
  +        formatter.setFormat("%7.7{priority} %{time}   [%8.8{category}] " +
  +                            "(%{uri}) %{thread}/%{class:short}: %{message}\\n%{throwable}");
  +        final ServletOutputLogTarget servTarget = new ServletOutputLogTarget(this.servletContext,
formatter);
   
           final Hierarchy defaultHierarchy = Hierarchy.getDefaultHierarchy();
           final ErrorHandler errorHandler = new DefaultErrorHandler();
  -        defaultHierarchy.setErrorHandler(errorHandler );
  +        defaultHierarchy.setErrorHandler(errorHandler);
           defaultHierarchy.setDefaultLogTarget(servTarget);
           defaultHierarchy.setDefaultPriority(logPriority);
           final Logger logger = new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""));
  @@ -816,7 +816,7 @@
   
                   // test if this is a qualified url
                   InputStream is = null;
  -                if ( logkitConfig.indexOf(':') == -1) {
  +                if (logkitConfig.indexOf(':') == -1) {
                       is = this.servletContext.getResourceAsStream(logkitConfig);
                       if (is == null) is = new FileInputStream(logkitConfig);
                   } else {
  @@ -827,6 +827,7 @@
                   final Configuration conf = builder.build(is);
                   ContainerUtil.configure(loggerManager, conf);
               }
  +
               // let's configure log4j
               final String log4jConfig = getInitParameter("log4j-config", null);
               if ( log4jConfig != null ) {
  @@ -845,7 +846,6 @@
               }
   
               ContainerUtil.initialize(loggerManager);
  -
           } catch (Exception e) {
               errorHandler.error("Could not set up Cocoon Logger, will use screen instead",
e, null);
           }
  @@ -1372,11 +1372,11 @@
                   getLogger().info("Reloading from: " + configFile.toExternalForm());
               }
               Cocoon c = (Cocoon) ClassUtils.newInstance("org.apache.cocoon.Cocoon");
  -            ContainerUtil.enableLogging(c, getCocoonLogger() );
  -            c.setLoggerManager( getLoggerManager() );
  +            ContainerUtil.enableLogging(c, getCocoonLogger());
  +            c.setLoggerManager(getLoggerManager());
               ContainerUtil.contextualize(c, this.appContext);
               final ComponentManager parent = this.getParentComponentManager();
  -            if ( parent != null ) {
  +            if (parent != null) {
                   ContainerUtil.compose(c, parent);
               }
               if (this.enableInstrumentation) {
  @@ -1423,8 +1423,7 @@
        * @return an <code>InstrumentManager</code> instance
        */
       private InstrumentManager getInstrumentManager()
  -        throws Exception
  -    {
  +    throws Exception {
           String imConfig = getInitParameter("instrumentation-config");
           if (imConfig == null) {
               throw new ServletException("Please define the init-param 'instrumentation-config'
in your web.xml");
  @@ -1547,13 +1546,14 @@
       /** Convenience method to access boolean servlet parameters */
       protected boolean getInitParameterAsBoolean(String name, boolean defaultValue) {
           String value = getInitParameter(name);
  -        if (value != null) {
  -            return BooleanUtils.toBoolean(value);
  -        }
  -        if (getLogger() != null && getLogger().isDebugEnabled()) {
  -            getLogger().debug(name + " was not set - defaulting to '" + defaultValue +
"'");
  +        if (value == null) {
  +            if (getLogger() != null && getLogger().isDebugEnabled()) {
  +                getLogger().debug(name + " was not set - defaulting to '" + defaultValue
+ "'");
  +            }
  +            return defaultValue;
           }
  -        return defaultValue;
  +
  +        return BooleanUtils.toBoolean(value);
       }
   
       protected int getInitParameterAsInteger(String name, int defaultValue) {
  
  
  
  1.9       +86 -32    cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
  
  Index: CocoonPortlet.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CocoonPortlet.java	23 Jun 2004 19:48:04 -0000	1.8
  +++ CocoonPortlet.java	23 Jun 2004 20:09:05 -0000	1.9
  @@ -15,11 +15,13 @@
    */
   package org.apache.cocoon.portlet;
   
  +import org.apache.avalon.excalibur.logger.Log4JLoggerManager;
   import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
   import org.apache.avalon.excalibur.logger.LoggerManager;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.avalon.framework.container.ContainerUtil;
  @@ -28,6 +30,7 @@
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.LogKitLogger;
   import org.apache.avalon.framework.logger.Logger;
  +
   import org.apache.cocoon.Cocoon;
   import org.apache.cocoon.ConnectionResetException;
   import org.apache.cocoon.Constants;
  @@ -45,6 +48,8 @@
   import org.apache.cocoon.util.IOUtils;
   import org.apache.cocoon.util.StringUtils;
   import org.apache.cocoon.util.log.CocoonLogFormatter;
  +import org.apache.cocoon.util.log.Log4JConfigurator;
  +
   import org.apache.commons.lang.BooleanUtils;
   import org.apache.excalibur.instrument.InstrumentManager;
   import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
  @@ -53,6 +58,7 @@
   import org.apache.log.Hierarchy;
   import org.apache.log.Priority;
   import org.apache.log.util.DefaultErrorHandler;
  +import org.apache.log4j.LogManager;
   
   import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
  @@ -790,7 +796,7 @@
       protected void initLogger() {
           final String logLevel = getInitParameter("log-level", "INFO");
   
  -        final String accesslogger = getInitParameter("servlet-logger");
  +        final String accesslogger = getInitParameter("servlet-logger", "cocoon");
   
           final Priority logPriority = Priority.getPriorityForName(logLevel);
   
  @@ -805,8 +811,15 @@
           defaultHierarchy.setDefaultLogTarget(servTarget);
           defaultHierarchy.setDefaultPriority(logPriority);
           final Logger logger = new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor(""));
  -        final LogKitLoggerManager logKitLoggerManager = new LogKitLoggerManager(defaultHierarchy);
  -        logKitLoggerManager.enableLogging(logger);
  +        final String loggerManagerClass =
  +            this.getInitParameter("logger-class", LogKitLoggerManager.class.getName());
  +
  +        // the log4j support requires currently that the log4j system is already configured
elsewhere
  +
  +        final LoggerManager loggerManager =
  +                newLoggerManager(loggerManagerClass, defaultHierarchy);
  +        ContainerUtil.enableLogging(loggerManager, logger);
  +
           final DefaultContext subcontext = new DefaultContext(this.appContext);
           subcontext.put("portlet-context", this.portletContext);
           if (this.portletContextPath == null) {
  @@ -821,32 +834,65 @@
           }
   
           try {
  -            logKitLoggerManager.contextualize(subcontext);
  -            this.loggerManager = logKitLoggerManager;
  -
  -            //Configure the logkit management
  -            String logkitConfig = getInitParameter("logkit-config", "/WEB-INF/logkit.xconf");
  +            ContainerUtil.contextualize(loggerManager, subcontext);
  +            this.loggerManager = loggerManager;
   
  -            // test if this is a qualified url
  -            InputStream is = null;
  -            if (logkitConfig.indexOf(':') == -1) {
  -                is = this.portletContext.getResourceAsStream(logkitConfig);
  -                if (is == null) is = new FileInputStream(logkitConfig);
  -            } else {
  -                URL logkitURL = new URL(logkitConfig);
  -                is = logkitURL.openStream();
  +            if (loggerManager instanceof Configurable) {
  +                //Configure the logkit management
  +                String logkitConfig = getInitParameter("logkit-config", "/WEB-INF/logkit.xconf");
  +
  +                // test if this is a qualified url
  +                InputStream is = null;
  +                if (logkitConfig.indexOf(':') == -1) {
  +                    is = this.portletContext.getResourceAsStream(logkitConfig);
  +                    if (is == null) is = new FileInputStream(logkitConfig);
  +                } else {
  +                    URL logkitURL = new URL(logkitConfig);
  +                    is = logkitURL.openStream();
  +                }
  +                final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  +                final Configuration conf = builder.build(is);
  +                ContainerUtil.configure(loggerManager, conf);
  +            }
  +
  +            // let's configure log4j
  +            final String log4jConfig = getInitParameter("log4j-config", null);
  +            if ( log4jConfig != null ) {
  +                final Log4JConfigurator configurator = new Log4JConfigurator(subcontext);
  +
  +                // test if this is a qualified url
  +                InputStream is = null;
  +                if ( log4jConfig.indexOf(':') == -1) {
  +                    is = this.portletContext.getResourceAsStream(log4jConfig);
  +                    if (is == null) is = new FileInputStream(log4jConfig);
  +                } else {
  +                    final URL log4jURL = new URL(log4jConfig);
  +                    is = log4jURL.openStream();
  +                }
  +                configurator.doConfigure(is, LogManager.getLoggerRepository());
               }
  -            final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  -            final Configuration conf = builder.build(is);
  -            logKitLoggerManager.configure(conf);
  +
  +            ContainerUtil.initialize(loggerManager);
           } catch (Exception e) {
               errorHandler.error("Could not set up Cocoon Logger, will use screen instead",
e, null);
           }
   
  -        if (accesslogger != null) {
  -            this.log = logKitLoggerManager.getLoggerForCategory(accesslogger);
  +        this.log = this.loggerManager.getLoggerForCategory(accesslogger);
  +    }
  +
  +    private LoggerManager newLoggerManager(String loggerManagerClass, Hierarchy hierarchy)
{
  +        if (loggerManagerClass.equals(LogKitLoggerManager.class.getName())) {
  +            return new LogKitLoggerManager(hierarchy);
  +        } else if (loggerManagerClass.equals(Log4JLoggerManager.class.getName()) ||
  +                   loggerManagerClass.equalsIgnoreCase("LOG4J")) {
  +            return new Log4JLoggerManager();
           } else {
  -            this.log = logKitLoggerManager.getLoggerForCategory("cocoon");
  +            try {
  +                Class clazz = Class.forName(loggerManagerClass);
  +                return (LoggerManager)clazz.newInstance();
  +            } catch (Exception e) {
  +                return new LogKitLoggerManager(hierarchy);
  +            }
           }
       }
   
  @@ -980,8 +1026,12 @@
           }
       }
   
  +    /**
  +     * Process the specified <code>ActionRequest</code> producing output
  +     * on the specified <code>ActionResponse</code>.
  +     */
       public void processAction(ActionRequest req, ActionResponse res)
  -            throws PortletException, IOException {
  +    throws PortletException, IOException {
   
           /* HACK for reducing class loader problems.                                   
 */
           /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib
*/
  @@ -1145,8 +1195,12 @@
           }
       }
   
  +    /**
  +     * Process the specified <code>RenderRequest</code> producing output
  +     * on the specified <code>RenderResponse</code>.
  +     */
       public void render(RenderRequest req, RenderResponse res)
  -            throws PortletException, IOException {
  +    throws PortletException, IOException {
   
           /* HACK for reducing class loader problems.                                   
 */
           /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib
*/
  @@ -1450,7 +1504,7 @@
           if (parentComponentManager != null && parentComponentManager instanceof
Disposable) {
               ((Disposable) parentComponentManager).dispose();
           }
  -        
  +
           parentComponentManager = null;
           if (parentComponentManagerClass != null) {
               try {
  @@ -1476,11 +1530,11 @@
           return parentComponentManager;
       }
   
  -
       /**
        * Creates the Cocoon object and handles exception handling.
        */
  -    private synchronized void createCocoon() throws PortletException {
  +    private synchronized void createCocoon()
  +    throws PortletException {
   
           /* HACK for reducing class loader problems.                                   
 */
           /* example: xalan extensions fail if someone adds xalan jars in tomcat3.2.1/lib
*/
  @@ -1552,7 +1606,7 @@
        * @return an <code>InstrumentManager</code> instance
        */
       private InstrumentManager getInstrumentManager()
  -            throws Exception {
  +    throws Exception {
           String imConfig = getInitParameter("instrumentation-config");
           if (imConfig == null) {
               throw new PortletException("Please define the init-param 'instrumentation-config'
in your web.xml");
  @@ -1603,7 +1657,7 @@
        * changed or we are reloading.
        */
       private void getCocoon(final String reloadParam)
  -            throws PortletException {
  +    throws PortletException {
           if (this.allowReload) {
               boolean reload = false;
   
  @@ -1680,9 +1734,9 @@
                   getLogger().debug(name + " was not set - defaulting to '" + defaultValue
+ "'");
               }
               return defaultValue;
  -        } else {
  -            return BooleanUtils.toBoolean(value);
           }
  +
  +        return BooleanUtils.toBoolean(value);
       }
   
       protected int getInitParameterAsInteger(String name, int defaultValue) {
  
  
  

Mime
View raw message