Subversion Repositories XServices

Rev

Rev 86 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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