src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 22,31 **** --- 22,35 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.xml.catalog; + import java.net.MalformedURLException; + import java.net.URISyntaxException; + import java.util.HashMap; + import java.util.Map; import jdk.xml.internal.SecuritySupport; /** * The CatalogFeatures holds a collection of features and properties. * <p>
*** 378,391 **** * * @param builder the builder to build the CatalogFeatures */ CatalogFeatures(Builder builder) { init(); ! setProperty(Feature.FILES.ordinal(), State.APIPROPERTY, builder.files); ! setProperty(Feature.PREFER.ordinal(), State.APIPROPERTY, builder.prefer); ! setProperty(Feature.DEFER.ordinal(), State.APIPROPERTY, builder.defer); ! setProperty(Feature.RESOLVE.ordinal(), State.APIPROPERTY, builder.resolve); } /** * Returns the value of the specified feature. * --- 382,392 ---- * * @param builder the builder to build the CatalogFeatures */ CatalogFeatures(Builder builder) { init(); ! setProperties(builder); } /** * Returns the value of the specified feature. *
*** 408,417 **** --- 409,427 ---- //read system properties or jaxp.properties readSystemProperties(); } /** + * Sets properties by the Builder. + * @param builder the CatalogFeatures builder + */ + private void setProperties(Builder builder) { + builder.values.entrySet().stream().forEach((entry) -> { + setProperty(entry.getKey().ordinal(), State.APIPROPERTY, entry.getValue()); + }); + } + /** * Sets the value of a property by its index, updates only if it shall override. * * @param index the index of the property * @param state the state of the property * @param value the value of the property
*** 430,444 **** --- 440,467 ---- } else if (index == Feature.RESOLVE.ordinal()) { if (!value.equals(RESOLVE_STRICT) && !value.equals(RESOLVE_CONTINUE) && !value.equals(RESOLVE_IGNORE)) { CatalogMessages.reportIAE(new Object[]{value, Feature.RESOLVE.name()}, null); } + } else if (index == Feature.FILES.ordinal()) { + try { + if (Util.verifyAndGetURI(value, null) == null) { + CatalogMessages.reportIAE(new Object[]{value, Feature.FILES.name()}, null); + } + }catch (MalformedURLException | URISyntaxException | IllegalArgumentException ex) { + CatalogMessages.reportIAE(new Object[]{value, Feature.FILES.name()}, ex); + } + } if (states[index] == null || state.compareTo(states[index]) >= 0) { values[index] = value; states[index] = state; } + } else { + if (state == State.SYSTEMPROPERTY || state == State.JAXPDOTPROPERTIES) { + CatalogMessages.reportIAE(new Object[]{value, Feature.values()[index].name()}, null); + } } } /** * Reads from system properties, or those in jaxp.properties
*** 484,496 **** /** * The Builder class for building the CatalogFeatures object. */ public static class Builder { /** ! * Variables for the features supported by CatalogFeatures. */ ! String files, prefer, defer, resolve; /** * Instantiation of Builder is not allowed. */ private Builder() {} --- 507,519 ---- /** * The Builder class for building the CatalogFeatures object. */ public static class Builder { /** ! * Values of the features supported by CatalogFeatures. */ ! Map<Feature, String> values = new HashMap<>(); /** * Instantiation of Builder is not allowed. */ private Builder() {}
*** 503,526 **** * @throws IllegalArgumentException if the value is not valid for the * Feature or has the wrong syntax for the {@code javax.xml.catalog.files} * property */ public Builder with(Feature feature, String value) { ! switch (feature) { ! case FILES : ! files = value; ! break; ! case PREFER : ! prefer = value; ! break; ! case DEFER : ! defer = value; ! break; ! case RESOLVE : ! resolve = value; ! break; } return this; } /** * Returns a CatalogFeatures object built by this builder. --- 526,539 ---- * @throws IllegalArgumentException if the value is not valid for the * Feature or has the wrong syntax for the {@code javax.xml.catalog.files} * property */ public Builder with(Feature feature, String value) { ! if (value == null || value.length() == 0) { ! CatalogMessages.reportIAE(new Object[]{value, feature.name()}, null); } + values.put(feature, value); return this; } /** * Returns a CatalogFeatures object built by this builder.