KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > Common


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: Common.java,v 1.2 2005/03/17 05:21:43 predrag Exp $
22  */

23
24 /*
25  *
26  * @author Dragan Radeka & Nenad Vico
27  * @since LBS1.8
28  * @version $Revision: 1.2 $
29  *
30  */

31 package org.enhydra.dods;
32
33 import java.io.File JavaDoc;
34 import java.io.InputStream JavaDoc;
35 import java.net.URL JavaDoc;
36 import java.net.URLClassLoader JavaDoc;
37 import java.io.FileInputStream JavaDoc;
38 import java.io.FilenameFilter JavaDoc;
39 import java.io.IOException JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.HashSet JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.Map JavaDoc;
44 import java.util.Properties JavaDoc;
45 import java.util.Set JavaDoc;
46 import java.util.Vector JavaDoc;
47
48 import org.enhydra.dods.wizard.DirectoryNameFilter;
49 import org.enhydra.xml.XMLConfig;
50 import org.enhydra.xml.XMLDocumentFactory;
51 import com.lutris.logging.Logger;
52 import com.lutris.util.ConfigException;
53 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
54 import javax.xml.parsers.DocumentBuilder JavaDoc;
55 import org.w3c.dom.Document JavaDoc;
56 import org.w3c.dom.Element JavaDoc;
57 import org.w3c.dom.NodeList JavaDoc;
58 import org.w3c.dom.Node JavaDoc;
59
60 public class Common {
61
62     /**
63      * Database Vendor driver specific configuration parameter name.
64      * values: true/false
65      */

66     
67     static public final String JavaDoc VENDOR_ORDERED_RESULT_SET = "OrderedResultSet";
68     
69
70     /**
71      * dods configuration switch property
72      */

73     static protected boolean configured = false;
74
75     /**
76      * dods configuration switch property
77      */

78     static protected String JavaDoc configDir = null;
79
80
81     /**
82      * dods configuration path (in dods-runtime.jar file )
83      */

84     static public final String JavaDoc DODS_CONF_JAR_PATH = "org/enhydra/dods/conf";
85     
86     /**
87      * default app configuration file.
88      */

89     
90     static public final String JavaDoc DATABASE_MANAGER_CONF_FILE="dods/conf/databaseManager.conf";
91
92
93
94     /**
95      * dods configuration property
96      */

97     static protected Properties JavaDoc dods_conf;
98
99     /**
100      * last used database read from doml file
101      */

102     static protected String JavaDoc dbase;
103
104     /**
105      * dods configuration
106      */

107     static protected XMLConfig dodsConf;
108
109     /**
110      * dods vendor configuration
111      */

112     static protected HashMap JavaDoc dodsVendorConfs;
113     
114
115     /**
116      * dods driver-vendor map
117      *
118      */

119     static protected HashMap JavaDoc dodsDriversMap;
120     
121     /**
122      * dods (driver_name/vendor) map
123      *
124      */

125     static protected Vector JavaDoc dodsDriversNamesVec;
126     static protected Vector JavaDoc dodsVendorsNamesVec;
127     static protected Vector JavaDoc dodsDriverClassVec;
128     
129
130
131
132     /**
133      * last used project root
134      */

135     static protected String JavaDoc projRoot;
136
137     /**
138      * last used doml file
139      */

140     static protected String JavaDoc domlfile;
141
142     /**
143      * last used template dir
144      */

145     static protected String JavaDoc customTemplateDir = null;
146     
147     
148     /**
149      * HashMap with changeAutocommit parameter value (from app conf file)
150      * for all logical databases (declared in same file) - default true
151      */

152      static protected HashMap JavaDoc changeAutocommit = new HashMap JavaDoc();
153      
154     /**
155      * last used template set
156      */

157     static protected String JavaDoc templateSet;
158  
159  
160     /**
161      * Sets value of changeAutocommit
162      * @param dbName database name
163      * @param value value to set
164      */

165     public static void setChangeAutocommit(String JavaDoc dbName, boolean value){
166         Boolean JavaDoc newValue= new Boolean JavaDoc(value);
167         changeAutocommit.put(dbName, newValue);
168     }
169     
170     
171     /**
172      * Return changeAutocommit value for given datbase name.
173      * @param dbName databse name
174      * @return changeAutocommit value for given datbase name.
175      */

176     public static boolean isChangeAutocommitEnabled(String JavaDoc dbName){
177         Boolean JavaDoc res = (Boolean JavaDoc)changeAutocommit.get(dbName);
178         if(res==null){
179             return true;
180         }else{
181             return res.booleanValue();
182         }
183     }
184   
185   
186     static private void init() {
187         if (!configured) {
188             if (configDir != null) {
189                 init(configDir);
190             } else {
191                 init(getDefaultConfigDir());
192             }
193         }
194     
195     }
196
197     static private void init(String JavaDoc confDir) {
198         setConfigDir(confDir);
199         String JavaDoc dodsFile = confDir + File.separator + "dodsConf.xml";
200         dodsFile.replace('\\', '/');
201         
202         Document JavaDoc doc = null;
203         if (confDir != null) {
204             doc = XMLDocumentFactory.parse(dodsFile);
205         }else{
206             try {
207                 Class JavaDoc comClass = Class.forName("org.enhydra.dods.Common");
208                 InputStream JavaDoc inStream =comClass.getClassLoader().getResourceAsStream(DODS_CONF_JAR_PATH+"/"+"dodsConf.xml");
209                 DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
210                 DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
211                 doc = builder.parse(inStream);
212             } catch (Exception JavaDoc e) {
213                 e.printStackTrace();
214             }
215         }
216         
217         dodsConf = XMLConfig.newXMLConfigInstance(doc);
218         dodsVendorConfs = new HashMap JavaDoc();
219         dodsDriversMap = new HashMap JavaDoc();
220         dodsDriversNamesVec = new Vector JavaDoc();
221         dodsVendorsNamesVec = new Vector JavaDoc();
222         dodsDriverClassVec = new Vector JavaDoc();
223         XMLConfig vendor = null;
224         String JavaDoc vendorName = null;
225         String JavaDoc vendorFile = null;
226         
227         
228         NodeList JavaDoc vendors = dodsConf.getSubElementsByTagName("Database/Vendor");
229
230         for (int i = 0; i < vendors.getLength(); i++) {
231             vendor = (XMLConfig) vendors.item(i);
232             vendorName = vendor.getAttribute("name");
233             vendorFile = confDir + File.separator + vendor.getText();
234             
235             if (confDir != null) {
236                 doc = XMLDocumentFactory.parse(vendorFile);
237             }else{
238                 try {
239                     Class JavaDoc comClass = Class.forName("org.enhydra.dods.Common");
240                     InputStream JavaDoc inStream =comClass.getClassLoader().getResourceAsStream(DODS_CONF_JAR_PATH+"/"+vendor.getText());
241                     DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
242                     DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
243                     doc = builder.parse(inStream);
244                 } catch (Exception JavaDoc e) {
245                     e.printStackTrace();
246                 }
247             }
248             
249             XMLConfig dodsVendorConf = XMLConfig.newXMLConfigInstance(doc);
250             dodsVendorConfs.put(vendorName, dodsVendorConf);
251         }
252
253
254         XMLConfig driverN;
255         XMLConfig driver;
256         NodeList JavaDoc driverClassesNl;
257         String JavaDoc driverVendorName;
258         String JavaDoc driverClassName;
259         String JavaDoc driverMetadataName;
260         NodeList JavaDoc driverVendorsNl = dodsConf.getSubElementsByTagName("Drivers/DatabaseVendor");
261         for (int i = 0; i < driverVendorsNl.getLength(); i++) {
262             driverN = (XMLConfig)driverVendorsNl.item(i);
263             driverVendorName = driverN.getAttribute("name");
264             driverClassesNl = driverN.getChildrenByTagName("Driver");
265             for (int j = 0; j < driverClassesNl.getLength(); j++) {
266                 driverClassName = null;
267                 driverMetadataName = null;
268                 driver = (XMLConfig)driverClassesNl.item(j);
269                 driverClassName = driver.getAttribute("class");
270                 driverMetadataName = driver.getAttribute("name");
271                 if (driverClassName !=null && driverClassName!=""){
272                     dodsDriversMap.put(driverClassName,driverVendorName);
273                 }
274                 if (driverMetadataName!=null && driverMetadataName!=""){
275                     dodsDriverClassVec.add(driverClassName);
276                     dodsDriversNamesVec.add(driverMetadataName);
277                     dodsVendorsNamesVec.add(driverVendorName);
278                 }
279             }
280         }
281         configured = true;
282     }
283
284     /**
285      * Get database vendor name for given driver class name.
286      *
287      * @param driverClassName Class name.
288      * @return Database Vendor name.
289      */

290     static public String JavaDoc getDatabaseVendor(String JavaDoc driverClassName) {
291         String JavaDoc res=null;
292         init();
293         if(driverClassName!=null && dodsDriversMap.containsKey(driverClassName)){
294             res = (String JavaDoc)dodsDriversMap.get(driverClassName);
295         }else{
296             System.out.println("Unknown JDBC Driver Vendor for : "+driverClassName+" using default (Standard) insted");
297             res = "Standard";
298         }
299         return res;
300     }
301
302     /**
303      * Get database vendor name for given driver class name.
304      *
305      * @param driverClassName Class name.
306      * @return Database Vendor name.
307      */

308     static public String JavaDoc getDatabaseVendorFromDriverName(String JavaDoc driverMetadataName)
309     throws ConfigException {
310         init();
311         int vendorIndex=-1;
312         for(int i=0;i<dodsDriversNamesVec.size();i++){
313             if (driverMetadataName.indexOf((String JavaDoc)dodsDriversNamesVec.elementAt(i))!=-1){
314                 String JavaDoc res =(String JavaDoc)dodsVendorsNamesVec.elementAt(i);
315                 return (String JavaDoc)dodsVendorsNamesVec.elementAt(i);
316             }
317         }
318         throw new ConfigException("Unknown JDBC Driver Vendor for : "+driverMetadataName);
319     }
320
321     /**
322      * Get database driver full class name for given driver name.
323      *
324      * @param driverClassName Class name.
325      * @return Database Vendor name.
326      */

327     static public String JavaDoc getDatabaseDriverClassFromDriverName(String JavaDoc driverMetadataName)
328     throws ConfigException {
329         init();
330         int vendorIndex=-1;
331         for(int i=0;i<dodsDriversNamesVec.size();i++){
332             if (driverMetadataName.indexOf((String JavaDoc)dodsDriversNamesVec.elementAt(i))!=-1){
333                 String JavaDoc res =(String JavaDoc)dodsVendorsNamesVec.elementAt(i);
334                 return (String JavaDoc)dodsDriverClassVec.elementAt(i);
335             }
336         }
337         throw new ConfigException("Unknown JDBC Driver for : "+driverMetadataName);
338     }
339     
340
341     /**
342      * Get dods configuration.
343      *
344      * @return Dods configuration.
345      */

346     static public XMLConfig getDodsConf() {
347         init();
348         return dodsConf;
349     }
350
351     /**
352      * Get dods conf property.
353      *
354      * @param key Key of the property.
355      * @param database Used database.
356      *
357      * @return Dods conf property.
358      */

359     static public String JavaDoc getDodsConfProperty(String JavaDoc key, String JavaDoc database) {
360         init();
361         XMLConfig vendor = (XMLConfig) dodsVendorConfs.get(database);
362
363         if (vendor != null) {
364             return vendor.getText(key);
365         }
366         return null;
367     }
368
369     /**
370      * Show dods.config properties.
371      */

372     static public void showDodsConf() {
373         init();
374         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
375         Iterator JavaDoc iter = dods_conf.entrySet().iterator();
376
377         while (iter.hasNext()) {
378             Map.Entry JavaDoc elm = (Map.Entry JavaDoc) iter.next();
379
380             ret.append(elm.getKey()).append("=").append(elm.getValue()).append("\n");
381         }
382     }
383
384     /**
385      * Get dods conf property.
386      *
387      * @return Dods conf vendor names.
388      */

389     static public Set JavaDoc getDodsConfVendorNames() {
390         init();
391         return dodsVendorConfs.keySet();
392     }
393
394     /**
395      * Get path to dods-ejen.properties.
396      *
397      * @return Path to dods-ejen.properties.
398      */

399     public static String JavaDoc getDodsEjenPropertyFilename() {
400         final String JavaDoc SYS_USER_HOME = "user.home";
401         final String JavaDoc DIR_ENHYDRA = ".enhydra";
402         final String JavaDoc PROPERTY_FILENAME = "dods-ejen.properties";
403         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
404
405         buf.append(System.getProperties().getProperty(SYS_USER_HOME));
406         buf.append(File.separator);
407         buf.append(DIR_ENHYDRA);
408         buf.append(File.separator);
409         buf.append(PROPERTY_FILENAME);
410         return buf.toString();
411     }
412
413     /**
414      * Get used doml file.
415      * @return Used doml file.
416      */

417     public static String JavaDoc getDomlFile() {
418         init();
419         String JavaDoc strDoml = null;
420
421         strDoml = System.getProperty("DOML_FILE");
422         String JavaDoc domlFile = null;
423
424         if (strDoml == null) {
425             File JavaDoc current = new File JavaDoc(".");
426             String JavaDoc[] files = current.list();
427
428             out:
429             for (int i = 0; i < files.length; i++) {
430                 if (files[i].toLowerCase().endsWith(".doml")) {
431                     domlFile = files[i];
432                     break out;
433                 } else {
434                     domlFile = null;
435                 }
436             }
437             strDoml = domlFile;
438         }
439         return strDoml;
440     }
441
442     /**
443      * Get used doml file name.
444      * @return Used doml file name.
445      */

446     public static String JavaDoc getDomlFileName() {
447         init();
448         String JavaDoc domlFileName = getDomlFile();
449         String JavaDoc fileSep = System.getProperty("file.separator");
450
451         if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
452             if (fileSep != "/") {
453                 domlFileName = domlFileName.replace('\\', '/');
454             }
455         }
456         return domlFileName.substring(domlFileName.lastIndexOf("/") + 1);
457     }
458
459     /**
460      * Get file name from used doml file name.
461      * @return file name from used doml file name.
462      */

