/** Returns the value in the proper format: "value". */ protected String getValue(String strUser, String strValue) { ArrayList aListValues = WUtil.strToAList(strValue); String strNewValue = ""; if (strValue == null || strValue.trim().length() <= 0) return ""; String strPath = FileUtil.openPath("SYSPROF" + File.separator + strUser) + File.pathSeparator + FileUtil.openPath("USRPROF" + File.separator + strUser); HashMap hmUser = WFileUtil.getHashMap(strPath); for (int i = 0; i < aListValues.size(); i++) { strNewValue = (String) aListValues.get(i); if (strNewValue == null) strNewValue = ""; // if the value is of the form: $home, then parse the value if (hmUser != null && strNewValue.indexOf('$') >= 0) { strValue = WFileUtil.parseValue(strNewValue, hmUser); if (strValue != null && strValue.trim().length() > 0) strNewValue = strValue; } } return strNewValue; }
/** Saves the data in the following format: Label:value e.g. Password Retries:3 */ protected void saveData() { StringBuffer sbData = new StringBuffer(); Component[] comps = getComponents(); String strLabel = null; String strValue = null; String strCmd = null; for (int i = 0; i < comps.length; i++) { Component comp = comps[i]; boolean bCmd = false; if (comp instanceof JLabel) { strLabel = ((JLabel) comp).getText(); sbData.append(strLabel); sbData.append(":"); // append to the cmd string if (strLabel.equalsIgnoreCase("Password Retries")) strCmd = RETRIES; else if (strLabel.indexOf("Default Expiration") >= 0) strCmd = MAXWEEKS; else if (strLabel.indexOf("Minimum Length") >= 0) strCmd = PASSLENGTH; else strCmd = ""; } else if (comp instanceof JTextField) { strValue = ((JTextField) comp).getText(); if (strValue == null) strValue = ""; sbData.append(strValue); sbData.append("\n"); // append to the cmd string if ((strCmd.indexOf(RETRIES) >= 0) || (strCmd.indexOf(MAXWEEKS) >= 0) || (strCmd.indexOf(PASSLENGTH) >= 0)) { strCmd = strCmd + "= " + strValue; bCmd = true; } } else if (comp instanceof JCheckBox) { strValue = ((JCheckBox) comp).isSelected() ? "yes" : "no"; sbData.append(strValue); sbData.append("\n"); } // call the unix script that can set these values if (bCmd) { String[] cmd = { WGlobal.SHTOOLCMD, WGlobal.SHTOOLOPTION, WGlobal.SUDO + WGlobal.SBIN + "auredt" + " " + strCmd }; WUtil.runScript(cmd); } } // write to the file BufferedWriter writer = WFileUtil.openWriteFile(m_strPath); WFileUtil.writeAndClose(writer, sbData); }
protected void buildPanel(String strPath) { BufferedReader reader = WFileUtil.openReadFile(strPath); String strLine; if (reader == null) return; try { while ((strLine = reader.readLine()) != null) { if (strLine.startsWith("#") || strLine.startsWith("%") || strLine.startsWith("@")) continue; StringTokenizer sTokLine = new StringTokenizer(strLine, ":"); // first token is the label e.g. Password Length if (sTokLine.hasMoreTokens()) { createLabel(sTokLine.nextToken(), this); } // second token is the value String strValue = sTokLine.hasMoreTokens() ? sTokLine.nextToken() : ""; if (strValue.equalsIgnoreCase("yes") || strValue.equalsIgnoreCase("no")) createChkBox(strValue, this); else createTxf(strValue, this); } } catch (Exception e) { Messages.writeStackTrace(e); // e.printStackTrace(); Messages.postDebug(e.toString()); } }
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(); } }
protected String gettitle(String strFreq) { StringBuffer sbufTitle = new StringBuffer().append("VnmrJ "); String strPath = FileUtil.openPath(FileUtil.SYS_VNMR + "/vnmrrev"); BufferedReader reader = WFileUtil.openReadFile(strPath); String strLine; String strtype = ""; if (reader == null) return sbufTitle.toString(); try { while ((strLine = reader.readLine()) != null) { strtype = strLine; } strtype = strtype.trim(); if (strtype.equals("merc")) strtype = "Mercury"; else if (strtype.equals("mercvx")) strtype = "Mercury-Vx"; else if (strtype.equals("mercplus")) strtype = "MERCURY plus"; else if (strtype.equals("inova")) strtype = "INOVA"; String strHostName = m_strHostname; if (strHostName == null) strHostName = ""; sbufTitle.append(" ").append(strHostName); sbufTitle.append(" ").append(strtype); sbufTitle.append(" - ").append(strFreq); reader.close(); } catch (Exception e) { // e.printStackTrace(); Messages.logError(e.toString()); } return sbufTitle.toString(); }
protected void buildPanel(String strPath) { strPath = FileUtil.openPath(strPath); ArrayList aListPath = new ArrayList(); BufferedReader reader = WFileUtil.openReadFile(strPath); if (reader == null) return; String strLine; try { while ((strLine = reader.readLine()) != null) { StringTokenizer strTok = new StringTokenizer(strLine, ":"); if (strTok.countTokens() < 4) continue; boolean bChecksum = false; boolean bShow = false; String strDir = strTok.nextToken(); String strChecksum = strTok.nextToken(); if (strChecksum.equalsIgnoreCase("checksum")) bChecksum = true; if (bChecksum && (strDir.equals("file") || strDir.equals("dir"))) { String strValue = strTok.nextToken(); String strShow = strTok.nextToken(); if (strShow.equalsIgnoreCase("yes")) bShow = true; if (bShow) aListPath.add(strValue); } } m_cmbPath = new JComboBox(aListPath.toArray()); JPanel pnlDisplay = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints( 0, 0, 1, 1, 0.2, 0.2, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); pnlDisplay.add(m_cmbPath, gbc); gbc.gridx = 1; pnlDisplay.add(m_cmbChecksum, gbc); add(pnlDisplay, BorderLayout.NORTH); add(m_txaChecksum, BorderLayout.CENTER); } catch (Exception e) { e.printStackTrace(); } }
protected void setTrayPresent(String strPath) { String strzone = "zones"; BufferedReader reader = WFileUtil.openReadFile(strPath); if (reader == null) return; String strLine; try { // if the zones are set to 0, then there is no tray present // set rackInfo(1,zones) 3 => tray 1 present // set rackInfo(2,zones) 0 => tray 2 not present while ((strLine = reader.readLine()) != null) { int index = strLine.indexOf(strzone); if (index < 0) continue; String strTray = strLine.substring(index - 2, index - 1); int nTray = 0; try { nTray = Integer.parseInt(strTray); } catch (Exception e) { } if (nTray <= 0) continue; int nZone = 0; try { strTray = strLine.substring(index + strzone.length() + 2, strLine.length()); nZone = Integer.parseInt(strTray); } catch (Exception e) { } Color colorbg = Color.white; String strTooltip = TRAY; if (nZone <= 0) { colorbg = Color.black; strTooltip = NOTRAY; } VBox pnlVast = m_pnlVast[nTray - 1]; pnlVast.setbackground(colorbg); pnlVast.setToolTipText(Util.getTooltipString(strTooltip)); } reader.close(); } catch (Exception e) { // e.printStackTrace(); Messages.writeStackTrace(e); } }
protected void setVast() { String strPath = FileUtil.openPath("SYSTEM/asm/gilsonNumber"); if (strPath == null) return; BufferedReader reader = WFileUtil.openReadFile(strPath); if (reader == null) return; String strLine; int i = 0; try { while ((strLine = reader.readLine()) != null) { strLine = strLine.trim(); if (i == 0 || !m_aStrVast[i - 1].equals(strLine)) { m_aStrVast[i] = strLine; i = i + 1; } } reader.close(); } catch (Exception e) { // e.printStackTrace(); Messages.writeStackTrace(e); } }
public void buildConfig() { BufferedReader in = WFileUtil.openReadFile(m_strPath); String strLine = null; if (in == null) { Messages.postError("Error opening file " + m_strPath); return; } try { m_pnlDisplay.removeAll(); m_pnlDisplay.setLayout(new WGridLayout(0, 2)); m_aListComp.clear(); while ((strLine = in.readLine()) != null) { if (strLine.startsWith("#") || strLine.startsWith("%") || strLine.startsWith("@")) continue; StringTokenizer sTokLine = new StringTokenizer(strLine, File.pathSeparator); createJComps(sTokLine); } setVisible(true); } catch (Exception e) { // e.printStackTrace(); Messages.writeStackTrace(e); } }
/** * 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()); } }
/** * Write the file by writing the values from the labels, and the values list. * * @param strFile the file to be written. * @param aListLabels arraylist of texfields of labels. * @param aListValues arraylist of texfields of values. */ protected void writeFile( String strUser, String strFile, ArrayList aListLabels, ArrayList aListValues) { String strPath = FileUtil.openPath(strFile); String strLabel = ""; String strValue = ""; StringBuffer sbValues = new StringBuffer(); JTextField txfLabel = null; JTextField txfValue = null; boolean bNewFile = false; int nFDAMode = Util.getPart11Mode(); // if it's the part11 pnl and the mode is nonFDA, // then don't write the file for this panel // the other way is not true. if (this instanceof DisplayParentDirectory) { if ((isPart11Pnl() && nFDAMode == Util.NONFDA)) { return; } } if (strPath == null) { strPath = FileUtil.savePath(strFile); bNewFile = true; } if (strPath == null || aListLabels == null) return; if (aListValues == null) aListValues = new ArrayList(); // Get the list of the textfields for values and labels. int nLblSize = aListLabels.size(); int nValueSize = aListValues.size(); ArrayList<String> labelList = new ArrayList<String>(); // Get the value from each textfield, and add it to the buffer. for (int i = 0; i < nLblSize; i++) { txfLabel = (JTextField) aListLabels.get(i); txfValue = (i < nValueSize) ? (JTextField) aListValues.get(i) : null; strLabel = (txfLabel != null) ? txfLabel.getText() : null; strValue = (txfValue != null) ? txfValue.getText() : ""; // We need to be sure they don't have two data directories with // the same labels. Save the label list if we are writing to // the "data" file. if (strFile.indexOf("data") != -1) { if (labelList.contains(strLabel)) { Messages.postError( "The Data Directory specifications " + "must not have duplicate Label names. " + "The Label \"" + strLabel + "\" is duplicated. " + "Skipping the second instance. Please " + "specify a new Label."); continue; } else labelList.add(strLabel); } if (strLabel == null || strLabel.trim().length() <= 0 || strValue.equals(INFOSTR)) continue; // for user template tab, don't need to parse the value if (!(this instanceof DisplayTemplate)) strValue = getValue(strUser, strValue); strLabel = strLabel.trim(); if (strValue != null) strValue = strValue.trim(); // sbValues.append("\""); sbValues.append(strLabel); // sbValues.append("\" "); sbValues.append(File.pathSeparator); sbValues.append(strValue); sbValues.append("\n"); } if (Util.isPart11Sys()) writeAuditTrail(strPath, strUser, sbValues); // write the data to the file. BufferedWriter writer = WFileUtil.openWriteFile(strPath); WFileUtil.writeAndClose(writer, sbValues); // if it's a template file, then make it writable for everyone. if (bNewFile) { String strCmd = "chmod 755 "; if (this instanceof DisplayTemplate) strCmd = "chmod 777 "; if (Util.iswindows()) strPath = UtilB.windowsPathToUnix(strPath); String[] cmd = {WGlobal.SHTOOLCMD, WGlobal.SHTOOLOPTION, strCmd + strPath}; WUtil.runScriptInThread(cmd); } }