<commit_before>package org.odk.collect.android.jr.extensions;

import org.javarosa.core.model.QuestionDataExtension;
import org.javarosa.xform.parse.QuestionExtensionParser;
import org.javarosa.xform.parse.XFormParser;
import org.kxml2.kdom.Element;

/**
 * An additional parser for the "upload" question type that looks for an extra attribute
 * specifying the maximum allowable dimension for an image
 *
 * @author amstone
 */
public class ImageRestrictionExtensionParser extends QuestionExtensionParser {

    public ImageRestrictionExtensionParser() {
        setElementName("upload");
    }

    @Override
    public QuestionDataExtension parse(Element elt) {
        String s = elt.getAttributeValue(XFormParser.NAMESPACE_JAVAROSA,
                "imageDimensionScaledMax");
        if (s != null) {
            if (s.endsWith("px")) {
                s = s.substring(0, s.length() - 2);
            }
            try {
                int maxDimens = Integer.parseInt(s);
                return new ImageRestrictionExtension(maxDimens);
            } catch (NumberFormatException e) {
                return null;
            }<commit_msg>throw XFormParseException if max dimen format is invalid<commit_after>package org.odk.collect.android.jr.extensions;

import org.javarosa.core.model.QuestionDataExtension;
import org.javarosa.xform.parse.QuestionExtensionParser;
import org.javarosa.xform.parse.XFormParseException;
import org.javarosa.xform.parse.XFormParser;
import org.kxml2.kdom.Element;

/**
 * An additional parser for the "upload" question type that looks for an extra attribute
 * specifying the maximum allowable dimension for an image
 *
 * @author amstone
 */
public class ImageRestrictionExtensionParser extends QuestionExtensionParser {

    public ImageRestrictionExtensionParser() {
        setElementName("upload");
    }

    @Override
    public QuestionDataExtension parse(Element elt) {
        String s = elt.getAttributeValue(XFormParser.NAMESPACE_JAVAROSA,
                "imageDimensionScaledMax");
        if (s != null) {
            if (s.endsWith("px")) {
                s = s.substring(0, s.length() - 2);
            }
            try {
                int maxDimens = Integer.parseInt(s);
                return new ImageRestrictionExtension(maxDimens);
            } catch (NumberFormatException e) {
                throw new XFormParseException("Invalid input for image max dimension: " + s);
            }
{'fraction_non_alphanumeric': 0.08757637474541752, 'fraction_numerical': 0.002443991853360489, 'mean_word_length': 2.807751937984496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5650221', 'n_tokens_mistral': 675, 'n_tokens_neox': 657, 'n_words': 160}