463     public static String JavaDoc getFileName() {
464         init();
465         String JavaDoc fileName = getDomlFileName();
466         int index = fileName.lastIndexOf(".");
467
468         if (index != -1) {
469             fileName = fileName.substring(0, index);
470         }
471         return fileName;
472     }
473
474     /**
475      * Get used databse vendor.
476      * @return used databse vendor.
477      */

478     public static String JavaDoc getDatabaseVendor() {
479         init();
480         String JavaDoc database = System.getProperty("DATABASE_VENDOR");
481         return database;
482     }
483
484     /**
485      * Get used databse vendor.
486      * @return used databse vendor.
487      */

488     public static String JavaDoc getSplitSQLPrimary(){
489         String JavaDoc ret="true";
490         try{
491             ret=Common.getDodsConfProperty("SplitSQLPrimary",getDatabaseVendor());
492             
493         }catch(Exception JavaDoc e){}
494         if (ret==null) return "true";
495         else return ret;
496         
497     }
498
499
500
501     /**
502      * Set used doml file.
503      * @param doml Used doml file.
504      */

505     public static void setDomlFile(String JavaDoc doml) {
506         domlfile = doml;
507     }
508
509     /**
510      * Set used configuration folder.
511      * @param confD Used configurationfolder.
512      */

513     public static void setConfigDir(String JavaDoc confD) {
514         if (confD != null) {
515             File JavaDoc tempFile = new File JavaDoc(confD + File.separator + "dodsConf.xml");
516             if (!tempFile.isFile()) {
517                     System.out.println("File dodsConf.xml not exists on path: '"
518                    + confD + "' using default insted");
519                    confD = getDefaultConfigDir();
520             }
521             configDir = confD;
522         } else {
523 // System.out.println("Using default configuration!");
524
configDir = getDefaultConfigDir();
525         }
526         configured = false;
527         
528     }
529     
530     /**
531      * Get default configuration folder.
532      *
533      */

