use of org.attoparser.AbstractMarkupHandler in project judge by zjnu-acm.
the class ProblemServiceImpl method attachment.
@Override
public List<String> attachment(long problemId, String requestLocale) {
MarkupParser parser = new MarkupParser(ParseConfiguration.htmlConfiguration());
Problem problem = findOne(problemId, requestLocale);
String description = problem.getDescription();
String input = problem.getInput();
String output = problem.getOutput();
String hint = problem.getHint();
String source = problem.getSource();
@SuppressWarnings("CollectionWithoutInitialCapacity") List<String> list = new ArrayList<>();
for (String string : new String[] { description, input, output, hint, source }) {
try {
if (string == null) {
continue;
}
parser.parse(string, new AbstractMarkupHandler() {
@Override
public void handleAttribute(char[] buffer, int nameOffset, int nameLen, int nameLine, int nameCol, int operatorOffset, int operatorLen, int operatorLine, int operatorCol, int valueContentOffset, int valueContentLen, int valueOuterOffset, int valueOuterLen, int valueLine, int valueCol) {
String name = new String(buffer, nameOffset, nameLen);
if (name.equalsIgnoreCase("href") || name.equalsIgnoreCase("src")) {
String value = new String(buffer, valueContentOffset, valueContentLen);
list.add(value);
}
}
});
} catch (ParseException ex) {
log.error("", ex);
}
}
return list;
}
Aggregations