Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 58201 invoked from network); 12 Jan 2006 00:11:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Jan 2006 00:11:45 -0000 Received: (qmail 71327 invoked by uid 500); 12 Jan 2006 00:11:45 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 71184 invoked by uid 500); 12 Jan 2006 00:11:44 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 71166 invoked by uid 99); 12 Jan 2006 00:11:43 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Jan 2006 16:11:43 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 11 Jan 2006 16:11:41 -0800 Received: (qmail 58120 invoked by uid 65534); 12 Jan 2006 00:11:21 -0000 Message-ID: <20060112001121.58117.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r368177 - in /cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks: ./ util/ Date: Thu, 12 Jan 2006 00:11:19 -0000 To: cvs@cocoon.apache.org From: danielf@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: danielf Date: Wed Jan 11 16:11:05 2006 New Revision: 368177 URL: http://svn.apache.org/viewcvs?rev=368177&view=rev Log: Whitespace formating. Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockCallStack.java cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockManager.java cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlocksContext.java cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/CoreUtil.java cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/LoggerUtil.java cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/ServletConfigurationWrapper.java cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/ServletContextWrapper.java Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockCallStack.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockCallStack.java?rev=368177&r1=368176&r2=368177&view=diff ============================================================================== --- cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockCallStack.java (original) +++ cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockCallStack.java Wed Jan 11 16:11:05 2006 @@ -67,7 +67,7 @@ public static Servlet getCurrentBlock() { final Stack stack = (Stack)blockStack.get(); if ( stack != null && !stack.isEmpty()) { - return (Servlet)stack.peek(); + return (Servlet)stack.peek(); } return null; } Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockManager.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockManager.java?rev=368177&r1=368176&r2=368177&view=diff ============================================================================== --- cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockManager.java (original) +++ cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockManager.java Wed Jan 11 16:11:05 2006 @@ -199,7 +199,7 @@ // a little bit clumsy. Question is what components, if any, the // blocks should have in common. public void setBlocks(Blocks blocks) { - this.blocks = blocks; + this.blocks = blocks; } /** @@ -225,12 +225,12 @@ // Servlet methods - public void init(ServletConfig servletConfig) throws ServletException { - super.init(servletConfig); + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); } - protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // Request to the own block + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Request to the own block try { // It is important to set the current block servlet each time // a new block is entered, this is used for the block @@ -240,14 +240,14 @@ } finally { BlockCallStack.leaveBlock(); } - } + } - public String getServletInfo() { - return "BlockManager"; - } + public String getServletInfo() { + return "BlockManager"; + } - public void destroy() { - super.destroy(); + public void destroy() { + super.destroy(); } public Servlet getBlockServlet() { Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlocksContext.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlocksContext.java?rev=368177&r1=368176&r2=368177&view=diff ============================================================================== --- cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlocksContext.java (original) +++ cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlocksContext.java Wed Jan 11 16:11:05 2006 @@ -30,40 +30,49 @@ */ public class BlocksContext extends ServletContextWrapper { - Blocks blocks; - /** - * @param servletContext - */ - public BlocksContext(ServletContext servletContext, Blocks blocks) { - super(servletContext); - this.blocks = blocks; - } - /* (non-Javadoc) - * @see org.apache.cocoon.blocks.ServletContextWrapper#getNamedDispatcher(java.lang.String) - */ - public RequestDispatcher getNamedDispatcher(String name) { - // TODO Auto-generated method stub - return super.getNamedDispatcher(name); - } - /* (non-Javadoc) - * @see org.apache.cocoon.blocks.ServletContextWrapper#getRequestDispatcher(java.lang.String) - */ - public RequestDispatcher getRequestDispatcher(String path) { - // TODO Auto-generated method stub - return super.getRequestDispatcher(path); - } - - private class NamedDispatcher implements RequestDispatcher { - - public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException { - // TODO Auto-generated method stub - - } - - public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException { - // TODO Auto-generated method stub - - } - - } + Blocks blocks; + + /** + * @param servletContext + */ + public BlocksContext(ServletContext servletContext, Blocks blocks) { + super(servletContext); + this.blocks = blocks; + } + + /* + * (non-Javadoc) + * + * @see org.apache.cocoon.blocks.ServletContextWrapper#getNamedDispatcher(java.lang.String) + */ + public RequestDispatcher getNamedDispatcher(String name) { + // TODO Auto-generated method stub + return super.getNamedDispatcher(name); + } + + /* + * (non-Javadoc) + * + * @see org.apache.cocoon.blocks.ServletContextWrapper#getRequestDispatcher(java.lang.String) + */ + public RequestDispatcher getRequestDispatcher(String path) { + // TODO Auto-generated method stub + return super.getRequestDispatcher(path); + } + + private class NamedDispatcher implements RequestDispatcher { + + public void forward(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + // TODO Auto-generated method stub + + } + + public void include(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + // TODO Auto-generated method stub + + } + + } } Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/CoreUtil.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/CoreUtil.java?rev=368177&r1=368176&r2=368177&view=diff ============================================================================== --- cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/CoreUtil.java (original) +++ cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/CoreUtil.java Wed Jan 11 16:11:05 2006 @@ -61,27 +61,30 @@ * This is an utility class to create a new Cocoon instance. * * TODO - Remove dependencies to LogKit and Log4J - * + * * @version $Id$ * @since 2.2 */ public class CoreUtil { /** Parameter map for the context protocol */ - private static final Map CONTEXT_PARAMETERS = Collections.singletonMap("force-traversable", Boolean.TRUE); + private static final Map CONTEXT_PARAMETERS = Collections.singletonMap( + "force-traversable", Boolean.TRUE); /** * Application Context Key for the servlet configuration + * * @since 2.1.3 */ public static final String CONTEXT_SERVLET_CONFIG = "servlet-config"; private ServletConfig config; - private ServletContext servletContext; + + private ServletContext servletContext; /** "legacy" support: create an avalon context. */ private final DefaultContext appContext = new ComponentContext(); - + private Context environmentContext; /** The settings. */ @@ -95,91 +98,101 @@ private ClassLoader classloader; - private File contextForWriting = null; - private String contextURL; - - public CoreUtil(ServletConfig config) throws ServletException { - this(config, "WEB-INF/web.xml"); - } - - /** + private File contextForWriting = null; + + private String contextURL; + + public CoreUtil(ServletConfig config) throws ServletException { + this(config, "WEB-INF/web.xml"); + } + + /** * Setup a new instance. + * * @param config - * @param knownFile path to a file that is supposed to be present in the servlet context - * and that is used for calculating the context URI + * @param knownFile + * path to a file that is supposed to be present in the servlet + * context and that is used for calculating the context URI * @throws ServletException */ - public CoreUtil(ServletConfig config, String knownFile) throws ServletException { - this.config = config; - this.servletContext = this.config.getServletContext(); - this.servletContext.log("Initializing Apache Cocoon " + Constants.VERSION); - - this.contextURL = CoreUtil.getContextURL(this.servletContext, knownFile); - String writeableContextPath = CoreUtil.getWritableContextPath(this.servletContext); - if (writeableContextPath != null) { - this.contextForWriting = new File(writeableContextPath); - } - this.environmentContext = new HttpContext(config.getServletContext()); - this.init(); + public CoreUtil(ServletConfig config, String knownFile) + throws ServletException { + this.config = config; + this.servletContext = this.config.getServletContext(); + this.servletContext.log("Initializing Apache Cocoon " + + Constants.VERSION); + + this.contextURL = CoreUtil + .getContextURL(this.servletContext, knownFile); + String writeableContextPath = CoreUtil + .getWritableContextPath(this.servletContext); + if (writeableContextPath != null) { + this.contextForWriting = new File(writeableContextPath); + } + this.environmentContext = new HttpContext(config.getServletContext()); + this.init(); } - + public static String getWritableContextPath(ServletContext servletContext) { - return servletContext.getRealPath("/"); + return servletContext.getRealPath("/"); + } + + /** + * @param servletContext + * @throws ServletException + */ + public static String getContextURL(ServletContext servletContext, + String knownFile) throws ServletException { + String path = CoreUtil.getWritableContextPath(servletContext); + String contextURL; + if (path == null) { + // Try to figure out the path of the root from that of a known file + servletContext.log("Figuring out root from " + knownFile); + try { + path = servletContext.getResource("/" + knownFile).toString(); + servletContext.log("Got " + path); + } catch (MalformedURLException me) { + throw new ServletException("Unable to get resource '" + + knownFile + "'.", me); + } + path = path.substring(0, path.length() - knownFile.length()); + servletContext.log("And servlet root " + path); + } + try { + if (path.indexOf(':') > 1) { + contextURL = path; + } else { + contextURL = new File(path).toURL().toExternalForm(); + } + } catch (MalformedURLException me) { + // VG: Novell has absolute file names starting with the + // volume name which is easily more then one letter. + // Examples: sys:/apache/cocoon or sys:\apache\cocoon + try { + contextURL = new File(path).toURL().toExternalForm(); + } catch (MalformedURLException ignored) { + throw new ServletException( + "Unable to determine servlet context URL.", me); + } + } + return contextURL; } - - /** - * @param servletContext - * @throws ServletException - */ - public static String getContextURL(ServletContext servletContext, String knownFile) throws ServletException { - String path = CoreUtil.getWritableContextPath(servletContext); - String contextURL; - if (path == null) { - // Try to figure out the path of the root from that of a known file - servletContext.log("Figuring out root from " + knownFile); - try { - path = servletContext.getResource("/" + knownFile).toString(); - servletContext.log("Got " + path); - } catch (MalformedURLException me) { - throw new ServletException("Unable to get resource '" + knownFile + "'.", me); - } - path = path.substring(0, path.length() - knownFile.length()); - servletContext.log("And servlet root " + path); - } - try { - if (path.indexOf(':') > 1) { - contextURL = path; - } else { - contextURL = new File(path).toURL().toExternalForm(); - } - } catch (MalformedURLException me) { - // VG: Novell has absolute file names starting with the - // volume name which is easily more then one letter. - // Examples: sys:/apache/cocoon or sys:\apache\cocoon - try { - contextURL = new File(path).toURL().toExternalForm(); - } catch (MalformedURLException ignored) { - throw new ServletException("Unable to determine servlet context URL.", me); - } - } - return contextURL; - } - + private void init() throws ServletException { // first let's set up the appContext with some values to make // the simple source resolver work // add root url try { - appContext.put(ContextHelper.CONTEXT_ROOT_URL, - new URL(this.contextURL)); + appContext.put(ContextHelper.CONTEXT_ROOT_URL, new URL( + this.contextURL)); } catch (MalformedURLException ignore) { // we simply ignore this } // add environment context this.appContext.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, - this.environmentContext); + this.environmentContext); // now add environment specific information this.appContext.put(CONTEXT_SERVLET_CONFIG, this.config); @@ -217,9 +230,9 @@ this.servletContext.log("Context URL: " + this.contextURL); this.servletContext.log("Writeable Context: " + this.contextForWriting); if (workDirParam != null) { - this.servletContext.log("Using work-directory " + workDir); + this.servletContext.log("Using work-directory " + workDir); } else { - this.servletContext.log("Using default work-directory " + workDir); + this.servletContext.log("Using default work-directory " + workDir); } final String uploadDirParam = this.settings.getUploadDirectory(); @@ -241,7 +254,8 @@ this.servletContext.log("Using upload-directory " + uploadDir); } else { uploadDir = new File(workDir, "upload-dir" + File.separator); - this.servletContext.log("Using default upload-directory " + uploadDir); + this.servletContext.log("Using default upload-directory " + + uploadDir); } uploadDir.mkdirs(); appContext.put(Constants.CONTEXT_UPLOAD_DIR, uploadDir); @@ -270,55 +284,62 @@ if (parent != null) { parent.mkdirs(); } - this.servletContext.log("cache-directory was not set - defaulting to " + cacheDir); + this.servletContext + .log("cache-directory was not set - defaulting to " + + cacheDir); } cacheDir.mkdirs(); appContext.put(Constants.CONTEXT_CACHE_DIR, cacheDir); this.settings.setCacheDirectory(cacheDir.getAbsolutePath()); - String configFileName = this.settings.getConfiguration(); - final String usedFileName; - - if (configFileName == null) { - this.servletContext.log("Servlet initialization argument 'configurations' not specified, attempting to use '/WEB-INF/cocoon.xconf'"); - usedFileName = "/WEB-INF/cocoon.xconf"; - } else { - usedFileName = configFileName; - } - - this.servletContext.log("Using configuration file: " + usedFileName); - - URL result; - try { - // test if this is a qualified url - if (usedFileName.indexOf(':') == -1) { - result = this.config.getServletContext().getResource(usedFileName); - } else { - result = new URL(usedFileName); - } - } catch (Exception mue) { - String msg = "Init parameter 'configurations' is invalid : " + usedFileName; - this.servletContext.log(msg, mue); - throw new ServletException(msg, mue); - } - - if (result == null) { - File resultFile = new File(usedFileName); - if (resultFile.isFile()) { - try { - result = resultFile.getCanonicalFile().toURL(); - } catch (Exception e) { - String msg = "Init parameter 'configurations' is invalid : " + usedFileName; - this.servletContext.log(msg, e); - throw new ServletException(msg, e); - } - } - } - - if (result == null) { - String msg = "Init parameter 'configurations' doesn't name an existing resource : " + usedFileName; - this.servletContext.log(msg); - throw new ServletException(msg); - } + String configFileName = this.settings.getConfiguration(); + final String usedFileName; + + if (configFileName == null) { + this.servletContext + .log("Servlet initialization argument 'configurations' not specified, attempting to use '/WEB-INF/cocoon.xconf'"); + usedFileName = "/WEB-INF/cocoon.xconf"; + } else { + usedFileName = configFileName; + } + + this.servletContext.log("Using configuration file: " + usedFileName); + + URL result; + try { + // test if this is a qualified url + if (usedFileName.indexOf(':') == -1) { + result = this.config.getServletContext().getResource( + usedFileName); + } else { + result = new URL(usedFileName); + } + } catch (Exception mue) { + String msg = "Init parameter 'configurations' is invalid : " + + usedFileName; + this.servletContext.log(msg, mue); + throw new ServletException(msg, mue); + } + + if (result == null) { + File resultFile = new File(usedFileName); + if (resultFile.isFile()) { + try { + result = resultFile.getCanonicalFile().toURL(); + } catch (Exception e) { + String msg = "Init parameter 'configurations' is invalid : " + + usedFileName; + this.servletContext.log(msg, e); + throw new ServletException(msg, e); + } + } + } + + if (result == null) { + String msg = "Init parameter 'configurations' doesn't name an existing resource : " + + usedFileName; + this.servletContext.log(msg); + throw new ServletException(msg); + } // update configuration final URL u = result; @@ -326,7 +347,8 @@ this.appContext.put(Constants.CONTEXT_CONFIG_URL, u); // set encoding - this.appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, settings.getFormEncoding()); + this.appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, settings + .getFormEncoding()); // set class loader this.appContext.put(Constants.CONTEXT_CLASS_LOADER, this.classloader); @@ -344,23 +366,26 @@ // The Cocoon container fetches the Core object using the context. this.appContext.put(Core.ROLE, core); - // FIXME - for now we just set an empty string as this information is looked up - // by other components + // FIXME - for now we just set an empty string as this information is + // looked up + // by other components this.appContext.put(Constants.CONTEXT_CLASSPATH, ""); } public Core getCore() { try { - return (Core)this.parentManager.lookup(Core.ROLE); + return (Core) this.parentManager.lookup(Core.ROLE); } catch (ServiceException neverIgnore) { // this should never happen! - throw new CoreFatalException("Fatal exception: no Cocoon core available.", neverIgnore); + throw new CoreFatalException( + "Fatal exception: no Cocoon core available.", neverIgnore); } } /** - * Create a new core instance. - * This method can be overwritten in sub classes. + * Create a new core instance. This method can be overwritten in sub + * classes. + * * @return A new core object. */ private Core createCore() { @@ -376,25 +401,28 @@ } public ServiceManager getServiceManager() { - return this.parentManager; + return this.parentManager; } - + /** * Instatiates the parent service manager, as specified in the * parent-service-manager init parameter. - * + * * If none is specified, the method returns null. - * + * * @return the parent service manager, or null. */ private ServiceManager getParentServiceManager(Core core) { - String parentServiceManagerClass = this.settings.getParentServiceManagerClassName(); + String parentServiceManagerClass = this.settings + .getParentServiceManagerClassName(); String parentServiceManagerInitParam = null; if (parentServiceManagerClass != null) { int dividerPos = parentServiceManagerClass.indexOf('/'); if (dividerPos != -1) { - parentServiceManagerInitParam = parentServiceManagerInitParam.substring(dividerPos + 1); - parentServiceManagerClass = parentServiceManagerClass.substring(0, dividerPos); + parentServiceManagerInitParam = parentServiceManagerInitParam + .substring(dividerPos + 1); + parentServiceManagerClass = parentServiceManagerClass + .substring(0, dividerPos); } } @@ -402,99 +430,124 @@ if (parentServiceManagerClass != null) { try { Class pcm = ClassUtils.loadClass(parentServiceManagerClass); - Constructor pcmc = pcm.getConstructor(new Class[]{String.class}); - parentServiceManager = (ServiceManager) pcmc.newInstance(new Object[]{parentServiceManagerInitParam}); + Constructor pcmc = pcm + .getConstructor(new Class[] { String.class }); + parentServiceManager = (ServiceManager) pcmc + .newInstance(new Object[] { parentServiceManagerInitParam }); ContainerUtil.enableLogging(parentServiceManager, this.log); - ContainerUtil.contextualize(parentServiceManager, this.appContext); + ContainerUtil.contextualize(parentServiceManager, + this.appContext); ContainerUtil.initialize(parentServiceManager); } catch (Exception e) { if (this.log.isErrorEnabled()) { - this.log.error("Could not initialize parent component manager.", e); + this.log + .error( + "Could not initialize parent component manager.", + e); } } } - return new SingleComponentServiceManager(parentServiceManager, core, Core.ROLE); + return new SingleComponentServiceManager(parentServiceManager, core, + Core.ROLE); } /** - * Get the settings for Cocoon. - * This method reads several property files and merges the result. If there - * is more than one definition for a property, the last one wins. - * The property files are read in the following order: - * 1) context://WEB-INF/properties/*.properties - * Default values for the core and each block - the order in which the files are read is not guaranteed. - * 2) context://WEB-INF/properties/[RUNNING_MODE]/*.properties - * Default values for the running mode - the order in which the files are read is not guaranteed. - * 3) Property providers (ToBeDocumented) - * 4) The environment (CLI, Servlet etc.) adds own properties (e.g. from web.xml) - * 5) Additional property file specified by the "org.apache.cocoon.settings" system property or - * if the property is not found, the file ".cocoon/settings.properties" is tried to be read from - * the user directory. - * 6) System properties - * + * Get the settings for Cocoon. This method reads several property files and + * merges the result. If there is more than one definition for a property, + * the last one wins. The property files are read in the following order: 1) + * context://WEB-INF/properties/*.properties Default values for the core and + * each block - the order in which the files are read is not guaranteed. 2) + * context://WEB-INF/properties/[RUNNING_MODE]/*.properties Default values + * for the running mode - the order in which the files are read is not + * guaranteed. 3) Property providers (ToBeDocumented) 4) The environment + * (CLI, Servlet etc.) adds own properties (e.g. from web.xml) 5) Additional + * property file specified by the "org.apache.cocoon.settings" system + * property or if the property is not found, the file + * ".cocoon/settings.properties" is tried to be read from the user + * directory. 6) System properties + * * @return A new Settings object */ private MutableSettings createSettings() { // get the running mode - final String mode = System.getProperty(Settings.PROPERTY_RUNNING_MODE, Settings.DEFAULT_RUNNING_MODE); + final String mode = System.getProperty(Settings.PROPERTY_RUNNING_MODE, + Settings.DEFAULT_RUNNING_MODE); this.config.getServletContext().log("Running in mode: " + mode); // create an empty settings objects final MutableSettings s = new MutableSettings(); // we need our own resolver - final SourceResolver resolver = this.createSourceResolver(new LoggerWrapper(this.config.getServletContext())); + final SourceResolver resolver = this + .createSourceResolver(new LoggerWrapper(this.config + .getServletContext())); // now read all properties from the properties directory this.readProperties("context://WEB-INF/properties", s, resolver); // read all properties from the mode dependent directory - this.readProperties("context://WEB-INF/properties/" + mode, s, resolver); + this + .readProperties("context://WEB-INF/properties/" + mode, s, + resolver); // Next look for custom property providers Iterator i = s.getPropertyProviders().iterator(); - while ( i.hasNext() ) { - final String className = (String)i.next(); + while (i.hasNext()) { + final String className = (String) i.next(); try { - PropertyProvider provider = (PropertyProvider)ClassUtils.newInstance(className); + PropertyProvider provider = (PropertyProvider) ClassUtils + .newInstance(className); s.fill(provider.getProperties()); } catch (Exception ignore) { - this.config.getServletContext().log("Unable to get property provider for class " + className, ignore); - this.config.getServletContext().log("Continuing initialization."); + this.config.getServletContext().log( + "Unable to get property provider for class " + + className, ignore); + this.config.getServletContext().log( + "Continuing initialization."); } } // fill from the environment configuration, like web.xml etc. // fill from the servlet parameters - SettingsHelper.fill(s, this.config); - if ( s.getWorkDirectory() == null ) { - final File workDir = (File)this.config.getServletContext().getAttribute("javax.servlet.context.tempdir"); - s.setWorkDirectory(workDir.getAbsolutePath()); - } - if ( s.getLoggingConfiguration() == null ) { - s.setLoggingConfiguration("/WEB-INF/logkit.xconf"); - } + SettingsHelper.fill(s, this.config); + if (s.getWorkDirectory() == null) { + final File workDir = (File) this.config.getServletContext() + .getAttribute("javax.servlet.context.tempdir"); + s.setWorkDirectory(workDir.getAbsolutePath()); + } + if (s.getLoggingConfiguration() == null) { + s.setLoggingConfiguration("/WEB-INF/logkit.xconf"); + } // read additional properties file - String additionalPropertyFile = s.getProperty(Settings.PROPERTY_USER_SETTINGS, - System.getProperty(Settings.PROPERTY_USER_SETTINGS)); - // if there is no property defining the addition file, we try it in the home directory - if ( additionalPropertyFile == null ) { - additionalPropertyFile = System.getProperty("user.home") + File.separator + ".cocoon/settings.properties"; + String additionalPropertyFile = s.getProperty( + Settings.PROPERTY_USER_SETTINGS, System + .getProperty(Settings.PROPERTY_USER_SETTINGS)); + // if there is no property defining the addition file, we try it in the + // home directory + if (additionalPropertyFile == null) { + additionalPropertyFile = System.getProperty("user.home") + + File.separator + ".cocoon/settings.properties"; final File testFile = new File(additionalPropertyFile); - if ( !testFile.exists() ) { + if (!testFile.exists()) { additionalPropertyFile = null; } } - if ( additionalPropertyFile != null ) { - this.config.getServletContext().log("Reading user settings from '" + additionalPropertyFile + "'"); + if (additionalPropertyFile != null) { + this.config.getServletContext().log( + "Reading user settings from '" + additionalPropertyFile + + "'"); final Properties p = new Properties(); try { - FileInputStream fis = new FileInputStream(additionalPropertyFile); + FileInputStream fis = new FileInputStream( + additionalPropertyFile); p.load(fis); fis.close(); } catch (IOException ignore) { - this.config.getServletContext().log("Unable to read '" + additionalPropertyFile + "'.", ignore); - this.config.getServletContext().log("Continuing initialization."); + this.config.getServletContext().log( + "Unable to read '" + additionalPropertyFile + "'.", + ignore); + this.config.getServletContext().log( + "Continuing initialization."); } } // now overwrite with system properties @@ -504,21 +557,26 @@ } /** - * Read all property files from the given directory and apply them to the settings. + * Read all property files from the given directory and apply them to the + * settings. */ - private void readProperties(String directoryName, - MutableSettings s, - SourceResolver resolver) { + private void readProperties(String directoryName, MutableSettings s, + SourceResolver resolver) { Source directory = null; try { - directory = resolver.resolveURI(directoryName, null, CONTEXT_PARAMETERS); + directory = resolver.resolveURI(directoryName, null, + CONTEXT_PARAMETERS); if (directory.exists() && directory instanceof TraversableSource) { - final Iterator c = ((TraversableSource) directory).getChildren().iterator(); + final Iterator c = ((TraversableSource) directory) + .getChildren().iterator(); while (c.hasNext()) { final Source src = (Source) c.next(); - if ( src.getURI().endsWith(".properties") ) { + if (src.getURI().endsWith(".properties")) { final InputStream propsIS = src.getInputStream(); - this.config.getServletContext().log("Reading settings from '" + src.getURI() + "'."); + this.config.getServletContext() + .log( + "Reading settings from '" + + src.getURI() + "'."); final Properties p = new Properties(); p.load(propsIS); propsIS.close(); @@ -527,8 +585,10 @@ } } } catch (IOException ignore) { - this.config.getServletContext().log("Unable to read from directory 'WEB-INF/properties'.", ignore); - this.config.getServletContext().log("Continuing initialization."); + this.config.getServletContext().log( + "Unable to read from directory 'WEB-INF/properties'.", + ignore); + this.config.getServletContext().log("Continuing initialization."); } finally { resolver.release(directory); } @@ -547,7 +607,7 @@ throw new CoreInitializationException( "Cannot setup source resolver.", ce); } - return resolver; + return resolver; } private static final class LoggerWrapper implements Logger { @@ -558,7 +618,7 @@ } private void text(String arg0, Throwable arg1) { - if ( arg1 != null ) { + if (arg1 != null) { this.context.log(arg0, arg1); } else { this.context.log(arg0); Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/LoggerUtil.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/LoggerUtil.java?rev=368177&r1=368176&r2=368177&view=diff ============================================================================== --- cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/LoggerUtil.java (original) +++ cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/util/LoggerUtil.java Wed Jan 11 16:11:05 2006 @@ -53,19 +53,21 @@ * This is an utility class to create a new Cocoon instance. * * TODO - Remove dependencies to LogKit and Log4J - * + * * @version $Id$ * @since 2.2 */ public class LoggerUtil { /** Parameter map for the context protocol */ - private static final Map CONTEXT_PARAMETERS = Collections.singletonMap("force-traversable", Boolean.TRUE); + private static final Map CONTEXT_PARAMETERS = Collections.singletonMap( + "force-traversable", Boolean.TRUE); private ServletConfig config; - /** "legacy" support: create an avalon context. */ + + /** "legacy" support: create an avalon context. */ private Context appContext; - + /** The settings. */ private Settings settings; @@ -79,16 +81,18 @@ /** * Setup a new instance. + * * @param config */ - public LoggerUtil(ServletConfig config, Context appContext, Settings settings) { - this.config = config; - this.appContext = appContext; - this.settings = settings; - // Init logger - this.initLogger(); + public LoggerUtil(ServletConfig config, Context appContext, + Settings settings) { + this.config = config; + this.appContext = appContext; + this.settings = settings; + // Init logger + this.initLogger(); } - + /** * Create a simple source resolver. */ @@ -102,7 +106,7 @@ throw new CoreInitializationException( "Cannot setup source resolver.", ce); } - return resolver; + return resolver; } private void initLogger() { @@ -117,19 +121,24 @@ } // create bootstrap logger - final BootstrapEnvironment.LogLevel level = BootstrapEnvironment.LogLevel.getLogLevelForName(logLevel); - final Logger bootstrapLogger = new ServletLogger(this.config, level.getLevel()); + final BootstrapEnvironment.LogLevel level = BootstrapEnvironment.LogLevel + .getLogLevelForName(logLevel); + final Logger bootstrapLogger = new ServletLogger(this.config, level + .getLevel()); // Create our own resolver - final SourceResolver resolver = this.createSourceResolver(bootstrapLogger); + final SourceResolver resolver = this + .createSourceResolver(bootstrapLogger); // create an own service manager for the logger manager final ServiceManager loggerManagerServiceManager = new SingleComponentServiceManager( - null, resolver, SourceResolver.ROLE); + null, resolver, SourceResolver.ROLE); // create an own context for the logger manager - final DefaultContext subcontext = new SettingsContext(this.appContext, this.settings); - subcontext.put("context-work", new File(this.settings.getWorkDirectory())); + final DefaultContext subcontext = new SettingsContext(this.appContext, + this.settings); + subcontext.put("context-work", new File(this.settings + .getWorkDirectory())); if (this.contextForWriting == null) { File logSCDir = new File(this.settings.getWorkDirectory(), "log"); logSCDir.mkdirs(); @@ -144,7 +153,8 @@ // the log4j support requires currently that the log4j system is already // configured elsewhere - final LoggerManager loggerManager = this.newLoggerManager(loggerManagerClass); + final LoggerManager loggerManager = this + .newLoggerManager(loggerManagerClass); ContainerUtil.enableLogging(loggerManager, bootstrapLogger); try { @@ -154,28 +164,30 @@ this.loggerManager = loggerManager; if (loggerManager instanceof Configurable) { - //Configure the logkit management + // Configure the logkit management String logkitConfig = settings.getLoggingConfiguration(); - if ( logkitConfig != null ) { + if (logkitConfig != null) { Source source = null; try { source = resolver.resolveURI(logkitConfig); final ConfigurationBuilder builder = new ConfigurationBuilder( settings); - final Configuration conf = builder.build(source.getInputStream()); + final Configuration conf = builder.build(source + .getInputStream()); final DefaultConfiguration categories = (DefaultConfiguration) conf .getChild("categories"); final DefaultConfiguration targets = (DefaultConfiguration) conf .getChild("targets"); final DefaultConfiguration factories = (DefaultConfiguration) conf .getChild("factories"); - + // now process includes final Configuration[] children = conf .getChildren("include"); for (int i = 0; i < children.length; i++) { - String directoryURI = children[i].getAttribute("dir"); + String directoryURI = children[i] + .getAttribute("dir"); final String pattern = children[i].getAttribute( "pattern", null); int[] parsedPattern = null; @@ -198,12 +210,14 @@ final Configuration includeConf = builder .build(s.getInputStream()); // add targets and categories - categories.addAllChildren(includeConf - .getChild("categories")); + categories + .addAllChildren(includeConf + .getChild("categories")); targets.addAllChildren(includeConf .getChild("targets")); - factories.addAllChildren(includeConf - .getChild("factories")); + factories + .addAllChildren(includeConf + .getChild("factories")); } } } else { @@ -219,9 +233,10 @@ } finally { resolver.release(directory); } - + // finally remove include - ((DefaultConfiguration) conf).removeChild(children[i]); + ((DefaultConfiguration) conf) + .removeChild(children[i]); } // override log level? if (settings.getOverrideLogLevel() != null) { @@ -246,18 +261,21 @@ /** * Create a new logger manager. - * @param loggerManagerClass The class name or one of the allowed shortcuts. + * + * @param loggerManagerClass + * The class name or one of the allowed shortcuts. * @return A new logger manager. */ private LoggerManager newLoggerManager(String loggerManagerClass) { - if ("LogKit".equalsIgnoreCase(loggerManagerClass) || loggerManagerClass == null) { + if ("LogKit".equalsIgnoreCase(loggerManagerClass) + || loggerManagerClass == null) { loggerManagerClass = CocoonLogKitLoggerManager.class.getName(); } else if ("LOG4J".equalsIgnoreCase(loggerManagerClass)) { loggerManagerClass = Log4JConfLoggerManager.class.getName(); } try { Class clazz = Class.forName(loggerManagerClass); - if ( PerRequestLoggerManager.class.isAssignableFrom(clazz) ) { + if (PerRequestLoggerManager.class.isAssignableFrom(clazz)) { } return (LoggerManager) clazz.newInstance(); } catch (Exception e) { @@ -267,16 +285,16 @@ public void overrideLogLevel(Configuration root, String value) { Configuration[] c = root.getChildren("category"); - for(int i=0;i