1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.jetspeed.page.psml; |
19 |
|
|
20 |
|
import java.io.FileNotFoundException; |
21 |
|
import java.util.HashMap; |
22 |
|
import java.util.Iterator; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import org.apache.commons.logging.Log; |
26 |
|
import org.apache.commons.logging.LogFactory; |
27 |
|
import org.apache.jetspeed.JetspeedActions; |
28 |
|
import org.apache.jetspeed.cache.file.FileCache; |
29 |
|
import org.apache.jetspeed.cache.file.FileCacheEntry; |
30 |
|
import org.apache.jetspeed.cache.file.FileCacheEventListener; |
31 |
|
import org.apache.jetspeed.idgenerator.IdGenerator; |
32 |
|
import org.apache.jetspeed.om.folder.Folder; |
33 |
|
import org.apache.jetspeed.om.folder.FolderNotFoundException; |
34 |
|
import org.apache.jetspeed.om.folder.InvalidFolderException; |
35 |
|
import org.apache.jetspeed.om.folder.psml.FolderImpl; |
36 |
|
import org.apache.jetspeed.om.folder.psml.MenuDefinitionImpl; |
37 |
|
import org.apache.jetspeed.om.folder.psml.MenuExcludeDefinitionImpl; |
38 |
|
import org.apache.jetspeed.om.folder.psml.MenuIncludeDefinitionImpl; |
39 |
|
import org.apache.jetspeed.om.folder.psml.MenuOptionsDefinitionImpl; |
40 |
|
import org.apache.jetspeed.om.folder.psml.MenuSeparatorDefinitionImpl; |
41 |
|
import org.apache.jetspeed.om.page.ContentPage; |
42 |
|
import org.apache.jetspeed.om.page.ContentPageImpl; |
43 |
|
import org.apache.jetspeed.om.page.Fragment; |
44 |
|
import org.apache.jetspeed.om.page.Link; |
45 |
|
import org.apache.jetspeed.om.page.Page; |
46 |
|
import org.apache.jetspeed.om.page.PageSecurity; |
47 |
|
import org.apache.jetspeed.om.page.SecurityConstraintImpl; |
48 |
|
import org.apache.jetspeed.om.page.SecurityConstraintsDef; |
49 |
|
import org.apache.jetspeed.om.page.psml.FragmentImpl; |
50 |
|
import org.apache.jetspeed.om.page.psml.FragmentPreferenceImpl; |
51 |
|
import org.apache.jetspeed.om.page.psml.LinkImpl; |
52 |
|
import org.apache.jetspeed.om.page.psml.PageImpl; |
53 |
|
import org.apache.jetspeed.om.page.psml.PageSecurityImpl; |
54 |
|
import org.apache.jetspeed.om.page.psml.SecurityConstraintsDefImpl; |
55 |
|
import org.apache.jetspeed.om.page.psml.SecurityConstraintsImpl; |
56 |
|
import org.apache.jetspeed.page.AbstractPageManager; |
57 |
|
import org.apache.jetspeed.page.FolderNotUpdatedException; |
58 |
|
import org.apache.jetspeed.page.PageManager; |
59 |
|
import org.apache.jetspeed.page.PageManagerSecurityUtils; |
60 |
|
import org.apache.jetspeed.page.PageNotFoundException; |
61 |
|
import org.apache.jetspeed.page.document.DocumentException; |
62 |
|
import org.apache.jetspeed.page.document.DocumentHandlerFactory; |
63 |
|
import org.apache.jetspeed.page.document.DocumentNotFoundException; |
64 |
|
import org.apache.jetspeed.page.document.FailedToDeleteDocumentException; |
65 |
|
import org.apache.jetspeed.page.document.FailedToUpdateDocumentException; |
66 |
|
import org.apache.jetspeed.page.document.FolderHandler; |
67 |
|
import org.apache.jetspeed.page.document.Node; |
68 |
|
import org.apache.jetspeed.page.document.NodeException; |
69 |
|
import org.apache.jetspeed.page.document.NodeSet; |
70 |
|
import org.apache.jetspeed.page.document.UnsupportedDocumentTypeException; |
71 |
|
import org.apache.jetspeed.page.document.psml.NodeSetImpl; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
public class CastorXmlPageManager extends AbstractPageManager implements PageManager, FileCacheEventListener |
82 |
|
{ |
83 |
0 |
private final static Log log = LogFactory.getLog(CastorXmlPageManager.class); |
84 |
|
|
85 |
0 |
private static Map modelClasses = new HashMap(); |
86 |
|
static |
87 |
|
{ |
88 |
0 |
modelClasses.put("FragmentImpl", FragmentImpl.class); |
89 |
0 |
modelClasses.put("PageImpl", PageImpl.class); |
90 |
0 |
modelClasses.put("FolderImpl", FolderImpl.class); |
91 |
0 |
modelClasses.put("LinkImpl", LinkImpl.class); |
92 |
0 |
modelClasses.put("PageSecurityImpl", PageSecurityImpl.class); |
93 |
0 |
modelClasses.put("FolderMenuDefinitionImpl", MenuDefinitionImpl.class); |
94 |
0 |
modelClasses.put("FolderMenuExcludeDefinitionImpl", MenuExcludeDefinitionImpl.class); |
95 |
0 |
modelClasses.put("FolderMenuIncludeDefinitionImpl", MenuIncludeDefinitionImpl.class); |
96 |
0 |
modelClasses.put("FolderMenuOptionsDefinitionImpl", MenuOptionsDefinitionImpl.class); |
97 |
0 |
modelClasses.put("FolderMenuSeparatorDefinitionImpl", MenuSeparatorDefinitionImpl.class); |
98 |
0 |
modelClasses.put("PageMenuDefinitionImpl", MenuDefinitionImpl.class); |
99 |
0 |
modelClasses.put("PageMenuExcludeDefinitionImpl", MenuExcludeDefinitionImpl.class); |
100 |
0 |
modelClasses.put("PageMenuIncludeDefinitionImpl", MenuIncludeDefinitionImpl.class); |
101 |
0 |
modelClasses.put("PageMenuOptionsDefinitionImpl", MenuOptionsDefinitionImpl.class); |
102 |
0 |
modelClasses.put("PageMenuSeparatorDefinitionImpl", MenuSeparatorDefinitionImpl.class); |
103 |
0 |
modelClasses.put("SecurityConstraintsImpl", SecurityConstraintsImpl.class); |
104 |
0 |
modelClasses.put("FolderSecurityConstraintImpl", SecurityConstraintImpl.class); |
105 |
0 |
modelClasses.put("PageSecurityConstraintImpl", SecurityConstraintImpl.class); |
106 |
0 |
modelClasses.put("FragmentSecurityConstraintImpl", SecurityConstraintImpl.class); |
107 |
0 |
modelClasses.put("LinkSecurityConstraintImpl", SecurityConstraintImpl.class); |
108 |
0 |
modelClasses.put("PageSecuritySecurityConstraintImpl", SecurityConstraintImpl.class); |
109 |
0 |
modelClasses.put("SecurityConstraintsDefImpl", SecurityConstraintsDefImpl.class); |
110 |
0 |
modelClasses.put("FragmentPreferenceImpl", FragmentPreferenceImpl.class); |
111 |
0 |
} |
112 |
|
|
113 |
0 |
private IdGenerator generator = null; |
114 |
|
private DocumentHandlerFactory handlerFactory; |
115 |
|
private FolderHandler folderHandler; |
116 |
|
private FileCache fileCache; |
117 |
|
|
118 |
|
public CastorXmlPageManager( IdGenerator generator, DocumentHandlerFactory handlerFactory, |
119 |
|
FolderHandler folderHandler, FileCache fileCache, |
120 |
|
boolean permissionsEnabled, class="keyword">boolean constraintsEnabled ) throws FileNotFoundException |
121 |
|
{ |
122 |
0 |
super(permissionsEnabled, constraintsEnabled, modelClasses); |
123 |
0 |
this.generator = generator; |
124 |
0 |
handlerFactory.setPermissionsEnabled(permissionsEnabled); |
125 |
0 |
handlerFactory.setConstraintsEnabled(constraintsEnabled); |
126 |
0 |
this.handlerFactory = handlerFactory; |
127 |
0 |
this.folderHandler = folderHandler; |
128 |
0 |
this.fileCache = fileCache; |
129 |
0 |
this.fileCache.addListener(class="keyword">this); |
130 |
0 |
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
public Fragment newFragment() |
141 |
|
{ |
142 |
|
|
143 |
0 |
FragmentImpl fragment = (FragmentImpl)super.newFragment(); |
144 |
0 |
fragment.setId(generator.getNextPeid()); |
145 |
0 |
return fragment; |
146 |
|
} |
147 |
|
|
148 |
|
public Fragment newPortletFragment() |
149 |
|
{ |
150 |
|
|
151 |
0 |
FragmentImpl fragment = (FragmentImpl)super.newFragment(); |
152 |
0 |
fragment.setType(Fragment.PORTLET); |
153 |
0 |
fragment.setId(generator.getNextPeid()); |
154 |
0 |
return fragment; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
public Page getPage(String path) throws PageNotFoundException, NodeException |
170 |
|
{ |
171 |
|
|
172 |
|
try |
173 |
|
{ |
174 |
0 |
FolderImpl folder = getNodeFolder(path); |
175 |
0 |
return folder.getPage(getNodeName(path)); |
176 |
|
} |
177 |
0 |
catch (FolderNotFoundException fnfe) |
178 |
|
{ |
179 |
0 |
throw new PageNotFoundException(fnfe.getMessage()); |
180 |
|
} |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
public void updatePage(Page page) throws NodeException |
191 |
|
{ |
192 |
|
|
193 |
0 |
if (page instanceof ContentPageImpl) |
194 |
|
{ |
195 |
0 |
page = ((ContentPageImpl)page).getPage(); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
0 |
if (page.getPath() != null) |
200 |
|
{ |
201 |
0 |
if (!page.getPath().equals(page.getId())) |
202 |
|
{ |
203 |
0 |
log.error("Page paths and ids must match!"); |
204 |
0 |
return; |
205 |
|
} |
206 |
|
} |
207 |
|
else |
208 |
|
{ |
209 |
0 |
log.error("Page paths and ids must be set!"); |
210 |
0 |
return; |
211 |
|
} |
212 |
|
|
213 |
|
try |
214 |
|
{ |
215 |
|
|
216 |
0 |
boolean newPage = false; |
217 |
0 |
FolderImpl parentFolder = getNodeFolder(page.getPath()); |
218 |
0 |
if (page.getParent() == null) |
219 |
|
{ |
220 |
0 |
page.setParent(parentFolder); |
221 |
0 |
newPage = true; |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
0 |
PageImpl pageImpl = (PageImpl)page; |
226 |
0 |
pageImpl.setPermissionsEnabled(handlerFactory.getPermissionsEnabled()); |
227 |
0 |
pageImpl.setConstraintsEnabled(handlerFactory.getConstraintsEnabled()); |
228 |
|
|
229 |
|
|
230 |
0 |
page.checkAccess(JetspeedActions.EDIT); |
231 |
|
|
232 |
|
|
233 |
0 |
handlerFactory.getDocumentHandler(Page.DOCUMENT_TYPE).updateDocument(page); |
234 |
|
|
235 |
|
|
236 |
0 |
if (parentFolder != null) |
237 |
|
{ |
238 |
0 |
NodeSetImpl parentAllNodes = (NodeSetImpl)parentFolder.getAllNodes(); |
239 |
0 |
if (!parentAllNodes.contains(page)) |
240 |
|
{ |
241 |
|
|
242 |
0 |
parentAllNodes.add(page); |
243 |
0 |
newPage = true; |
244 |
|
} |
245 |
0 |
else if (parentAllNodes.get(page.getPath()) != page) |
246 |
|
{ |
247 |
|
|
248 |
0 |
parentAllNodes.remove(page); |
249 |
0 |
parentAllNodes.add(page); |
250 |
|
} |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
0 |
if (newPage) |
255 |
|
{ |
256 |
0 |
notifyNewNode(page); |
257 |
|
} |
258 |
|
else |
259 |
|
{ |
260 |
0 |
notifyUpdatedNode(page); |
261 |
|
} |
262 |
|
} |
263 |
0 |
catch (FolderNotFoundException fnfe) |
264 |
|
{ |
265 |
0 |
throw new NodeException(fnfe.getMessage()); |
266 |
0 |
} |
267 |
0 |
} |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
public void removePage(Page page) throws NodeException |
277 |
|
{ |
278 |
|
|
279 |
0 |
if (page instanceof ContentPageImpl) |
280 |
|
{ |
281 |
0 |
page = ((ContentPageImpl)page).getPage(); |
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
0 |
page.checkAccess(JetspeedActions.EDIT); |
286 |
|
|
287 |
|
try |
288 |
|
{ |
289 |
0 |
FolderImpl folder = getNodeFolder(page.getPath()); |
290 |
|
|
291 |
|
|
292 |
0 |
handlerFactory.getDocumentHandler(Page.DOCUMENT_TYPE).removeDocument(page); |
293 |
|
|
294 |
|
|
295 |
0 |
((NodeSetImpl)folder.getAllNodes()).remove(page); |
296 |
|
|
297 |
|
|
298 |
0 |
notifyRemovedNode(page); |
299 |
|
} |
300 |
0 |
catch (FolderNotFoundException fnfe) |
301 |
|
{ |
302 |
0 |
throw new NodeException(fnfe.getMessage()); |
303 |
|
} |
304 |
0 |
catch (DocumentNotFoundException dnfe) |
305 |
|
{ |
306 |
0 |
throw new NodeException(dnfe.getMessage()); |
307 |
0 |
} |
308 |
0 |
} |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
public Link getLink(String path) throws DocumentNotFoundException, UnsupportedDocumentTypeException, NodeException |
323 |
|
{ |
324 |
|
|
325 |
|
try |
326 |
|
{ |
327 |
0 |
FolderImpl folder = getNodeFolder(path); |
328 |
0 |
return folder.getLink(getNodeName(path)); |
329 |
|
} |
330 |
0 |
catch (FolderNotFoundException fnfe) |
331 |
|
{ |
332 |
0 |
throw new DocumentNotFoundException(fnfe.getMessage()); |
333 |
|
} |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
public void updateLink(Link link) throws NodeException |
344 |
|
{ |
345 |
|
|
346 |
0 |
if (link.getPath() != null) |
347 |
|
{ |
348 |
0 |
if (!link.getPath().equals(link.getId())) |
349 |
|
{ |
350 |
0 |
log.error("Link paths and ids must match!"); |
351 |
0 |
return; |
352 |
|
} |
353 |
|
} |
354 |
|
else |
355 |
|
{ |
356 |
0 |
log.error("Link paths and ids must be set!"); |
357 |
0 |
return; |
358 |
|
} |
359 |
|
|
360 |
|
try |
361 |
|
{ |
362 |
|
|
363 |
0 |
boolean newLink = false; |
364 |
0 |
FolderImpl parentFolder = getNodeFolder(link.getPath()); |
365 |
0 |
if (link.getParent() == null) |
366 |
|
{ |
367 |
0 |
link.setParent(parentFolder); |
368 |
0 |
newLink = true; |
369 |
|
} |
370 |
|
|
371 |
|
|
372 |
0 |
LinkImpl linkImpl = (LinkImpl)link; |
373 |
0 |
linkImpl.setPermissionsEnabled(handlerFactory.getPermissionsEnabled()); |
374 |
0 |
linkImpl.setConstraintsEnabled(handlerFactory.getConstraintsEnabled()); |
375 |
|
|
376 |
|
|
377 |
0 |
link.checkAccess(JetspeedActions.EDIT); |
378 |
|
|
379 |
|
|
380 |
0 |
handlerFactory.getDocumentHandler(Link.DOCUMENT_TYPE).updateDocument(link); |
381 |
|
|
382 |
|
|
383 |
0 |
if (parentFolder != null) |
384 |
|
{ |
385 |
0 |
NodeSetImpl parentAllNodes = (NodeSetImpl)parentFolder.getAllNodes(); |
386 |
0 |
if (!parentAllNodes.contains(link)) |
387 |
|
{ |
388 |
|
|
389 |
0 |
parentAllNodes.add(link); |
390 |
0 |
newLink = true; |
391 |
|
} |
392 |
0 |
else if (parentAllNodes.get(link.getPath()) != link) |
393 |
|
{ |
394 |
|
|
395 |
0 |
parentAllNodes.remove(link); |
396 |
0 |
parentAllNodes.add(link); |
397 |
|
} |
398 |
|
} |
399 |
|
|
400 |
|
|
401 |
0 |
if (newLink) |
402 |
|
{ |
403 |
0 |
notifyNewNode(link); |
404 |
|
} |
405 |
|
else |
406 |
|
{ |
407 |
0 |
notifyUpdatedNode(link); |
408 |
|
} |
409 |
|
} |
410 |
0 |
catch (FolderNotFoundException fnfe) |
411 |
|
{ |
412 |
0 |
throw new NodeException(fnfe.getMessage()); |
413 |
0 |
} |
414 |
0 |
} |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
public void removeLink(Link link) throws NodeException |
424 |
|
{ |
425 |
|
|
426 |
0 |
link.checkAccess(JetspeedActions.EDIT); |
427 |
|
|
428 |
|
try |
429 |
|
{ |
430 |
0 |
FolderImpl folder = getNodeFolder(link.getPath()); |
431 |
|
|
432 |
|
|
433 |
0 |
handlerFactory.getDocumentHandler(Link.DOCUMENT_TYPE).removeDocument(link); |
434 |
|
|
435 |
|
|
436 |
0 |
((NodeSetImpl)folder.getAllNodes()).remove(link); |
437 |
|
|
438 |
|
|
439 |
0 |
notifyRemovedNode(link); |
440 |
|
} |
441 |
0 |
catch (FolderNotFoundException fnfe) |
442 |
|
{ |
443 |
0 |
throw new NodeException(fnfe.getMessage()); |
444 |
|
} |
445 |
0 |
catch (DocumentNotFoundException dnfe) |
446 |
|
{ |
447 |
0 |
throw new NodeException(dnfe.getMessage()); |
448 |
0 |
} |
449 |
0 |
} |
450 |
|
|
451 |
|
public boolean checkConstraint(String securityConstraintName, String actions) |
452 |
|
{ |
453 |
|
try |
454 |
|
{ |
455 |
0 |
PageSecurity security = this.getPageSecurity(); |
456 |
0 |
SecurityConstraintsDef def = security.getSecurityConstraintsDef(securityConstraintName); |
457 |
0 |
if (def != null) |
458 |
|
{ |
459 |
0 |
return PageManagerSecurityUtils.checkConstraint(def, actions); |
460 |
|
} |
461 |
|
} |
462 |
0 |
catch (Exception e) |
463 |
|
{ |
464 |
0 |
log.error(e.getMessage(), e); |
465 |
0 |
} |
466 |
0 |
return false; |
467 |
|
} |
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
|
476 |
|
|
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
public PageSecurity getPageSecurity() throws DocumentNotFoundException, UnsupportedDocumentTypeException, NodeException |
481 |
|
{ |
482 |
|
|
483 |
|
try |
484 |
|
{ |
485 |
0 |
FolderImpl folder = getNodeFolder(Folder.PATH_SEPARATOR); |
486 |
0 |
return folder.getPageSecurity(); |
487 |
|
} |
488 |
0 |
catch (FolderNotFoundException fnfe) |
489 |
|
{ |
490 |
0 |
throw new DocumentNotFoundException(fnfe.getMessage()); |
491 |
|
} |
492 |
|
} |
493 |
|
|
494 |
|
|
495 |
|
|
496 |
|
|
497 |
|
public void updatePageSecurity(PageSecurity pageSecurity) throws NodeException, FailedToUpdateDocumentException |
498 |
|
{ |
499 |
|
|
500 |
|
|
501 |
0 |
if (pageSecurity.getPath() != null) |
502 |
|
{ |
503 |
0 |
if (!pageSecurity.getPath().equals(Folder.PATH_SEPARATOR + PageSecurity.DOCUMENT_TYPE)) |
504 |
|
{ |
505 |
0 |
log.error("PageSecurity path must be: " + Folder.PATH_SEPARATOR + PageSecurity.DOCUMENT_TYPE); |
506 |
0 |
return; |
507 |
|
} |
508 |
0 |
if (!pageSecurity.getPath().equals(pageSecurity.getId())) |
509 |
|
{ |
510 |
0 |
log.error("PageSecurity paths and ids must match!"); |
511 |
0 |
return; |
512 |
|
} |
513 |
|
} |
514 |
|
else |
515 |
|
{ |
516 |
0 |
log.error("PageSecurity paths and ids must be set!"); |
517 |
0 |
return; |
518 |
|
} |
519 |
|
|
520 |
|
try |
521 |
|
{ |
522 |
|
|
523 |
0 |
boolean newPageSecurity = false; |
524 |
0 |
FolderImpl parentFolder = getNodeFolder(Folder.PATH_SEPARATOR); |
525 |
0 |
if (pageSecurity.getParent() == null) |
526 |
|
{ |
527 |
0 |
pageSecurity.setParent(parentFolder); |
528 |
0 |
newPageSecurity = true; |
529 |
|
} |
530 |
|
|
531 |
|
|
532 |
0 |
PageSecurityImpl pageSecurityImpl = (PageSecurityImpl)pageSecurity; |
533 |
0 |
pageSecurityImpl.setPermissionsEnabled(handlerFactory.getPermissionsEnabled()); |
534 |
0 |
pageSecurityImpl.setConstraintsEnabled(handlerFactory.getConstraintsEnabled()); |
535 |
|
|
536 |
|
|
537 |
0 |
pageSecurity.checkAccess(JetspeedActions.EDIT); |
538 |
|
|
539 |
|
|
540 |
0 |
handlerFactory.getDocumentHandler(PageSecurity.DOCUMENT_TYPE).updateDocument(pageSecurity); |
541 |
|
|
542 |
|
|
543 |
0 |
if (parentFolder != null) |
544 |
|
{ |
545 |
0 |
NodeSetImpl parentAllNodes = (NodeSetImpl)parentFolder.getAllNodes(); |
546 |
0 |
if (!parentAllNodes.contains(pageSecurity)) |
547 |
|
{ |
548 |
|
|
549 |
0 |
parentAllNodes.add(pageSecurity); |
550 |
0 |
newPageSecurity = true; |
551 |
|
} |
552 |
0 |
else if (parentAllNodes.get(pageSecurity.getPath()) != pageSecurity) |
553 |
|
{ |
554 |
|
|
555 |
0 |
parentAllNodes.remove(pageSecurity); |
556 |
0 |
parentAllNodes.add(pageSecurity); |
557 |
|
} |
558 |
|
} |
559 |
|
|
560 |
|
|
561 |
0 |
if (newPageSecurity) |
562 |
|
{ |
563 |
0 |
notifyNewNode(pageSecurity); |
564 |
|
} |
565 |
|
else |
566 |
|
{ |
567 |
0 |
notifyUpdatedNode(pageSecurity); |
568 |
|
} |
569 |
|
} |
570 |
0 |
catch (FolderNotFoundException fnfe) |
571 |
|
{ |
572 |
0 |
throw new NodeException(fnfe.getMessage()); |
573 |
0 |
} |
574 |
0 |
} |
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
public void removePageSecurity(PageSecurity pageSecurity) throws NodeException, FailedToDeleteDocumentException |
580 |
|
{ |
581 |
|
|
582 |
0 |
pageSecurity.checkAccess(JetspeedActions.EDIT); |
583 |
|
|
584 |
|
try |
585 |
|
{ |
586 |
0 |
FolderImpl folder = getNodeFolder(Folder.PATH_SEPARATOR); |
587 |
|
|
588 |
|
|
589 |
0 |
handlerFactory.getDocumentHandler(PageSecurity.DOCUMENT_TYPE).removeDocument(pageSecurity); |
590 |
|
|
591 |
|
|
592 |
0 |
((NodeSetImpl)folder.getAllNodes()).remove(pageSecurity); |
593 |
|
|
594 |
|
|
595 |
0 |
notifyRemovedNode(pageSecurity); |
596 |
|
} |
597 |
0 |
catch (FolderNotFoundException fnfe) |
598 |
|
{ |
599 |
0 |
throw new NodeException(fnfe.getMessage()); |
600 |
|
} |
601 |
0 |
catch (DocumentNotFoundException dnfe) |
602 |
|
{ |
603 |
0 |
throw new NodeException(dnfe.getMessage()); |
604 |
0 |
} |
605 |
0 |
} |
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
public Folder getFolder(String folderPath) throws FolderNotFoundException, InvalidFolderException, NodeException |
620 |
|
{ |
621 |
|
|
622 |
0 |
Folder folder = folderHandler.getFolder(folderPath); |
623 |
0 |
folder.checkAccess(JetspeedActions.VIEW); |
624 |
0 |
return folder; |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
public NodeSet getFolders(Folder folder) throws DocumentException |
631 |
|
{ |
632 |
|
|
633 |
0 |
return folder.getFolders(); |
634 |
|
} |
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
|
639 |
|
public Folder getFolder(Folder folder, String name) throws FolderNotFoundException, DocumentException |
640 |
|
{ |
641 |
|
|
642 |
0 |
return folder.getFolder(name); |
643 |
|
} |
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
public NodeSet getPages(Folder folder) throws NodeException |
649 |
|
{ |
650 |
|
|
651 |
0 |
return folder.getPages(); |
652 |
|
} |
653 |
|
|
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
public Page getPage(Folder folder, String name) throws PageNotFoundException, NodeException |
658 |
|
{ |
659 |
|
|
660 |
0 |
return folder.getPage(name); |
661 |
|
} |
662 |
|
|
663 |
|
|
664 |
|
|
665 |
|
|
666 |
|
public NodeSet getLinks(Folder folder) throws NodeException |
667 |
|
{ |
668 |
|
|
669 |
0 |
return folder.getLinks(); |
670 |
|
} |
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
|
public Link getLink(Folder folder, String name) throws DocumentNotFoundException, NodeException |
676 |
|
{ |
677 |
|
|
678 |
0 |
return folder.getLink(name); |
679 |
|
} |
680 |
|
|
681 |
|
|
682 |
|
|
683 |
|
|
684 |
|
public PageSecurity getPageSecurity(Folder folder) throws DocumentNotFoundException, NodeException |
685 |
|
{ |
686 |
|
|
687 |
0 |
return folder.getPageSecurity(); |
688 |
|
} |
689 |
|
|
690 |
|
|
691 |
|
|
692 |
|
|
693 |
|
public NodeSet getAll(Folder folder) throws DocumentException |
694 |
|
{ |
695 |
|
|
696 |
0 |
return folder.getAll(); |
697 |
|
} |
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
|
703 |
|
|
704 |
|
|
705 |
|
|
706 |
|
public void updateFolder(Folder folder) throws NodeException, FolderNotUpdatedException |
707 |
|
{ |
708 |
|
|
709 |
0 |
updateFolder(folder, false); |
710 |
0 |
} |
711 |
|
|
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
public void updateFolder(Folder folder, boolean deep) throws NodeException, FolderNotUpdatedException |
716 |
|
{ |
717 |
|
|
718 |
0 |
if (folder.getPath() != null) |
719 |
|
{ |
720 |
0 |
if (!folder.getPath().equals(folder.getId())) |
721 |
|
{ |
722 |
0 |
log.error("Folder paths and ids must match!"); |
723 |
0 |
return; |
724 |
|
} |
725 |
|
} |
726 |
|
else |
727 |
|
{ |
728 |
0 |
log.error("Folder paths and ids must be set!"); |
729 |
0 |
return; |
730 |
|
} |
731 |
|
|
732 |
|
try |
733 |
|
{ |
734 |
|
|
735 |
0 |
boolean newFolder = false; |
736 |
0 |
FolderImpl parentFolder = null; |
737 |
0 |
if (!folder.getPath().equals(Folder.PATH_SEPARATOR)) |
738 |
|
{ |
739 |
0 |
parentFolder = getNodeFolder(folder.getPath()); |
740 |
0 |
if (folder.getParent() == null) |
741 |
|
{ |
742 |
0 |
folder.setParent(parentFolder); |
743 |
0 |
newFolder = true; |
744 |
|
} |
745 |
|
} |
746 |
|
else |
747 |
|
{ |
748 |
0 |
folder.setParent(null); |
749 |
|
} |
750 |
|
|
751 |
|
|
752 |
|
|
753 |
0 |
FolderImpl folderImpl = (FolderImpl)folder; |
754 |
0 |
folderImpl.setPermissionsEnabled(handlerFactory.getPermissionsEnabled()); |
755 |
0 |
folderImpl.setConstraintsEnabled(handlerFactory.getConstraintsEnabled()); |
756 |
0 |
folderImpl.setFolderHandler(folderHandler); |
757 |
|
|
758 |
|
|
759 |
0 |
folder.checkAccess(JetspeedActions.EDIT); |
760 |
|
|
761 |
|
|
762 |
0 |
folderHandler.updateFolder(folder); |
763 |
|
|
764 |
|
|
765 |
0 |
if (parentFolder != null) |
766 |
|
{ |
767 |
0 |
NodeSetImpl parentAllNodes = (NodeSetImpl)parentFolder.getAllNodes(); |
768 |
0 |
if (!parentAllNodes.contains(folder)) |
769 |
|
{ |
770 |
|
|
771 |
0 |
parentAllNodes.add(folder); |
772 |
0 |
newFolder = true; |
773 |
|
} |
774 |
0 |
else if (parentAllNodes.get(folder.getPath()) != folder) |
775 |
|
{ |
776 |
|
|
777 |
0 |
parentAllNodes.remove(folder); |
778 |
0 |
parentAllNodes.add(folder); |
779 |
|
} |
780 |
|
} |
781 |
|
|
782 |
|
|
783 |
0 |
if (deep) |
784 |
|
{ |
785 |
|
|
786 |
0 |
updateFolderNodes(folderImpl); |
787 |
|
} |
788 |
|
|
789 |
|
|
790 |
0 |
if (newFolder) |
791 |
|
{ |
792 |
0 |
notifyNewNode(folder); |
793 |
|
} |
794 |
|
else |
795 |
|
{ |
796 |
0 |
notifyUpdatedNode(folder); |
797 |
|
} |
798 |
|
} |
799 |
0 |
catch (FolderNotFoundException fnfe) |
800 |
|
{ |
801 |
0 |
throw new NodeException(fnfe.getMessage()); |
802 |
0 |
} |
803 |
0 |
} |
804 |
|
|
805 |
|
|
806 |
|
|
807 |
|
|
808 |
|
|
809 |
|
|
810 |
|
|
811 |
|
private void updateFolderNodes(FolderImpl folderImpl) throws FolderNotUpdatedException |
812 |
|
{ |
813 |
|
try |
814 |
|
{ |
815 |
|
|
816 |
0 |
NodeSet nodes = folderImpl.getAllNodes(); |
817 |
0 |
Iterator nodesIter = nodes.iterator(); |
818 |
0 |
while (nodesIter.hasNext()) |
819 |
|
{ |
820 |
0 |
Node node = (Node) nodesIter.next(); |
821 |
0 |
if (node instanceof Page) |
822 |
|
{ |
823 |
0 |
updatePage((Page)node); |
824 |
|
} |
825 |
0 |
else if (node instanceof Link) |
826 |
|
{ |
827 |
0 |
updateLink((Link)node); |
828 |
|
} |
829 |
0 |
else if (node instanceof PageSecurity) |
830 |
|
{ |
831 |
0 |
updatePageSecurity((PageSecurity)node); |
832 |
|
} |
833 |
0 |
} |
834 |
|
|
835 |
|
|
836 |
0 |
nodesIter = nodes.iterator(); |
837 |
0 |
while (nodesIter.hasNext()) |
838 |
|
{ |
839 |
0 |
Node node = (Node) nodesIter.next(); |
840 |
0 |
if (node instanceof Folder) |
841 |
|
{ |
842 |
0 |
updateFolder((Folder)node, true); |
843 |
|
} |
844 |
0 |
} |
845 |
|
} |
846 |
0 |
catch (FolderNotUpdatedException fnue) |
847 |
|
{ |
848 |
0 |
throw fnue; |
849 |
|
} |
850 |
0 |
catch (SecurityException se) |
851 |
|
{ |
852 |
0 |
throw se; |
853 |
|
} |
854 |
0 |
catch (Exception e) |
855 |
|
{ |
856 |
0 |
throw new FolderNotUpdatedException("Folder " + folderImpl.getPath() + " not updated.", e); |
857 |
0 |
} |
858 |
0 |
} |
859 |
|
|
860 |
|
|
861 |
|
|
862 |
|
|
863 |
|
|
864 |
|
|
865 |
|
|
866 |
|
|
867 |
|
public void removeFolder(Folder folder) throws NodeException |
868 |
|
{ |
869 |
|
|
870 |
0 |
folder.checkAccess(JetspeedActions.EDIT); |
871 |
|
|
872 |
|
try |
873 |
|
{ |
874 |
0 |
FolderImpl parentFolder = null; |
875 |
0 |
if (!folder.getPath().equals(Folder.PATH_SEPARATOR)) |
876 |
|
{ |
877 |
0 |
parentFolder = getNodeFolder(folder.getPath()); |
878 |
|
} |
879 |
|
|
880 |
|
|
881 |
0 |
folderHandler.removeFolder(folder); |
882 |
|
|
883 |
|
|
884 |
0 |
if (parentFolder != null) |
885 |
|
{ |
886 |
0 |
((NodeSetImpl)parentFolder.getAllNodes()).remove(folder); |
887 |
|
} |
888 |
|
|
889 |
|
|
890 |
0 |
notifyRemovedNode(folder); |
891 |
|
} |
892 |
0 |
catch (FolderNotFoundException fnfe) |
893 |
|
{ |
894 |
0 |
throw new NodeException(fnfe.getMessage()); |
895 |
0 |
} |
896 |
0 |
} |
897 |
|
|
898 |
|
|
899 |
|
|
900 |
|
|
901 |
|
public void reset() |
902 |
|
{ |
903 |
|
|
904 |
0 |
super.reset(); |
905 |
|
|
906 |
|
|
907 |
|
|
908 |
0 |
fileCache.evictAll(); |
909 |
0 |
} |
910 |
|
|
911 |
|
|
912 |
|
|
913 |
|
|
914 |
|
|
915 |
|
|
916 |
|
|
917 |
|
|
918 |
|
|
919 |
|
|
920 |
|
|
921 |
|
|
922 |
|
private FolderImpl getNodeFolder(String nodePath) throws NodeException, InvalidFolderException, FolderNotFoundException |
923 |
|
{ |
924 |
0 |
int folderIndex = nodePath.lastIndexOf(Folder.PATH_SEPARATOR); |
925 |
0 |
if (folderIndex > 0) |
926 |
|
{ |
927 |
0 |
return (FolderImpl) folderHandler.getFolder(nodePath.substring(0, folderIndex)); |
928 |
|
} |
929 |
0 |
return (FolderImpl) folderHandler.getFolder(Folder.PATH_SEPARATOR); |
930 |
|
} |
931 |
|
|
932 |
|
|
933 |
|
|
934 |
|
|
935 |
|
|
936 |
|
|
937 |
|
|
938 |
|
|
939 |
|
|
940 |
|
private String getNodeName(String nodePath) |
941 |
|
{ |
942 |
0 |
int folderIndex = nodePath.lastIndexOf(Folder.PATH_SEPARATOR); |
943 |
0 |
if (folderIndex > -1) |
944 |
|
{ |
945 |
0 |
return nodePath.substring(folderIndex+1); |
946 |
|
} |
947 |
0 |
return nodePath; |
948 |
|
} |
949 |
|
|
950 |
|
|
951 |
|
|
952 |
|
|
953 |
|
|
954 |
|
|
955 |
|
|
956 |
|
|
957 |
|
|
958 |
|
|
959 |
|
public void refresh( FileCacheEntry entry ) throws Exception |
960 |
|
{ |
961 |
|
|
962 |
|
|
963 |
0 |
Node refreshedNode = null; |
964 |
0 |
if (entry.getDocument() instanceof Node) |
965 |
|
{ |
966 |
0 |
refreshedNode = (Node)entry.getDocument(); |
967 |
|
} |
968 |
0 |
if (entry.getFile().exists()) |
969 |
|
{ |
970 |
0 |
notifyUpdatedNode(refreshedNode); |
971 |
|
} |
972 |
|
else |
973 |
|
{ |
974 |
0 |
notifyRemovedNode(refreshedNode); |
975 |
|
} |
976 |
0 |
} |
977 |
|
|
978 |
|
|
979 |
|
|
980 |
|
|
981 |
|
|
982 |
|
|
983 |
|
|
984 |
|
|
985 |
|
|
986 |
|
|
987 |
|
public void evict( FileCacheEntry entry ) throws Exception |
988 |
|
{ |
989 |
|
|
990 |
|
|
991 |
|
|
992 |
|
|
993 |
|
|
994 |
0 |
} |
995 |
|
|
996 |
|
|
997 |
|
|
998 |
|
|
999 |
|
public ContentPage getContentPage(String path) throws PageNotFoundException, NodeException |
1000 |
|
{ |
1001 |
0 |
return new ContentPageImpl(getPage(path)); |
1002 |
|
} |
1003 |
|
|
1004 |
|
public Page copy(Page source) |
1005 |
|
{ |
1006 |
0 |
return null; |
1007 |
|
} |
1008 |
|
|
1009 |
|
public int addPages(Page[] pages) |
1010 |
|
throws NodeException |
1011 |
|
{ |
1012 |
0 |
this.updatePage(pages[0]); |
1013 |
0 |
this.updatePage(pages[1]); |
1014 |
0 |
throw new NodeException("Its gonna blow captain!"); |
1015 |
|
} |
1016 |
|
|
1017 |
|
} |