KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bluecubs > xinco > conf > XincoConfigSingletonServer


1 /**
2  *Copyright 2004 blueCubs.com
3  *
4  *Licensed under the Apache License, Version 2.0 (the "License");
5  *you may not use this file except in compliance with the License.
6  *You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *Unless required by applicable law or agreed to in writing, software
11  *distributed under the License is distributed on an "AS IS" BASIS,
12  *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *See the License for the specific language governing permissions and
14  *limitations under the License.
15  *
16  *************************************************************
17  * This project supports the blueCubs vision of giving back
18  * to the community in exchange for free software!
19  * More information on: http://www.bluecubs.org
20  *************************************************************
21  *
22  * Name: XincoConfigSingletonServer
23  *
24  * Description: configuration class on server side
25  *
26  * Original Author: Alexander Manes
27  * Date: 2004
28  *
29  * Modifications:
30  *
31  * Who? When? What?
32  * - - -
33  *
34  *************************************************************
35  */

36
37 package com.bluecubs.xinco.conf;
38
39 import javax.naming.InitialContext JavaDoc;
40 import java.util.Vector JavaDoc;
41
42 /**
43  * This class handles the server configuration of xinco.
44  * Edit values in context.xml
45  */

46 public class XincoConfigSingletonServer {
47
48     public String JavaDoc FileRepositoryPath = null;
49     public String JavaDoc FileIndexPath = null;
50     public String JavaDoc FileArchivePath = null;
51     public long FileArchivePeriod = 0;
52     public int FileIndexerCount = 0;
53     public Vector JavaDoc IndexFileTypesClass = null;
54     public Vector JavaDoc IndexFileTypesExt = null;
55     public String JavaDoc[] IndexNoIndex = null;
56     public String JavaDoc JNDIDB = null;
57     public int MaxSearchResult = 0;
58     private static XincoConfigSingletonServer instance = null;
59         
60     public static XincoConfigSingletonServer getInstance() {
61
62         if (instance == null) {
63             instance = new XincoConfigSingletonServer();
64         }
65         return instance;
66
67     }
68
69     //private constructor to avoid instance generation with new-operator!
70
private XincoConfigSingletonServer() {
71         try {
72             FileRepositoryPath = (String JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/FileRepositoryPath");
73             if (!(FileRepositoryPath.substring(FileRepositoryPath.length()-1).equals(System.getProperty("file.separator")))) {
74                 FileRepositoryPath = FileRepositoryPath + System.getProperty("file.separator");
75             }
76             //optional: FileIndexPath
77
try {
78                 FileIndexPath = (String JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/FileIndexPath");
79             } catch (Exception JavaDoc ce) {
80                 FileIndexPath = FileRepositoryPath + "index";
81             }
82             if (!(FileIndexPath.substring(FileIndexPath.length()-1).equals(System.getProperty("file.separator")))) {
83                 FileIndexPath = FileIndexPath + System.getProperty("file.separator");
84             }
85             FileArchivePath = (String JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/FileArchivePath");
86             if (!(FileArchivePath.substring(FileArchivePath.length()-1).equals(System.getProperty("file.separator")))) {
87                 FileArchivePath = FileArchivePath + System.getProperty("file.separator");
88             }
89             FileArchivePeriod = ((Long JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/FileArchivePeriod")).longValue();
90             
91             FileIndexerCount = ((Integer JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/FileIndexerCount")).intValue();
92             IndexFileTypesClass = new Vector JavaDoc();
93             IndexFileTypesExt = new Vector JavaDoc();
94             for (int i=0;i<FileIndexerCount;i++) {
95                 IndexFileTypesClass.add((String JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/FileIndexer_" + (i+1) + "_Class"));
96                 IndexFileTypesExt.add(((String JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/FileIndexer_" + (i+1) + "_Ext")).split(";"));
97             }
98             IndexNoIndex = ((String JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/IndexNoIndex")).split(";");
99             
100             JNDIDB = (String JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/JNDIDB");
101             MaxSearchResult = ((Integer JavaDoc)(new InitialContext JavaDoc()).lookup("java:comp/env/xinco/MaxSearchResult")).intValue();
102         } catch (Exception JavaDoc e) {
103             FileRepositoryPath = "";
104             FileIndexPath = "";
105             FileArchivePath = "";
106             FileArchivePeriod = 14400000;
107             FileIndexerCount = 4;
108             IndexFileTypesClass = new Vector JavaDoc();
109             IndexFileTypesExt = new Vector JavaDoc();
110             String JavaDoc[] tsa = null;
111             IndexFileTypesClass.add("com.bluecubs.xinco.index.filetypes.XincoIndexAdobePDF");
112             tsa = null;
113             tsa[0] = "pdf";
114             IndexFileTypesExt.add(tsa);
115             IndexFileTypesClass.add("com.bluecubs.xinco.index.filetypes.XincoIndexMSWord");
116             tsa = null;
117             tsa[0] = "doc";
118             IndexFileTypesExt.add(tsa);
119             IndexFileTypesClass.add("com.bluecubs.xinco.index.filetypes.XincoIndexMSExcel");
120             tsa = null;
121             tsa[0] = "xls";
122             IndexFileTypesExt.add(tsa);
123             IndexFileTypesClass.add("com.bluecubs.xinco.index.filetypes.XincoIndexHTML");
124             tsa = null;
125             tsa[0] = "htm";
126             tsa[1] = "html";
127             tsa[2] = "php";
128             tsa[3] = "jsp";
129             IndexFileTypesExt.add(tsa);
130             IndexNoIndex[0] = "";
131             IndexNoIndex[1] = "com";
132             IndexNoIndex[2] = "exe";
133
134             JNDIDB = "java:comp/env/jdbc/XincoDB";
135             MaxSearchResult = 30;
136         }
137     }
138
139 }
140
Popular Tags