Changeset 31962

Show
Ignore:
Timestamp:
12.09.2017 17:19:04 (2 months ago)
Author:
rmw36
Message:

Macronizer changes: 1. adding an ethical disclaimer to the main web page (temporarily still in English for the Maori jsp file too, but Te Taka will be translating this.) 2. Adding more logging to the macronizer. This required setting up a log4j.properties file (and adding its jar file copied from GS3), and modifying the existing java code DirectInput? and FileUpload? to make calls to logger. Modifications to build.xml to copy the new template log4j.properties.in file into web/WEB-INF/classes where the log4j.props needs to live. 3. Corrected the svn mime-type property on build.xml so that it's no longer mistaken for a binary file

Location:
other-projects/the-macronizer/trunk
Files:
2 added
6 modified

Legend:

Unmodified
Added
Removed
  • other-projects/the-macronizer/trunk/build.xml

    • Property svn:mime-type changed from application/xml to text/xml
    r30063 r31962  
    99  <property name="build.dir.exp"   location="web" /> 
    1010  <property name="lib.dir.exp"  location="web/WEB-INF/lib" /> 
     11  <property name="webinf.dir"  location="web/WEB-INF" /> 
    1112   
    1213  <!-- 
     
    4041  </target> 
    4142     
    42   <target depends="init" name="build"> 
     43  <target name="build" depends="init"> 
    4344    <javac source="${javac.source}" target="${javac.target}" debug="${javac.debug}" 
    4445       encoding="utf-8" 
     
    4950    <path refid="classpath.exp"/> 
    5051    <pathelement location="src/jars/servlet-api.jar"/> 
    51     <pathelement path="src/java"/>             
     52    <pathelement path="src/java"/> 
     53    <pathelement path="webinf.dir"/> 
    5254      </classpath> 
    5355    </javac> 
     56 
     57    <!-- http://ant.apache.org/manual/Tasks/copy.html 
     58     By default, files are only copied if the source file is newer than the destination file, 
     59     or when the destination file does not exist. However, you can explicitly overwrite files 
     60     with the overwrite attribute.--> 
     61    <copy file="${build.dir.exp}/log4j.properties.in" tofile="/greenstone/greenstone3/web/WEB-INF/classes/log4j.properties"/> 
     62 
     63    <!-- mkdir Creates a directory. Also non-existent parent directories are created, 
     64     when necessary. Does nothing if the directory already exist. --> 
     65    <mkdir dir="${build.dir.exp}/logs"/> 
    5466  </target> 
    5567 
    5668     
    57   <target depends="build" name="war"> 
     69  <target name="war" depends="build"> 
    5870    <jar destfile="${dist.filename.exp}">   
    5971      <fileset dir="${build.dir.exp}" /> 
  • other-projects/the-macronizer/trunk/src/java/web/servlets/DirectInput.java

    r30061 r31962  
    2323import monogram.plugin.PluginConfiguration; 
    2424import monogram.plugin.PluginManager; 
     25import org.apache.log4j.*; 
    2526 
    2627/** 
     
    3233    private final String UNEXPECTED_ERROR = "An unexpected error has occurred. Please try again or contact the web administrator if the problem persists."; 
    3334    private final String UTF8_ENCODING = "utf-8"; 
    34     public static boolean DI; // This will be used in a test in the mongramRestorer to add html to highligth the changes on the webpage output.  
     35    public static boolean DI; // This will be used in a test in the mongramRestorer to add html to highlight the changes on the webpage output.  
    3536    private File tmpdir; 
     37    //Create an instance of the Logger object created for this class in log4j.properties 
     38    static Logger logger = Logger.getLogger(web.servlets.DirectInput.class.getName()); 
    3639 
    3740    @Override 
     
    8689        File file = File.createTempFile("mi-tmp-", ".txt", tmpdir); 
    8790        write(file, "utf-8", fragment); 
    88  
     91         
    8992        //Create a fileview 
    9093        PluginConfiguration configuration = new PluginConfiguration(); 
     
    107110            RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(path + "/main.jsp"); 
    108111            dispatcher.forward(request, response); 
     112        //Generate an "info" level logger message including the input('fragment') and output('restoredFragment') 
     113        logger.info("Input:"+fragment+"Output: "+restoredFragment); 
    109114        } catch (Exception e) { 
    110115           request.setAttribute("errorMessage", UNEXPECTED_ERROR); 
    111116           forward(path + "/error.jsp", request, response); 
    112117        } finally { 
    113             file.delete(); 
    114         if (restoredFile != null) { 
    115         restoredFile.delete(); 
    116         } 
     118    file.delete(); 
     119      if (restoredFile != null) { 
     120        restoredFile.delete(); 
     121      } 
    117122        } 
    118123    } 
  • other-projects/the-macronizer/trunk/src/java/web/servlets/FileUpload.java

    r30062 r31962  
    11package web.servlets; 
    22 
     3import java.io.BufferedReader; 
    34import java.io.File; 
     5import java.io.FileReader; 
    46import java.io.IOException; 
     7import java.lang.StringBuilder; 
    58import java.util.List; 
    69import javax.servlet.RequestDispatcher; 
     
    1619import util.FileUtil; 
    1720import monogram.plugin.PluginManager; 
     21import org.apache.log4j.*; 
    1822 
    1923/** 
     
    2529 
    2630    private File tmpdir; 
     31 
     32    //Create an instance of the Logger object created for this class in log4j.properties             
     33    static Logger logger = Logger.getLogger(web.servlets.DirectInput.class.getName()); 
    2734 
    2835    @Override 
     
    7784            request.setAttribute("options", properties.getOptions()); 
    7885            forward(address + "/main.jsp", request, response); 
     86        String outputText = stringFromFile(restoredFile); 
     87        logger.error("Output:"+outputText); 
    7988        } catch (UnsupportedOperationException e) { 
    8089            FileUtil.deleteFile(restoredFile); 
     
    126135                    requestData.setFile(file); 
    127136                    requestData.setFilename(item.getName()); 
     137            String logText=stringFromFile(file); 
     138            logger.error("Input:"+logText); 
    128139                } 
    129140            } 
     
    133144        return requestData; 
    134145    } 
    135  
     146     
     147    private String stringFromFile(File file)throws IOException{ 
     148    BufferedReader reader = new BufferedReader(new FileReader(file)); 
     149    String line = null; 
     150    StringBuilder sb = new StringBuilder(); 
     151    try{ 
     152        while((line=reader.readLine())!=null){ 
     153        sb.append(line); 
     154        } 
     155        return sb.toString(); 
     156    } 
     157    catch (Exception e){ 
     158        e.printStackTrace(); 
     159    } 
     160    finally{ 
     161        reader.close(); 
     162    } 
     163    } 
     164     
    136165    private PluginConfiguration configure(Properties properties) { 
    137166        final File file = properties.getFile(); 
  • other-projects/the-macronizer/trunk/web/index.jsp

    r29855 r31962  
    55--%> 
    66 
    7 <%@page contentType="text/html" pageEncoding="UTF-8"%> 
    8 <!DOCTYPE html> 
    9 <html> 
    10     <head> 
    11         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    12         <title>JSP test Page</title> 
    13     </head> 
    14     <body> 
    15         <h1>Hello World!</h1> 
    16     </body> 
    17 </html> 
     7<% response.sendRedirect("jsp/mi/main.jsp"); %> 
  • other-projects/the-macronizer/trunk/web/jsp/en/footer.jsp

    r29855 r31962  
    2121</div> 
    2222<div id="copyright"> 
     23    <p>This website collects simple usage logs which will be used for development purposes only. No details which could be used to identify individuals will be collected and the data will be kept securely at the University of Waikato. If you do not wish for your activity to be included, click <a href="mailto:tetaka@waikato.ac.nz">here</a> to notify Dr. Te Taka Keegan. </p> 
    2324    <p class="note">Copyright &copy; 2014 University of Waikato</p> 
    2425</div> 
  • other-projects/the-macronizer/trunk/web/jsp/mi/footer.jsp

    r29855 r31962  
    2121</div> 
    2222<div id="copyright"> 
     23    <p>This website collects simple usage logs which will be used for development purposes only. No details which could be used to identify individuals will be collected and the data will be kept securely at the University of Waikato. If you do not wish for your activity to be included, click <a href="mailto:tetaka@waikato.ac.nz">here</a> to notify Dr. Te Taka Keegan.</p>  
    2324    <p class="note">Manatārua &copy; 2011 nā John Cocks</p> 
    2425</div>