Hello, Could someone please take a look at the two files below as soon as possible? Something is wrong with the code and I am unable to figure it out. It generates 16 errors -- mostly "expected ;", but from what I can see all the required semicolons are there!
If someone more experienced woth JSP could help, I would greatly appreciate it! This is an urgent problem and is frustrating me a great deal. Thanks in advance! -Mike File #1: breadcrumb.jsp <[EMAIL PROTECTED] import="java.util.Properties, java.io.InputStream, java.io.IOException"%> <!-- BreadCrumb maker 1.0 --> <%-- Reads a breadcrumb.properties file containing stuff like this: start=<b> end=</b> pre=<a href="$path"> post=</a> middle=\ > /=home /cat1=Category 1 /cat2=Category 2 /cat1/index.jsp= The main page For the path 'http://localhost:8080/breadcrumb/cat1/index.jsp', that will create a string: <b><a href="/breadcrumb/">home</a> ><a href="/breadcrumb/cat1">Category 1</a> ><a href="/breadcrumb/cat1/index.jsp"> The main page </a> NOTE: If you change this file, be sure to touch any files including it, or the changes won't be picked up. Jeff Turner <[EMAIL PROTECTED]> http://opensource.socialchange.net.au/breadcrumbs/ 16/08/2001 $Revision$ $Date$ --%> <%! public static final String CONFIG="/ssi/breadcrumb.properties"; // if starting with '/', will be relative to htdocs. Otherwise, relative to calling page (*not* this included page) %> <%! public static final int MAX_DEPTH=20; // max number of iterations before we halt with an error %> <%! public static final String PATH_TOKEN="$path"; // If this string is encountered in the CONFIG file, it is replaced with the current path %> <%! public static final boolean PRINTERRORS=true; // If false, any errors will result in "" output. Otherwise, behaviour is determined by COMMENTERRORS %> <%! public static final boolean COMMENTERRORS=false; // If true, errors will be printed in comments. If false, errors will be visible. %> <%! /** * Method to create a breadcrumb trail (or whatever it's called). */ String search(HttpServletRequest req) { Properties props = new Properties(); try { InputStream in = getServletConfig().getServletContext().getResourceAsStream(CONFIG); props.load(in); } catch (Exception e) { return printErr("could not find or read "+CONFIG); } try { String start = (String)props.get("start"); String end = (String)props.get("end"); String post = (String)props.get("post"); String pre = (String)props.get("pre"); String middle = (String)props.get("middle"); StringBuffer result = new StringBuffer(); // Note: this algorithm traverses the path backwards, from the end to the root. // Hence the ordering of 'post' before 'pre' int count = 0; String path = req.getRequestURI().substring( req.getContextPath().length() ); // remaining path String desc = null; // description for current path boolean inMiddle = false; // true if we've previously hit a non-null path boolean last=false; // true if we're on the last path ("/") while ( true ) { if (last) path = "/"; // we need *some* character for the root.. this is as good as any desc = (String)props.get(path); if (desc != null) { if (inMiddle) { result.insert(0, middle); } else inMiddle = true; if (post != null) { result.insert(0, subst(req, post, path)); } result.insert(0, subst(req, desc, path)); if (pre != null) { result.insert(0, subst(req, pre, path)); } } if (last) break; // set up the path for our next iteration path = path.substring(0, path.lastIndexOf(System.getProperty("file.separator"))); // strip from the last '/' onwards. In the last case, this will result in "" if (path.equals("")) last = true; // .. because I'm not confident some weird usage won't break the algorithm count++; if (count > MAX_DEPTH) { return printErr("Inifinite loop detected in breadcrumbs"); } } result.insert(0, start); return result.toString(); } catch (Throwable t) { return printErr("Couldn't generate breadcrumbs: "+t); } } /** * Replaces all occurrences of tokens in original, with values. In the case of * PATH_TOKEN, replaces it with the context path plus the context-relative path. */ private static String subst( HttpServletRequest req, final String original, final String path) { return replaceSubString(original, PATH_TOKEN, req.getContextPath()+path); } private static String printErr(String msg) { if (!PRINTERRORS) return ""; StringBuffer buf = new StringBuffer(); if (COMMENTERRORS) { buf.append("<!--"); } else { buf.append("<font color='red'>"); } buf.append(msg); if (COMMENTERRORS) { buf.append("-->"); } else { buf.append("</font>"); } return buf.toString(); } /** * Replace substrings of one string with another string and return altered string. * * @param original input string * @param oldString the substring section to replace * @param newString the new substring replacing old substring section * @return converted string */ private static String replaceSubString( final String original, final String oldString, final String newString ) { final StringBuffer sb = new StringBuffer(); int end = original.indexOf( oldString ); int start = 0; final int stringSize = oldString.length(); while( end != -1 ) { sb.append( original.substring( start, end ) ); sb.append( newString ); start = end + stringSize; end = original.indexOf( oldString, start ); } end = original.length(); sb.append( original.substring( start, end ) ); return sb.toString(); } %> <%= search(request) %> *********************************************************************************** File #2: breadcrumb.properties # Breadcrumbs file. Used to decorate a path. # # A path, eg '/foo/bar/index.jsp', will match the following paths, in order: # '/' # '/foo/' # '/foo/bar/' # '/foo/bar/index.jsp' # # The format for this file is simple name=value pairs. # Possible entries: # # start # inserted before everything else, eg <ul> # end # inserted after everything else, eg </ul> # pre # inserted before every matched path, eg <li> # post # inserted after every matched path, eg </li> # middle # inserted between every pair of matching paths, eg '|' # / # matches home directory # /* # matches specified directory # # The values for the above variables may contain the string '$path', which will # be replaced with the server-relative path to the currently matched path # segment. # For example: # pre=<a href="$name"> # post=</a> # # will wrap each path segment in a link to that location. If '/index.jsp' # matches, it will be rendered as '/mysite/index.jsp'. # # A full example # For the path 'http://localhost:8080/breadcrumb/cat1/index.jsp', the example # path matchers will create a string: # <b><a href="/breadcrumb/">home</a> ><a href="/breadcrumb/cat1">Category 1</a> ><a href="/breadcrumb/cat1/index.jsp">? The main page </a> # # # Jeff Turner # http://opensource.socialchange.net.au/breadcrumbs/ # 16/08/2001 # $Revision$ $Date$ start=<b> end=</b> pre=<a href="$path"> post=</a> middle=\ > /=Home Page /cat1=Category 1 /cat1/index.jsp=Main cat1 page /cat1/subcat1/=Subcat 1 /cat1/subcat1/index.jsp=Main subcat1 page /cat2=Category 2 /cat2/index.jsp=Main cat2 page /cat2/subcat1/index.jsp=Main subcat2 page =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant archives, FAQs and Forums on JSPs can be found at: http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com