KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > networkplaces > store > cifs > CIFSStore


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.networkplaces.store.cifs;
21
22 import jcifs.Config;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import com.sslexplorer.networkplaces.AbstractNetworkPlaceMount;
28 import com.sslexplorer.networkplaces.AbstractNetworkPlaceStore;
29 import com.sslexplorer.policyframework.LaunchSession;
30 import com.sslexplorer.properties.Property;
31 import com.sslexplorer.properties.impl.systemconfig.SystemConfigKey;
32 import com.sslexplorer.vfs.utils.URI;
33 import com.sslexplorer.vfs.utils.URI.MalformedURIException;
34 import com.sslexplorer.vfs.webdav.DAVUtilities;
35
36 /**
37  * CIFS implementation of a {@link AbstractNetworkPlaceStore},handles URIs with
38  * schemes of <i>smb</i> or <i>cifs</i>.
39  *
40  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
41  */

42 public class CIFSStore extends AbstractNetworkPlaceStore {
43     final static Log log = LogFactory.getLog(CIFSStore.class);
44     /**
45      * CIFS scheme name
46      */

47     public final static String JavaDoc CIFS_SCHEME = "cifs";
48     /**
49      * SMB scheme name
50      */

51     public final static String JavaDoc SMB_SCHEME = "smb";
52
53     /**
54      * Constructor.
55      */

56     public CIFSStore() {
57         super("cifs", System.getProperty("jcifs.encoding", "cp860"));
58         try {
59             setIfNotEmpty("jcifs.netbios.wins");
60             setIfNotEmpty("jcifs.netbios.baddr");
61             setIfNotEmpty("jcifs.netbios.scope");
62             setIfNotEmpty("jcifs.smb.client.laddr");
63             setIfNotEmpty("jcifs.netbios.laddr");
64             setIfNotEmpty("jcifs.netbios.lmhosts");
65             setIfNotEmpty("jcifs.smb.client.disablePlainTextPasswords");
66             setIfNotEmpty("jcifs.netbios.hostname");
67             setIfNotEmpty("jcifs.netbios.soTimeout");
68             setIfNotEmpty("jcifs.netbios.retryCount");
69             setIfNotEmpty("jcifs.netbios.retryTimeout");
70             setIfNotEmpty("jcifs.resolveOrder");
71             setIfNotEmpty("jcifs.smb.client.responseTimeout");
72             setIfNotEmpty("jcifs.smb.client.soTimeout");
73
74             String JavaDoc guestUser = Property.getProperty(new SystemConfigKey("cifs.guestUser")).replace('\\', ';').replace('/', ';');
75             String JavaDoc guestPassword = Property.getProperty(new SystemConfigKey("cifs.guestPassword"));
76             if(!guestUser.equals("")) {
77                 Config.setProperty("cifs.guestUser", guestUser);
78             }
79             if(!guestPassword.equals("")) {
80                 Config.setProperty("cifs.guestUser", guestPassword);
81             }
82         } catch (Exception JavaDoc e) {
83             log.error("Failed to configure JCIFS. CIFS browsing may not act as expected.", e);
84         }
85     }
86
87     /**
88      * @param name
89      */

90     static void setIfNotEmpty(String JavaDoc name) {
91         String JavaDoc val =Property.getProperty(new SystemConfigKey(name)).trim();
92         if (!val.equals("")) {
93             Config.setProperty(name, val);
94         }
95
96     }
97
98     /* (non-Javadoc)
99      * @see com.sslexplorer.vfs.AbstractNetworkPlaceStore#createMount(com.sslexplorer.policyframework.LaunchSession)
100      */

101     protected AbstractNetworkPlaceMount createMount(LaunchSession launchSession) throws Exception JavaDoc {
102         return new CIFSMount(launchSession, this);
103     }
104     
105     /* (non-Javadoc)
106      * @see com.sslexplorer.vfs.webdav.AbstractNetworkPlaceStore#getGuestUsername(com.sslexplorer.vfs.webdav.DAVTransaction)
107      */

108     public String JavaDoc getGuestUsername() {
109         return Property.getProperty(new SystemConfigKey("cifs.guestUser"));
110     }
111     
112     /* (non-Javadoc)
113      * @see com.sslexplorer.vfs.webdav.AbstractNetworkPlaceStore#getGuestPassword(com.sslexplorer.vfs.webdav.DAVTransaction)
114      */

115     public char[] getGuestPassword() {
116         return Property.getProperty(new SystemConfigKey("cifs.guestPassword")).toCharArray();
117     }
118 }
Popular Tags