Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../../img/srcFileCovDistChart0.png 48% of files have more coverage
28   130   4   14
2   68   0,14   2
2     2  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  PebbleContextListener       Line # 52 28 0% 4 32 0% 0.0
 
No Tests
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.web.listener;
33   
34    import net.sourceforge.pebble.Configuration;
35    import net.sourceforge.pebble.PebbleContext;
36    import net.sourceforge.pebble.dao.DAOFactory;
37    import net.sourceforge.pebble.domain.*;
38    import org.apache.commons.logging.Log;
39    import org.apache.commons.logging.LogFactory;
40    import org.springframework.context.ApplicationContext;
41    import org.springframework.web.context.support.WebApplicationContextUtils;
42   
43    import javax.servlet.ServletContextEvent;
44    import javax.servlet.ServletContextListener;
45    import java.util.Collection;
46   
47    /**
48    * Allows the blog to be loaded when this web application is started up.
49    *
50    * @author Simon Brown
51    */
 
52    public class PebbleContextListener implements ServletContextListener {
53   
54    /** the log used by this class */
55    private static Log log = LogFactory.getLog(PebbleContextListener.class);
56   
57    /**
58    * Called when the web application is started.
59    *
60    * @param event a ServletContextEvent instance
61    */
 
62  0 toggle public void contextInitialized(ServletContextEvent event) {
63  0 long startTime = System.currentTimeMillis();
64  0 log.info("Starting Pebble");
65   
66  0 ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
67  0 Configuration config = (Configuration)applicationContext.getBean("pebbleConfiguration");
68   
69  0 DAOFactory.setConfiguredFactory(config.getDaoFactory());
70  0 PebbleContext ctx = PebbleContext.getInstance();
71  0 ctx.setConfiguration(config);
72  0 ctx.setWebApplicationRoot(event.getServletContext().getRealPath("/"));
73   
74  0 BlogManager.getInstance().setMultiBlog(config.isMultiBlog());
75  0 BlogManager.getInstance().startBlogs();
76   
77    // find those blogs with no entries and add a welcome note
78  0 Collection<Blog> blogs = (Collection<Blog>)BlogManager.getInstance().getBlogs();
79  0 for (Blog blog : blogs) {
80  0 try {
81    // and add a default entry, if one doesn't exist
82  0 if (blog.getNumberOfBlogEntries() == 0) {
83  0 log.info("Creating 'welcome note' blog entry for " + blog.getId());
84  0 BlogEntry blogEntry = new BlogEntry(blog);
85  0 blogEntry.setTitle("Welcome");
86  0 blogEntry.setBody(
87    "<p>\n" +
88    "Welcome to your new Pebble powered blog. Here are a few suggestions for getting started.\n" +
89    "</p>\n" +
90    "\n" +
91    "<ul>\n" +
92    "<li>Login to see the admin features of your blog. The default username is <code>username</code> and the password is <code>password</code>.</li>\n" +
93    "<li>Modify your <a href=\"viewBlogProperties.secureaction\">blog properties</a></li>\n" +
94    "<li><a href=\"addBlogEntry.secureaction\">Create a new blog entry</a>.</li>\n" +
95    "<li>Give out a link to your <a href=\"./rss.xml\">RSS</a> feed.</li>\n" +
96    "<li>Remove the default user and create your own user on the <a href=\"viewUsers.secureaction\">users page</a>.</li>\n" +
97    "<li>Take a look at the <a href=\"./help/index.html\">online help</a>.</li>\n" +
98    "<li>Delete this blog entry when you're finished with it.</li>\n" +
99    "</ul>\n" +
100    "\n" +
101    "<p>\n" +
102    "Have fun!\n" +
103    "</p>");
104  0 blogEntry.setAuthor("username");
105  0 blogEntry.setPublished(true);
106  0 BlogService service = new BlogService();
107  0 service.putBlogEntry(blogEntry);
108    }
109    } catch (BlogServiceException e) {
110  0 log.warn("Could not store 'welcome note' blog entry for " + blog.getId());
111    }
112    }
113   
114  0 long endTime = System.currentTimeMillis();
115  0 log.info("Pebble started in " + (endTime-startTime) + "ms");
116    }
117   
118    /**
119    * Called when the web application is shutdown.
120    *
121    * @param event a ServletContextEvent instance
122    */
 
123  0 toggle public void contextDestroyed(ServletContextEvent event) {
124  0 log.info("Stopping Pebble");
125  0 BlogManager.getInstance().stopBlogs();
126   
127  0 log.info("Pebble stopped");
128    }
129   
130    }