534     public static String JavaDoc getDefaultConfigDir() {
535         String JavaDoc dodsHome = System.getProperty("DODS_HOME");
536         if (dodsHome == null) {
537             dodsHome = System.getProperty("enhydra.home");
538             if (dodsHome != null) {
539                 dodsHome = dodsHome + File.separator + "dods";
540             } else {
541                 return null;
542             }
543         }
544         String JavaDoc resultStr = dodsHome + File.separator + "build" + File.separator
545                 + "conf";
546         return resultStr;
547     }
548     
549     /**
550      * Get used configuration folder.
551      *
552      */

553     public static String JavaDoc getConfigDir() {
554         init();
555         String JavaDoc resultStr = configDir;
556
557         if (configDir == null) {
558             resultStr = getDefaultConfigDir();
559         }
560         return resultStr;
561     }
562
563     /**
564      * Get configuration file from URL as inputStream.
565      * @param confURL Aditional search path for configuration file (folder or *.jar).
566      * If null then system classPath is used
567      * @param confFile configuration file name (from folder or *.jar file).
568      * If null then try to get default configuraton file from org/enhydra/dods/conf/databaseManager.conf
569      * @return InputStream with configuration file.
570      * If can not found confFile or confFile==null then try to get default.
571      */

572     public static InputStream JavaDoc getConfFileFromURL(URL JavaDoc confURL, String JavaDoc confFile)
573         throws ConfigException {
574         URL JavaDoc[] cURL;
575         if (confURL!=null){
576             cURL= new URL JavaDoc[1];
577             cURL[0]=confURL;
578         }else{
579             cURL= new URL JavaDoc[0];
580         }
581     // URLClassLoader ucl = new URLClassLoader(cURL,Common.class.getClassLoader());
582
ClassLoader JavaDoc ucl = Common.class.getClassLoader();
583             
584         InputStream JavaDoc configIS = null;
585         if (confFile!=null){
586             try{
587                 configIS = ucl.getResourceAsStream(confFile);
588             }catch(Exception JavaDoc e){}
589         }
590         if (configIS==null){
591             try{
592                 configIS = ucl.getResourceAsStream(DATABASE_MANAGER_CONF_FILE);
593             }catch(Exception JavaDoc e){
594                 throw new ConfigException(e);
595             }
596         }
597         return configIS;
598     }
599
600
601
602     /**
603      * Set Custom Template configuration folder.
604      * @param dirString path to template folder
605      */

