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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,87 +13,110 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package net.brutex.xservices.ws.impl; package net.brutex.xservices.ws.impl;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.jws.WebService; import javax.jws.WebService;
import net.brutex.xservices.types.StringMatchType; import net.brutex.xservices.types.StringMatchType;
import net.brutex.xservices.types.StringReplaceType; 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.StringService;
import net.brutex.xservices.ws.XServicesFault; 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 * @author Brian Rosenberger, bru(at)brutex.de
* @since 0.5.0 *
*
*/ */
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.StringService", serviceName = StringService.SERVICE_NAME) @WebService(targetNamespace="http://ws.xservices.brutex.net", endpointInterface="net.brutex.xservices.ws.StringService", serviceName="StringService")
public class StringServiceImpl implements 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);
int count = 0;
while (matcher.find()) {
count++;
}
if (flags.contains("g")) {
return new StringReplaceType(matcher.replaceAll(replace), count);
}
if (count > 1)
count = 1;
return new StringReplaceType(matcher.replaceFirst(replace),
count);
}
catch (Exception e) {
throw new XServicesFault(e);
}
}
public StringReplaceType replaceRegEx(String res, String search, public StringMatchType matchRegEx(String res, String search, String flags)
String replace, String flags) throws XServicesFault { throws XServicesFault
try { {
int allflags = getFlags(flags); int allflags = getFlags(flags);
Pattern pattern = Pattern.compile(search, allflags); Pattern pattern = Pattern.compile(search, allflags);
Matcher matcher = pattern.matcher(res); Matcher matcher = pattern.matcher(res);
int count = 0; StringMatchType rm = new StringMatchType();
while (matcher.find()) {
count++; for (int i=0; i <= matcher.groupCount(); i++) {
} while(matcher.find()) {
if (flags.contains("g")) { rm.addStringMatch(matcher.start(i), matcher.end(i), "group-"+i, matcher.group(i));
return new StringReplaceType(matcher.replaceAll(replace), count); }
} else { matcher.reset();
if (count > 1) }
count = 1; return rm;
return new StringReplaceType(matcher.replaceFirst(replace), }
count);
} public String encodeToXMLEntities(String res)
} catch (Exception e) { throws XServicesFault
throw new XServicesFault(e); {
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;
}
@Override
public StringMatchType matchRegEx(String res, String search, String flags)
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));
}
}
return rm;
}
private int getFlags(String flags) {
int allflags = 0;
if(flags.contains("i")) {
allflags = allflags + Pattern.CASE_INSENSITIVE;
}
if(flags.contains("m")) {
allflags = allflags + Pattern.MULTILINE;
}
if(flags.contains("u")) {
allflags = allflags + Pattern.UNICODE_CASE;
}
if(flags.contains("s")) {
allflags = allflags + Pattern.DOTALL;
}
if(flags.contains("d")) {
allflags = allflags + Pattern.UNIX_LINES;
}
if(flags.contains("x")) {
allflags = allflags + Pattern.COMMENTS;
}
return allflags;
} }
private int getFlags(String flags) {
int allflags = 0;
if (flags.contains("i")) {
allflags += 2;
}
if (flags.contains("m")) {
allflags += 8;
}
if (flags.contains("u")) {
allflags += 64;
}
if (flags.contains("s")) {
allflags += 32;
}
if (flags.contains("d")) {
allflags++;
}
if (flags.contains("x")) {
allflags += 4;
}
return allflags;
}
} }