| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 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 |
|
|
| 49 |
|
|
| 50 |
|
@author |
| 51 |
|
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 4 |
Complexity Density: 0,14 |
|
| 52 |
|
public class PebbleContextListener implements ServletContextListener { |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
private static Log log = LogFactory.getLog(PebbleContextListener.class); |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
@param |
| 61 |
|
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 3 |
Complexity Density: 0,12 |
|
| 62 |
0
|
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 |
|
|
| 78 |
0
|
Collection<Blog> blogs = (Collection<Blog>)BlogManager.getInstance().getBlogs(); |
| 79 |
0
|
for (Blog blog : blogs) { |
| 80 |
0
|
try { |
| 81 |
|
|
| 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 |
|
|
| 120 |
|
|
| 121 |
|
@param |
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 123 |
0
|
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 |
|
} |