KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > taglib > Breadcrumbs


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.taglib;
24
25 import java.io.*;
26 import org.meshcms.core.*;
27 import org.meshcms.util.*;
28
29 /**
30  * Inserts breadcrumbs for the current page.
31  */

32 public final class Breadcrumbs extends AbstractTag {
33   public static final String JavaDoc MODE_TITLES = "titles";
34   public static final String JavaDoc MODE_LINKS = "links";
35   public static final String JavaDoc DEFAULT_SEPARATOR = " ";
36
37   private String JavaDoc separator = DEFAULT_SEPARATOR;
38   private String JavaDoc mode;
39   private String JavaDoc style;
40   private String JavaDoc target;
41   private String JavaDoc current = "true";
42   private String JavaDoc pre;
43   private String JavaDoc post;
44
45   public void setSeparator(String JavaDoc separator) {
46     this.separator = Utils.noNull(separator, DEFAULT_SEPARATOR);
47   }
48
49   public void setMode(String JavaDoc mode) {
50     this.mode = mode;
51   }
52
53   public void setStyle(String JavaDoc style) {
54     this.style = style;
55   }
56
57   public void setTarget(String JavaDoc target) {
58     this.target = target;
59   }
60
61   public void setPre(String JavaDoc pre) {
62     this.pre = pre;
63   }
64
65   public void setPost(String JavaDoc post) {
66     this.post = post;
67   }
68
69   public void writeTag() throws IOException {
70     PageInfo[] breadcrumbs = webSite.getSiteMap().getBreadcrumbs(pagePath);
71     String JavaDoc[] outs;
72
73     if (mode != null && mode.equals(MODE_LINKS)) {
74       outs = webSite.getLinkList(breadcrumbs, request.getContextPath(), target,
75                                 style);
76     } else {
77       outs = webSite.getTitles(breadcrumbs);
78     }
79
80     if (Utils.isTrue(current)) {
81       int last = 0;
82
83       if (outs == null) {
84         outs = new String JavaDoc[1];
85       } else {
86         last = outs.length;
87         String JavaDoc[] temp = new String JavaDoc[last + 1];
88         System.arraycopy(outs, 0, temp, 0, last);
89         outs = temp;
90       }
91
92       PageInfo pageInfo = webSite.getSiteMap().getPageInfo(pagePath);
93       outs[last] = (pageInfo == null) ? getPage().getTitle() :
94           webSite.getSiteInfo().getPageTitle(pageInfo);
95     }
96
97     Writer w = getOut();
98
99     if (outs != null && outs.length > 0) {
100       if (pre != null) {
101         w.write(pre);
102       }
103
104       w.write(Utils.generateList(outs, separator));
105
106       if (post != null) {
107         w.write(post);
108       }
109     } else {
110       w.write(" ");
111     }
112   }
113
114   public String JavaDoc getSeparator() {
115     return separator;
116   }
117
118   public String JavaDoc getMode() {
119     return mode;
120   }
121
122   public String JavaDoc getStyle() {
123     return style;
124   }
125
126   public String JavaDoc getTarget() {
127     return target;
128   }
129
130   public String JavaDoc getCurrent() {
131     return current;
132   }
133
134   public void setCurrent(String JavaDoc current) {
135     this.current = current;
136   }
137
138   public String JavaDoc getPre() {
139     return pre;
140   }
141
142   public String JavaDoc getPost() {
143     return post;
144   }
145 }
146
Popular Tags