KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > strutsutil > InitPlugIn


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7  http://www.apache.org/licenses/LICENSE-2.0
8
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15
16 package com.jdon.strutsutil;
17
18 import java.io.InputStream JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import javax.servlet.ServletContext JavaDoc;
24 import javax.servlet.ServletException JavaDoc;
25
26 import org.apache.struts.action.ActionServlet;
27 import org.apache.struts.action.PlugIn;
28 import org.apache.struts.config.ModuleConfig;
29 import org.apache.struts.config.PlugInConfig;
30
31 import com.jdon.container.config.app.AppConfigureCollection;
32 import com.jdon.container.startup.ContainerSetupScript;
33 import com.jdon.util.FileLocator;
34 import com.jdon.util.StringUtil;
35
36 /**
37  * Struts应用框架åˆ?始化
38  *
39  *
40  * 需è¦?在struts_config.xml中加入:
41  * <plug-in className="com.jdon.strutsutil.InitPlugIn"/>
42  *
43  * 设置本åˆ?始化,å?¯ä½¿ç”¨å¯¹è±¡æ± ç­‰æŠ€æœ¯é…?ç½®
44  *
45  * <p>Copyright: Jdon.com Copyright (c) 2003</p>
46  * <p></p>
47  * @author banq
48  * @version 1.0
49  */

50
51 public class InitPlugIn implements PlugIn {
52     public final static String JavaDoc module = InitPlugIn.class.getName();
53
54     private ContainerSetupScript css = new ContainerSetupScript();
55
56     private FileLocator fileLocator = new FileLocator();
57
58     private ActionServlet servlet = null;
59
60     private ModuleConfig config = null;
61
62     public void init(ActionServlet servlet, ModuleConfig config)
63             throws ServletException JavaDoc {
64         // Remember our associated configuration and servlet
65
this.config = config;
66         this.servlet = servlet;
67
68         ServletContext JavaDoc sc = servlet.getServletContext();
69
70         String JavaDoc config_file = "";
71         PlugInConfig[] plugInConfigs = config.findPlugInConfigs();
72         int length = plugInConfigs.length;
73         for (int i = 0; i < length; i++) {
74             Set JavaDoc entries = plugInConfigs[i].getProperties().entrySet();
75             Iterator JavaDoc iter = entries.iterator();
76             while (iter.hasNext()) {
77                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
78                 if (AppConfigureCollection.CONFIG_NAME.equals(entry.getKey())) { //å?¯èƒ½æœ‰å¤šä¸ªé…?ç½®
79
config_file = (String JavaDoc) entry.getValue();
80                     String JavaDoc[] configs = StringUtil.split(config_file, ",");
81                     for (int j = 0; j < configs.length; j++) {
82                         if (checkExsit(configs[j])) {
83                             css.prepare(configs[j], sc);
84                         }
85                     }
86
87                 }
88             }
89         }
90     }
91
92     public boolean checkExsit(String JavaDoc config_file) {
93         boolean ret = false;
94         InputStream JavaDoc xmlFile = null;
95         try {
96             xmlFile = fileLocator.getConfPathXmlStream(config_file);
97             if (xmlFile != null)
98                 ret = true;
99         } catch (Exception JavaDoc ex) {
100
101         }
102         return ret;
103     }
104
105     public void destroy() {
106         css.destroyed(servlet.getServletContext());
107         config = null;
108         servlet = null;
109     }
110
111 }
112
Popular Tags