cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r882636 - in /cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet: RequestProcessor.java XMLSitemapServlet.java
Date Fri, 20 Nov 2009 16:32:40 GMT
Author: reinhard
Date: Fri Nov 20 16:32:39 2009
New Revision: 882636

URL: http://svn.apache.org/viewvc?rev=882636&view=rev
Log:
split the XMLSitemapServlet into two parts: one servlet specific one and the other responsible
for the request processing. This helps with the integration into Wicket.

Added:
    cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
  (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java

Added: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java?rev=882636&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
Fri Nov 20 16:32:39 2009
@@ -0,0 +1,361 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ *
+ */
+package org.apache.cocoon.servlet;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.callstack.CallStack;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.servlet.node.LastModifiedCollector;
+import org.apache.cocoon.servlet.node.MimeTypeCollector;
+import org.apache.cocoon.servlet.node.StatusCodeCollector;
+import org.apache.cocoon.servlet.util.HttpContextHelper;
+import org.apache.cocoon.servlet.util.ManifestUtils;
+import org.apache.cocoon.servlet.util.ObjectModelProvider;
+import org.apache.cocoon.servlet.util.SettingsHelper;
+import org.apache.cocoon.servletservice.CallStackHelper;
+import org.apache.cocoon.sitemap.Invocation;
+import org.apache.cocoon.sitemap.InvocationImpl;
+import org.apache.cocoon.sitemap.SitemapBuilder;
+import org.apache.cocoon.sitemap.node.SitemapNode;
+import org.apache.cocoon.spring.configurator.ResourceUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.BeanFactory;
+
+public class RequestProcessor {
+
+    private static final long serialVersionUID = 1L;
+
+    private URL baseURL;
+    private BeanFactory beanFactory;
+    private boolean inServletServiceFramework;
+    private final Log logger = LogFactory.getLog(this.getClass());
+    private ServletContext servletContext;
+    private SitemapNode sitemapNode;
+    private String sitemapPath;
+    private String version = "";
+
+    public RequestProcessor(ServletContext servletContext, String sitemapPath, BeanFactory
beanFactory)
+            throws SitemapNotFoundException, InvalidBaseUrlException, SitemapInitializationException
{
+        if (servletContext == null) {
+            throw new NullPointerException("A 'ServletContext' has to be passed.");
+        }
+        if (beanFactory == null) {
+            throw new NullPointerException("A Spring 'BeanFactory' has to be passed.");
+        }
+
+        this.servletContext = servletContext;
+        this.sitemapPath = sitemapPath;
+        this.beanFactory = beanFactory;
+
+        this.initializeInServletServiceFramework();
+        this.initializeBaseURL();
+        this.initializeVersionNumber();
+        this.initializeSitemap();
+    }
+
+    public void service(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException {
+        long start = System.nanoTime();
+        this.logRequest(request);
+
+        try {
+            if (this.inServletServiceFramework) {
+                this.sendSitemapResponse(request, response);
+                return;
+            }
+
+            // if it runs ouside of the Servlet-Service framework, the CallStack has
+            // to be prepared
+            try {
+                CallStackHelper.enterServlet(this.servletContext, request, response);
+                this.sendSitemapResponse(request, response);
+            } finally {
+                CallStackHelper.leaveServlet();
+            }
+        } finally {
+            if (this.logger.isInfoEnabled()) {
+                this.logger.info("Sitemap execution for " + request.getRequestURI() + " took
"
+                        + (System.nanoTime() - start) / 1000000f + " ms.");
+            }
+        }
+    }
+
+    private String calcSitemapRequestURI(HttpServletRequest request) {
+        if (!this.inServletServiceFramework) {
+            return request.getServletPath();
+        }
+
+        // the Servlet-Service framework uses the servlet path as mount
+        // path of a servlet
+        String contextPath = request.getContextPath();
+        String mountPath = request.getServletPath();
+        return request.getRequestURI().substring(contextPath.length() + mountPath.length());
+    }
+
+    private URL getBaseURL() {
+        return this.baseURL;
+    }
+
+    @SuppressWarnings("unchecked")
+    private Map<String, Object> getInvocationParameters(HttpServletRequest req) {
+        Map<String, Object> invocationParameters = new HashMap<String, Object>();
+
+        for (Enumeration<String> names = req.getParameterNames(); names.hasMoreElements();)
{
+            String name = names.nextElement();
+            invocationParameters.put(name, req.getParameter(name));
+        }
+
+        return invocationParameters;
+    }
+
+    private String getSitemapPath() {
+        String sitemapPath = this.sitemapPath;
+        if (sitemapPath == null) {
+            sitemapPath = "/sitemap.xmap";
+        }
+
+        if (!sitemapPath.startsWith("/")) {
+            sitemapPath = "/" + sitemapPath;
+        }
+
+        return sitemapPath;
+    }
+
+    private void initializeBaseURL() throws InvalidBaseUrlException {
+        try {
+            String baseURL = this.getSitemapPath();
+            baseURL = baseURL.substring(0, baseURL.lastIndexOf('/') + 1);
+
+            this.baseURL = this.servletContext.getResource(baseURL);
+
+            if (this.logger.isDebugEnabled()) {
+                this.logger.debug("Setting the baseURL to " + this.baseURL);
+            }
+        } catch (MalformedURLException e) {
+            throw new InvalidBaseUrlException("An exception occurred while retrieving the
base "
+                    + "URL from the servlet context.", e);
+        }
+    }
+
+    private void initializeInServletServiceFramework() {
+        this.inServletServiceFramework = CallStack.getCurrentFrame() != null;
+    }
+
+    private void initializeSitemap() throws SitemapNotFoundException, SitemapInitializationException
{
+        URL url = null;
+        SitemapBuilder sitemapBuilder = null;
+        try {
+            sitemapBuilder = (SitemapBuilder) this.beanFactory.getBean(SitemapBuilder.class.getName());
+            url = this.servletContext.getResource(this.getSitemapPath());
+        } catch (Exception e) {
+            throw new SitemapInitializationException("Can't initialize sitemap.", e);
+        }
+
+        // if the sitemap URL can't be resolved by the ServletContext, null is returned
+        if (url == null) {
+            // prepare a meaningful exception
+            String baseURL = this.getBaseURL().toExternalForm();
+            if (baseURL.endsWith("/")) {
+                baseURL = baseURL.substring(0, baseURL.length() - 1);
+            }
+            throw new SitemapNotFoundException("Can't find sitemap at " + baseURL + this.getSitemapPath());
+        }
+
+        this.sitemapNode = sitemapBuilder.build(url);
+    }
+
+    /**
+     * Read versioning information from the Cocoon 3 Servlet module
+     */
+    private void initializeVersionNumber() {
+        Properties pomProperties = ResourceUtils.getPOMProperties("org.apache.cocoon.servlet",
"cocoon-servlet");
+        if (pomProperties == null) {
+            return;
+        }
+
+        String servletModuleVersion = pomProperties.getProperty("version");
+        if (servletModuleVersion != null) {
+            this.version = servletModuleVersion;
+        }
+
+        if (this.version.endsWith("SNAPSHOT")) {
+            String buildNumber = "";
+            try {
+                String buildNumberAttr = ManifestUtils.getAttribute(this.getClass(), "Implementation-Build");
+                if (buildNumberAttr != null && !"".equals(buildNumberAttr) &&
!"na".equals(buildNumberAttr)) {
+                    buildNumber = "/rev" + buildNumberAttr;
+                }
+            } catch (IOException e) {
+                if (this.logger.isDebugEnabled()) {
+                    this.logger.debug("Error while reading an attribute from the manifest.",
e);
+                }
+            }
+            this.version += buildNumber;
+        }
+    }
+
+    private void invoke(String requestURI, Map<String, Object> parameters, OutputStream
outputStream) {
+        InvocationImpl invocation = (InvocationImpl) this.beanFactory.getBean(Invocation.class.getName());
+
+        invocation.setBaseURL(this.getBaseURL());
+        invocation.setRequestURI(requestURI);
+        invocation.setParameters(parameters);
+        invocation.setOutputStream(outputStream);
+        invocation.setObjectModel(ObjectModelProvider.provide(parameters));
+
+        this.sitemapNode.invoke(invocation);
+    }
+
+    private void logRequest(HttpServletRequest request) {
+        if (this.logger.isInfoEnabled()) {
+            this.logger.info("Performing " + request.getMethod().toUpperCase() + " request
at "
+                    + request.getRequestURI());
+        }
+        if (this.logger.isDebugEnabled()) {
+            this.logger.debug("The base URL for this request is " + this.getBaseURL());
+        }
+    }
+
+    private Map<String, Object> prepareParameters(HttpServletRequest request, HttpServletResponse
response,
+            Settings settings) {
+        Map<String, Object> parameters = this.getInvocationParameters(request);
+        HttpContextHelper.storeRequest(request, parameters);
+        HttpContextHelper.storeResponse(response, parameters);
+        HttpContextHelper.storeServletContext(this.servletContext, parameters);
+        SettingsHelper.storeSettings(settings, parameters);
+        return parameters;
+    }
+
+    private void sendSitemapResponse(HttpServletRequest request, HttpServletResponse response)
throws IOException {
+        Settings settings = (Settings) this.beanFactory.getBean(Settings.class.getName());
+
+        // invoke the sitemap engine
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
+        this.invoke(this.calcSitemapRequestURI(request), this.prepareParameters(request,
response, settings), baos);
+
+        // collect meta information from the previous run of the sitemap engine
+        long lastModified = LastModifiedCollector.getLastModified();
+        int contentLengh = baos.size();
+
+        // send the Last-Modified header
+        if (lastModified > -1) {
+            response.setDateHeader("Last-Modified", lastModified);
+        }
+
+        // set the X-Cocoon-Version header
+        if (!"false".equals(settings.getProperty("org.apache.cocoon.show-version"))) {
+            response.setHeader("X-Cocoon-Version", this.version);
+        }
+
+        // conditional request support
+        long ifLastModifiedSince = request.getDateHeader("If-Modified-Since");
+        if (ifLastModifiedSince > 0 && lastModified > 0) {
+            if (ifLastModifiedSince / 1000 >= lastModified / 1000) {
+                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+
+                if (this.logger.isInfoEnabled()) {
+                    this.logger.info("The requested resource " + request.getRequestURI()
+                            + " hasn't changed: ifLastModifiedSince=" + ifLastModifiedSince
+ ", lastModified="
+                            + lastModified + ". Hence 304 (NOT_MODIFIED) was sent as status
code.");
+                }
+
+                return;
+            }
+        }
+
+        // Content-Type handling
+        String mimeType = MimeTypeCollector.getMimeType();
+        if (mimeType == null || "".equals(mimeType) || "content/unknown".equals(mimeType))
{
+            mimeType = this.servletContext.getMimeType(request.getRequestURI());
+        }
+        if (mimeType != null) {
+            response.setContentType(mimeType);
+        }
+
+        // Status code handling
+        int statusCode = StatusCodeCollector.getStatusCode();
+        response.setStatus(statusCode);
+
+        // write the sitemap result to the output stream
+        if (contentLengh > 0) {
+            response.setContentLength(contentLengh);
+            if (this.logger.isInfoEnabled()) {
+                this.logger.info("Going to send response: mimeType=" + mimeType + ", contentLength="
+ contentLengh
+                        + ", statusCode=" + statusCode + ", lastModified=" + lastModified);
+            }
+
+            response.getOutputStream().write(baos.toByteArray());
+        }
+    }
+
+    public static class InvalidBaseUrlException extends RequestProcessorException {
+
+        private static final long serialVersionUID = 1L;
+
+        public InvalidBaseUrlException(String message, Throwable cause) {
+            super(message, cause);
+        }
+    }
+
+    public static class RequestProcessorException extends Exception {
+
+        private static final long serialVersionUID = 1L;
+
+        public RequestProcessorException(String message) {
+            super(message);
+        }
+
+        public RequestProcessorException(String message, Throwable cause) {
+            super(message, cause);
+        }
+    }
+
+    public static class SitemapInitializationException extends RequestProcessorException
{
+
+        private static final long serialVersionUID = 1L;
+
+        public SitemapInitializationException(String message, Throwable cause) {
+            super(message, cause);
+        }
+    }
+
+    public static class SitemapNotFoundException extends RequestProcessorException {
+
+        private static final long serialVersionUID = 1L;
+
+        public SitemapNotFoundException(String message) {
+            super(message);
+        }
+    }
+}
\ No newline at end of file

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java?rev=882636&r1=882635&r2=882636&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-servlet/src/main/java/org/apache/cocoon/servlet/XMLSitemapServlet.java
Fri Nov 20 16:32:39 2009
@@ -18,241 +18,50 @@
  */
 package org.apache.cocoon.servlet;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
 
-import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.servlet.node.LastModifiedCollector;
-import org.apache.cocoon.servlet.node.MimeTypeCollector;
-import org.apache.cocoon.servlet.node.StatusCodeCollector;
-import org.apache.cocoon.servlet.util.HttpContextHelper;
-import org.apache.cocoon.servlet.util.ManifestUtils;
-import org.apache.cocoon.servlet.util.ObjectModelProvider;
-import org.apache.cocoon.servlet.util.SettingsHelper;
-import org.apache.cocoon.sitemap.Invocation;
-import org.apache.cocoon.sitemap.InvocationImpl;
-import org.apache.cocoon.sitemap.SitemapBuilder;
-import org.apache.cocoon.sitemap.node.SitemapNode;
-import org.apache.cocoon.spring.configurator.ResourceUtils;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
 
-public class XMLSitemapServlet extends HttpServlet implements BeanFactoryAware {
+/**
+ * The Cocoon 3 servlet. It works with and without the Servlet-Service framework.
+ */
+public class XMLSitemapServlet extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
-    private BeanFactory beanFactory;
 
-    private boolean initialized;
+    private RequestProcessor requestProcessor;
     private final Log logger = LogFactory.getLog(this.getClass());
-    private ServletConfig servletConfig;
-    private SitemapNode sitemapNode;
-    private String version = "";
 
     @Override
-    public void init(ServletConfig config) throws ServletException {
-        this.servletConfig = config;
-        super.init(this.servletConfig);
-        this.initVersionNumber();
-    }
-
-    public void invoke(String requestURI, Map<String, Object> parameters, OutputStream
outputStream)
-            throws ServletException {
-        InvocationImpl invocation = (InvocationImpl) this.beanFactory.getBean(Invocation.class.getName());
-
-        invocation.setBaseURL(this.getBaseURL());
-        invocation.setRequestURI(requestURI);
-        invocation.setParameters(parameters);
-        invocation.setOutputStream(outputStream);
-        invocation.setObjectModel(ObjectModelProvider.provide(parameters));
-
-        this.sitemapNode.invoke(invocation);
-    }
-
-    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
-        this.beanFactory = beanFactory;
-    }
-
-    @Override
-    protected void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
-            IOException {
-        long start = System.nanoTime();
-        this.logRequest(request);
-
+    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
         this.lazyInitialize();
 
         try {
-            Settings settings = (Settings) this.beanFactory.getBean(Settings.class.getName());
-
-            // assemble parameters
-            Map<String, Object> parameters = this.getInvocationParameters(request);
-            HttpContextHelper.storeRequest(request, parameters);
-            HttpContextHelper.storeResponse(response, parameters);
-            HttpContextHelper.storeServletContext(this.getServletContext(), parameters);
-            SettingsHelper.storeSettings(settings, parameters);
-
-            // invoke the sitemap engine
-            ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
-            this.invoke(this.calcSitemapRequestURI(request), parameters, baos);
-
-            // collect meta information from the previous run of the sitemap engine
-            long lastModified = LastModifiedCollector.getLastModified();
-            int contentLengh = baos.size();
-
-            // send the Last-Modified header
-            if (lastModified > -1) {
-                response.setDateHeader("Last-Modified", lastModified);
-            }
-
-            // set the X-Cocoon-Version header
-            if (!"false".equals(settings.getProperty("org.apache.cocoon.show-version")))
{
-                response.setHeader("X-Cocoon-Version", this.version);
-            }
-
-            // conditional request support
-            long ifLastModifiedSince = request.getDateHeader("If-Modified-Since");
-            if (ifLastModifiedSince > 0 && ifLastModifiedSince / 1000 >= lastModified
/ 1000 && lastModified > 0) {
-                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
-                if (this.logger.isInfoEnabled()) {
-                    this.logger.info("The requested resource " + request.getRequestURI()
-                            + " hasn't changed: ifLastModifiedSince=" + ifLastModifiedSince
+ ", lastModified="
-                            + lastModified + ". Hence 304 (NOT_MODIFIED) was sent as status
code.");
-                }
-
-                return;
-            }
-
-            // Content-Type handling
-            String mimeType = MimeTypeCollector.getMimeType();
-            if (mimeType == null || "".equals(mimeType) || "content/unknown".equals(mimeType))
{
-                mimeType = this.servletConfig.getServletContext().getMimeType(request.getRequestURI());
-            }
-            if (mimeType != null) {
-                response.setContentType(mimeType);
-            }
-
-            // Status code handling
-            int statusCode = StatusCodeCollector.getStatusCode();
-            response.setStatus(statusCode);
-
-            // write the sitemap result to the output stream
-            if (contentLengh > 0) {
-                response.setContentLength(contentLengh);
-                if (this.logger.isInfoEnabled()) {
-                    this.logger.info("Going to send response: mimeType=" + mimeType + ",
contentLength=" + contentLengh
-                            + ", statusCode=" + statusCode + ", lastModified=" + lastModified);
-                }
-
-                response.getOutputStream().write(baos.toByteArray());
-            }
-        } catch (Exception e) {
-            throw this.wrapException(e, "An exception occurred while executing the sitemap.");
-        } finally {
-            this.logger.info("Sitemap execution took " + (System.nanoTime() - start) / 1000000f
+ " ms.");
-        }
-    }
-
-    private String calcSitemapRequestURI(HttpServletRequest request) {
-        String contextPath = request.getContextPath();
-        String mountPath = request.getServletPath();
-        return request.getRequestURI().substring(contextPath.length() + mountPath.length());
-    }
-
-    private URL getBaseURL() throws ServletException {
-        try {
-            return this.servletConfig.getServletContext().getResource("/");
-        } catch (MalformedURLException e) {
-            throw this.wrapException(e, "An exception occurred while retrieving the base
"
-                    + "URL from the servlet context.");
+            this.requestProcessor.service(req, resp);
+        } catch (RuntimeException e) {
+            this.wrapException(e, "Cocoon can't process the request.");
         }
     }
 
-    @SuppressWarnings("unchecked")
-    private Map<String, Object> getInvocationParameters(HttpServletRequest req) {
-        Map<String, Object> invocationParameters = new HashMap<String, Object>();
-
-        for (Enumeration<String> names = req.getParameterNames(); names.hasMoreElements();)
{
-            String name = names.nextElement();
-            invocationParameters.put(name, req.getParameter(name));
-        }
-
-        return invocationParameters;
-    }
-
-    private String getSitemapPath() {
-        String sitemapPath = this.getInitParameter("sitemap-path");
-        if (sitemapPath == null) {
-            sitemapPath = "/sitemap.xmap";
-        }
-
-        if (!sitemapPath.startsWith("/")) {
-            sitemapPath = "/" + sitemapPath;
-        }
-
-        return sitemapPath;
-    }
-
-    /**
-     * Read versioning information from the Cocoon 3 Servlet module
-     */
-    private void initVersionNumber() {
-        String servletModuleVersion = ResourceUtils.getPOMProperties("org.apache.cocoon.servlet",
"cocoon-servlet")
-                .getProperty("version");
-        if (servletModuleVersion != null) {
-            this.version = servletModuleVersion;
-        }
-
-        if (this.version.endsWith("SNAPSHOT")) {
-            String buildNumber = "";
-            try {
-                String buildNumberAttr = ManifestUtils.getAttribute(this.getClass(), "Implementation-Build");
-                if (buildNumberAttr != null && !"".equals(buildNumberAttr) &&
!"na".equals(buildNumberAttr)) {
-                    buildNumber = "/rev" + buildNumberAttr;
-                }
-            } catch (IOException e) {
-                if (this.logger.isDebugEnabled()) {
-                    this.logger.debug("Error while reading an attribute from the manifest.",
e);
-                }
+    private void lazyInitialize() throws ServletException {
+        synchronized (this) {
+            if (this.requestProcessor != null) {
+                return;
             }
-            this.version += buildNumber;
-        }
-    }
 
-    private synchronized void lazyInitialize() throws ServletException {
-        if (!this.initialized) {
             try {
-                SitemapBuilder sitemapBuilder = (SitemapBuilder) this.beanFactory.getBean(SitemapBuilder.class
-                        .getName());
-                URL url = this.servletConfig.getServletContext().getResource(this.getSitemapPath());
-                this.sitemapNode = sitemapBuilder.build(url);
+                this.requestProcessor = new RequestProcessor(this.getServletContext(), this
+                        .getInitParameter("sitemap-path"), WebAppContextUtils.getCurrentWebApplicationContext());
             } catch (Exception e) {
-                throw this.wrapException(e, "An exception occurred while building the sitemap.");
+                this.wrapException(e, "Can't initialize the RequestProcessor correctly.");
             }
-            this.initialized = true;
-        }
-    }
-
-    private void logRequest(HttpServletRequest request) throws ServletException {
-        if (this.logger.isInfoEnabled()) {
-            this.logger.info("Performing " + request.getMethod().toUpperCase() + " request
at "
-                    + request.getRequestURI());
-        }
-        if (this.logger.isDebugEnabled()) {
-            this.logger.debug("The base URL for this request is " + this.getBaseURL());
         }
     }
 



Mime
View raw message