new StringService

git-svn-id: https://brutex.net/svn/xservices/trunk@86 e7e49efb-446e-492e-b9ec-fcafc1997a86
tag-20130205r
Brian Rosenberger 2012-05-21 18:23:11 +00:00
parent 373d73f3d8
commit 995a8b8119
4 changed files with 173 additions and 0 deletions

View File

@ -0,0 +1,37 @@
/*
* Copyright 2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.types;
import javax.xml.bind.annotation.XmlType;
/**
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlType
public class StringReplaceType {
public String string;
public int count;
public StringReplaceType() {}
public StringReplaceType(String string, int count) {
this();
this.string = string;
this.count = count;
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright 2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.types.StringReplaceType;
import net.brutex.xservices.types.TargetNodeType;
import net.brutex.xservices.types.ant.AttachmentType;
import net.brutex.xservices.types.ant.CollectionType;
import net.brutex.xservices.types.ant.FileResource;
import net.brutex.xservices.util.BrutexNamespaces;
import org.apache.cxf.annotations.WSDLDocumentation;
/**
* String operation services.
* @author Brian Rosenberger
* @since 0.5.0
*
*/
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
public interface StringService {
public static final String SERVICE_NAME = "StringService";
final String OPERATION_REPLACEREGEX = "replaceRegEx";
final static String PARAM_STRING = "string";
final static String PARAM_SEARCH = "search";
final static String PARAM_REPLACE = "replace";
final static String PARAM_FLAGS = "regexflags";
;
/**
* String replace using regular expression.
* @param res String
* @param search regex search pattern
* @param replace string replacement
* @param flags regex flags
*
* @return replacement
* @throws XServicesFault
*/
@WebMethod(operationName=OPERATION_REPLACEREGEX)
@WSDLDocumentation(value="Store text based data")
public abstract StringReplaceType replaceRegEx(
@WebParam(name = PARAM_STRING) String res,
@WebParam(name = PARAM_SEARCH) String search,
@WebParam(name = PARAM_REPLACE) String replace,
@WebParam(name = PARAM_FLAGS) String flags) throws XServicesFault;
}

View File

@ -0,0 +1,61 @@
/*
* Copyright 2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.ws.impl;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jws.WebService;
import net.brutex.xservices.types.StringReplaceType;
import net.brutex.xservices.util.BrutexNamespaces;
import net.brutex.xservices.ws.StringService;
import net.brutex.xservices.ws.XServicesFault;
/**
* @author Brian Rosenberger
* @since 0.5.0
*
*/
@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 {
int allflags = 0;
if(flags.contains("i")) {
allflags = allflags + Pattern.CASE_INSENSITIVE;
}
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);
} else {
if(count>1) count = 1;
return new StringReplaceType(matcher.replaceFirst(replace), count);
}
}
}

View File

@ -55,6 +55,10 @@
implementor="net.brutex.xservices.ws.impl.MiscServiceImpl" address="/MiscService"> implementor="net.brutex.xservices.ws.impl.MiscServiceImpl" address="/MiscService">
</jaxws:endpoint> </jaxws:endpoint>
<jaxws:endpoint id="stringservice"
implementor="net.brutex.xservices.ws.impl.StringServiceImpl" address="/StringService">
</jaxws:endpoint>
<jaxws:endpoint id="storageservice" <jaxws:endpoint id="storageservice"
implementor="net.brutex.xservices.ws.impl.StorageServiceImpl" address="/StorageService"> implementor="net.brutex.xservices.ws.impl.StorageServiceImpl" address="/StorageService">
</jaxws:endpoint> </jaxws:endpoint>