606     public static void setCustomTemplateDir(String JavaDoc dirString) {
607         customTemplateDir = dirString;
608     }
609
610     /**
611      * Get Custom Template configuration folder.
612      *
613      */

614     public static String JavaDoc getCustomTemplateDir() {
615         init();
616         return customTemplateDir;
617     }
618
619     /**
620      * Get used project root.
621      * @return Project root.
622      */

623     public static String JavaDoc getProjectRoot() {
624         String JavaDoc projectRoot = null;
625
626         projectRoot = System.getProperty("PROJECT_ROOT");
627         if (projectRoot == null) {
628             projectRoot = ".";
629         }
630         return projectRoot;
631     }
632
633     /**
634      * Set used project root.
635      * @param projectRoot Project root.
636      */

637     public static void setProjectRoot(String JavaDoc projectRoot) {
638         projRoot = projectRoot;
639     }
640
641     /**
642      * Get used template set.
643      * @return template set.
644      */

645     public static String JavaDoc getTemplateSet() {
646         String JavaDoc tempSet = System.getProperty("TEMPLATESET");
647
648         if (tempSet == null) {
649             tempSet = "standard";
650         }
651         if (tempSet.equals("multidb")) {
652             tempSet = "standard";
653         }
654         if (tempSet.equals("webdocwf")) {
655             tempSet = "webdocwf";
656         }
657         if (tempSet.equals("multidb_webdocwf")) {
658             tempSet = "webdocwf";
659         }
660         return tempSet;
661     }
662
663     /**
664      * Set used template set.
665      * @param set Template set.
666      */

