Search in sources :

Example 1 with AbstractMarkupHandler

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;
}
Also used : AbstractMarkupHandler(org.attoparser.AbstractMarkupHandler) ArrayList(java.util.ArrayList) Problem(cn.edu.zjnu.acm.judge.domain.Problem) ParseException(org.attoparser.ParseException) MarkupParser(org.attoparser.MarkupParser)

Aggregations

Problem (cn.edu.zjnu.acm.judge.domain.Problem)1 ArrayList (java.util.ArrayList)1 AbstractMarkupHandler (org.attoparser.AbstractMarkupHandler)1 MarkupParser (org.attoparser.MarkupParser)1 ParseException (org.attoparser.ParseException)1