2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.io
.FileInputStream
;
21 import java
.util
.Enumeration
;
22 import java
.util
.Iterator
;
23 import java
.util
.Properties
;
25 import lib
.TestParameters
;
26 import util
.PropertyName
;
29 * This class parses the ini files and stores the data
31 * inside TestParameters
33 public class CfgParser
36 protected boolean debug
= false;
37 protected String iniFile
= "";
39 public CfgParser(String ini
)
47 public void getIniParameters(TestParameters param
)
49 debug
= param
.DebugIsActive
;
50 Properties cfg
= null;
51 if (iniFile
.equals(""))
53 //no iniFile given, search one in the users home directory
54 cfg
= getProperties(getDefaultFileName(true));
55 //try to search the user dir if no iniFile could be found yet
58 cfg
= getProperties(getDefaultFileName(false));
63 cfg
= getProperties(iniFile
);
68 Enumeration
<Object
> cfgEnum
= cfg
.keys();
69 while (cfgEnum
.hasMoreElements())
71 String pName
= (String
) cfgEnum
.nextElement();
72 Object pValue
= cfg
.getProperty(pName
);
74 if (pValue
instanceof String
)
76 pValue
= ((String
) pValue
).trim();
79 param
.put(pName
.trim(), pValue
);
81 if (pName
.equals(PropertyName
.TEST_DOCUMENT_PATH
))
84 param
.put("DOCPTH", pValue
);
85 System
.setProperty("DOCPTH", (String
) pValue
);
88 else if (pName
.equals(PropertyName
.SRC_ROOT
))
91 System
.setProperty(pName
, (String
) pValue
);
97 debug
= param
.DebugIsActive
;
99 //check for platform dependent parameters
100 //this would have a $OperatingSystem as prefix
101 String os
= (String
) param
.get(PropertyName
.OPERATING_SYSTEM
);
102 if (os
!= null && os
.length() > 1)
105 //found something that could be a prefix
106 //check all parameters for this
107 Iterator
<String
> keys
= param
.keySet().iterator();
108 while (keys
.hasNext())
110 String key
= keys
.next();
111 if (key
.startsWith(os
))
113 Object oldValue
= param
.get(key
);
114 String newKey
= key
.substring(os
.length() + 1);
116 param
.put(newKey
, oldValue
);
123 protected Properties
getProperties(String name
)
125 // get the resource file
126 Properties prop
= new Properties();
129 System
.out
.println("Looking for " + name
);
133 FileInputStream propFile
= new FileInputStream(name
);
135 System
.out
.println("Parsing properties from " + name
);
142 java
.net
.URL url
= this.getClass().getResource("/" + name
);
145 System
.out
.println("Parsing properties from " + name
);
146 java
.net
.URLConnection connection
= url
.openConnection();
147 java
.io
.InputStream in
= connection
.getInputStream();
153 //Exception while reading prop-file, returning null
161 protected String
getDefaultFileName(boolean home
)
163 String fileSeparator
= System
.getProperty("file.separator");
167 //look inside the home directory
168 path
= System
.getProperty("user.home");
172 path
= System
.getProperty("user.dir");
174 if (fileSeparator
.equals("/"))
176 //suppose I'm on Unix-platform
177 return path
+ fileSeparator
+ ".runner.props";
181 //suppose I'm on Windows
182 return path
+ fileSeparator
+ "runner.props";