667     public static void setTemplateSet(String JavaDoc set) {
668         templateSet = set;
669     }
670
671     /**
672      * Get used extensions (template set).
673      * @return extensions (template set).
674      */

675     public static String JavaDoc getExtensions() {
676         String JavaDoc tempSet = null;
677
678         tempSet = System.getProperty("TEMPLATESET");
679         if (tempSet == null) {
680             tempSet = "standard";
681         }
682         return tempSet;
683     }
684
685     /**
686      * Get force parameter.
687      * @return Force parameter.
688      */

689     public static String JavaDoc getForce() {
690         String JavaDoc force = System.getProperty("FORCE");
691
692         return force;
693     }
694
695     /**
696      * Get install properties file.
697      * @return Get dods.properties file.
698      */

699     public static String JavaDoc getInstallProperties() {
700         String JavaDoc dodsHome = null;
701         String JavaDoc home = null;
702         try {
703             Properties JavaDoc properties = new Properties JavaDoc();
704             String JavaDoc strFileSep = System.getProperty("file.separator");
705             home = System.getProperty("DODS_HOME");
706             dodsHome = home + strFileSep + "build"+ strFileSep + "dods.properties";
707             if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
708                 if (dodsHome != "/") {
709                     dodsHome = dodsHome.replace('/', '\\');
710                 }
711             }
712             if (home == null) {
713                 dodsHome = System.getProperty("ENHYDRA_DIR") + strFileSep
714                         + "dods.properties";
715                 if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
716                     if (dodsHome != "/") {
717                         dodsHome = dodsHome.replace('/', '\\');
718                     }
719                 }
720             }
721         } catch (NullPointerException JavaDoc nullpointerexception) {}
722         return dodsHome;
723     }
724
725     /**
726      * Get enhydra root.
727      * @return Enhydra root.
728      */

