//普通字典 private void makeGeneralDictinary(ServletContextEvent event){ // TODO Auto-generated method stub //取得appliction上下文 ServletContext context = event.getServletContext(); ApplicationContext ctx =WebApplicationContextUtils.getRequiredWebApplicationContext(context); //取得特定bean //spsxtDictionaryDao SpsxtDictionaryDao dao=(SpsxtDictionaryDao)ctx.getBean("spsxtDictionaryDao"); try { List<Map<String,String>> list =(List<Map<String,String>>)dao.querySpsxtDictionary(); String prevDmlb=""; List dmList=new ArrayList(); for(Map<String,String> theMap :list){ String currentDmlb=theMap.get("dmlb"); if(!currentDmlb.equals(prevDmlb)){//新的代码开始 //将dmList中的内容转换为JSON格式,然后写入到文件中,同时再次实例化dmList,为处理下一个代码表做准备 if(!prevDmlb.equals("")){//排除首次 saveJSON2File(dmList,prevDmlb); } prevDmlb=currentDmlb;//保存这个新的代码类别 dmList=new ArrayList(); }//end if(dmlb.equals(prevDmlb) dmList.add(new SpsxtDictionaryVO(theMap.get("dm"),theMap.get("dmyy"),theMap.get("pym"))); }//end for //保存最后一个代码表 saveJSON2File(dmList,prevDmlb); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
//Tree字典 private void makeTreeDictinary(ServletContextEvent event){ // TODO Auto-generated method stub //取得appliction上下文 ServletContext context = event.getServletContext(); ApplicationContext ctx =WebApplicationContextUtils.getRequiredWebApplicationContext(context); //取得特定bean //spsxtDictionaryDao SpsxtDictionaryDao dao=(SpsxtDictionaryDao)ctx.getBean("spsxtDictionaryDao"); List<TreeJson> spsxtTree=null; try { spsxtTree=dao.getQueryIndustryTree();//行业类别Tree saveJSONTree2File(TreeJson.formatTree(spsxtTree),"IndustryTree");//保存到代码表文件中 spsxtTree=dao.getQueryResolutionTree();//分辨率Tree saveJSONTree2File(TreeJson.formatTree(spsxtTree),"ResolutionTree");//保存到代码表文件中 spsxtTree=dao.getQuerySightTree();//是否夜视Tree saveJSONTree2File(TreeJson.formatTree(spsxtTree),"SighTree");//保存到代码表文件中 spsxtTree=dao.getQueryPropertyTree();//属性Tree saveJSONTree2File(TreeJson.formatTree(spsxtTree),"PropertyTree");//保存到代码表文件中 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
//为客户端翻译用的js对象 private void makeJavascriptObject(ServletContextEvent event){ // TODO Auto-generated method stub //取得appliction上下文 ServletContext context = event.getServletContext(); ApplicationContext ctx =WebApplicationContextUtils.getRequiredWebApplicationContext(context); //取得特定bean //spsxtDictionaryDao SpsxtDictionaryDao dao=(SpsxtDictionaryDao)ctx.getBean("spsxtDictionaryDao"); try { List<String> list =(List<String>)dao.getQueryForTranslation(); StringBuilder sb=new StringBuilder(); for(int i=0;i<list.size();i++){ sb.append(list.get(i)+"\n"); } //Gson gson = new Gson(); String jsonList=sb.toString();//转换为json字符串 System.out.println(jsonList); //保存js脚本代码 OutputStreamWriter writer; String fileName=dictPath+"/js/"+"jf_sxtScript.js"; writer = new OutputStreamWriter(new FileOutputStream(fileName),"UTF-8"); System.out.println(fileName+"---js脚本写入成功!!!"); writer.write(jsonList); writer.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }