Mercurial > hg > digilib-old
changeset 56:2ea78a56ecf8
Use system specific pathSeparator for documents paths (; on Win).
Fix Error accessing files when only one document path was specified.
(ROC)
author | robcast |
---|---|
date | Tue, 27 Aug 2002 12:29:07 +0200 |
parents | 1a0b955ef254 |
children | be2a8a672344 |
files | servlet/src/digilib/io/FileOps.java servlet/src/digilib/io/XMLListLoader.java servlet/src/digilib/servlet/DocumentBean.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/ServletOps.java |
diffstat | 5 files changed, 39 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/io/FileOps.java Tue Aug 27 12:19:24 2002 +0200 +++ b/servlet/src/digilib/io/FileOps.java Tue Aug 27 12:29:07 2002 +0200 @@ -118,18 +118,11 @@ util.dprintln(4, "getVariantFile ("+dirs+", "+fn+", "+n+")"); File f = null; - int start = 0; - int inc = 1; - int end = dirs.length; - if (fwd == false) { - start = dirs.length - 1; - inc = -1; - end = 0; - } + int nvar = dirs.length; - for (int i = start; i != end; i += inc) { + for (int i = 0; i < nvar; i++) { try { - f = getFile(dirs[i]+fn, n); + f = getFile(dirs[(fwd) ? i : (nvar-i-1)]+fn, n); } catch (FileOpException e) { f = null; } @@ -149,18 +142,11 @@ util.dprintln(4, "getNumFilesVariant ("+dirs+", "+fn+")"); int nf = 0; - int start = 0; - int inc = 1; - int end = dirs.length; - if (fwd == false) { - start = dirs.length - 1; - inc = -1; - end = 0; - } + int nvar = dirs.length; - for (int i = start; i != end; i += inc) { + for (int i = 0; i < nvar; i++) { try { - nf = getNumFiles(dirs[i]+fn); + nf = getNumFiles(dirs[(fwd) ? i : (nvar-i-1)]+fn); } catch (FileOpException e) { nf = 0; }
--- a/servlet/src/digilib/io/XMLListLoader.java Tue Aug 27 12:19:24 2002 +0200 +++ b/servlet/src/digilib/io/XMLListLoader.java Tue Aug 27 12:29:07 2002 +0200 @@ -53,7 +53,7 @@ private Hashtable listData; private Stack nameSpace; - + public Hashtable getData() { return listData; }
--- a/servlet/src/digilib/servlet/DocumentBean.java Tue Aug 27 12:19:24 2002 +0200 +++ b/servlet/src/digilib/servlet/DocumentBean.java Tue Aug 27 12:29:07 2002 +0200 @@ -55,19 +55,10 @@ * basedir-list : List of document directories */ String bl = servletOp.tryToGetInitParam("basedir-list", null); - if ((bl != null)&&(bl.length() > 0)) { - // split list into directories - StringTokenizer dirs = new StringTokenizer(bl, ":"); - int n = dirs.countTokens(); - if (n > 0) { - // add directories into array - baseDirs = new String[n]; - for (int i = 0; i < n; i++) { - baseDirs[i] = dirs.nextToken(); - } - } - util.dprintln(3, "basedir-list: "+bl); - } + // split list into directories + baseDirs = servletOp.tryToGetPathArray(bl, baseDirs); + util.dprintln(3, "basedir-list: "+bl); + /** * auth-url-path : part of URL to indicate authenticated access */
--- a/servlet/src/digilib/servlet/Scaler.java Tue Aug 27 12:19:24 2002 +0200 +++ b/servlet/src/digilib/servlet/Scaler.java Tue Aug 27 12:29:07 2002 +0200 @@ -81,13 +81,7 @@ // base directories in order of preference (prescaled versions first) String baseDirList = servletOp.tryToGetInitParam("basedir-list", "/docuserver/scaled/small:/docuserver/images:/docuserver/scans/quellen"); // split list into directories - StringTokenizer dirs = new StringTokenizer(baseDirList, ":"); - int n = dirs.countTokens(); - // add directories into array - baseDirs = new String[n]; - for (int i = 0; i < n; i++) { - baseDirs[i] = dirs.nextToken(); - } + baseDirs = servletOp.tryToGetPathArray(baseDirList, baseDirs); // use authentication information String useAuth = servletOp.tryToGetInitParam("use-authorization", "true"); if ((useAuth.indexOf("false") > 0)||(useAuth.indexOf("FALSE") > 0)) {
--- a/servlet/src/digilib/servlet/ServletOps.java Tue Aug 27 12:19:24 2002 +0200 +++ b/servlet/src/digilib/servlet/ServletOps.java Tue Aug 27 12:29:07 2002 +0200 @@ -78,6 +78,33 @@ } /** + * convert a string with a list of pathnames into an array of strings + * using the system's path seperator string + */ + public String[] getPathArray(String paths) { + // split list into directories + StringTokenizer dirs = new StringTokenizer(paths, java.io.File.pathSeparator); + int n = dirs.countTokens(); + if (n < 1) { + return null; + } + // add directories into array + String[] pathArray = new String[n]; + for (int i = 0; i < n; i++) { + pathArray[i] = dirs.nextToken(); + } + return pathArray; + } + + /** + * getPathArray with default fall back + */ + public String[] tryToGetPathArray(String paths, String[] defaultPath) { + String[] pa = getPathArray(paths); + return (pa != null) ? pa : defaultPath; + } + + /** * print a servlet response and exit */ public static void htmlMessage(String s, HttpServletResponse response) throws IOException {