static ApiExport fromJson()

in src/main/java/org/apache/sling/feature/extension/apiregions/api/ApiExport.java [303:352]


    static ApiExport fromJson(final ApiRegion region, final JsonValue val) throws IOException {
        if (val.getValueType() == ValueType.STRING) {
            final String name = ((JsonString) val).getString();
            if (!name.startsWith("#")) {
                final ApiExport export = new ApiExport(name);
                if (!region.add(export)) {
                    throw new IOException("Export " + export.getName()
                            + " is defined twice in region " + region.getName());
                }
                return export;
            }
            return null;
        } else if (val.getValueType() == ValueType.OBJECT) {
            final JsonObject expObj = (JsonObject) val;
            final ApiExport export = new ApiExport(expObj.getString(NAME_KEY));
            if (!region.add(export)) {
                throw new IOException("Export " + export.getName() + " is defined twice in region "
                        + region.getName());
            }

            boolean setPreviousArtifact = false;
            for (final String key : expObj.keySet()) {
                if (NAME_KEY.equals(key)) {
                    continue; // already set

                } else if (TOGGLE_KEY.equals(key)) {
                    export.setToggle(expObj.getString(key));

                } else if (PREVIOUS_ARTIFACT_ID_KEY.equals(key)) {
                    if ( setPreviousArtifact ) {
                        throw new IOException("Export " + export.getName() + " is defining previous artifact id twice in region "
                                + region.getName());
                    }
                    export.setPreviousArtifactId(ArtifactId.parse(expObj.getString(key)));
                    setPreviousArtifact = true;

                } else if ( DEPRECATED_KEY.equals(key)) {
                    final JsonValue dValue = expObj.get(DEPRECATED_KEY);
                    export.parseDeprecation(dValue);

                    // everything else is stored as a string property
                } else {
                    export.getProperties().put(key, expObj.getString(key));
                }
            }
            return export;
        } else {
            throw new IOException("Region " + region.getName() + " has wrong type for package export : " + val.getValueType().name());
        }
    }