01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/portal/tags/sakai_2-4-1/portal-service-impl/impl/src/java/org/sakaiproject/portal/service/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.service;
21:
22: /**
23: * @author ieb
24: * @since Sakai 2.4
25: * @version $Rev: 29143 $
26: */
27:
28: public class PortalStringUtil {
29: /**
30: * replaces the first occurance of a string without reverting to regex or
31: * creating arrays/vectors etc could also have used StringUtil for this
32: * perpose, but wanted something simpler.
33: *
34: * @param path
35: * @param marker
36: * @param replacement
37: * @return
38: */
39: public static String replaceFirst(String path, String marker,
40: String replacement) {
41: if (path == null) {
42: return path;
43: }
44: int i = path.indexOf(marker);
45: if (i >= 0) {
46: String before = path.substring(0, i);
47: String after = path.substring(i + marker.length());
48: return before + replacement + after;
49: }
50: return path;
51: }
52: }
|