Subversion Repositories XServices

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
86 brianR 1
/*
2
 *   Copyright 2012 Brian Rosenberger (Brutex Network)
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
15
 */
16
package net.brutex.xservices.ws.impl;
17
 
18
 
19
 
20
import java.util.regex.Matcher;
21
import java.util.regex.Pattern;
22
 
23
import javax.jws.WebService;
24
 
25
import net.brutex.xservices.types.StringReplaceType;
26
import net.brutex.xservices.util.BrutexNamespaces;
27
import net.brutex.xservices.ws.StringService;
28
import net.brutex.xservices.ws.XServicesFault;
29
 
30
/**
31
 * @author Brian Rosenberger
32
 * @since 0.5.0
33
 *
34
 */
35
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.StringService", serviceName = StringService.SERVICE_NAME)
36
public class StringServiceImpl implements StringService {
37
 
38
	public StringReplaceType replaceRegEx(String res, String search, String replace,
39
			String flags) throws XServicesFault {
40
 
41
		int allflags = 0;
42
		if(flags.contains("i")) {
43
			allflags = allflags + Pattern.CASE_INSENSITIVE;
44
		}
45
		Pattern pattern = Pattern.compile(search, allflags);
46
		Matcher matcher = pattern.matcher(res);
47
		int count = 0;
48
		while( matcher.find()) {
49
			count++;
50
		}
51
		if(flags.contains("g")) {
52
			return new StringReplaceType(matcher.replaceAll(replace), count);
53
		} else {
54
			if(count>1) count = 1;
55
			return new StringReplaceType(matcher.replaceFirst(replace), count);
56
		}
57
 
58
	}
59
 
60
 
61
}