Arbeitsstand Anfang Februar

git-svn-id: https://brutex.net/svn/xservices/trunk@115 e7e49efb-446e-492e-b9ec-fcafc1997a86
tag-20130205r
Brian Rosenberger 2013-02-05 14:44:47 +00:00
parent f2a2f39d1a
commit c08cf4af39
1 changed files with 91 additions and 68 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
* Copyright 2013 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,30 +13,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws.impl;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jws.WebService;
import net.brutex.xservices.types.StringMatchType;
import net.brutex.xservices.types.StringReplaceType;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.types.StringSplitType;
import net.brutex.xservices.ws.StringService;
import net.brutex.xservices.ws.XServicesFault;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.text.translate.CharSequenceTranslator;
import org.apache.commons.lang3.text.translate.NumericEntityEscaper;
/**
* @author Brian Rosenberger
* @since 0.5.0
* @author Brian Rosenberger, bru(at)brutex.de
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.StringService", serviceName = StringService.SERVICE_NAME)
public class StringServiceImpl implements StringService {
public StringReplaceType replaceRegEx(String res, String search,
String replace, String flags) throws XServicesFault {
try {
@WebService(targetNamespace="http://ws.xservices.brutex.net", endpointInterface="net.brutex.xservices.ws.StringService", serviceName="StringService")
public class StringServiceImpl
implements StringService
{
public StringReplaceType replaceRegEx(String res, String search, String replace, String flags)
throws XServicesFault
{
try
{
int allflags = getFlags(flags);
Pattern pattern = Pattern.compile(search, allflags);
Matcher matcher = pattern.matcher(res);
@ -46,54 +52,71 @@ public class StringServiceImpl implements StringService {
}
if (flags.contains("g")) {
return new StringReplaceType(matcher.replaceAll(replace), count);
} else {
}
if (count > 1)
count = 1;
return new StringReplaceType(matcher.replaceFirst(replace),
count);
}
} catch (Exception e) {
catch (Exception e) {
throw new XServicesFault(e);
}
}
@Override
public StringMatchType matchRegEx(String res, String search, String flags)
throws XServicesFault {
throws XServicesFault
{
int allflags = getFlags(flags);
Pattern pattern = Pattern.compile(search, allflags);
Matcher matcher = pattern.matcher(res);
StringMatchType rm = new StringMatchType();
while (matcher.find()) {
for (int i=0; i <= matcher.groupCount(); i++) {
rm.addStringMatch(matcher.start(), matcher.end(), matcher.group(i));
while(matcher.find()) {
rm.addStringMatch(matcher.start(i), matcher.end(i), "group-"+i, matcher.group(i));
}
matcher.reset();
}
return rm;
}
public String encodeToXMLEntities(String res)
throws XServicesFault
{
StringEscapeUtils fac = new StringEscapeUtils();
StringEscapeUtils.ESCAPE_XML.with(new CharSequenceTranslator[] { NumericEntityEscaper.between(128, 2147483647) });
return StringEscapeUtils.escapeXml(res);
}
public StringSplitType splitString(String paramString, String delimiter) throws XServicesFault {
StringTokenizer tk = new StringTokenizer(paramString, delimiter);
StringSplitType result = new StringSplitType();
while(tk.hasMoreTokens()) {
result.addStringMatch( tk.nextToken() );
}
return result;
}
private int getFlags(String flags) {
int allflags = 0;
if (flags.contains("i")) {
allflags = allflags + Pattern.CASE_INSENSITIVE;
allflags += 2;
}
if (flags.contains("m")) {
allflags = allflags + Pattern.MULTILINE;
allflags += 8;
}
if (flags.contains("u")) {
allflags = allflags + Pattern.UNICODE_CASE;
allflags += 64;
}
if (flags.contains("s")) {
allflags = allflags + Pattern.DOTALL;
allflags += 32;
}
if (flags.contains("d")) {
allflags = allflags + Pattern.UNIX_LINES;
allflags++;
}
if (flags.contains("x")) {
allflags = allflags + Pattern.COMMENTS;
allflags += 4;
}
return allflags;
}
}