KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > webdav > JahiaMacroListener


1 package org.jahia.services.webdav;
2
3 import org.apache.slide.event.MacroListener;
4 import org.apache.slide.event.MacroEvent;
5 import org.apache.slide.event.VetoException;
6 import org.apache.slide.content.*;
7 import org.apache.slide.structure.Structure;
8 import org.apache.slide.structure.StructureImpl;
9 import org.apache.slide.security.Security;
10 import org.apache.slide.security.ACLSecurityImpl;
11 import org.apache.slide.lock.Lock;
12 import org.apache.slide.lock.LockImpl;
13 import org.apache.log4j.Logger;
14
15 /**
16  * Created by IntelliJ IDEA.
17  * User: toto
18  * Date: 28 juin 2004
19  * Time: 16:30:34
20  * <p/>
21  * $Author: tdraier $
22  * $Date: 2005-10-03 17:19:14 +0200 (Mon, 03 Oct 2005) $
23  * $Id: JahiaMacroListener.java 10790 2005-10-03 15:19:14Z tdraier $
24  * $RCSfile$
25  * $Revision: 10790 $
26  * $Source$
27  * $State$
28  */

29 public class JahiaMacroListener implements MacroListener {
30     private static Logger logger = Logger.getLogger (JahiaMacroListener.class);
31
32     public JahiaMacroListener() {
33     }
34
35     public void copy(MacroEvent event) throws VetoException {
36         try {
37 // Content helper = getContentHelper(event);
38
// NodeRevisionDescriptors srcNrds = helper.retrieve(event.getToken(),
39
// event.getTargetURI());
40
// NodeRevisionDescriptor srcNrd = helper.retrieve(event.getToken(),
41
// srcNrds);
42
// NodeRevisionDescriptors destNrds = helper.retrieve(event.getToken(),
43
// event.getTargetURI());
44
// NodeRevisionDescriptor destNrd = helper.retrieve(event.getToken(),
45
// destNrds);
46
//
47
// String displayName = getFilename(event.getTargetURI());
48
// if (getFilename(event.getSourceURI()).equals(srcNrd.getName())) {
49
// if (!displayName.equals(destNrd.getName())) {
50
// destNrd.setName(displayName);
51
// helper.store(event.getToken(), event.getTargetURI(), destNrd, null);
52
// }
53
// }
54
} catch (Exception JavaDoc e) {
55
56         }
57     }
58
59     public void move(MacroEvent event) throws VetoException {
60         JahiaWebdavBaseService.getInstance().move( event.getSourceURI(), event.getTargetURI(), event.getNamespace().getName());
61     }
62
63     public void delete(MacroEvent event) throws VetoException {
64     }
65
66     /**
67      * Returns the last part of an URI that is normaly called the name of
68      * the collection of file.
69      * <p>I bet there is anywhere such a method but I havn't found it.
70      * @param uri
71      * @return the name of the resource given by uri
72      */

73    private static String JavaDoc getFilename(String JavaDoc uri) {
74        if (uri.indexOf('/') == -1) {
75           return uri;
76        }
77        if (uri.equals("/")) {
78           return "";
79        }
80        if (uri.endsWith("/")) {
81           return uri.substring(1+uri.lastIndexOf('/', uri.length() - 2),
82                                uri.length() - 1);
83        } else {
84           return uri.substring(1+uri.lastIndexOf('/'));
85        }
86    }
87
88     private Content getContentHelper(MacroEvent event) {
89        Security security = new ACLSecurityImpl(event.getNamespace(),
90                                                event.getNamespace().getConfig());
91        Lock lock = new LockImpl(event.getNamespace(),
92                                 event.getNamespace().getConfig(),
93                                 security);
94        Structure structure = new StructureImpl(event.getNamespace(),
95                                 event.getNamespace().getConfig(),
96                                 security,
97                                 lock);
98        Content helper = new ContentImpl(
99              event.getNamespace(),
100              event.getNamespace().getConfig(),
101              security,
102              structure,
103              lock);
104        return helper;
105     }
106
107 }
108
Popular Tags