return StringEscapeUtils.escapeJava(ds.getMessageTerminator());
}
@DwrPermission(user = true)
public ProcessResult testString(String raw) {
ProcessResult pr = new ProcessResult();
String msg = StringEscapeUtils.unescapeJava(raw);
SerialDataSourceVO ds = (SerialDataSourceVO) Common.getUser().getEditDataSource();
if(ds.getId() == -1) {
pr.addContextualMessage("testString", "serial.test.needsSave");
return pr;
}
DataPointDao dpd = new DataPointDao();
List<DataPointVO> points = dpd.getDataPoints(ds.getId(), null);
if(ds.getUseTerminator()) {
if(msg.indexOf(ds.getMessageTerminator()) != -1) {
msg = msg.substring(0, msg.indexOf(ds.getMessageTerminator())+1);
Pattern p = Pattern.compile(ds.getMessageRegex());
Matcher m = p.matcher(msg);
if(!m.matches()) {
pr.addContextualMessage("testString", "serial.test.noMessageMatch");
return pr;
}
String identifier = m.group(ds.getPointIdentifierIndex());
for(DataPointVO pnt : points) {
SerialPointLocatorVO plVo = (SerialPointLocatorVO) pnt.getPointLocator();
if(identifier.equals(plVo.getPointIdentifier())) {
Pattern v = Pattern.compile(plVo.getValueRegex());
Matcher vm = v.matcher(msg);
if(vm.find())
pr.addContextualMessage("testString", "serial.test.consumed", pnt.getName(), vm.group(0));
}
}
}
else {
pr.addContextualMessage("testString", "serial.test.noTerminator");
return pr;
}
}
else {
for(DataPointVO pnt : points) {
SerialPointLocatorVO plVo = (SerialPointLocatorVO) pnt.getPointLocator();
Pattern p = Pattern.compile(plVo.getValueRegex());
Matcher m = p.matcher(msg);
if(m.find())
pr.addContextualMessage("testString", "serial.test.consumed", pnt.getName(), m.group(0));
}
}
return pr;
}