| 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.service; |
| 33 |
|
|
| 34 |
|
import net.sourceforge.pebble.ContentCache; |
| 35 |
|
import net.sourceforge.pebble.comparator.StaticPageByNameComparator; |
| 36 |
|
import net.sourceforge.pebble.dao.DAOFactory; |
| 37 |
|
import net.sourceforge.pebble.dao.PersistenceException; |
| 38 |
|
import net.sourceforge.pebble.dao.StaticPageDAO; |
| 39 |
|
import net.sourceforge.pebble.domain.Blog; |
| 40 |
|
import net.sourceforge.pebble.domain.StaticPage; |
| 41 |
|
import org.apache.commons.logging.Log; |
| 42 |
|
import org.apache.commons.logging.LogFactory; |
| 43 |
|
|
| 44 |
|
import java.util.ArrayList; |
| 45 |
|
import java.util.Collections; |
| 46 |
|
import java.util.Date; |
| 47 |
|
import java.util.List; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@author |
| 54 |
|
|
|
|
|
| 0% |
Uncovered Elements: 83 (83) |
Complexity: 18 |
Complexity Density: 0,28 |
|
| 55 |
|
public class StaticPageService { |
| 56 |
|
|
| 57 |
|
private static final Log log = LogFactory.getLog(StaticPageService.class); |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
@param |
| 63 |
|
@return |
| 64 |
|
@throws |
| 65 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0,25 |
|
| 66 |
0
|
public List<StaticPage> getStaticPages(Blog blog) throws StaticPageServiceException {... |
| 67 |
0
|
List<StaticPage> staticPages = new ArrayList<StaticPage>(); |
| 68 |
0
|
try { |
| 69 |
0
|
DAOFactory factory = DAOFactory.getConfiguredFactory(); |
| 70 |
0
|
StaticPageDAO dao = factory.getStaticPageDAO(); |
| 71 |
0
|
staticPages.addAll(dao.loadStaticPages(blog)); |
| 72 |
|
} catch (PersistenceException pe) { |
| 73 |
0
|
throw new StaticPageServiceException(blog, pe); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
0
|
Collections.sort(staticPages, new StaticPageByNameComparator()); |
| 77 |
|
|
| 78 |
0
|
return staticPages; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
@param |
| 85 |
|
@param |
| 86 |
|
@return |
| 87 |
|
@throws |
| 88 |
|
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 5 |
Complexity Density: 0,29 |
|
| 89 |
0
|
public StaticPage getStaticPageById(Blog blog, String pageId) throws StaticPageServiceException {... |
| 90 |
0
|
StaticPage staticPage; |
| 91 |
0
|
ContentCache cache = ContentCache.getInstance(); |
| 92 |
|
|
| 93 |
0
|
try { |
| 94 |
0
|
staticPage = cache.getStaticPage(blog, pageId); |
| 95 |
0
|
if (staticPage != null) { |
| 96 |
0
|
log.debug("Got static page " + pageId+ " from cache"); |
| 97 |
|
} else { |
| 98 |
0
|
log.debug("Loading static page " + pageId+ " from disk"); |
| 99 |
|
|
| 100 |
0
|
DAOFactory factory = DAOFactory.getConfiguredFactory(); |
| 101 |
0
|
StaticPageDAO dao = factory.getStaticPageDAO(); |
| 102 |
0
|
staticPage = dao.loadStaticPage(blog, pageId); |
| 103 |
0
|
if (staticPage != null) { |
| 104 |
0
|
staticPage.setPersistent(true); |
| 105 |
0
|
cache.putStaticPage(staticPage); |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
} catch (PersistenceException pe) { |
| 109 |
0
|
throw new StaticPageServiceException(blog, pe); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
0
|
if (staticPage != null) { |
| 113 |
0
|
staticPage = (StaticPage)staticPage.clone(); |
| 114 |
|
} |
| 115 |
|
|
| 116 |
0
|
return staticPage; |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
@param |
| 123 |
|
@param |
| 124 |
|
@return |
| 125 |
|
@throws |
| 126 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 127 |
0
|
public StaticPage getStaticPageByName(Blog blog, String name) throws StaticPageServiceException {... |
| 128 |
0
|
String id = blog.getStaticPageIndex().getStaticPage(name); |
| 129 |
0
|
return getStaticPageById(blog, id); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
@param |
| 136 |
|
@throws |
| 137 |
|
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0,25 |
|
| 138 |
0
|
public void putStaticPage(StaticPage staticPage) throws StaticPageServiceException {... |
| 139 |
0
|
ContentCache cache = ContentCache.getInstance(); |
| 140 |
0
|
DAOFactory factory = DAOFactory.getConfiguredFactory(); |
| 141 |
0
|
StaticPageDAO dao = factory.getStaticPageDAO(); |
| 142 |
0
|
Blog blog = staticPage.getBlog(); |
| 143 |
|
|
| 144 |
0
|
synchronized (blog) { |
| 145 |
0
|
try { |
| 146 |
0
|
StaticPage sp = getStaticPageById(blog, staticPage.getId()); |
| 147 |
|
|
| 148 |
0
|
if (!staticPage.isPersistent() && sp != null) { |
| 149 |
|
|
| 150 |
|
|
| 151 |
0
|
staticPage.setDate(new Date(staticPage.getDate().getTime() + 1)); |
| 152 |
0
|
putStaticPage(staticPage); |
| 153 |
|
} else { |
| 154 |
0
|
dao.storeStaticPage(staticPage); |
| 155 |
0
|
staticPage.setPersistent(true); |
| 156 |
0
|
cache.removeStaticPage(staticPage); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
0
|
staticPage.getBlog().getSearchIndex().index(staticPage); |
| 160 |
0
|
staticPage.getBlog().getStaticPageIndex().index(staticPage); |
| 161 |
|
} catch (PersistenceException pe) { |
| 162 |
0
|
throw new StaticPageServiceException(blog, pe); |
| 163 |
|
} |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
@param |
| 171 |
|
@throws |
| 172 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0,18 |
|
| 173 |
0
|
public void removeStaticPage(StaticPage staticPage) throws StaticPageServiceException {... |
| 174 |
0
|
ContentCache cache = ContentCache.getInstance(); |
| 175 |
0
|
DAOFactory factory = DAOFactory.getConfiguredFactory(); |
| 176 |
0
|
StaticPageDAO dao = factory.getStaticPageDAO(); |
| 177 |
0
|
Blog blog = staticPage.getBlog(); |
| 178 |
|
|
| 179 |
0
|
try { |
| 180 |
0
|
dao.removeStaticPage(staticPage); |
| 181 |
0
|
cache.removeStaticPage(staticPage); |
| 182 |
|
|
| 183 |
0
|
staticPage.getBlog().getSearchIndex().unindex(staticPage); |
| 184 |
0
|
staticPage.getBlog().getStaticPageIndex().unindex(staticPage); |
| 185 |
|
} catch (PersistenceException pe) { |
| 186 |
|
|
| 187 |
0
|
cache.removeStaticPage(staticPage); |
| 188 |
|
|
| 189 |
0
|
throw new StaticPageServiceException(staticPage.getBlog(), pe); |
| 190 |
|
} |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
@param |
| 197 |
|
@return |
| 198 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
| 199 |
0
|
public boolean lock(StaticPage staticPage) {... |
| 200 |
0
|
if (staticPage.isPersistent()) { |
| 201 |
0
|
boolean success = DAOFactory.getConfiguredFactory().getStaticPageDAO().lock(staticPage); |
| 202 |
0
|
ContentCache.getInstance().removeStaticPage(staticPage); |
| 203 |
|
|
| 204 |
0
|
return success; |
| 205 |
|
} else { |
| 206 |
0
|
return true; |
| 207 |
|
} |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
@param |
| 214 |
|
@return |
| 215 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
| 216 |
0
|
public boolean unlock(StaticPage staticPage) {... |
| 217 |
0
|
if (staticPage.isPersistent()) { |
| 218 |
0
|
boolean success = DAOFactory.getConfiguredFactory().getStaticPageDAO().unlock(staticPage); |
| 219 |
0
|
ContentCache.getInstance().removeStaticPage(staticPage); |
| 220 |
|
|
| 221 |
0
|
return success; |
| 222 |
|
} else { |
| 223 |
0
|
return true; |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
} |