1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package convwatch; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.File; 27cdf0e10cSrcweir import java.io.RandomAccessFile; 28cdf0e10cSrcweir import java.util.ArrayList; 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** 31cdf0e10cSrcweir Helper class to give a simple API to read/write windows like ini files 32cdf0e10cSrcweir */ 33cdf0e10cSrcweir /* public */ // is only need, if we need this class outside package convwatch 34cdf0e10cSrcweir class IniFile 35cdf0e10cSrcweir { 36cdf0e10cSrcweir /** 37cdf0e10cSrcweir * internal representation of the ini file content. 38cdf0e10cSrcweir * Problem, if ini file changed why other write something difference, we don't realise this. 39cdf0e10cSrcweir */ 40cdf0e10cSrcweir String m_sFilename; 41cdf0e10cSrcweir ArrayList m_aList; 42cdf0e10cSrcweir boolean m_bListContainUnsavedChanges = false; 43cdf0e10cSrcweir 44cdf0e10cSrcweir /** 45cdf0e10cSrcweir open a ini file by it's name 46cdf0e10cSrcweir @param _sFilename string a filename, if the file doesn't exist, a new empty ini file will create. 47cdf0e10cSrcweir write back to disk only if there are really changes. 48cdf0e10cSrcweir */ IniFile(String _sFilename)49cdf0e10cSrcweir public IniFile(String _sFilename) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir m_sFilename = _sFilename; 52cdf0e10cSrcweir m_aList = loadLines(); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir loadLines()55cdf0e10cSrcweir ArrayList loadLines() 56cdf0e10cSrcweir { 57cdf0e10cSrcweir File aFile = new File(m_sFilename); 58cdf0e10cSrcweir ArrayList aLines = new ArrayList(); 59cdf0e10cSrcweir if (! aFile.exists()) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir GlobalLogWriter.get().println("couldn't find file " + m_sFilename); 62cdf0e10cSrcweir // DebugHelper.exception(BasicErrorCode.SbERR_FILE_NOT_FOUND, ""); 63cdf0e10cSrcweir // m_bListContainUnsavedChanges = false; 64cdf0e10cSrcweir return aLines; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir RandomAccessFile aReader = null; 67cdf0e10cSrcweir try 68cdf0e10cSrcweir { 69cdf0e10cSrcweir aReader = new RandomAccessFile(aFile,"r"); 70cdf0e10cSrcweir String aLine = ""; 71cdf0e10cSrcweir while (aLine != null) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir aLine = aReader.readLine(); 74cdf0e10cSrcweir if (aLine != null) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir aLines.add(aLine); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80cdf0e10cSrcweir catch (java.io.FileNotFoundException fne) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir GlobalLogWriter.get().println("couldn't open file " + m_sFilename); 83cdf0e10cSrcweir GlobalLogWriter.get().println("Message: " + fne.getMessage()); 84cdf0e10cSrcweir // DebugHelper.exception(BasicErrorCode.SbERR_FILE_NOT_FOUND, ""); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir catch (java.io.IOException ie) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir GlobalLogWriter.get().println("Exception occurs while reading from file " + m_sFilename); 89cdf0e10cSrcweir GlobalLogWriter.get().println("Message: " + ie.getMessage()); 90cdf0e10cSrcweir // DebugHelper.exception(BasicErrorCode.SbERR_INTERNAL_ERROR, ie.getMessage()); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir try 93cdf0e10cSrcweir { 94cdf0e10cSrcweir aReader.close(); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir catch (java.io.IOException ie) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir GlobalLogWriter.get().println("Couldn't close file " + m_sFilename); 99cdf0e10cSrcweir GlobalLogWriter.get().println("Message: " + ie.getMessage()); 100cdf0e10cSrcweir // DebugHelper.exception(BasicErrorCode.SbERR_INTERNAL_ERROR, ie.getMessage()); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir return aLines; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir /** 106cdf0e10cSrcweir * @return true, if the ini file contain some readable data 107cdf0e10cSrcweir */ is()108cdf0e10cSrcweir public boolean is() 109cdf0e10cSrcweir { 110cdf0e10cSrcweir return m_aList.size() > 1 ? true : false; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // ----------------------------------------------------------------------------- 114cdf0e10cSrcweir isRemark(String _sLine)115cdf0e10cSrcweir boolean isRemark(String _sLine) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir if ( ((_sLine.length() < 2) ) || 118cdf0e10cSrcweir ( _sLine.startsWith("#")) || 119cdf0e10cSrcweir ( _sLine.startsWith(";")) ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir return true; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir return false; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir getItem(int i)126cdf0e10cSrcweir String getItem(int i) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir return (String)m_aList.get(i); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir buildSectionName(String _sSectionName)131cdf0e10cSrcweir String buildSectionName(String _sSectionName) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir String sFindSection = "[" + _sSectionName + "]"; 134cdf0e10cSrcweir return sFindSection; 135cdf0e10cSrcweir } toLowerIfNeed(String _sName)136cdf0e10cSrcweir String toLowerIfNeed(String _sName) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir return _sName.toLowerCase(); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir // return the number where this section starts findSection(String _sSection)142cdf0e10cSrcweir int findSection(String _sSection) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir String sFindSection = toLowerIfNeed(buildSectionName(_sSection)); 145cdf0e10cSrcweir // ----------- find _sSection --------------- 146cdf0e10cSrcweir int i; 147cdf0e10cSrcweir for (i=0; i<m_aList.size();i++) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir String sLine = toLowerIfNeed(getItem(i).trim()); 150cdf0e10cSrcweir if (isRemark(sLine)) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir continue; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir if (sFindSection.equals("[]")) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir // special case, empty Section. 157cdf0e10cSrcweir return i - 1; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir if (sLine.startsWith(sFindSection)) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir return i; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir return -1; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir // return the line number, where the key is found. findKey(String _sSection, String _sKey)168cdf0e10cSrcweir int findKey(String _sSection, String _sKey) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir int i = findSection(_sSection); 171cdf0e10cSrcweir if (i == -1) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir // Section not found, therefore the value can't exist 174cdf0e10cSrcweir return -1; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir return findKeyFromKnownSection(i, _sKey); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir // i must be the index in the list, where the well known section starts findKeyFromKnownSection(int _nSectionIndex, String _sKey)180cdf0e10cSrcweir int findKeyFromKnownSection(int _nSectionIndex, String _sKey) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir _sKey = toLowerIfNeed(_sKey); 183cdf0e10cSrcweir for (int j=_nSectionIndex + 1; j<m_aList.size();j++) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir String sLine = getItem(j).trim(); 186cdf0e10cSrcweir 187cdf0e10cSrcweir if (isRemark(sLine)) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir continue; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir if (sLine.startsWith("[") /* && sLine.endsWith("]") */) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir // found end. 195cdf0e10cSrcweir break; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir int nEqual = sLine.indexOf("="); 199cdf0e10cSrcweir if (nEqual >= 0) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir String sKey = toLowerIfNeed(sLine.substring(0, nEqual).trim()); 202cdf0e10cSrcweir if (sKey.equals(_sKey)) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir return j; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir } 207cdf0e10cSrcweir } 208cdf0e10cSrcweir return -1; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir // i must be the index in the list, where the well known section starts findLastKnownKeyIndex(int _nSectionIndex, String _sKey)212cdf0e10cSrcweir int findLastKnownKeyIndex(int _nSectionIndex, String _sKey) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir _sKey = toLowerIfNeed(_sKey); 215cdf0e10cSrcweir int i = _nSectionIndex + 1; 216cdf0e10cSrcweir for (int j=i; j<m_aList.size();j++) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir String sLine = getItem(j).trim(); 219cdf0e10cSrcweir 220cdf0e10cSrcweir if (isRemark(sLine)) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir continue; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir if (sLine.startsWith("[") /* && sLine.endsWith("]") */) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir // found end. 228cdf0e10cSrcweir return j; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir int nEqual = sLine.indexOf("="); 232cdf0e10cSrcweir if (nEqual >= 0) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir String sKey = toLowerIfNeed(sLine.substring(0, nEqual).trim()); 235cdf0e10cSrcweir if (sKey.equals(_sKey)) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir return j; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir } 241cdf0e10cSrcweir return i; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir getValue(int _nIndex)244cdf0e10cSrcweir String getValue(int _nIndex) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir String sLine = getItem(_nIndex).trim(); 247cdf0e10cSrcweir if (isRemark(sLine)) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir return ""; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir int nEqual = sLine.indexOf("="); 252cdf0e10cSrcweir if (nEqual >= 0) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir String sKey = sLine.substring(0, nEqual).trim(); 255cdf0e10cSrcweir String sValue = sLine.substring(nEqual + 1).trim(); 256cdf0e10cSrcweir return sValue; 257cdf0e10cSrcweir } 258cdf0e10cSrcweir return ""; 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir /** 262cdf0e10cSrcweir @param _sSection string 263cdf0e10cSrcweir @param _sKey string 264cdf0e10cSrcweir @return the value found in the inifile which is given by the section and key parameter 265cdf0e10cSrcweir */ getValue(String _sSection, String _sKey)266cdf0e10cSrcweir public String getValue(String _sSection, String _sKey) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir String sValue = ""; 269cdf0e10cSrcweir int i = findKey(_sSection, _sKey); 270cdf0e10cSrcweir if (i == -1) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir // Section not found, therefore the value can't exist 273cdf0e10cSrcweir return ""; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir sValue = getValue(i); 277cdf0e10cSrcweir 278cdf0e10cSrcweir return sValue; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir /** 282cdf0e10cSrcweir write back the ini file to the disk, only if there exist changes 283cdf0e10cSrcweir */ store()284cdf0e10cSrcweir public void store() 285cdf0e10cSrcweir { 286cdf0e10cSrcweir if (m_bListContainUnsavedChanges == false) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir // nothing has changed, so no need to store 289cdf0e10cSrcweir return; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir File aFile = new File(m_sFilename); 293cdf0e10cSrcweir if (aFile.exists()) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir // System.out.println("couldn't find file " + m_sFilename); 296cdf0e10cSrcweir aFile.delete(); 297cdf0e10cSrcweir if (aFile.exists()) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir GlobalLogWriter.get().println("Couldn't delete the file " + m_sFilename); 300cdf0e10cSrcweir return; 301cdf0e10cSrcweir // DebugHelper.exception(BasicErrorCode.SbERR_INTERNAL_ERROR, "Couldn't delete the file " + m_sFilename); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir } 304cdf0e10cSrcweir // if (! aFile.canWrite()) 305cdf0e10cSrcweir // { 306cdf0e10cSrcweir // System.out.println("Couldn't write to file " + m_sFilename); 307cdf0e10cSrcweir // DebugHelper.exception(BasicErrorCode.SbERR_INTERNAL_ERROR, ""); 308cdf0e10cSrcweir // } 309cdf0e10cSrcweir try 310cdf0e10cSrcweir { 311cdf0e10cSrcweir RandomAccessFile aWriter = new RandomAccessFile(aFile, "rw"); 312cdf0e10cSrcweir for (int i=0; i<m_aList.size();i++) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir String sLine = getItem(i); 315cdf0e10cSrcweir aWriter.writeBytes(sLine); 316cdf0e10cSrcweir aWriter.writeByte((int)'\n'); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir aWriter.close(); 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir catch (java.io.FileNotFoundException fne) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir GlobalLogWriter.get().println("couldn't open file for writing " + m_sFilename); 324cdf0e10cSrcweir GlobalLogWriter.get().println("Message: " + fne.getMessage()); 325cdf0e10cSrcweir // DebugHelper.exception(BasicErrorCode.SbERR_FILE_NOT_FOUND, ""); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir catch(java.io.IOException ie) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir GlobalLogWriter.get().println("Exception occurs while writing to file " + m_sFilename); 330cdf0e10cSrcweir GlobalLogWriter.get().println("Message: " + ie.getMessage()); 331cdf0e10cSrcweir // DebugHelper.exception(BasicErrorCode.SbERR_INTERNAL_ERROR, ie.getMessage()); 332cdf0e10cSrcweir } 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir 336cdf0e10cSrcweir 337cdf0e10cSrcweir /** 338cdf0e10cSrcweir insert a value 339cdf0e10cSrcweir there are 3 cases 340cdf0e10cSrcweir 1. section doesn't exist, goto end and insert a new section, insert a new key value pair 341cdf0e10cSrcweir 2. section exist but key not, search section, search key, if key is -1 get last known key position and insert new key value pair there 342cdf0e10cSrcweir 3. section exist and key exist, remove the old key and insert the key value pair at the same position 343cdf0e10cSrcweir */ insertValue(String _sSection, String _sKey, String _sValue)344cdf0e10cSrcweir public void insertValue(String _sSection, String _sKey, String _sValue) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir int i = findSection(_sSection); 347cdf0e10cSrcweir if (i == -1) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir // case 1: section doesn't exist 350cdf0e10cSrcweir String sFindSection = buildSectionName(_sSection); 351cdf0e10cSrcweir 352cdf0e10cSrcweir m_aList.add(sFindSection); 353cdf0e10cSrcweir String sKeyValuePair = _sKey + "=" + _sValue; 354cdf0e10cSrcweir m_aList.add(sKeyValuePair); 355cdf0e10cSrcweir m_bListContainUnsavedChanges = true; 356cdf0e10cSrcweir return; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir int j = findKeyFromKnownSection(i, _sKey); 359cdf0e10cSrcweir if (j == -1) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir // case 2: section exist, but not the key 362cdf0e10cSrcweir j = findLastKnownKeyIndex(i, _sKey); 363cdf0e10cSrcweir String sKeyValuePair = _sKey + "=" + _sValue; 364cdf0e10cSrcweir m_aList.add(j, sKeyValuePair); 365cdf0e10cSrcweir m_bListContainUnsavedChanges = true; 366cdf0e10cSrcweir return; 367cdf0e10cSrcweir } 368cdf0e10cSrcweir else 369cdf0e10cSrcweir { 370cdf0e10cSrcweir // case 3: section exist, and also the key 371cdf0e10cSrcweir String sKeyValuePair = _sKey + "=" + _sValue; 372cdf0e10cSrcweir m_aList.set(j, sKeyValuePair); 373cdf0e10cSrcweir m_bListContainUnsavedChanges = true; 374cdf0e10cSrcweir } 375cdf0e10cSrcweir } 376cdf0e10cSrcweir // ----------------------------------------------------------------------------- 377cdf0e10cSrcweir // String replaceEvaluatedValue(String _sSection, String _sValue) 378cdf0e10cSrcweir // { 379cdf0e10cSrcweir // String sValue = _sValue; 380cdf0e10cSrcweir // int nIndex = 0; 381cdf0e10cSrcweir // while (( nIndex = sValue.indexOf("$(", nIndex)) >= 0) 382cdf0e10cSrcweir // { 383cdf0e10cSrcweir // int nNextIndex = sValue.indexOf(")", nIndex); 384cdf0e10cSrcweir // if (nNextIndex >= 0) 385cdf0e10cSrcweir // { 386cdf0e10cSrcweir // String sKey = sValue.substring(nIndex + 2, nNextIndex); 387cdf0e10cSrcweir // String sNewValue = getValue(_sSection, sKey); 388cdf0e10cSrcweir // if (sNewValue != null && sNewValue.length() > 0) 389cdf0e10cSrcweir // { 390cdf0e10cSrcweir // String sRegexpKey = "\\$\\(" + sKey + "\\)"; 391cdf0e10cSrcweir // sValue = sValue.replaceAll(sRegexpKey, sNewValue); 392cdf0e10cSrcweir // } 393cdf0e10cSrcweir // nIndex = nNextIndex; 394cdf0e10cSrcweir // } 395cdf0e10cSrcweir // else 396cdf0e10cSrcweir // { 397cdf0e10cSrcweir // nIndex += 2; 398cdf0e10cSrcweir // } 399cdf0e10cSrcweir // } 400cdf0e10cSrcweir // return sValue; 401cdf0e10cSrcweir // } 402cdf0e10cSrcweir // ----------------------------------------------------------------------------- 403cdf0e10cSrcweir 404cdf0e10cSrcweir // public String getLocalEvaluatedValue(String _sSection, String _sKey) 405cdf0e10cSrcweir // { 406cdf0e10cSrcweir // String sValue = getValue(_sSection, _sKey); 407cdf0e10cSrcweir // sValue = replaceEvaluatedValue(_sSection, sValue); 408cdf0e10cSrcweir // return sValue; 409cdf0e10cSrcweir // } 410cdf0e10cSrcweir 411cdf0e10cSrcweir // ----------------------------------------------------------------------------- 412cdf0e10cSrcweir 413cdf0e10cSrcweir // this is a special behaviour. 414cdf0e10cSrcweir // public String getGlobalLocalEvaluatedValue(String _sSection, String _sKey) 415cdf0e10cSrcweir // { 416cdf0e10cSrcweir // String sGlobalValue = getKey("global", _sKey); 417cdf0e10cSrcweir // String sLocalValue = getKey(_sSection, _sKey); 418cdf0e10cSrcweir // if (sLocalValue.length() == 0) 419cdf0e10cSrcweir // { 420cdf0e10cSrcweir // sGlobalValue = replaceEvaluatedKey(_sSection, sGlobalValue); 421cdf0e10cSrcweir // sGlobalValue = replaceEvaluatedKey("global", sGlobalValue); 422cdf0e10cSrcweir // return sGlobalValue; 423cdf0e10cSrcweir // } 424cdf0e10cSrcweir // sLocalValue = replaceEvaluatedKey(_sSection, sLocalValue); 425cdf0e10cSrcweir // sLocalValue = replaceEvaluatedKey("global", sLocalValue); 426cdf0e10cSrcweir // 427cdf0e10cSrcweir // return sLocalValue; 428cdf0e10cSrcweir // } 429cdf0e10cSrcweir 430cdf0e10cSrcweir 431cdf0e10cSrcweir /** 432cdf0e10cSrcweir * some tests for this class 433cdf0e10cSrcweir */ 434cdf0e10cSrcweir // public static void main(String[] args) 435cdf0e10cSrcweir // { 436cdf0e10cSrcweir // IniFile aIniFile = new IniFile("/tmp/inifile"); 437cdf0e10cSrcweir // String sValue = aIniFile.getValue("Section","Key"); 438cdf0e10cSrcweir // // insert a new value to a already exist section 439cdf0e10cSrcweir // aIniFile.insertValue("Section","Key2","a new value in a existing section"); 440cdf0e10cSrcweir // // replace a value 441cdf0e10cSrcweir // aIniFile.insertValue("Section","Key","replaced value"); 442cdf0e10cSrcweir // // create a new value 443cdf0e10cSrcweir // aIniFile.insertValue("New Section", "Key", "a new key value pair"); 444cdf0e10cSrcweir // 445cdf0e10cSrcweir // String sValue2 = aIniFile.getValue("Section2","Key"); 446cdf0e10cSrcweir // aIniFile.store(); 447cdf0e10cSrcweir // } 448cdf0e10cSrcweir } 449