View Javadoc
1 /* 2 * Copyright (c) 2004, Henri Yandell 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or 6 * without modification, are permitted provided that the 7 * following conditions are met: 8 * 9 * + Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * + Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * + Neither the name of OSJava nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 package org.osjava.taglib.trail; 34 35 import java.util.List; 36 import java.util.ArrayList; 37 import java.util.Iterator; 38 39 public class BreadCrumbs { 40 41 private List trail = new ArrayList(); 42 private List normalizedTrail = new ArrayList(); 43 44 // needs lots of thought, this current version breaks after 45 // the first norm 46 47 // i need to be able to look at the http-referer too 48 // if someone hits back once or twice etc, then chooses a 49 // sibling, i have to be able to see that 50 51 // also have to fix the .do/.jsp problem. servlet filter? 52 53 public void addToTrail(String referer, BreadCrumb bc) { 54 trail.add(bc); 55 56 // if crumb equals last crumb, do not add to norm 57 if( !normalizedTrail.isEmpty() ) { 58 BreadCrumb last = (BreadCrumb) normalizedTrail.get( normalizedTrail.size() - 1 ); 59 if(bc.equals(last)) { 60 return; 61 } 62 } 63 64 // if crumb can be found in the trail, remove all entries 65 // after the crumb, and don't add to norm 66 if(normalizedTrail.contains(bc)) { 67 int idx = normalizedTrail.indexOf(bc); 68 normalizedTrail = normalizedTrail.subList(0, idx + 1); 69 return; 70 } 71 72 // if crumb's referer can be found in the trail, remove 73 // all entries after the crumb's referer, then add to norm 74 if(referer != null) { 75 Iterator itr = normalizedTrail.iterator(); 76 while(itr.hasNext()) { 77 BreadCrumb tmp = (BreadCrumb) itr.next(); 78 if(tmp.getUrl().equals(referer)) { 79 int idx = normalizedTrail.indexOf(tmp); 80 normalizedTrail = normalizedTrail.subList(0, idx + 1); 81 break; 82 } 83 } 84 } 85 86 normalizedTrail.add( bc ); 87 } 88 89 public Iterator iterateTrail() { 90 return trail.iterator(); 91 } 92 93 public Iterator iterateNormalizedTrail() { 94 return normalizedTrail.iterator(); 95 } 96 97 }

This page was automatically generated by Maven