Example usage for org.json Property Property

List of usage examples for org.json Property Property

Introduction

In this page you can find the example usage for org.json Property Property.

Prototype

Property

Source Link

Usage

From source file:com.cdd.bao.importer.KeywordMapping.java

public KeywordMapping(String mapFN) {
    file = new File(mapFN);

    // try to load the file, but it's OK if it fails
    JSONObject json = null;/*from w  w w . j  a v  a2s  .c om*/
    try {
        Reader rdr = new FileReader(file);
        json = new JSONObject(new JSONTokener(rdr));
        rdr.close();
    } catch (JSONException ex) {
        Util.writeln("NOTE: reading file " + file.getAbsolutePath() + " failed: " + ex.getMessage());
    } catch (IOException ex) {
        return;
    } // includes file not found, which is OK

    try {
        for (JSONObject obj : json.optJSONArrayEmpty("identifiers").toObjectArray()) {
            Identifier id = new Identifier();
            id.regex = regexOrName(obj.optString("regex"), obj.optString("name"));
            id.prefix = obj.optString("prefix");
            identifiers.add(id);
        }
        for (JSONObject obj : json.optJSONArrayEmpty("textBlocks").toObjectArray()) {
            TextBlock txt = new TextBlock();
            txt.regex = regexOrName(obj.optString("regex"), obj.optString("name"));
            txt.title = obj.optString("title");
            textBlocks.add(txt);
        }
        for (JSONObject obj : json.optJSONArrayEmpty("properties").toObjectArray()) {
            Property prop = new Property();
            prop.regex = regexOrName(obj.optString("regex"), obj.optString("name"));
            prop.propURI = obj.optString("propURI");
            prop.groupNest = obj.optJSONArrayEmpty("groupNest").toStringArray();
            properties.add(prop);
        }
        for (JSONObject obj : json.optJSONArrayEmpty("values").toObjectArray()) {
            Value val = new Value();
            val.regex = regexOrName(obj.optString("regex"), obj.optString("name"));
            val.valueRegex = regexOrName(obj.optString("valueRegex"), obj.optString("valueName"));
            val.valueURI = obj.optString("valueURI");
            val.propURI = obj.optString("propURI");
            val.groupNest = obj.optJSONArrayEmpty("groupNest").toStringArray();
            values.add(val);
        }
        for (JSONObject obj : json.optJSONArrayEmpty("literals").toObjectArray()) {
            Literal lit = new Literal();
            lit.regex = regexOrName(obj.optString("regex"), obj.optString("name"));
            lit.valueRegex = regexOrName(obj.optString("valueRegex"), obj.optString("valueName"));
            lit.propURI = obj.optString("propURI");
            lit.groupNest = obj.optJSONArrayEmpty("groupNest").toStringArray();
            literals.add(lit);
        }
        for (JSONObject obj : json.optJSONArrayEmpty("references").toObjectArray()) {
            Reference ref = new Reference();
            ref.regex = regexOrName(obj.optString("regex"), obj.optString("name"));
            ref.valueRegex = regexOrName(obj.optString("valueRegex"), obj.optString("valueName"));
            ref.prefix = obj.optString("prefix");
            ref.propURI = obj.optString("propURI");
            ref.groupNest = obj.optJSONArrayEmpty("groupNest").toStringArray();
            references.add(ref);
        }
        for (JSONObject obj : json.optJSONArrayEmpty("assertions").toObjectArray()) {
            Assertion asrt = new Assertion();
            asrt.propURI = obj.optString("propURI");
            asrt.groupNest = obj.optJSONArrayEmpty("groupNest").toStringArray();
            asrt.valueURI = obj.optString("valueURI");
            assertions.add(asrt);
        }
    } catch (JSONException ex) {
        Util.writeln("NOTE: parsing error");
        ex.printStackTrace();
        Util.writeln(
                "*** Execution will continue, but part of the mapping has not been loaded and may be overwritten.");
    }
}