📄 p219au102.java
字号:
/* **************************************************************** *//* System Name : 億乕僞儖仌僌儖乕僾僂僄傾僾儘僕僃僋僩 * File Name : 僐儞僥儞僣偺僷僗曄姺僣乕儖(p219au112.java) * Compiler : JDK 1.5.0 * Description : 僐儞僼傿僌僼傽僀儖偺僷僗儚乕僪曄峏張棟僋儔僗 * ---------------------------------------------------------------- * Modification History * Date Name Description * ----------- -------------- ----------------------------------- * 2007/11/XX Initial Release * ---------------------------------------------------------------- *//* **************************************************************** */import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.sql.Connection;import java.sql.SQLException;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import model.UidPwd;import model.dao.p219au100DAO;import common.AddConst;import common.DatabaseHandle;import common.FileOption;import common.TraceLogger;import common.AddInfo;import common.AddMsg;public class p219au102{ private static TraceLogger trace = new TraceLogger(); private static AddInfo info = new AddInfo(); private static AddMsg adm = new AddMsg(); /****************************************************************** * 儊僀儞張棟 * @param * @return * @throws * @version ******************************************************************/ public static void main(String[] args) { p219au10201 sub = new p219au10201(); trace.debug(adm.getMsg("M219S01I",new String[]{AddConst.BATCH_102})); sub.setFileDataToList(); if (args.length>0){ if (args[0].equals("1")) { sub.updateConfigFile(1); sub.updateOracleUser(); } if (args[0].equals("2")) { sub.updateConfigFile(2); sub.updateOracleUser(); } } trace.debug(adm.getMsg("M219S02I",new String[]{AddConst.BATCH_101})); }}class p219au10201 { private Map uidpwd_map; //僆儔僋儖僷僗儚乕僪Map private static TraceLogger trace = new TraceLogger(); private static AddInfo info = new AddInfo(); private static AddMsg adm = new AddMsg(); /****************************************************************** * 僐儞僗僩儔僋僞 * @param * @return * @throws * @version ******************************************************************/ public p219au10201() { uidpwd_map = new HashMap(); } /****************************************************************** * 僐儞僼傿僌僼傽僀儖偺僷僗儚乕僪曄峏 * @param String 埫崋壔僷僗儚乕僪僼傽僀儖僷僗 * @param String 僆儔僋儖儐乕僓ID * @param String 媽乮僇儗儞僩乯僷僗儚乕僪 * @param String 怴乮曄峏屻乯僷僗儚乕僪 * @return boolean 僷僗儚乕僪曄峏寢壥 * @throws exception IOException 幚峴帪僄儔乕 * @version ******************************************************************/ private boolean modifyPassWord(String sFilePath,String userName,String oldPass,String newPass){ boolean flag=false; boolean isExecute=true; File myFilePath = new File(sFilePath); if(userName==null||(userName=userName.trim()).equals("")) { System.out.print("The value of userName is Null or blank value please confirm the input!"); isExecute=false; } if(oldPass==null||(oldPass=oldPass.trim()).equals("")) { System.out.print("The value of oldPass is Null or blank value please confirm the input!"); isExecute=false; } if(newPass==null||(newPass=newPass.trim()).equals("")) { System.out.print("The value of newPass is Null or blank value please confirm the input!"); isExecute=false; } if(!myFilePath.exists()){ isExecute=false; trace.debug(adm.getMsg("M219xxxx",new String[]{AddConst.BATCH_102})); System.out.println("The xml file does not exist!"); } if(isExecute) { boolean isCorrectUserName=false; boolean isCorrectPass=false; BufferedReader in=null; String content=""; boolean isOverWrite=false; try { String temp=null; in = new BufferedReader(new FileReader(myFilePath)); while ((temp=in.readLine()) != null) { content+=temp+"\n\r"; if(temp.indexOf("<name>username</name>")!=-1&&(temp=in.readLine())!= null){ content+=temp+"\n\r"; if(temp.indexOf("<value>"+userName+"</value>")!=-1&&(temp=in.readLine())!= null){ content+=temp+"\n\r"; isCorrectUserName=true; if(temp.indexOf("</parameter>")!=-1&&(temp=in.readLine())!= null){ content+=temp+"\n\r"; if(temp.indexOf("<parameter>")!=-1&&(temp=in.readLine())!= null){ content+=temp+"\n\r"; if(temp.indexOf("<name>password</name>")!=-1&&(temp=in.readLine())!= null){ if(temp.indexOf("<value>"+oldPass+"</value>")!=-1){ temp=temp.replaceAll("<value>"+oldPass+"</value>", "<value>"+newPass+"</value>"); isOverWrite=true; isCorrectPass=true; } content+=temp+"\n\r"; } } } } } } in.close(); }catch (IOException e) { if(in!=null) { try { in.close(); in=null; } catch (IOException ee) { ee.printStackTrace(); } } e.printStackTrace(); } if(!isCorrectUserName) { System.out.println("The input userName is not occur in the xml file!"); } else { if(!isCorrectPass) { System.out.println("The input oldPass is wrong!"); } } if(isOverWrite){ if(new FileOption().copyFile(sFilePath, sFilePath+AddConst.EXT)){ String[] curContentArray = content.split("\n\r"); BufferedWriter resultFile=null; try{ resultFile = new BufferedWriter(new FileWriter(myFilePath)); for(int i = 0;i<curContentArray.length;i++){ resultFile.write(curContentArray[i]); resultFile.newLine(); } flag=true; resultFile.flush(); resultFile.close(); }catch(IOException e){ if(resultFile!=null) { try { resultFile.close(); resultFile=null; } catch (Exception ee) { ee.printStackTrace(); } } } } } } return flag; } /****************************************************************** * 僆儔僋儖僷僗儚乕僪曄峏 * @param * @return * @throws exception Exception 幚峴帪僄儔乕 * @version ******************************************************************/ public void updateOracleUser(){ try { Connection con = null; p219au100DAO dao = new p219au100DAO(); Iterator it = uidpwd_map.keySet().iterator(); while(it.hasNext()) { String uid=(String)it.next(); UidPwd dat = (UidPwd)uidpwd_map.get(uid); try { con = DatabaseHandle.getInstance().getConnection(dat.getUid(),dat.getOldPwd()); dao.setUid(dat.getUid()); dao.setNewPwd(dat.getNewPwd()); boolean rtn = dao.dat_updusrDAO(con); if (rtn==false){ System.out.println("Update Oracle user error. user id="+dat.getUid()); trace.debug(adm.getMsg("M219S32W",new String[]{AddConst.BATCH_102})); } } catch (SQLException ex){ trace.debug(adm.getMsg("M219S31W",new String[]{AddConst.BATCH_102})); } } } catch (Exception exp){ trace.debug(adm.getMsg("M219xxxx",new String[]{AddConst.BATCH_102})); System.out.println(exp.toString()); } } /****************************************************************** * 僐儞僼傿僌僼傽僀儖偺僷僗儚乕僪曄峏張棟 * @param int 僐儞僼傿僌僼傽僀儖僞僀僾 * @return * @throws * @version ******************************************************************/ public void updateConfigFile(int type){ String config_file=""; if (type==1){ config_file = AddConst.CONFIG_FILE1; } if (type==2){ config_file =AddConst.CONFIG_FILE2; } Iterator it = uidpwd_map.keySet().iterator(); while(it.hasNext()) { String uid=(String)it.next(); UidPwd dat = (UidPwd)uidpwd_map.get(uid); boolean val = modifyPassWord(config_file,dat.getUid(),dat.getOldPwd(),dat.getNewPwd()); if (val == false){ System.out.println("Update "+config_file+" user error. user id="+dat.getUid()); trace.debug(adm.getMsg("M219S52W",new String[]{AddConst.BATCH_102})); } } } /****************************************************************** * 埫崋壔僷僗儚乕僪僼傽僀儖撉崬 * @param * @return * @throws exception Exception 幚峴帪僄儔乕 * @version ******************************************************************/ public void setFileDataToList(){ uidpwd_map = new HashMap(); try{ String file = AddConst.UIDPWD_FILE_PATH; File tmp = new File(file); boolean yn = tmp.exists(); if(!yn) { System.out.println(file+" does not exist."); } long size = tmp.length(); if (size>0){ BufferedReader in= new BufferedReader(new FileReader(file)); String str = null; FileReader fw=new FileReader(AddConst.UIDPWD_FILE_PATH); BufferedReader bfr=new BufferedReader(fw); String temp=""; while((temp=bfr.readLine())!=null) { String status = temp.substring(21,23); String uid = temp.substring(24,54); String oldpwd = temp.substring(56,120); String newpwd = temp.substring(121,185); if (status.equals("RQ")) { UidPwd dat = new UidPwd(); dat.setUid(uid.trim()); dat.setOldPwd(oldpwd.trim()); dat.setNewPwd(newpwd.trim()); uidpwd_map.put(uid.trim(), dat); } } } else { System.out.println(file+" file size is 0"); } } catch (Exception exp){ System.out.println(exp.toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -