KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > vfs > store > apps > ApplicationStore


1 package com.sslexplorer.vfs.store.apps;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.ArrayList JavaDoc;
6 import java.util.Collection JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.apache.commons.vfs.FileObject;
13
14 import com.sslexplorer.extensions.ExtensionBundle;
15 import com.sslexplorer.extensions.store.ExtensionStore;
16 import com.sslexplorer.policyframework.LaunchSession;
17 import com.sslexplorer.security.PasswordCredentials;
18 import com.sslexplorer.vfs.AbstractStore;
19 import com.sslexplorer.vfs.AbstractVFSMount;
20 import com.sslexplorer.vfs.FileObjectVFSResource;
21 import com.sslexplorer.vfs.VFSMount;
22 import com.sslexplorer.vfs.VFSResource;
23 import com.sslexplorer.vfs.utils.URI;
24 import com.sslexplorer.vfs.utils.URI.MalformedURIException;
25 import com.sslexplorer.vfs.webdav.DAVUtilities;
26
27 /**
28  * {@link AbstractStore} implementation that creates mounts based on the
29  * applications available in the <i>Extension Store</i>.
30  * <p>
31  * This is used by HTML applications and the Agent (for Java application) to
32  * download files required.
33  * <p>
34  * It hides folders called <i>private</i> or <i>upgrade</i>.
35  *
36  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
37  */

38 public class ApplicationStore extends AbstractStore {
39     
40     final static Log log = LogFactory.getLog(ApplicationStore.class);
41
42     /**
43      * Constructor.
44      */

45     public ApplicationStore() {
46         super("apps", "UTF-8");
47     }
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see com.sslexplorer.vfs.webdav.AbstractStore#getMountFromString(java.lang.String,
53      * com.sslexplorer.security.SessionInfo)
54      */

55     public VFSMount getMountFromString(String JavaDoc mountName, LaunchSession launchSession) {
56         try {
57             if (ExtensionStore.getInstance().getExtensionBundle(mountName) != null) {
58                 return new ApplicationStoreMount(launchSession, ExtensionStore.getInstance().getExtensionBundle(mountName));
59             } else
60                 return null;
61         } catch (Exception JavaDoc e) {
62             log.error("Failed to create application store mount.", e);
63             return null;
64         }
65
66     }
67
68     public Collection JavaDoc<String JavaDoc> getMountNames() throws Exception JavaDoc {
69         Iterator JavaDoc itr = ExtensionStore.getInstance().getExtensionBundles().iterator();
70         List JavaDoc<String JavaDoc> l = new ArrayList JavaDoc<String JavaDoc>();
71         while (itr.hasNext()) {
72             ExtensionBundle b = (ExtensionBundle) itr.next();
73             l.add(b.getId());
74         }
75         return l;
76     }
77
78     /*
79      * (non-Javadoc)
80      *
81      * @see com.sslexplorer.vfs.webdav.DAVStore#validateUserEnteredPath(java.lang.String)
82      */

83     public String JavaDoc createURIFromPath(String JavaDoc path) throws IllegalArgumentException JavaDoc {
84         throw new IllegalArgumentException JavaDoc();
85     }
86
87     class ApplicationStoreMount extends AbstractVFSMount {
88
89         private ExtensionBundle bundle;
90
91         ApplicationStoreMount(LaunchSession launchSession, ExtensionBundle bundle) throws MalformedURIException {
92             super(launchSession, ApplicationStore.this, bundle.getId(), true);
93             this.bundle = bundle;
94         }
95
96         public VFSResource getResource(String JavaDoc path, PasswordCredentials requestCredentials)
97                         throws IOException JavaDoc {
98             if (path.equalsIgnoreCase("private") || path.equalsIgnoreCase("upgrade")) {
99                 throw new IOException JavaDoc("Permission denied.");
100             }
101             VFSResource parent = null;
102             if (path.equals("")) {
103                 parent = getStore().getStoreResource();
104             }
105             return new FileObjectVFSResource(getLaunchSession(), this,
106                             parent,
107                             path,
108                             getStore().getRepository(),
109                             requestCredentials);
110         }
111
112         /*
113          * (non-Javadoc)
114          *
115          * @see com.sslexplorer.vfs.AbstractVFSMount#getRootVFSURI(java.lang.String)
116          */

117         public URI getRootVFSURI(String JavaDoc charset) throws MalformedURIException {
118             File JavaDoc baseDir = bundle.getBaseDir();
119             if("true".equals(System.getProperty("sslexplorer.useDevConfig"))) {
120                 String JavaDoc basedir = ".." + File.separator + bundle.getId() + File.separator + "build" + File.separator + "extension";
121                 File JavaDoc f = new File JavaDoc(basedir);
122                 if(f.exists()) {
123                     baseDir = f;
124                 }
125             }
126             return new URI(baseDir.toURI().toString());
127         }
128
129         protected FileObject createVFSFileObject(String JavaDoc path, PasswordCredentials credentials) throws IOException JavaDoc {
130             URI uri = getRootVFSURI();
131             uri.setPath(DAVUtilities.concatenatePaths(uri.getPath(), path));
132             FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString());
133             return root;
134         }
135     }
136 }
137
Popular Tags