KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > snip > SnipPath


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25
26 package org.snipsnap.snip;
27
28 import org.snipsnap.config.Configuration;
29 import org.snipsnap.app.Application;
30
31 import java.io.IOException JavaDoc;
32 import java.io.Writer JavaDoc;
33
34 /**
35  * Handle trees of snips with paths.
36  *
37  * @author stephan
38  * @version $Id: SnipPath.java 1013 2003-09-29 07:41:13Z leo $
39  */

40
41 public class SnipPath {
42   private Snip snip;
43
44   public SnipPath(Snip snip) {
45     this.snip = snip;
46   }
47
48   //@TODO: make this a object not static, return object from Snip
49
public Writer JavaDoc append(Writer JavaDoc writer, SnipSpace space) {
50     try {
51       Configuration config = Application.get().getConfiguration();
52       String JavaDoc name = snip.getName();
53       if (!name.startsWith(config.getStartSnip())) {
54         SnipLink.appendLink(writer, config.getStartSnip());
55         writer.write(" > ");
56       }
57
58       String JavaDoc part = null;
59       String JavaDoc snipName = null;
60       int lastIndex = 0;
61       int i = 0;
62       int index = name.indexOf('/');
63       while (index != -1 && i++ < 10) {
64         part = name.substring(lastIndex, index);
65         snipName = name.substring(0, index);
66         if(space.exists(snipName) ||
67            Application.get().getConfiguration().allow(Configuration.APP_PERM_CREATESNIP)) {
68           SnipLink.appendLink(writer, snipName, part);
69         } else {
70           writer.write(part);
71         }
72         lastIndex = index + 1;
73         index = name.indexOf('/', lastIndex);
74         writer.write(" > ");
75       }
76       // do not link last element of path because
77
// we display the this element already
78
writer.write(name.substring(lastIndex));
79     } catch (IOException JavaDoc e) {
80       System.out.println("SnipPath: Error writing to writer.");
81     }
82     return writer;
83   }
84
85 }
86
Popular Tags