bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / runner / helper / CfgParser.java
blob7c7e17a208c0009a49164e8c036608416587f00b
1 /*
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 .
18 package helper;
20 import java.io.FileInputStream;
22 import java.util.Enumeration;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.Map;
26 import java.util.Properties;
28 import lib.TestParameters;
29 import util.PropertyName;
31 /**
32 * This class parses the ini files and stores the data
33 * <br>
34 * inside TestParameters
36 public class CfgParser
39 private boolean debug = false;
40 private String iniFile = "";
42 public CfgParser(String ini)
44 this.iniFile = ini;
47 public void getIniParameters(TestParameters param)
49 debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
50 Properties cfg = getProperties(iniFile);
52 if (cfg != null)
54 Enumeration<Object> cfgEnum = cfg.keys();
55 while (cfgEnum.hasMoreElements())
57 String pName = (String) cfgEnum.nextElement();
58 Object pValue = cfg.getProperty(pName);
60 if (pValue instanceof String)
62 pValue = ((String) pValue).trim();
65 param.put(pName.trim(), pValue);
67 if (pName.equals(PropertyName.TEST_DOCUMENT_PATH))
70 param.put("DOCPTH", pValue);
71 System.setProperty("DOCPTH", (String) pValue);
74 else if (pName.equals(PropertyName.SRC_ROOT))
77 System.setProperty(pName, (String) pValue);
83 debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
85 //check for platform dependent parameters
86 //this would have a $OperatingSystem as prefix
87 String os = (String) param.get(PropertyName.OPERATING_SYSTEM);
88 if (os != null && os.length() > 1)
91 Map<String, Object> aux = new HashMap<String, Object>();
92 for (Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator(); it.hasNext();)
94 Map.Entry<String, Object> entry = it.next();
95 String key = entry.getKey();
96 if (key.startsWith(os))
98 Object oldValue = entry.getValue();
99 String newKey = key.substring(os.length() + 1);
100 it.remove();
101 aux.put(newKey, oldValue);
104 param.putAll(aux);
109 private Properties getProperties(String name)
111 // get the resource file
112 Properties prop = new Properties();
113 if (debug)
115 System.out.println("Looking for " + name);
119 FileInputStream propFile = new FileInputStream(name);
120 prop.load(propFile);
121 System.out.println("Parsing properties from " + name);
122 propFile.close();
124 catch (Exception e)
128 java.net.URL url = this.getClass().getResource("/" + name);
129 if (url != null)
131 System.out.println("Parsing properties from " + name);
132 java.net.URLConnection connection = url.openConnection();
133 java.io.InputStream in = connection.getInputStream();
134 prop.load(in);
137 catch (Exception ex)
139 //Exception while reading prop-file, returning null
140 return null;
144 return prop;