729     public static String JavaDoc getDODSRoot() {
730         String JavaDoc enhHome = null;
731
732         try {
733             String JavaDoc strFileSep = System.getProperty("file.separator");
734
735             enhHome = System.getProperty("DODS_HOME");
736             if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
737                 if (enhHome != "/") {
738                     enhHome = enhHome.replace('\\', '/');
739                 }
740             }
741             if (enhHome == null) {
742                 String JavaDoc strInstall = getInstallProperties();
743
744                 if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
745                     if (System.getProperty("file.separator") != "/") {
746                         strInstall = strInstall.replace('/', '\\');
747                     }
748                 }
749                 FileInputStream JavaDoc fisInstallProp = new FileInputStream JavaDoc(strInstall);
750                 Properties JavaDoc properties = new Properties JavaDoc();
751
752                 properties.load(fisInstallProp);
753                 enhHome = properties.getProperty("enhydra.root");
754                 if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
755                     if (enhHome != "/") {
756                         enhHome = enhHome.replace('/', '\\');
757                     }
758                 }
759             }
760         } catch (NullPointerException JavaDoc nullpointerexception) {} catch (IOException JavaDoc ioexception) {}
761         return enhHome;
762     }
763
764     /**
765      * Get install properties file.
766      * @return Install properties file.
767      */

768     public static String JavaDoc getInstallPropertiesParam() {
769         String JavaDoc enhydraRoot = null;
770         String JavaDoc dodsConf = null;
771         String JavaDoc strReturn = null;
772
773         init();
774         try {
775             Properties JavaDoc properties = new Properties JavaDoc();
776             String JavaDoc strFileSep = System.getProperty("file.separator");
777             String JavaDoc strInstall = getInstallProperties();
778
779             if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
780                 if (strFileSep != "/") {
781                     strInstall = strInstall.replace('/', '\\');
782                 }
783             }
784             FileInputStream JavaDoc fisInstallProp = new FileInputStream JavaDoc(strInstall);
785
786             properties.load(fisInstallProp);
787             enhydraRoot = properties.getProperty("enhydra.root");
788             if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
789                 if (enhydraRoot != "/") {
790                     enhydraRoot = enhydraRoot.replace('/', '\\');
791                 }
792             }
793             dodsConf = properties.getProperty("dods.conf");
794             if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
795                 if (dodsConf != "/") {
796                     dodsConf = dodsConf.replace('/', '\\');
797                 }
798             }
799             fisInstallProp.close();
800         } catch (IOException JavaDoc ioexception) {} catch (NullPointerException JavaDoc nullpointerexception) {}
801         strReturn = "<property name=\"enhydra.root\" value=\"" + enhydraRoot
802                 + "\"/>\n";
803         strReturn = strReturn + "<property name=\"dods.conf\" value=\""
804                 + dodsConf + "\"/>\n";
805         return strReturn;
806     }
807
808     /**
809      * Get template directory.
810      * @return Template directory.
811      */

