Subversion Repositories XServices

Rev

Rev 87 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 87 Rev 93
Line 18... Line 18...
18
import java.util.regex.Matcher;
18
import java.util.regex.Matcher;
19
import java.util.regex.Pattern;
19
import java.util.regex.Pattern;
Line 20... Line 20...
20
 
20
 
Line -... Line 21...
-
 
21
import javax.jws.WebService;
21
import javax.jws.WebService;
22
 
22
 
23
import net.brutex.xservices.types.StringMatchType;
23
import net.brutex.xservices.types.StringReplaceType;
24
import net.brutex.xservices.types.StringReplaceType;
24
import net.brutex.xservices.util.BrutexNamespaces;
25
import net.brutex.xservices.util.BrutexNamespaces;
Line 34... Line 35...
34
public class StringServiceImpl implements StringService {
35
public class StringServiceImpl implements StringService {
Line 35... Line 36...
35
 
36
 
36
	public StringReplaceType replaceRegEx(String res, String search,
37
	public StringReplaceType replaceRegEx(String res, String search,
37
			String replace, String flags) throws XServicesFault {
38
			String replace, String flags) throws XServicesFault {
38
		try {
39
		try {
39
			int allflags = 0;
-
 
40
			if (flags.contains("i")) {
-
 
41
				allflags = allflags + Pattern.CASE_INSENSITIVE;
-
 
42
			}
40
			int allflags = getFlags(flags);
43
			Pattern pattern = Pattern.compile(search, allflags);
41
			Pattern pattern = Pattern.compile(search, allflags);
44
			Matcher matcher = pattern.matcher(res);
42
			Matcher matcher = pattern.matcher(res);
45
			int count = 0;
43
			int count = 0;
46
			while (matcher.find()) {
44
			while (matcher.find()) {
Line 58... Line 56...
58
			throw new XServicesFault(e);
56
			throw new XServicesFault(e);
59
		}
57
		}
Line 60... Line 58...
60
 
58
 
Line -... Line 59...
-
 
59
	}
-
 
60
 
-
 
61
	@Override
-
 
62
	public StringMatchType matchRegEx(String res, String search, String flags)
-
 
63
			throws XServicesFault {
-
 
64
		int allflags = getFlags(flags);
-
 
65
		Pattern pattern = Pattern.compile(search, allflags);
-
 
66
		Matcher matcher = pattern.matcher(res);
-
 
67
		StringMatchType rm = new StringMatchType();
-
 
68
		while (matcher.find()) {			
-
 
69
			rm.addStringMatch(matcher.start(), matcher.end(), matcher.group());
-
 
70
		}
-
 
71
		return rm;
-
 
72
	}
-
 
73
	
-
 
74
	private int getFlags(String flags) {
-
 
75
		int allflags = 0;
-
 
76
		if(flags.contains("i")) {
-
 
77
			allflags = allflags + Pattern.CASE_INSENSITIVE;
-
 
78
		}
-
 
79
		if(flags.contains("m")) {
-
 
80
			allflags = allflags + Pattern.MULTILINE;
-
 
81
		}
-
 
82
		if(flags.contains("u")) {
-
 
83
			allflags = allflags + Pattern.UNICODE_CASE;
-
 
84
		}
-
 
85
		if(flags.contains("s")) {
-
 
86
			allflags = allflags + Pattern.DOTALL;
-
 
87
		}
-
 
88
		if(flags.contains("d")) {
-
 
89
			allflags = allflags + Pattern.UNIX_LINES;
-
 
90
		}
-
 
91
		if(flags.contains("x")) {
-
 
92
			allflags = allflags + Pattern.COMMENTS;
-
 
93
		}
-
 
94
		return allflags;
61
	}
95
	}