# HG changeset patch # User slarti # Date 1065003183 -7200 # Node ID 6002ea661acd759e4e8a6ae8ea02bedaf985f08b # Parent 7a237ba63a3d7753f0e201fca65135b71bafd0f0 Added the method getTextFile(...) and used it in the processRequest(...) method. The file compiled a week ago but here I have no servlet-environment to test it again... diff -r 7a237ba63a3d -r 6002ea661acd servlet/src/digilib/servlet/Texter.java --- a/servlet/src/digilib/servlet/Texter.java Tue Sep 16 21:02:48 2003 +0200 +++ b/servlet/src/digilib/servlet/Texter.java Wed Oct 01 12:13:03 2003 +0200 @@ -8,7 +8,7 @@ under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + Please read license.txt for the full details. A copy of the GPL may be found at http://www.gnu.org/copyleft/lgpl.html @@ -38,7 +38,7 @@ import digilib.io.TextFile; /** Servlet for displaying text - * + * * @author casties * */ @@ -135,62 +135,47 @@ processRequest(request, response); } - protected void processRequest( - HttpServletRequest request, - HttpServletResponse response) - throws ServletException, IOException { - /* - * request parameters - */ + protected void processRequest( + HttpServletRequest request, + HttpServletResponse response) + throws ServletException, IOException { - DigilibRequest dlRequest = - (DigilibRequest) request.getAttribute("digilib.servlet.request"); - - try { - - /* - * find the file to load/send - */ + /* + * request parameters + */ + DigilibRequest dlRequest = + (DigilibRequest) request.getAttribute("digilib.servlet.request"); + try { - // get PathInfo - String loadPathName = dlRequest.getFilePath(); - // find the file(set) - TextFile fileToLoad = - (TextFile) dirCache.getFile( - loadPathName, - dlRequest.getPn(), - FileOps.CLASS_TEXT); - if (fileToLoad == null) { - throw new FileOpException( - "File " - + loadPathName - + "(" - + dlRequest.getPn() - + ") not found."); - } + /* + * find the file to load/send + */ + if(this.getTextFile(dlRequest,"/txt") != null) { + servletOp.sendFile(this.getTextFile(dlRequest,"txt").getFile(), response); + } else if(this.getTextFile(dlRequest,"") != null) { + servletOp.sendFile(this.getTextFile(dlRequest,"").getFile(), response); + } else { + ServletOps.htmlMessage("No Text-File!", response); + } - /* - * do something with the file - */ - - + } catch (FileOpException e) { + util.dprintln(1, "ERROR: File IO Error: " + e); + try { + ServletOps.htmlMessage("ERROR: File IO Error: "+ e, response); + } catch (FileOpException ex) { } // so we don't get a loop + } + } - /* - * send the result - */ - - servletOp.sendFile(fileToLoad.getFile(), response); - - - } catch (FileOpException e) { - util.dprintln(1, "ERROR: File IO Error: " + e); - try { - ServletOps.htmlMessage("ERROR: File IO Error: " + e, response); - } catch (FileOpException ex) { - } // so we don't get a loop - } - - } - + /** + * Looks for a file in the given subDirectory. + * @param dlRequest The received request which has the file path. + * @param subDirectory The subDirectory of the file path where the file should be found. + * @return The wanted Textfile or null if there wasn't a file. + */ + private TextFile getTextFile(DigilibRequest dlRequest,String subDirectory) { + String loadPathName = dlRequest.getFilePath() + subDirectory; + // find the file(set) + return (TextFile) dirCache.getFile(loadPathName,dlRequest.getPn(),FileOps.CLASS_TEXT); + } }