KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > snip > name > PathRemoveFormatter


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

27
28
29 /**
30  * Formatter that capitalizes the name
31  *
32  * @author stephan
33  * @version $Id: PathRemoveFormatter.java 950 2003-08-27 09:22:47Z stephan $
34  */

35
36 public class PathRemoveFormatter implements NameFormatter {
37   // Null Object Pattern
38
private NameFormatter parent = new NoneFormatter();
39
40   public void setParent(NameFormatter parent) {
41     this.parent = parent;
42   }
43
44   public String JavaDoc format(String JavaDoc name) {
45     String JavaDoc parentName = parent.format(name);
46     int index = parentName.lastIndexOf("/");
47     if (-1 == index) {
48       return parentName;
49     } else if (parentName.length() == index+1) {
50       return parentName.substring(0,index);
51     } else {
52       return parentName.substring(index+1);
53     }
54   }
55 }
56
Popular Tags