1 | /*
|
---|
2 | * GSPath.java
|
---|
3 | * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 | package org.greenstone.gsdl3.util;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * GSPath - utility class for greenstone
|
---|
23 | *
|
---|
24 | * modifies and examines message address paths and names
|
---|
25 | *
|
---|
26 | * @author <a href="mailto:[email protected]">Katherine Don</a>
|
---|
27 | * @version $Revision: 3235 $
|
---|
28 | *
|
---|
29 | */
|
---|
30 |
|
---|
31 | public class GSPath {
|
---|
32 |
|
---|
33 | /** adds new_link to the end of path
|
---|
34 | *
|
---|
35 | * @return the new path
|
---|
36 | */
|
---|
37 | static public String appendLink(String path, String new_link) {
|
---|
38 | if (path.equals("")) {
|
---|
39 | return new_link;
|
---|
40 | }
|
---|
41 | return path +"/"+new_link;
|
---|
42 | }
|
---|
43 |
|
---|
44 | /** adds new_link to the front of path
|
---|
45 | *
|
---|
46 | * @return the new path
|
---|
47 | */
|
---|
48 | static public String prependLink(String path, String new_link) {
|
---|
49 | if (path.equals("")) {
|
---|
50 | return new_link;
|
---|
51 | }
|
---|
52 | return new_link+"/"+path;
|
---|
53 | }
|
---|
54 |
|
---|
55 | /** returns the first name in the path
|
---|
56 | *
|
---|
57 | */
|
---|
58 | static public String getFirstLink(String path) {
|
---|
59 |
|
---|
60 | int i = path.indexOf("/");
|
---|
61 | if (i==0) { // have a '/' on the front
|
---|
62 | path = path.substring(1);
|
---|
63 | i= path.indexOf("/");
|
---|
64 | }
|
---|
65 | if (i==-1) { // '/' not found
|
---|
66 | return path;
|
---|
67 | }
|
---|
68 |
|
---|
69 | return path.substring(0,i);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /** removes the first name in the path
|
---|
73 | *
|
---|
74 | * @return the modified path
|
---|
75 | */
|
---|
76 | static public String removeFirstLink(String path) {
|
---|
77 | int i = path.indexOf("/");
|
---|
78 | if (i==0) { // have a '/' on the front
|
---|
79 | path = path.substring(1);
|
---|
80 | i= path.indexOf("/");
|
---|
81 | }
|
---|
82 | if (i==-1) { // '/' not found - remove the whole path
|
---|
83 | return "";
|
---|
84 | }
|
---|
85 | return path.substring(i+1); // remove the '/' char
|
---|
86 | }
|
---|
87 |
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|