spring

  1 package ese.modify;
  2 import java.io.BufferedReader;
  3 import java.io.File;
  4 import java.io.FileInputStream;
  5 import java.io.FileNotFoundException;
  6 import java.io.FileOutputStream;
  7 import java.io.IOException;
  8 import java.io.InputStreamReader;
  9 import java.io.OutputStreamWriter;
 10 
 11 import javax.annotation.Resource;
 12 import javax.servlet.http.HttpServletRequest;
 13 import javax.servlet.http.HttpServletResponse;
 14 
 15 import org.apache.log4j.Logger;
 16 import org.springframework.stereotype.Controller;
 17 import org.springframework.web.bind.annotation.RequestMapping;
 18 import org.springframework.web.bind.annotation.RequestMethod;
 19 import org.springframework.web.bind.annotation.RequestParam;
 20 import org.springframework.web.bind.annotation.ResponseBody;
 21 
 22 import ese.configure.Configuration;
 23 import ese.configure.ConfigurationManager;
 24 import ese.controller.BaseController;
 25 
 26 @Controller
 27 public class Modifyconf2 extends BaseController{
 28     //private org.codehaus.jackson.map.ObjectMapper jsonMapper = new org.codehaus.jackson.map.ObjectMapper();
 29     
 30     //@Resource
 31     private ConfigurationManager configuremanager;
 32     
 33     @RequestMapping(value="read.do",method=RequestMethod.GET)
 34     public @ResponseBody
 35     String read(@RequestParam("readpath") String readpath,HttpServletRequest request,HttpServletResponse response) throws IOException{
 36         
 37         //String url2 = ResourceUtils.findResource(readpath);
 38         Configuration conf = configuremanager.getConfiguration();
 39         String path = conf.getProperty("configFilePath");
 40         //String url2 = path + readpath;
 41         String url2 =  readpath;
 42         
 43         String content=readtxt2(url2);
 44         //content=readtxt2(url2);
 45 /*        try {
 46             jsonMapper.writeValue(response.getOutputStream(), "success");
 47             } catch (Exception e) {
 48             logger.debug("in modifyconf.do jsonMapper.writeValue wrong.");
 49         } */
 50     
 51         return content;
 52     }
 53     
 54     @RequestMapping(value="modify.do",method=RequestMethod.GET)
 55     public @ResponseBody
 56     String modify(@RequestParam("modifypath") String modifypath,@RequestParam("content") String content,HttpServletRequest request,HttpServletResponse response) throws IOException{
 57 
 58         Configuration conf = configuremanager.getConfiguration();
 59         String path = conf.getProperty("configFilePath");
 60         String url2 = path + modifypath;
 61         
 62         //String url = ResourceUtils.findResource(modifypath);
 63         savetxt(url2,content);
 64         return "Success";
 65     }
 66     
 67     private void savetxt(String url,String content) {
 68         File file=new File(url);
 69         OutputStreamWriter outputStreamWriter = null;
 70         try {
 71             outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file),"UTF-8");
 72         } catch (Exception e) {
 73             // TODO Auto-generated catch block
 74             e.printStackTrace();
 75         }
 76         try {
 77             outputStreamWriter.write(content);
 78             outputStreamWriter.close();
 79         
 80         } catch (IOException e) {
 81             // TODO Auto-generated catch block
 82             e.printStackTrace();
 83         }
 84     
 85     }
 86     
 87     private String readtxt2(String url){
 88         BufferedReader rd = null;
 89         try {
 90             rd = new BufferedReader(new InputStreamReader(new FileInputStream(url)));
 91         } catch (FileNotFoundException e1) {
 92             // TODO Auto-generated catch block
 93             e1.printStackTrace();
 94         }
 95         StringBuffer sb = new StringBuffer();
 96         String line;
 97         try {
 98             while ((line = rd.readLine()) != null)
 99             {
100                 sb.append(line);
101                 
102                 sb.append("\r\n");
103                 //sb.append(rd.)
104             }
105         }catch (Exception e) {
106             // TODO Auto-generated catch block
107             e.printStackTrace();
108         }
109         try {
110             rd.close();
111         } catch (IOException e) {
112             // TODO Auto-generated catch block
113             e.printStackTrace();
114         }
115         line= sb.toString();
116         return line;
117     }
118 
119     
120 
121 }
  1 <!DOCTYPE html>
  2 <html lang="en">
  3   <head>
  4     <meta charset="utf-8">
  5     <title>修改配置</title>
  6     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7     <meta name="keywords" content="amdin editor" />
  8     <meta name="description" content="" />
  9     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 10     
 11 <style type="text/css" media="screen">
 12 #editor{
 13      margin:30px;
 14     height: 500px;
 15     width: 90%;
 16     position: absolute;
 17     z-index:1;
 18 
 19 }
 20 .inputclass{
 21 border-bottom-style:none;
 22 border-top-style:none;border-left-style:none;
 23 border-right-style:none;
 24 background:transparent;
 25 }
 26 li, li a
 27 {font-family: Arial, Sans-Serif;font-size: 15px;font-weight: bold;color: #525252;text-decoration: none;}
 28 #dropdown_nav
 29 {width:100%;padding: 0px;display: inline-block;list-style: none;-moz-box-shadow: inset 0px 0px 1px #fff;-webkit-box-shadow: inset 0px 0px 1px #fff;border: 1px solid #ccc;-moz-border-radius: 5px;-webkit-border-radius: 5px;background: #e2e2e2;background: -moz-linear-gradient(#f3f3f3, #e2e2e2);background: -webkit-gradient(linear, 0 0, 0 100%, from(#f3f3f3), to(#e2e2e2));}
 30 #dropdown_nav li
 31 {z-index:2;padding: 10px 0px 9px 0px;float: left;position: relative;display: inline-block;}
 32 #dropdown_nav li a
 33 {padding: 10px 15px 10px 15px;text-shadow: -1px 1px 0px #f6f6f6;-moz-box-shadow: inset 0px 0px 1px #fff;-webkit-box-shadow: inset 0px 0px 1px #fff;border-right: 1px solid #ccc;}
 34 #dropdown_nav li a: hover
 35 {background: #f9f9f9;background: -moz-linear-gradient(#f9f9f9, #e8e8e8);background: -webkit-gradient(linear, 0 0, 0 100%, from(#f9f9f9), to(#e8e8e8));}
 36 #dropdown_nav li a: active
 37 {background: #e2e2e2;background: -moz-linear-gradient(#e2e2e2, #f3f3f3);background: -webkit-gradient(linear, 0 0, 0 100%, from(#e2e2e2), to(#f3f3f3));}
 38 #dropdown_nav li a.first
 39 {-moz-border-radius: 5px 0px 0px 5px;-webkit-border-radius: 5px 0px 0px 5px;}
 40 #dropdown_nav .sub_nav
 41 {width: 150px;padding: 0px;position: absolute;top: 38px;left: 0px;border: 1px solid #ccc;background: #e2e2e2;}
 42 #dropdown_nav .sub_nav li
 43 {width: 150px;padding: 0px;}
 44 #dropdown_nav .sub_nav li a
 45 {display: block;border-bottom: 1px solid #ccc;background: -moz-linear-gradient(#f3f3f3, #e2e2e2);background: -webkit-gradient(linear, 0 0, 0 100%, from(#f3f3f3), to(#e2e2e2));}
 46 #dropdown_nav .sub_nav li a: hover
 47 {background: #f9f9f9;background: -moz-linear-gradient(#f9f9f9, #e8e8e8);background: -webkit-gradient(linear, 0 0, 0 100%, from(#f9f9f9), to(#e8e8e8));}
 48 #dropdown_nav .sub_nav li a: active
 49 {background: #e2e2e2;background: -moz-linear-gradient(#e2e2e2, #f3f3f3);background: -webkit-gradient(linear, 0 0, 0 100%, from(#e2e2e2), to(#f3f3f3));}
 50  </style>
 51   </head>
 52 
 53   <body>
 54  
 55 <table  style="width:100%">
 56        <tr height="75%">
 57                <td height="100%">
 58                 <ul id="dropdown_nav">
 59                     <li><a href="#">字体大小</a>
 60                         <ul class="sub_nav">
 61                             <li><a href="#" onclick="fontsize1('10px')">10px</a></li>
 62                             <li><a href="#" onclick="fontsize1('12px')">12px</a></li>
 63                             <li><a href="#" onclick="fontsize1('14px')">14px</a></li>
 64                             <li><a href="#" onclick="fontsize1('16px')">16px</a></li>
 65                             <li><a href="#" onclick="fontsize1('18px')">18px</a></li>
 66                             <li><a href="#" onclick="fontsize1('20px')">20px</a></li>
 67                         </ul>
 68                     </li>
 69                     <li><a href="#">文件</a>
 70                         <ul class="sub_nav">
 71                             <li><a href="#" onclick="read('url.txt')">url.txt</a></li>
 72                             <li><a href="#" onclick="read('config.properties')">config.properties</a></li>
 73                             <li><a href="#" onclick="read('websitesinfo.txt')">websitesinfo.txt</a></li>
 74                         </ul>
 75                     </li>
 76                     <li><a href="#" onclick="modify()">保存</a></li>
 77                     <li><a href="#" onclick="edit()">编辑</a></li>
 78                     <li>*修改的文件名:<input id="content" class="inputclass" readonly="readonly"></input> </li>
 79                 </ul>
 80                    <div id="editor">
 81     
 82                 </div>
 83                </td>
 84        </tr>
 85        
 86 </table>
 87  
 88 <script type="text/javascript" src="resources/js/jquery-1.9.1.js"></script>
 89 <script type="text/javascript" src="resources/js/jquery-ui-1.10.3.custom.js"></script>
 90 <script src="resources/ace-0.2.0/src/ace.js" type="text/javascript" charset="utf-8"></script>
 91 <script src="resources/ace-0.2.0/src/theme-merbivore.js" type="text/javascript" charset="utf-8"></script>
 92 <script src="resources/ace-0.2.0/src/mode-javascript.js" type="text/javascript" charset="utf-8"></script>
 93 <script src="resources/ace-0.2.0/src/theme-idle_fingers.js" type="text/javascript" charset="utf-8"></script>
 94 <script>
 95 var editor = ace.edit("editor");
 96 window.onload = function() {
 97     $("#content").val(null);
 98     editor.setTheme("ace/theme/merbivore");
 99     editor.setShowPrintMargin(false);
100     editor.setReadOnly(true);
101     //doc:js plain java mode:text java textile javascript theme:idle_fingers dawn twilight
102     //split:none below beside 
103     //highlight_active show_gutter:jishu show_print_margin:shuxian enable_behaviours
104     var JavaScriptMode = require("ace/mode/text").Mode;
105     editor.getSession().setMode(new JavaScriptMode());
106     //alert(editor.session.getValue());
107     //editor.session.setValue("the new text here");
108     //editor.getSession().on('change', function(e) {
109     // e.type, etc
110     //});
111     //editor.find('foo');
112     //editor.replace('bar');
113     //editor.replaceAll('bar');
114     //editor.session.getLength();
115     //editor.gotoLine(lineNumber);
116     //editor.insert("Something cool");
117     //editor.session.getTextRange(editor.getSelectionRange()); dedao xuanzhong de
118     //editor.selection.getCursor();
119     //editor.getSession().setUseWrapMode(true);
120     document.getElementById('editor').style.fontSize='14px';
121 };
122 function fontsize1(size){
123     document.getElementById('editor').style.fontSize=size;
124 }
125 
126 function edit(){ 
127     var path=document.getElementById("content").value;
128     if(path==null || path==""){}
129     else{
130     editor.setReadOnly(false);}
131     }
132 
133 
134 function  read(readpath){
135     editor.setReadOnly(true);
136     $("#content").val(readpath);
137      $.ajax({url:"read.do?readpath="+readpath,
138         success:
139         function(data){
140         editor.session.setValue(data);
141         //editor.insert(data);
142         
143     }});  
144     }
145    
146    
147 function modify(){
148     var modifypath=document.getElementById("content").value;
149     //alert(modifypath);
150     //alert(modifypath);
151     if(!confirm("你确定要修改"+modifypath+"吗?")){
152     
153     }
154     else{
155      var content=editor.session.getValue();
156     editor.setReadOnly(true);
157       $.ajax({
158          url: "modify.do",
159          data:{modifypath:modifypath,
160               content:content},
161          success:function(data){
162          
163              }
164      });
165     }
166    }
167 $(function() {
168     //We initially hide the all dropdown menus
169     $('#dropdown_nav li').find('.sub_nav').hide();
170     //When hovering over the main nav link we find the dropdown menu to the corresponding link.
171     $('#dropdown_nav li').hover(function() {
172         //Find a child of 'this' with a class of .sub_nav and make the beauty fadeIn.
173         $(this).find('.sub_nav').fadeIn(100);
174     }, function() {
175         //Do the same again, only fadeOut this time.
176         $(this).find('.sub_nav').fadeOut(50);
177     });
178 });
179 
180 </script>
181 </body>
182 </html>

 

posted @ 2013-11-28 15:54  蓦然回首的包子  阅读(180)  评论(0)    收藏  举报