1 package net.sourceforge.blogentis.storage;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import net.sourceforge.blogentis.om.Blog;
26 import net.sourceforge.blogentis.plugins.BlogPluginService;
27 import net.sourceforge.blogentis.turbine.BlogRunData;
28 import net.sourceforge.blogentis.turbine.BlogRunDataService;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.slide.common.ServiceAccessException;
33 import org.apache.slide.common.SlideToken;
34 import org.apache.slide.content.AbstractContentInterceptor;
35 import org.apache.slide.content.NodeRevisionContent;
36 import org.apache.slide.content.NodeRevisionDescriptor;
37 import org.apache.slide.content.NodeRevisionDescriptors;
38 import org.apache.slide.content.NodeRevisionNumber;
39 import org.apache.slide.lock.ObjectLockedException;
40 import org.apache.slide.security.AccessDeniedException;
41 import org.apache.slide.structure.LinkedObjectNotFoundException;
42 import org.apache.slide.structure.ObjectNotFoundException;
43
44 /***
45 * This class invalidates the template cache that FileRetrieverService keeps.
46 *
47 * @author abas
48 */
49 public class FileRetrieverInterceptor
50 extends AbstractContentInterceptor {
51 private static Log log = LogFactory.getLog(FileRetrieverInterceptor.class);
52
53 protected Blog getBlog(String slideUri) {
54 BlogRunData data = BlogRunDataService.getCurrentRunData();
55 if (data == null)
56 return null;
57 return data.getBlog();
58 }
59
60 protected String getPathFor(Blog blog, String slideUri) {
61
62 if (blog == null)
63 return null;
64 String prefix = "/blog/" + blog.getName() + '/';
65 if (!slideUri.startsWith(prefix))
66 return null;
67 return slideUri.substring(prefix.length() - 1);
68 }
69
70 protected IStorageExtensionPoint getExtPointFor(Blog b) {
71 if (b == null)
72 return null;
73 return (IStorageExtensionPoint)BlogPluginService
74 .locateExtensionPoint(b, IStorageExtensionPoint.class);
75 }
76
77 public void postRetrieveContent(
78 SlideToken token,
79 NodeRevisionDescriptors revisionDescriptors,
80 NodeRevisionDescriptor revisionDescriptor,
81 NodeRevisionContent revisionContent)
82 throws AccessDeniedException, ObjectNotFoundException,
83 LinkedObjectNotFoundException, ObjectLockedException,
84 ServiceAccessException {
85 if (revisionDescriptors == null)
86 return;
87 String uri = revisionDescriptors.getUri();
88 Blog b = getBlog(uri);
89 IStorageExtensionPoint extPoint = getExtPointFor(b);
90 if (extPoint == null)
91 return;
92 String path = getPathFor(b, uri);
93 if (path == null)
94 return;
95 extPoint.postRetrieveContent(path, revisionDescriptors,
96 revisionDescriptor, revisionContent);
97 }
98
99 public void postStoreContent(SlideToken token,
100 NodeRevisionDescriptors revisionDescriptors,
101 NodeRevisionDescriptor revisionDescriptor,
102 NodeRevisionContent revisionContent)
103 throws AccessDeniedException, ObjectNotFoundException,
104 LinkedObjectNotFoundException, ObjectLockedException,
105 ServiceAccessException {
106 if (revisionDescriptors == null)
107 return;
108
109 if (log.isDebugEnabled())
110 log.debug("Modified file:" + revisionDescriptors.getUri());
111 TemplateResourceLoader.resourceUpdated(revisionDescriptors.getUri());
112 String uri = revisionDescriptors.getUri();
113 Blog b = getBlog(uri);
114 IStorageExtensionPoint extPoint = getExtPointFor(b);
115 if (extPoint == null)
116 return;
117 String path = getPathFor(b, uri);
118 if (path == null)
119 return;
120 extPoint.postRetrieveContent(path, revisionDescriptors,
121 revisionDescriptor, revisionContent);
122 }
123
124 public void preRemoveContent(SlideToken token,
125 NodeRevisionDescriptors revisionDescriptors,
126 NodeRevisionDescriptor revisionDescriptor)
127 throws AccessDeniedException, ObjectNotFoundException,
128 LinkedObjectNotFoundException, ObjectLockedException,
129 ServiceAccessException {
130
131 if (revisionDescriptors == null)
132 return;
133 if (log.isDebugEnabled())
134 log.debug("Removed file:" + revisionDescriptors.getUri());
135 TemplateResourceLoader.resourceUpdated(revisionDescriptors
136 .getOriginalUri());
137 String uri = revisionDescriptors.getUri();
138 Blog b = getBlog(uri);
139 IStorageExtensionPoint extPoint = getExtPointFor(b);
140 if (extPoint == null)
141 return;
142 String path = getPathFor(b, uri);
143 if (path == null)
144 return;
145 extPoint.preRemoveContent(path, revisionDescriptors, revisionDescriptor);
146 }
147
148 public void preRetrieveContent(SlideToken token,
149 NodeRevisionDescriptors revisionDescriptors,
150 NodeRevisionNumber revisionNumber,
151 NodeRevisionDescriptor revisionDescriptor)
152 throws AccessDeniedException, ObjectNotFoundException,
153 LinkedObjectNotFoundException, ObjectLockedException,
154 ServiceAccessException {
155 if (revisionDescriptors == null)
156 return;
157 String uri = revisionDescriptors.getUri();
158 Blog b = getBlog(uri);
159 IStorageExtensionPoint extPoint = getExtPointFor(b);
160 if (extPoint == null)
161 return;
162 String path = getPathFor(b, uri);
163 if (path == null)
164 return;
165 extPoint.preRetrieveContent(path, revisionDescriptors, revisionNumber,
166 revisionDescriptor);
167 }
168
169 public void preStoreContent(SlideToken token,
170 NodeRevisionDescriptors revisionDescriptors,
171 NodeRevisionDescriptor revisionDescriptor,
172 NodeRevisionContent revisionContent)
173 throws AccessDeniedException, ObjectNotFoundException,
174 LinkedObjectNotFoundException, ObjectLockedException,
175 ServiceAccessException {
176 if (revisionDescriptors == null)
177 return;
178 String uri = revisionDescriptors.getUri();
179 Blog b = getBlog(uri);
180 IStorageExtensionPoint extPoint = getExtPointFor(b);
181 if (extPoint == null)
182 return;
183 String path = getPathFor(b, uri);
184 if (path == null)
185 return;
186 extPoint.preStoreContent(path, revisionDescriptors, revisionDescriptor,
187 revisionContent);
188 }
189 }