use of net.sf.saxon.regex.RegexIterator in project exist by eXist-db.
the class FunAnalyzeString method match.
private void match(final MemTreeBuilder builder, final RegexIterator regexIterator) throws net.sf.saxon.trans.XPathException {
builder.startElement(QN_MATCH, null);
regexIterator.processMatchingSubstring(new RegexIterator.MatchHandler() {
@Override
public void characters(final CharSequence s) {
builder.characters(s);
}
@Override
public void onGroupStart(final int groupNumber) throws net.sf.saxon.trans.XPathException {
final AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", QN_NR.getLocalPart(), QN_NR.getLocalPart(), "int", Integer.toString(groupNumber));
builder.startElement(QN_GROUP, attributes);
}
@Override
public void onGroupEnd(final int groupNumber) throws net.sf.saxon.trans.XPathException {
builder.endElement();
}
});
builder.endElement();
}
use of net.sf.saxon.regex.RegexIterator in project exist by eXist-db.
the class FunAnalyzeString method analyzeString.
private void analyzeString(final MemTreeBuilder builder, final String input, String pattern, final String flags) throws XPathException {
final Configuration config = context.getBroker().getBrokerPool().getSaxonConfiguration();
final List<String> warnings = new ArrayList<>(1);
try {
final RegularExpression regularExpression = config.compileRegularExpression(pattern, flags, "XP30", warnings);
// TODO(AR) cache the regular expression... might be possible through Saxon config
final RegexIterator regexIterator = regularExpression.analyze(input);
Item item;
while ((item = regexIterator.next()) != null) {
if (regexIterator.isMatching()) {
match(builder, regexIterator);
} else {
nonMatch(builder, item);
}
}
for (final String warning : warnings) {
LOG.warn(warning);
}
} catch (final net.sf.saxon.trans.XPathException e) {
switch(e.getErrorCodeLocalPart()) {
case "FORX0001":
throw new XPathException(this, ErrorCodes.FORX0001, e.getMessage());
case "FORX0002":
throw new XPathException(this, ErrorCodes.FORX0002, e.getMessage());
case "FORX0003":
throw new XPathException(this, ErrorCodes.FORX0003, e.getMessage());
default:
throw new XPathException(this, e.getMessage());
}
}
}
Aggregations