Changeset 7626
- Timestamp:
- Mar 7, 2019, 2:43:04 PM (5 years ago)
- Location:
- trunk/www/filemanager/files
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/filemanager/files/ajax.jsp
r7625 r7626 37 37 import="java.io.Writer" 38 38 import="java.io.Reader" 39 import="java.nio.charset.Charset" 40 import="java.nio.charset.CodingErrorAction" 41 import="java.nio.charset.CharsetEncoder" 42 import="java.nio.charset.CharacterCodingException" 39 43 %> 40 44 <% … … 62 66 else if ("StoreFile".equals(cmd)) 63 67 { 68 String charset = null; 64 69 try 65 70 { 66 71 int size = Values.getInt(request.getParameter("size"), -1); 72 charset = Values.getStringOrNull(request.getParameter("charset")); 73 67 74 dc = sc.newDbControl(); 68 75 File f = File.getById(dc, itemId); 69 76 Reader in = request.getReader(); 70 String charset = f.getCharacterSet();71 77 if (charset == null) 72 78 { 73 charset = "UTF-8"; 74 f.setCharacterSet(charset); 79 charset = Values.getString(f.getCharacterSet(), "UTF-8"); 75 80 } 81 boolean charsetModified = !charset.equals(f.getCharacterSet()); 82 if (charsetModified) f.setCharacterSet(charset); 83 Charset cs = Charset.forName(charset); 84 if (!cs.canEncode()) 85 { 86 throw new UnsupportedOperationException("Encoding is not supported by '" + charset + "'."); 87 } 88 CharsetEncoder encoder = Charset.forName(charset).newEncoder(); 89 encoder.onMalformedInput(CodingErrorAction.REPORT); 90 encoder.onUnmappableCharacter(CodingErrorAction.REPORT); 76 91 Writer toFile = new OutputStreamWriter( 77 f.getUploadStream(false, f.isCompressed()), charset);92 f.getUploadStream(false, f.isCompressed()), encoder); 78 93 int copied = (int)FileUtil.copy(in, toFile); 79 94 if (size >= 0 && copied != size) … … 85 100 toFile.close(); 86 101 dc.commit(); 87 json.put("message", "File saved successfully"); 102 json.put("message", "File saved " + (charsetModified ? " with character set " + charset : " successfully")); 103 } 104 catch (CharacterCodingException ex) 105 { 106 throw new Exception("Save failed: The text contains characters that can't be encoded in '" + charset + "'."); 88 107 } 89 108 catch (Exception ex) 90 109 { 91 ex.printStackTrace();92 110 throw new Exception("Save failed: " + ex.getMessage(), ex); 93 111 } -
trunk/www/filemanager/files/edit_file_data.js
r7604 r7626 28 28 var editFile = {}; 29 29 var originalText = ''; 30 var originalCharset = ''; 30 31 var isModified = false; 31 32 … … 41 42 Events.addEventHandler('filedata', 'keydown', editFile.detectTab); 42 43 Events.addEventHandler('filedata', 'keyup', editFile.detectChanges); 44 Events.addEventHandler('filedata', 'blur', editFile.detectChangesFull); 45 Events.addEventHandler('charset', 'change', editFile.detectChangesFull); 43 46 } 44 47 … … 58 61 frm.filedata.value = request.responseText; 59 62 originalText = frm.filedata.value; 63 originalCharset = frm.charset.value; 60 64 editFile.setModified(false); 61 65 editFile.updateLineNumbers(); … … 123 127 url += '&cmd=StoreFile&item_id='+Data.get('page-data', 'file-id'); 124 128 url += '&size='+frm.filedata.value.length; 129 url += '&charset='+frm.charset.value; 125 130 var request = Ajax.getXmlHttpRequest(); 126 131 request.open("POST", url, true); … … 134 139 if (response.status != 'ok') 135 140 { 136 Forms.showNotification('btnSave', response.message );141 Forms.showNotification('btnSave', response.message, 'bigger-notify'); 137 142 return; 138 143 } … … 155 160 } 156 161 162 editFile.detectChangesFull = function() 163 { 164 var frm = document.forms['file']; 165 var modified = frm.filedata.value != originalText || frm.charset.value != originalCharset; 166 editFile.setModified(modified); 167 168 Doc.addOrRemoveClass('charsetSection','utf8-warning', frm.charset.value != 'UTF-8' && frm.charset.value != originalCharset); 169 } 170 157 171 editFile.detectChanges = function() 158 172 { 159 if (!isModified) 160 { 161 var frm = document.forms['file']; 162 if (frm.filedata.value != originalText) 163 { 164 editFile.setModified(true); 165 } 166 } 167 } 168 173 if (!isModified) editFile.detectChangesFull(); 174 } 169 175 170 176 editFile.detectTab = function(event) -
trunk/www/filemanager/files/edit_file_data.jsp
r6378 r7626 39 39 import="net.sf.basedb.clients.web.util.HTML" 40 40 import="net.sf.basedb.util.Values" 41 import="net.sf.basedb.core.Config" 41 42 import="java.util.List" 42 43 import="java.util.Set" 43 44 import="java.util.HashSet" 45 import="java.nio.charset.Charset" 44 46 %> 45 47 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> … … 74 76 { 75 77 position: absolute; 76 top: 0 em;77 left: 0 em;78 bottom: 0 em;78 top: 0; 79 left: 0; 80 bottom: 0; 79 81 width: 3.6em; 82 padding-top: 2px; 80 83 padding-right: 0.4em; 81 84 text-align: right; … … 90 93 { 91 94 position: absolute; 92 top: 0em;95 top: 2px; 93 96 left: 4em; 94 bottom: 0 em;95 right: 0 em;97 bottom: 0; 98 right: 0; 96 99 margin-left: 2px; 97 100 } … … 101 104 width: 100%; 102 105 height: 100%; 103 border: 0px; 104 margin: 0px; 105 padding: 0px; 106 border: 0; 107 margin: 0; 108 padding: 0; 109 } 110 111 .bigger-notify 112 { 113 width: 30em; 114 } 115 116 #charsetSection 117 { 118 top: auto; 119 bottom: 0; 120 height: 2.4em; 121 left: auto; 122 right: calc(50% + 7em); 123 z-index: 2; 124 } 125 126 #nonUtf8Warning 127 { 128 visibility: hidden; 129 } 130 131 #charsetSection.utf8-warning #nonUtf8Warning 132 { 133 visibility: visible; 106 134 } 107 135 </style> … … 125 153 >Loading file; please wait...</textarea> 126 154 </div> 155 </div> 156 157 <div id="charsetSection" class="absolutefull"> 158 <b>Character set</b> 159 <select name="charset" id="charset"> 160 <% 161 String currentCharset = Values.getString(file.getCharacterSet(), "UTF-8"); 162 int numCommon = Config.getCommonCharsets().size(); 163 int i = 0; 164 boolean hasSelected = false; 165 for (String charset : Config.getAllCharsets()) 166 { 167 // The UTF-32 charset is not working well in browsers and we do not include non-encoding character sets 168 if (charset.startsWith("UTF-32") || !Charset.forName(charset).canEncode()) continue; 169 boolean selected = false; 170 if (!hasSelected) 171 { 172 selected = charset.equalsIgnoreCase(currentCharset); 173 hasSelected |= selected; 174 } 175 %> 176 <option value="<%=charset%>" <%=selected ? "selected" : ""%> 177 <%=i==numCommon ? "style=\"border-top: 1px solid #666666;\"" : "" %>><%=charset%> 178 <% 179 i++; 180 } 181 if (!hasSelected && currentCharset != null) 182 { 183 %> 184 <option value="<%=currentCharset%>" selected><%=currentCharset%> 185 <% 186 } 187 %> 188 </select> 189 <span id="nonUtf8Warning"><img src="../../images/warning.png" 190 title="The selected character set may not be able to encode all characters"></span> 127 191 </div> 128 192 </form>
Note: See TracChangeset
for help on using the changeset viewer.