Difference between revisions of "Extend OCR field parsers"
From OpenKM Documentation
(Created page with "{{TOCright}} __TOC__ {{Note|From OpenKM 6.4+ the Plug-in system of OpenKM allows you to quickly expand the functionality offered by the platform, extending the available OCR ...") |
(No difference)
|
Revision as of 19:01, 7 September 2013
Step 1 - Create class
- Tthe new class should be under com.openkm.ocr.template.parser ( this is mandatory )
- Important do not forget to set the tag @PluginImplementation before the class definition
package com.openkm.ocr.template.parser;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import com.openkm.dao.bean.OCRTemplateField;
import com.openkm.ocr.template.OCRParserEmptyValueException;
import com.openkm.ocr.template.OCRTemplateException;
import com.openkm.ocr.template.OCRTemplateParser;
/**
* StringParser
*
* @author jllort
*
*/
@PluginImplementation
public class StringParser implements OCRTemplateParser {
@Override
public Object parse(OCRTemplateField otf, String text) throws OCRTemplateException, OCRParserEmptyValueException {
if (text == null || text.equals("")) {
throw new OCRParserEmptyValueException("Empty value");
}
if (otf.getPattern() == null || otf.getPattern().equals("")) {
return text != null ? text.trim() : null;
} else {
Pattern pattern = Pattern.compile(otf.getPattern(), Pattern.UNICODE_CASE);
Matcher matcher = pattern.matcher(text);
if (matcher.matches()) {
return text != null ? text.trim() : null;
} else {
throw new OCRTemplateException("Bad format, parse exception");
}
}
}
@Override
public String getName() {
return "String";
}
@Override
public boolean isPatternRequired() {
return false;
}
}
Step 2 - Publish
Create your own jar and copy into $TOMCAT_HOME/lib folder.