Bump version to 24.04.3.4
[LibreOffice.git] / qadevOOo / runner / helper / CfgParser.java
bloba93e725fd99be92f70fb586b154ef9cafcb58bb0
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.Properties;
25 import lib.TestParameters;
26 import util.PropertyName;
28 /**
29 * This class parses the ini files and stores the data
30 * <br>
31 * inside TestParameters
33 public class CfgParser
36 private boolean debug = false;
37 private String iniFile = "";
39 public CfgParser(String ini)
41 this.iniFile = ini;
44 public void getIniParameters(TestParameters param)
46 debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
47 Properties cfg = getProperties(iniFile);
49 if (cfg != null)
51 Enumeration<Object> cfgEnum = cfg.keys();
52 while (cfgEnum.hasMoreElements())
54 String pName = (String) cfgEnum.nextElement();
55 String pValue = cfg.getProperty(pName);
57 if (pValue != null)
59 pValue = pValue.trim();
62 param.put(pName.trim(), pValue);
64 if (pName.equals(PropertyName.TEST_DOCUMENT_PATH))
67 param.put("DOCPTH", pValue);
68 System.setProperty("DOCPTH", (String) pValue);
71 else if (pName.equals(PropertyName.SRC_ROOT))
74 System.setProperty(pName, (String) pValue);
80 debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
83 private Properties getProperties(String name)
85 // get the resource file
86 Properties prop = new Properties();
87 if (debug)
89 System.out.println("Looking for " + name);
91 try
93 FileInputStream propFile = new FileInputStream(name);
94 try {
95 prop.load(propFile);
96 System.out.println("Parsing properties from " + name);
97 } finally {
98 propFile.close();
101 catch (Exception e)
105 java.net.URL url = this.getClass().getResource("/" + name);
106 if (url != null)
108 System.out.println("Parsing properties from " + name);
109 java.net.URLConnection connection = url.openConnection();
110 java.io.InputStream in = connection.getInputStream();
111 try {
112 prop.load(in);
113 } finally {
114 in.close();
118 catch (Exception ex)
120 //Exception while reading prop-file, returning null
121 return null;
125 return prop;