KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > store > site > SiteStore


1 package com.sslexplorer.vfs.store.site;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.Arrays JavaDoc;
6 import java.util.Collection JavaDoc;
7
8 import org.apache.commons.vfs.FileObject;
9
10 import com.sslexplorer.boot.ContextHolder;
11 import com.sslexplorer.extensions.ExtensionBundle;
12 import com.sslexplorer.policyframework.LaunchSession;
13 import com.sslexplorer.security.PasswordCredentials;
14 import com.sslexplorer.vfs.AbstractStore;
15 import com.sslexplorer.vfs.AbstractVFSMount;
16 import com.sslexplorer.vfs.FileObjectVFSResource;
17 import com.sslexplorer.vfs.VFSMount;
18 import com.sslexplorer.vfs.VFSResource;
19 import com.sslexplorer.vfs.utils.URI;
20 import com.sslexplorer.vfs.utils.URI.MalformedURIException;
21 import com.sslexplorer.vfs.webdav.DAVUtilities;
22
23 /**
24  * Store for site specific resources such as custom icons.
25  *
26  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
27  */

28 public class SiteStore extends AbstractStore {
29     
30     private File JavaDoc siteDir;
31
32     /**
33      * Constructor.
34      */

35     public SiteStore() {
36         super("site", "UTF-8");
37         siteDir = new File JavaDoc(ContextHolder.getContext().getConfDirectory(), "site");
38         if(!siteDir.exists()) {
39             siteDir.mkdirs();
40         }
41     }
42
43     /*
44      * (non-Javadoc)
45      *
46      * @see com.sslexplorer.vfs.webdav.AbstractStore#getMountFromString(java.lang.String,
47      * com.sslexplorer.security.SessionInfo)
48      */

49     public VFSMount getMountFromString(String JavaDoc mountName, LaunchSession launchSession) {
50         if(mountName.equals("icons")) {
51             return new SiteIconsMount();
52         }
53         return null;
54     }
55
56     /* (non-Javadoc)
57      * @see com.sslexplorer.vfs.VFSStore#getMountNames()
58      */

59     public Collection JavaDoc<String JavaDoc> getMountNames() throws Exception JavaDoc {
60         return Arrays.asList(new String JavaDoc[] { "icons" });
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see com.sslexplorer.vfs.webdav.DAVStore#validateUserEnteredPath(java.lang.String)
67      */

68     public String JavaDoc createURIFromPath(String JavaDoc path) throws IllegalArgumentException JavaDoc {
69         throw new IllegalArgumentException JavaDoc();
70     }
71
72     class SiteIconsMount extends AbstractVFSMount {
73
74         private ExtensionBundle bundle;
75
76         SiteIconsMount() {
77             super(null, SiteStore.this, "icons", false);
78         }
79
80         public VFSResource getResource(String JavaDoc path, PasswordCredentials requestCredentials)
81                         throws IOException JavaDoc {
82             VFSResource parent = null;
83             if (path.equals("")) {
84                 parent = getStore().getStoreResource();
85             }
86             return new FileObjectVFSResource(getLaunchSession(), this,
87                             parent,
88                             path,
89                             getStore().getRepository(),
90                             requestCredentials);
91         }
92
93         /*
94          * (non-Javadoc)
95          *
96          * @see com.sslexplorer.vfs.AbstractVFSMount#getRootVFSURI(java.lang.String)
97          */

98         public URI getRootVFSURI(String JavaDoc charset) throws MalformedURIException {
99             File JavaDoc baseDir = new File JavaDoc(siteDir, "icons");
100             if(!baseDir.exists()) {
101                 baseDir.mkdirs();
102             }
103             return new URI(baseDir.toURI().toString());
104         }
105
106         protected FileObject createVFSFileObject(String JavaDoc path, PasswordCredentials credentials) throws IOException JavaDoc {
107             URI uri = getRootVFSURI();
108             uri.setPath(DAVUtilities.concatenatePaths(uri.getPath(), path));
109             FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString());
110             return root;
111         }
112     }
113 }
114
Popular Tags