Subversion Repositories XServices

Rev

Rev 86 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 86 Rev 87
Line 13... Line 13...
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;
Line 17... Line -...
17
 
-
 
18
 
-
 
19
 
17
 
20
import java.util.regex.Matcher;
18
import java.util.regex.Matcher;
Line 21... Line 19...
21
import java.util.regex.Pattern;
19
import java.util.regex.Pattern;
Line 33... Line 31...
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 {
Line 37... Line 35...
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
 
Line 58... Line -...
58
	}
-
 
59
 
61
	}