1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 import lib
.TestParameters
;
30 import java
.util
.Properties
;
31 import java
.util
.Enumeration
;
32 import java
.io
.FileInputStream
;
33 import util
.PropertyName
;
36 * This class parses the ini files and stores the data
38 * inside TestParameters
40 public class CfgParser
43 protected boolean debug
= false;
44 protected String iniFile
= "";
46 public CfgParser(String ini
)
54 public void getIniParameters(TestParameters param
)
56 debug
= param
.DebugIsActive
;
57 Properties cfg
= null;
58 if (iniFile
.equals(""))
60 //no iniFile given, search one in the users home directory
61 cfg
= getProperties(getDefaultFileName(true));
62 //try to search the user dir if no iniFile could be found yet
65 cfg
= getProperties(getDefaultFileName(false));
70 cfg
= getProperties(iniFile
);
75 Enumeration cfgEnum
= cfg
.keys();
76 while (cfgEnum
.hasMoreElements())
78 String pName
= (String
) cfgEnum
.nextElement();
79 Object pValue
= cfg
.getProperty(pName
);
81 if (pValue
instanceof String
)
83 pValue
= ((String
) pValue
).trim();
86 param
.put(pName
.trim(), pValue
);
88 if (pName
.equals(PropertyName
.TEST_DOCUMENT_PATH
))
91 param
.put("DOCPTH", (String
) pValue
);
92 System
.setProperty("DOCPTH", (String
) pValue
);
95 else if (pName
.equals(PropertyName
.SRC_ROOT
))
98 System
.setProperty(pName
, (String
) pValue
);
104 debug
= param
.DebugIsActive
;
106 //check for platform dependend parameters
107 //this would have a $OperatingSystem as prefix
108 String os
= (String
) param
.get(PropertyName
.OPERATING_SYSTEM
);
109 if (os
!= null && os
.length() > 1)
112 //found something that could be a prefex
113 //check all parameters for this
114 Enumeration keys
= param
.keys();
115 while (keys
.hasMoreElements())
117 String key
= (String
) keys
.nextElement();
118 if (key
.startsWith(os
))
120 Object oldValue
= param
.get(key
);
121 String newKey
= key
.substring(os
.length() + 1);
123 param
.put(newKey
, oldValue
);
130 protected Properties
getProperties(String name
)
132 // get the resource file
133 Properties prop
= new Properties();
136 System
.out
.println("Looking for " + name
);
140 FileInputStream propFile
= new FileInputStream(name
);
142 System
.out
.println("Parsing properties from " + name
);
149 java
.net
.URL url
= this.getClass().getResource("/" + name
);
152 System
.out
.println("Parsing properties from " + name
);
153 java
.net
.URLConnection connection
= url
.openConnection();
154 java
.io
.InputStream in
= connection
.getInputStream();
160 //Exception while reading prop-file, returning null
168 protected String
getDefaultFileName(boolean home
)
170 String fileSeparator
= System
.getProperty("file.separator");
174 //look inside the home directory
175 path
= System
.getProperty("user.home");
179 path
= System
.getProperty("user.dir");
181 if (fileSeparator
.equals("/"))
183 //suppose I'm on Unix-platform
184 return path
+ fileSeparator
+ ".runner.props";
188 //suppose I'm on Windows
189 return path
+ fileSeparator
+ "runner.props";