812     public static String JavaDoc getTemplateDir() {
813         String JavaDoc templateDir = null;
814
815         init();
816         try {
817             Properties JavaDoc properties = new Properties JavaDoc();
818             String JavaDoc strFileSep = System.getProperty("file.separator");
819             String JavaDoc strInstall = getInstallProperties();
820
821             if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
822                 if (strFileSep != "/") {
823                     strInstall = strInstall.replace('/', '\\');
824                 }
825             }
826             FileInputStream JavaDoc fisDodsEjen = new FileInputStream JavaDoc(strInstall);
827
828             properties.load(fisDodsEjen);
829             fisDodsEjen.close();
830             templateDir = properties.getProperty("template.dir");
831             if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
832                 if (templateDir != "/") {
833                     templateDir = templateDir.replace('/', '\\');
834                 }
835             }
836         } catch (IOException JavaDoc ioexception) {} catch (NullPointerException JavaDoc nullpointerexception) {return null;}
837         return templateDir;
838     }
839
840     /**
841      * Get all template set directories.
842      * @return all template set directories.
843      */

844     public static HashSet JavaDoc getAllTemplateSets() {
845         HashSet JavaDoc dirs = new HashSet JavaDoc();
846
847         init();
848         try {
849             File JavaDoc templateDirs = new File JavaDoc(Common.getTemplateDir());
850             String JavaDoc[] temp = templateDirs.list((FilenameFilter JavaDoc) new DirectoryNameFilter());
851
852             dirs.add("standard");
853             for (int i = 0; i < temp.length; i++) {
854                 dirs.add(temp[i]);
855             }
856         } catch (NullPointerException JavaDoc nullpointerexception) {}
857         return dirs;
858     }
859
860     /**
861      * Transform specify name in capital letters.
862      *
863      * @param name Class member name (column table name).
864      *
865      * @return Capitalized name.
866      */

867     static public String JavaDoc capitalizeName(String JavaDoc name) { // throws Exception {
868
String JavaDoc otherLetters = name.substring(1);
869
870         return name.toUpperCase(java.util.Locale.ENGLISH).substring(0, 1).concat(otherLetters);
871     }
872
873     /**
874      * Transform name in upper case name.
875      *
876      * @param name Class member name (column table name).
877      *
878      * @return upper case name.
879      */

880     static public String JavaDoc upperCaseName(String JavaDoc name) {
881         return name.toUpperCase();
882     }
883
884     
885     
886     /**
887      * Replace all occurence of forReplace with replaceWith in input string.
888      * @param input represents input string
889      * @param forReplace represents substring for replace
890      * @param replaceWith represents replaced string value
891      * @return new string with replaced values
892      */

893     public static String JavaDoc replaceAll(String JavaDoc input, String JavaDoc forReplace,
894                                     String JavaDoc replaceWith) {
895       if( input == null ) return null;
896       StringBuffer JavaDoc result = new StringBuffer JavaDoc();
897       boolean hasMore = true;
898       while (hasMore) {
899           int start = input.indexOf(forReplace);
900           int end = start + forReplace.length();
901           if (start != -1) {
902              result.append(input.substring(0, start) + replaceWith);
903              input = input.substring(end);
904           } else {
905               hasMore = false;
906               result.append(input);
907           }
908       }
909       if (result.toString().equals("")) return input; //nothing is changed
910
else return result.toString();
911     }
912
913     
914     public static void main(String JavaDoc[] args) {
915         showDodsConf();
916         System.out.println("Database.OidJdbcType = "
917                 + getDodsConfProperty("Database.OidJdbcType", "Standard"));
918     }
919 }
920
Popular Tags