Search in sources :

Example 1 with UnknownPropertyException

use of org.apache.jena.shared.UnknownPropertyException in project jena by apache.

the class JenaReader method processArpOptions.

/**
     * Supported properties: 
     * error-mode (String) default, lax, strict,
     * strict-ignore, strict-warning, strict-error, strict.error <br/> 
     * embedding (String/Boolean) true, false<br/>
     * ERR_* (String/Integer) em_warning, em.error, em_ignore, em_error<br/>
     * IGN_* ditto<br/>
     * WARN_* ditto<br/>
     * iri-rules (String), "Jena", "IRI", "strict", "lax"
     */
@SuppressWarnings("deprecation")
static Object processArpOptions(ARPOptions options, String str, Object v, RDFErrorHandler eh) {
    // ARPOptions options = arpf.getOptions();
    str = str.toUpperCase();
    if (v == null)
        v = "";
    if (v instanceof String) {
        v = ((String) v).toUpperCase(Locale.ENGLISH);
    }
    if (str.equals("ERROR-MODE")) {
        if (v instanceof String) {
            String val = (String) v;
            if (val.equals("LAX")) {
                options.setLaxErrorMode();
                return null;
            }
            if (val.equals("DEFAULT")) {
                options.setDefaultErrorMode();
                return null;
            }
            if (val.equals("STRICT")) {
                options.setStrictErrorMode();
                return null;
            }
            if (val.equals("STRICT-WARNING")) {
                options.setStrictErrorMode(EM_WARNING);
                return null;
            }
            if (val.equals("STRICT-FATAL")) {
                options.setStrictErrorMode(EM_FATAL);
                return null;
            }
            if (val.equals("STRICT-IGNORE")) {
                options.setStrictErrorMode(EM_IGNORE);
                return null;
            }
            if (val.equals("STRICT-ERROR")) {
                options.setStrictErrorMode(EM_ERROR);
                return null;
            }
        }
        eh.error(new IllegalArgumentException("Property \"ERROR-MODE\" takes the following values: " + "\"default\", \"lax\", \"strict\", \"strict-ignore\", \"strict-warning\", \"strict-error\", \"strict.error\"."));
        return null;
    }
    if (str.equals("EMBEDDING")) {
        if (v instanceof String) {
            v = Boolean.valueOf((String) v);
        }
        if ((v instanceof Boolean))
            return options.setEmbedding(((Boolean) v).booleanValue());
        // Illegal value.
        eh.error(new IllegalArgumentException("Property \"EMBEDDING\" requires a boolean value."));
        boolean old = options.setEmbedding(false);
        options.setEmbedding(old);
        return old;
    }
    if (str.startsWith("ERR_") || str.startsWith("IGN_") || str.startsWith("WARN_")) {
        int cond = ParseException.errorCode(str);
        if (cond == -1) {
        // error, see end of function.
        } else {
            if (v instanceof String) {
                if (!((String) v).startsWith("EM_")) {
                // error, see below.
                } else {
                    int val = ParseException.errorCode((String) v);
                    if (val == -1) {
                    // error, see below.
                    } else {
                        int rslt = options.setErrorMode(cond, val);
                        return rslt;
                    }
                }
            } else if (v instanceof Integer) {
                int val = ((Integer) v).intValue();
                switch(val) {
                    case EM_IGNORE:
                    case EM_WARNING:
                    case EM_ERROR:
                    case EM_FATAL:
                        int rslt = options.setErrorMode(cond, val);
                        return rslt;
                    default:
                }
            }
            // Illegal value.
            eh.error(new IllegalArgumentException("Property \"" + str + "\" cannot have value: " + v.toString()));
            int old = options.setErrorMode(cond, EM_ERROR);
            options.setErrorMode(cond, old);
            return old;
        }
    }
    if (str.equals("IRI-RULES")) {
        IRIFactory old = options.getIRIFactory();
        if (v.equals("STRICT")) {
            options.setIRIFactory(IRIFactory.semanticWebImplementation());
        } else if (v.equals("IRI")) {
            options.setIRIFactory(IRIFactory.iriImplementation());
        } else if (v.equals("LAX")) {
            options.setIRIFactory(IRIFactory.jenaImplementation());
        } else
            eh.error(new IllegalArgumentException("Property \"IRI-RULES\" requires one of 'STRICT', 'IRI' or 'LAX'"));
        return old;
    }
    eh.error(new UnknownPropertyException(str));
    return null;
}
Also used : IRIFactory(org.apache.jena.iri.IRIFactory) UnknownPropertyException(org.apache.jena.shared.UnknownPropertyException)

Aggregations

IRIFactory (org.apache.jena.iri.IRIFactory)1 UnknownPropertyException (org.apache.jena.shared.UnknownPropertyException)1