KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > networkplaces > NetworkPlaceInstall


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;
21
22 import java.io.File JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import com.sslexplorer.boot.ContextHolder;
29 import com.sslexplorer.extensions.ExtensionInstaller;
30 import com.sslexplorer.extensions.ExtensionInstaller.ExtensionInstallOp;
31
32
33 /**
34  * Installer operation to convert and sanity check network place paths.
35  *
36  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
37  */

38 public class NetworkPlaceInstall implements ExtensionInstallOp {
39     
40     final static Log log = LogFactory.getLog(NetworkPlaceInstall.class);
41     final static String JavaDoc VARIABLE_PATTERN = "\\$\\{[^}]*\\}";
42     final static String JavaDoc PROTOTYPE_PATTERN = "_prototype_[^_]*_[^_]*_";
43
44     /* (non-Javadoc)
45      * @see com.sslexplorer.extensions.ExtensionInstaller.ExtensionInstallOp#doOp(com.sslexplorer.extensions.ExtensionInstaller)
46      */

47     public void doOp(ExtensionInstaller install) throws Exception JavaDoc {
48         NetworkPlaceDatabase npd = NetworkPlaceDatabaseFactory.getInstance();
49         List JavaDoc<NetworkPlace> networkPlaces = npd.getNetworkPlaces();
50         int errs = 0;
51         File JavaDoc oldTagLib = new File JavaDoc("webapp" + File.separator + "WEB-INF" + File.separator + "vfs.tld");
52         if(oldTagLib.exists()) {
53             log.info("Deleting old tag lib " + oldTagLib.getAbsolutePath());
54             oldTagLib.delete();
55         }
56         
57         for(NetworkPlace networkPlace : networkPlaces) {
58             try {
59                 NetworkPlaceUtil.convertNetworkPlace(networkPlace);
60                 npd.updateNetworkPlace(networkPlace.getResourceId(), networkPlace.getScheme(), networkPlace.getResourceName(),
61                     networkPlace.getResourceDescription(), networkPlace.getHost(), networkPlace.getPath(), networkPlace.getPort(), networkPlace.getUsername(), networkPlace.getPassword(), networkPlace.isReadOnly(), networkPlace.isAllowRecursive(), networkPlace.isNoDelete(), networkPlace.isShowHidden());
62             }
63             catch(Exception JavaDoc e) {
64                 errs ++;
65                 log.error("Failed to convert network place '" + networkPlace.getResourceName() + "'. Please manually check and amend.");
66             }
67         }
68         if(errs > 0) {
69             throw new Exception JavaDoc("Failed to convert " + errs + " network places. Please check the log for the names of the " +
70                     "failed network places that failed and then manually amend these resources.");
71         }
72     }
73
74     /* (non-Javadoc)
75      * @see com.sslexplorer.extensions.ExtensionInstaller.ExtensionInstallOp#getPhase()
76      */

77     public String JavaDoc getPhase() {
78         return ExtensionInstaller.ON_ACTIVATE;
79     }
80
81 }
82
Popular Tags