mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-11-11 09:46:31 +08:00
make parser static
This commit is contained in:
parent
31ca9524b3
commit
aa75a82a5b
4 changed files with 28 additions and 53 deletions
|
@ -1,13 +1,37 @@
|
|||
package com.ctrip.zeus.service.model;
|
||||
|
||||
import com.ctrip.zeus.service.model.handler.RewriteParseHandler;
|
||||
import com.ctrip.zeus.service.model.handler.impl.ParseException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by zhoumy on 2015/6/29.
|
||||
*/
|
||||
public interface PathRewriteParser {
|
||||
public class PathRewriteParser {
|
||||
|
||||
boolean validate(String value);
|
||||
public static boolean validate(String value) {
|
||||
return new RewriteParseHandler().validate(value.getBytes());
|
||||
}
|
||||
|
||||
List<String> getValues(String value);
|
||||
public static List<String> getValues(String value) {
|
||||
List<String> output = new ArrayList<>();
|
||||
List<String> result = new ArrayList<>();
|
||||
try {
|
||||
new RewriteParseHandler().handleContent(value.getBytes(), output);
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
String oneRecord = "";
|
||||
for (int i = 0; i < output.size(); i++) {
|
||||
if (i % 2 == 0)
|
||||
oneRecord = "\"" + output.get(i) + "\"";
|
||||
else {
|
||||
oneRecord += " " + output.get(i) + ";";
|
||||
result.add(oneRecord);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,12 @@ package com.ctrip.zeus.service.model.handler;
|
|||
import com.ctrip.zeus.service.model.handler.impl.ParseException;
|
||||
import com.ctrip.zeus.service.model.handler.impl.ParserState;
|
||||
import com.ctrip.zeus.service.model.handler.impl.Tokenizer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by zhoumy on 2015/6/23.
|
||||
*/
|
||||
@Component("rewriteParseHandler")
|
||||
public class RewriteParseHandler {
|
||||
ParserState currentState;
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ public class DefaultGroupValidator implements GroupValidator {
|
|||
private ActiveConfService activeConfService;
|
||||
@Resource
|
||||
private SlbRepository slbRepository;
|
||||
@Resource
|
||||
private PathRewriteParser pathRewriteParser;
|
||||
|
||||
@Override
|
||||
public void validate(Group group) throws Exception {
|
||||
|
@ -49,7 +47,7 @@ public class DefaultGroupValidator implements GroupValidator {
|
|||
return false;
|
||||
Set<Long> virtualServerIds = new HashSet<>();
|
||||
for (GroupSlb gs : group.getGroupSlbs()) {
|
||||
if (gs.getRewrite() != null && !gs.getRewrite().isEmpty() && !pathRewriteParser.validate(gs.getRewrite())) {
|
||||
if (gs.getRewrite() != null && !gs.getRewrite().isEmpty() && !PathRewriteParser.validate(gs.getRewrite())) {
|
||||
throw new ValidationException("Invalid rewrite value.");
|
||||
}
|
||||
VirtualServer vs = slbRepository.getVirtualServer(gs.getVirtualServer().getId(),
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
package com.ctrip.zeus.service.model.impl;
|
||||
|
||||
import com.ctrip.zeus.service.model.PathRewriteParser;
|
||||
import com.ctrip.zeus.service.model.handler.RewriteParseHandler;
|
||||
import com.ctrip.zeus.service.model.handler.impl.ParseException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by zhoumy on 2015/6/29.
|
||||
*/
|
||||
@Component("pathRewriteParser")
|
||||
public class DefaultRewriteParser implements PathRewriteParser {
|
||||
@Resource
|
||||
private RewriteParseHandler rewriteParseHandler;
|
||||
|
||||
@Override
|
||||
public boolean validate(String value) {
|
||||
return rewriteParseHandler.validate(value.getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getValues(String value) {
|
||||
List<String> output = new ArrayList<>();
|
||||
List<String> result = new ArrayList<>();
|
||||
try {
|
||||
rewriteParseHandler.handleContent(value.getBytes(), output);
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
String oneRecord = "";
|
||||
for (int i = 0; i < output.size(); i++) {
|
||||
if (i % 2 == 0)
|
||||
oneRecord = "\"" + output.get(i) + "\"";
|
||||
else {
|
||||
oneRecord += " " + output.get(i) + ";";
|
||||
result.add(oneRecord);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue