01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/portal/tags/sakai_2-4-1/portal-impl/impl/src/java/org/sakaiproject/portal/charon/PortalStringUtil.java $
03: * $Id: PortalStringUtil.java 29143 2007-04-19 01:10:38Z ajpoland@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.portal.charon;
21:
22: /**
23: * A Utitlity class to do string replacement prior to JDK 1.5
24: *
25: * @author ieb
26: * @since Sakai 2.4
27: * @version $Rev: 29143 $
28: *
29: */
30: public class PortalStringUtil {
31: /**
32: * replaces the first occurance of a string without reverting to regex or
33: * creating arrays/vectors etc could also have used StringUtil for this
34: * perpose, but wanted something simpler.
35: *
36: * @param path
37: * @param marker
38: * @param replacement
39: * @return
40: */
41: public static String replaceFirst(String path, String marker,
42: String replacement) {
43: if (path == null) {
44: return path;
45: }
46: int i = path.indexOf(marker);
47: if (i >= 0) {
48: String before = path.substring(0, i);
49: String after = path.substring(i + marker.length());
50: return before + replacement + after;
51: }
52: return path;
53: }
54: }
|