protected void writeAuditTrail(String strPath, String strUser, StringBuffer sbValues) { BufferedReader reader = WFileUtil.openReadFile(strPath); String strLine; ArrayList aListData = WUtil.strToAList(sbValues.toString(), false, "\n"); StringBuffer sbData = sbValues; String strPnl = (this instanceof DisplayTemplate) ? "Data Template " : "Data Dir "; if (reader == null) { Messages.postDebug("Error opening file " + strPath); return; } try { while ((strLine = reader.readLine()) != null) { // if the line in the file is not in the arraylist, // then that line has been deleted if (!aListData.contains(strLine)) WUserUtil.writeAuditTrail(new Date(), strUser, "Deleted " + strPnl + strLine); // remove the lines that are also in the file or those which // have been deleted. aListData.remove(strLine); } // Traverse through the remaining new lines in the arraylist, // and write it to the audit trail for (int i = 0; i < aListData.size(); i++) { strLine = (String) aListData.get(i); WUserUtil.writeAuditTrail(new Date(), strUser, "Added " + strPnl + strLine); } reader.close(); } catch (Exception e) { e.printStackTrace(); } }
/** * Save the data to the file. Read the data from the file, and copy everything to the * stringbuffer. The lines in the file are of the form: * auditDir:system:/vnmr/part11/auditTrails:system file:standard:text:yes Based on these formats, * get the value of either the directory or the checkbox from the corresponding components, and * replace that value in the stringbuffer. */ protected void saveData() { BufferedReader reader = WFileUtil.openReadFile(m_strPath); String strLine = null; StringBuffer sbData = new StringBuffer(); if (reader == null) return; int nLineInd = 0; try { while ((strLine = reader.readLine()) != null) { // if the line starts with a comment from sccs, add '#' to it, // to make it a comment if (strLine.startsWith("%") || strLine.startsWith("@")) strLine = "# " + strLine; if (strLine.startsWith("#")) { sbData.append(strLine + "\n"); continue; } StringTokenizer sTok = new StringTokenizer(strLine, File.pathSeparator); boolean bFile = false; boolean bLineEnd = false; boolean bDir = false; for (int i = 0; sTok.hasMoreTokens(); i++) { String strValue = sTok.nextToken(); if (i == 0) { bFile = strValue.equalsIgnoreCase("file") ? true : false; bDir = false; if (strValue.equalsIgnoreCase("dir")) bDir = true; } else { // Case => file:standard:procpar:yes // skip over 'standard', 'procpar', // and get the value 'yes' or 'no' from the checkbox if (bFile) { if (i == 3) { String strNewValue = getValue(nLineInd); if (strNewValue != null) strValue = strNewValue; bLineEnd = true; } else bLineEnd = false; } else if (bDir) { bLineEnd = false; if (i == 3) bLineEnd = true; } // Case => part11Dir:/vnmr/part11/data 0r // Case => dataType:FDA // skip over 'part11Dir' // and get the value of the directory from the textfield, // or from the combobox else { if (i == 1) { String strNewValue = getValue(nLineInd); if (strNewValue != null) strValue = strNewValue; bLineEnd = true; } else bLineEnd = false; } } // copy the value to the stringbuffer sbData.append(strValue); if (!bLineEnd) sbData.append(File.pathSeparator); } nLineInd++; sbData.append("\n"); } // write the data to the file reader.close(); BufferedWriter writer = WFileUtil.openWriteFile(m_strPath); WFileUtil.writeAndClose(writer, sbData); m_objTimer = new javax.swing.Timer( 200, new ActionListener() { public void actionPerformed(ActionEvent e) { VItemAreaIF.firePropertyChng(Global.PART11_CONFIG_FILE, "all", ""); m_objTimer.stop(); } }); m_objTimer.start(); } catch (Exception e) { Messages.writeStackTrace(e); // e.printStackTrace(); Messages.postDebug(e.toString()); } }
/** Reads the file, and sets the label and the values in the hashmap. */ protected void setHM(String strPath, HashMap hmPnl) { BufferedReader reader = WFileUtil.openReadFile(strPath); boolean bFileEmpty = true; boolean bPart11Pnl = isPart11Pnl(); boolean bDefaultFile = isDefaultFile(); // if the file is empty, then create an empty set of textfields. if (reader == null) { // displayNewTxf("",""); return; } String strLine = null; StringTokenizer strTok; try { // read the file, and create a new set of textfields, // with the values from the file. while ((strLine = reader.readLine()) != null) { String strLabel = ""; String strValue = ""; bFileEmpty = false; if (strLine.startsWith("#") || strLine.startsWith("@") || strLine.startsWith("%") || strLine.startsWith("\"@")) continue; if (strLine.startsWith("\"")) strTok = new StringTokenizer(strLine, "\""); else strTok = new StringTokenizer(strLine, File.pathSeparator + ",\n"); if (!strTok.hasMoreTokens()) continue; strLabel = strTok.nextToken(); // the format for the part11 Default file is a little different // only parse out the part11Dir, and don't display other defaults if (bPart11Pnl && bDefaultFile) { if (!strLabel.equalsIgnoreCase("part11Dir")) continue; } if (strTok.hasMoreTokens()) { while (strTok.hasMoreTokens()) { strValue += strTok.nextToken(); if (strTok.hasMoreTokens()) strValue += " "; } } // append "/data/$name" to part11Dir if (bPart11Pnl && bDefaultFile && strLabel.equalsIgnoreCase("part11Dir")) { StringBuffer sbDir = new StringBuffer(strValue); if (sbDir.lastIndexOf(File.separator) < sbDir.length() - 1) sbDir.append(File.separator); sbDir.append("data" + File.separator + "$"); sbDir.append(WGlobal.NAME); strValue = sbDir.toString(); } // displayNewTxf(strLabel, strValue); if (strLabel != null && strLabel.trim().length() > 0) hmPnl.put(strLabel, strValue); } reader.close(); } catch (Exception e) { Messages.writeStackTrace(e); // e.printStackTrace(); Messages.postDebug(e.toString()); } }