KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cofax > util > LifeCycleUpdater


1 /*
2  * LifeCycleUpdater is part of the Cofax content management sytem library.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Please see http://www.cofax.org for contact information and other
19  * related informaion.
20  *
21  * $Header: /cvsroot/cofax/cofax/src/org/cofax/util/LifeCycleUpdater.java,v 1.2.2.1 2006/12/11 16:30:01 fxrobin Exp $
22  */

23
24 package org.cofax.util;
25
26 import java.util.*;
27
28 import org.cofax.*;
29 import org.cofax.cms.*;
30
31 /**
32  * A batch to disable articles that are out of their life cycle
33  *
34  * @author Badr Chentouf
35  *
36  * @version 1.0
37  *
38  */

39
40 public class LifeCycleUpdater {
41
42     public static void main(String JavaDoc args[]) {
43
44         // Print out a worthless version number
45
System.out.println("Cofax v1.0 - Update life cycles");
46
47         // Get the shared config file to run from
48
String JavaDoc configLocation = args[0];
49         XMLConfig configFile = new XMLConfig();
50         configFile.setXMLFileName(configLocation);
51         if (!configFile.load()) {
52             System.err.println(configFile.getLastError());
53         }
54         // Load variables from configFile
55
String JavaDoc dataStoreName = configFile.getString("dataStoreName");
56         String JavaDoc dataStore = configFile.getString("dataStoreClass");
57         String JavaDoc databaseIdentifier = configFile.getString("databaseIdentifier");
58         Properties dbProps = new Properties();
59
60         dbProps.setProperty("drivers", configFile.getString("dataStoreDriver"));
61         dbProps.setProperty("logfile", configFile.getString("dataStoreLogFile"));
62         dbProps.setProperty(dataStoreName + ".url", configFile.getString("dataStoreUrl"));
63         dbProps.setProperty(dataStoreName + ".user", configFile.getString("dataStoreUser"));
64         dbProps.setProperty(dataStoreName + ".password", configFile.getString("dataStorePassword"));
65         dbProps.setProperty(dataStoreName + ".initconns", configFile.getString("dataStoreInitconns"));
66         dbProps.setProperty(dataStoreName + ".maxconns", configFile.getString("dataStoreMaxconns"));
67         dbProps.setProperty(dataStoreName + ".connusagelimit", configFile.getString("dataStoreConnusagelimit"));
68         dbProps.setProperty(dataStoreName + ".testquery", configFile.getString("dataStoreTestquery"));
69         dbProps.setProperty(dataStoreName + ".loglevel", configFile.getString("dataStoreLoglevel"));
70
71         // create and initialize cofax database class
72
System.out.print("Connecting to SQL database...\n");
73         DataStore db = null;
74         try {
75             System.out.print("DataStore = " + (Class.forName(dataStore)));
76             db = (DataStore) (Class.forName(dataStore)).newInstance();
77             db.init(dbProps);
78             db.setDataStoreName(dataStoreName);
79         } catch (ClassNotFoundException JavaDoc e) {
80             System.out.println("ERROR: Data store class not found.: " + e);
81             return;
82         } catch (InstantiationException JavaDoc e) {
83             System.out.println("ERROR loading data store class.: " + e);
84             return;
85         } catch (IllegalAccessException JavaDoc e) {
86             System.out.println("Error loading data store class.: " + e);
87             return;
88         }
89         System.out.print("Connected\n");
90
91         if (db.connect()) {
92             try {
93                 CofaxToolsLifeCycle htCycle = new CofaxToolsLifeCycle();
94                 boolean success = htCycle.updateAllPublications(db);
95                 System.out.print("Done\n");
96             } catch (Exception JavaDoc e) {
97                 System.out.print("updateLifeCycles : Exception : " + e);
98             } finally {
99                 db.disConnect();
100             }
101         } else {
102             System.out.println("\nERROR: Could not get a connection." + db.getLastError());
103         }
104     }
105 }
106
Popular Tags