1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.ginp.commands;
20
21 import java.io.File;
22 import java.io.FileWriter;
23 import java.io.InputStream;
24 import java.io.InputStreamReader;
25 import java.util.Vector;
26
27 import net.sf.ginp.config.Configuration;
28 import net.sf.ginp.CommandParameter;
29 import net.sf.ginp.GinpModel;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 /**
34 * Class to collect and write folder and picture data to xml data files.
35 *
36 * @author Doug Culnane
37 * @version $Revision: 303 $
38 */
39 public class UploadConfig implements Command {
40
41 private Log log = LogFactory.getLog(UploadConfig.class);
42
43 /**
44 * Description of the Method
45 *
46 * @param model Description of the Parameter
47 * @param params Description of the Parameter
48 */
49 public void action(GinpModel model, Vector params) {
50
51
52 if (Configuration.configOK()) {
53 return;
54 }
55
56 File confFile = new File(Configuration.getConfigfilelocation());
57
58
59 if (confFile.exists()) {
60 log.error("Config File there but NOT OK. Fix it or remove it.");
61 return;
62 }
63
64 for (int i = 0; i < params.size(); i++) {
65 CommandParameter param = (CommandParameter) params.get(i);
66 log.debug(param.getName() + " = " + param.getValue());
67 if (param.getName().equals("configfile")) {
68 try {
69 InputStream is = (InputStream) param.getObject();
70 InputStreamReader isr = new InputStreamReader(is);
71 FileWriter fw = new FileWriter(confFile);
72 int b = isr.read();
73 while ( b != -1) {
74 fw.write(b);
75 b = isr.read();
76 }
77 fw.flush();
78 } catch (Exception ex){
79 log.error("Error writing Config File from upload stream.", ex);
80 }
81 }
82 }
83 if (Configuration.configOK()) {
84 log.info("Uploaded valid Config");
85 }
86 model.setUserName("admin");
87 model.setCurrentPage("setup2.jsp");
88 }
89 }
90