Changeset 35721
- Timestamp:
- 2021-11-08T15:33:27+13:00 (2 years ago)
- Location:
- other-projects/the-macronizer/trunk/src/java/web/servlets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/the-macronizer/trunk/src/java/web/servlets/DirectInput.java
r35720 r35721 139 139 } 140 140 141 logger. info("Macron restoration succeeded. Input: " + fragment + " | Output: " + restoredFragment);141 logger.debug("Macron restoration succeeded. Input: " + fragment + " | Output: " + restoredFragment); 142 142 } 143 143 catch (Exception ex) -
other-projects/the-macronizer/trunk/src/java/web/servlets/FileUpload.java
r35720 r35721 13 13 import javax.servlet.http.HttpServletResponse; 14 14 15 import com.google.gson.Gson; 16 import com.google.gson.stream.JsonWriter; 17 15 18 import monogram.plugin.PluginConfiguration; 16 19 import monogram.plugin.PluginManager; … … 25 28 26 29 /** 30 * Represents a servlet for macronising the contents of a file. 27 31 * @author University of Waikato - Te Whare WÄnanga o Waikato 28 * @version 1.029 * @since 32 * @version 2.0 33 * @since 2014-11-20 30 34 */ 31 35 public class FileUpload extends HttpServlet { … … 33 37 // Create an instance of the logger object defined for the DirectInput servlet in log4j.properties. 34 38 private static final Logger logger = Logger.getLogger(web.servlets.DirectInput.class.getName()); 39 40 private final Gson gsonInstance = new Gson(); 35 41 36 42 private File tmpdir; … … 115 121 116 122 restoredFile = pluginManager.run(configuration); 117 request.setAttribute("file", restoredFile); 118 request.setAttribute("fileType", configuration.getFileType()); 119 request.setAttribute("charsetEncoding", "utf-8"); 120 request.setAttribute("filename", properties.getFilename()); 121 request.setAttribute("preserveMacrons", properties.getPreserveExistingMacrons()); 122 request.setAttribute("options", properties.getShowAdvancedOptions()); 123 124 forward(properties.getJspForwardPath() + "/main.jsp", request, response); 123 124 if (properties.getOutputType() == OutputType.Json) 125 { 126 response.setContentType("application/json; charset=UTF-8"); 127 JsonWriter writer = gsonInstance.newJsonWriter(response.getWriter()); 128 writer.beginObject(); 129 130 writer.name("fileName"); 131 writer.value(properties.getFileName()); 132 133 writer.name("filePath"); 134 writer.value(restoredFile.getPath()); 135 136 writer.name("fileType"); 137 writer.value(configuration.getFileType()); 138 139 writer.endObject(); 140 writer.flush(); 141 } 142 else 143 { 144 request.setAttribute("file", restoredFile); 145 request.setAttribute("fileType", configuration.getFileType()); 146 request.setAttribute("charsetEncoding", "utf-8"); 147 request.setAttribute("filename", properties.getFileName()); 148 request.setAttribute("preserveMacrons", properties.getPreserveExistingMacrons()); 149 request.setAttribute("options", properties.getShowAdvancedOptions()); 150 151 forward(properties.getJspForwardPath() + "/main.jsp", request, response); 152 } 125 153 } 126 154 catch (UnsupportedOperationException uoex) … … 305 333 { 306 334 final File file = properties.getFile(); 307 final String fileType = properties.getFileType().equals("(detect automatically)") ? FileUtil.guessFileType(file) : properties.getFileType(); 308 final String charsetEncoding = properties.getCharsetEncoding().equals("(detect automatically)") ? "utf8" : properties.getCharsetEncoding(); 335 336 String fileType = properties.getFileType(); 337 if (fileType == null || fileType.equals("(detect automatically)")) 338 { 339 fileType = FileUtil.guessFileType(file); 340 } 341 342 String charsetEncoding = properties.getCharsetEncoding(); 343 if (charsetEncoding == null || charsetEncoding.equals("(detect automatically)")) 344 { 345 charsetEncoding = "utf8"; 346 } 309 347 310 348 final PluginConfiguration configuration = new PluginConfiguration(); … … 328 366 private OutputType outputType; 329 367 368 public Properties() { 369 this.outputType = OutputType.JspRedirect; 370 } 371 330 372 public File getFile() { 331 373 return file; 332 374 } 333 375 334 public String getFile name() {376 public String getFileName() { 335 377 return filename; 336 378 }
Note:
See TracChangeset
for help on using the changeset viewer.