|
|
|
|
|
*/ |
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
* (the "License"); you may not use this file except in compliance with |
|
* the License. You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.sun.org.apache.xerces.internal.util; |
|
|
|
import com.sun.org.apache.xerces.internal.impl.Constants; |
|
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; |
|
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; |
|
import java.util.ArrayList; |
|
import java.util.Arrays; |
|
import java.util.HashMap; |
|
import java.util.List; |
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class ParserConfigurationSettings |
|
implements XMLComponentManager { |
|
|
|
protected static final String PARSER_SETTINGS = |
|
Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; |
|
|
|
// |
|
// Data |
|
// |
|
|
|
// data |
|
|
|
|
|
protected List<String> fRecognizedProperties; |
|
|
|
|
|
protected Map<String, Object> fProperties; |
|
|
|
|
|
protected List<String> fRecognizedFeatures; |
|
|
|
|
|
protected Map<String, Boolean> fFeatures; |
|
|
|
|
|
protected XMLComponentManager fParentSettings; |
|
|
|
// |
|
// Constructors |
|
// |
|
|
|
|
|
public ParserConfigurationSettings() { |
|
this(null); |
|
} // <init>() |
|
|
|
|
|
|
|
|
|
*/ |
|
public ParserConfigurationSettings(XMLComponentManager parent) { |
|
|
|
|
|
fRecognizedFeatures = new ArrayList<>(); |
|
fRecognizedProperties = new ArrayList<>(); |
|
|
|
|
|
fFeatures = new HashMap<>(); |
|
fProperties = new HashMap<>(); |
|
|
|
|
|
fParentSettings = parent; |
|
|
|
} // <init>(XMLComponentManager) |
|
|
|
// |
|
// XMLParserConfiguration methods |
|
// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void addRecognizedFeatures(String[] featureIds) { |
|
|
|
|
|
int featureIdsCount = featureIds != null ? featureIds.length : 0; |
|
for (int i = 0; i < featureIdsCount; i++) { |
|
String featureId = featureIds[i]; |
|
if (!fRecognizedFeatures.contains(featureId)) { |
|
fRecognizedFeatures.add(featureId); |
|
} |
|
} |
|
|
|
} // addRecognizedFeatures(String[]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setFeature(String featureId, boolean state) |
|
throws XMLConfigurationException { |
|
|
|
|
|
FeatureState checkState = checkFeature(featureId); |
|
if (checkState.isExceptional()) { |
|
throw new XMLConfigurationException(checkState.status, featureId); |
|
} |
|
|
|
fFeatures.put(featureId, state); |
|
} // setFeature(String,boolean) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void addRecognizedProperties(String[] propertyIds) { |
|
fRecognizedProperties.addAll(Arrays.asList(propertyIds)); |
|
} // addRecognizedProperties(String[]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setProperty(String propertyId, Object value) |
|
throws XMLConfigurationException { |
|
|
|
|
|
PropertyState checkState = checkProperty(propertyId); |
|
if (checkState.isExceptional()) { |
|
throw new XMLConfigurationException(checkState.status, propertyId); |
|
} |
|
fProperties.put(propertyId, value); |
|
|
|
} // setProperty(String,Object) |
|
|
|
// |
|
// XMLComponentManager methods |
|
// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public boolean getFeature(String featureId) |
|
throws XMLConfigurationException { |
|
|
|
FeatureState state = getFeatureState(featureId); |
|
if (state.isExceptional()) { |
|
throw new XMLConfigurationException(state.status, featureId); |
|
} |
|
return state.state; |
|
} // getFeature(String):boolean |
|
|
|
@Override |
|
public final boolean getFeature(String featureId, boolean defaultValue) { |
|
FeatureState state = getFeatureState(featureId); |
|
if (state.isExceptional()) { |
|
return defaultValue; |
|
} |
|
return state.state; |
|
} |
|
|
|
@Override |
|
public FeatureState getFeatureState(String featureId) { |
|
Boolean state = fFeatures.get(featureId); |
|
|
|
if (state == null) { |
|
FeatureState checkState = checkFeature(featureId); |
|
if (checkState.isExceptional()) { |
|
return checkState; |
|
} |
|
return FeatureState.is(false); |
|
} |
|
return FeatureState.is(state); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public Object getProperty(String propertyId) |
|
throws XMLConfigurationException { |
|
|
|
PropertyState state = getPropertyState(propertyId); |
|
if (state.isExceptional()) { |
|
throw new XMLConfigurationException(state.status, propertyId); |
|
} |
|
|
|
return state.state; |
|
} // getProperty(String):Object |
|
|
|
@Override |
|
public final Object getProperty(String propertyId, Object defaultValue) { |
|
PropertyState state = getPropertyState(propertyId); |
|
if (state.isExceptional()) { |
|
return defaultValue; |
|
} |
|
|
|
return state.state; |
|
} |
|
|
|
@Override |
|
public PropertyState getPropertyState(String propertyId) { |
|
Object propertyValue = fProperties.get(propertyId); |
|
|
|
if (propertyValue == null) { |
|
PropertyState state = checkProperty(propertyId); |
|
if (state.isExceptional()) { |
|
return state; |
|
} |
|
} |
|
|
|
return PropertyState.is(propertyValue); |
|
} |
|
|
|
// |
|
// Protected methods |
|
// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected FeatureState checkFeature(String featureId) |
|
throws XMLConfigurationException { |
|
|
|
|
|
if (!fRecognizedFeatures.contains(featureId)) { |
|
if (fParentSettings != null) { |
|
return fParentSettings.getFeatureState(featureId); |
|
} |
|
else { |
|
return FeatureState.NOT_RECOGNIZED; |
|
} |
|
} |
|
|
|
|
|
return FeatureState.RECOGNIZED; |
|
} // checkFeature(String) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected PropertyState checkProperty(String propertyId) |
|
throws XMLConfigurationException { |
|
|
|
|
|
if (!fRecognizedProperties.contains(propertyId)) { |
|
if (fParentSettings != null) { |
|
PropertyState state = fParentSettings.getPropertyState(propertyId); |
|
if (state.isExceptional()) { |
|
return state; |
|
} |
|
} |
|
else { |
|
return PropertyState.NOT_RECOGNIZED; |
|
} |
|
} |
|
return PropertyState.RECOGNIZED; |
|
} // checkProperty(String) |
|
|
|
} // class ParserConfigurationSettings |