package cz.hobrasoft.pdfmu;

import cz.hobrasoft.pdfmu.error.ErrorType;
import cz.hobrasoft.pdfmu.operation.OperationException;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author <a href="mailto:filip.bartek@hobrasoft.cz">Filip Bartek</a>
 */
public class ExceptionMessagePattern {

    private final ErrorType errorType;
    private final String regex;
    private final List<String> groupNames;

    public ExceptionMessagePattern(ErrorType errorType, String regex, List<String> groupNames) {
        this.errorType = errorType;
        this.regex = regex;
        this.groupNames = groupNames;
    }

    public OperationException getOperationException(Exception e) {
        String message = e.getMessage();
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(message);
        if (m.matches()) {
            SortedMap<String, String> arguments = PdfmuUtils.getMatcherGroups(m, groupNames);
            SortedMap<String, Object> argumentsObjects = new TreeMap<>();
            argumentsObjects.putAll(arguments);
            return new OperationException(errorType, e, argumentsObjects);
        }
        return null;
    }
}

@@ -728,24 +728,288 @@
 ;%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * Tries to convert an exception to an %7B@link OperationException%7D.%0D%0A     *%0D%0A     * @param e the exception to parse%0D%0A     * @return an instance of %7B@link OperationException%7D if the pattern matches%0D%0A     * the message of e, or null otherwise.%0D%0A     */%0D%0A
     public O

Add javadoc