325N/A/*
325N/A * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A *
325N/A * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.fastinfoset.stax;
325N/A
325N/Aimport java.util.HashMap;
325N/Aimport javax.xml.stream.XMLInputFactory;
325N/Aimport javax.xml.stream.XMLOutputFactory;
325N/Aimport com.sun.xml.internal.fastinfoset.CommonResourceBundle;
325N/A
325N/Apublic class StAXManager {
325N/A protected static final String STAX_NOTATIONS = "javax.xml.stream.notations";
325N/A protected static final String STAX_ENTITIES = "javax.xml.stream.entities";
325N/A
325N/A HashMap features = new HashMap();
325N/A
325N/A public static final int CONTEXT_READER = 1;
325N/A public static final int CONTEXT_WRITER = 2;
325N/A
325N/A
325N/A /** Creates a new instance of StAXManager */
325N/A public StAXManager() {
325N/A }
325N/A
325N/A public StAXManager(int context) {
325N/A switch(context){
325N/A case CONTEXT_READER:{
325N/A initConfigurableReaderProperties();
325N/A break;
325N/A }
325N/A case CONTEXT_WRITER:{
325N/A initWriterProps();
325N/A break;
325N/A }
325N/A }
325N/A }
325N/A
325N/A public StAXManager(StAXManager manager){
325N/A
325N/A HashMap properties = manager.getProperties();
325N/A features.putAll(properties);
325N/A }
325N/A
325N/A private HashMap getProperties(){
325N/A return features ;
325N/A }
325N/A
325N/A private void initConfigurableReaderProperties(){
325N/A //spec v1.0 default values
325N/A features.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
325N/A features.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
325N/A features.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
325N/A features.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
325N/A features.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
325N/A features.put(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
325N/A features.put(XMLInputFactory.REPORTER, null);
325N/A features.put(XMLInputFactory.RESOLVER, null);
325N/A features.put(XMLInputFactory.ALLOCATOR, null);
325N/A features.put(STAX_NOTATIONS,null );
325N/A }
325N/A
325N/A private void initWriterProps(){
325N/A features.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE);
325N/A }
325N/A
325N/A /**
325N/A * public void reset(){
325N/A * features.clear() ;
325N/A * }
325N/A */
325N/A public boolean containsProperty(String property){
325N/A return features.containsKey(property) ;
325N/A }
325N/A
325N/A public Object getProperty(String name){
325N/A checkProperty(name);
325N/A return features.get(name);
325N/A }
325N/A
325N/A public void setProperty(String name, Object value){
325N/A checkProperty(name);
325N/A if (name.equals(XMLInputFactory.IS_VALIDATING) &&
325N/A Boolean.TRUE.equals(value)){
325N/A throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.validationNotSupported") +
325N/A CommonResourceBundle.getInstance().getString("support_validation"));
325N/A } else if (name.equals(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES) &&
325N/A Boolean.TRUE.equals(value)) {
325N/A throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.externalEntities") +
325N/A CommonResourceBundle.getInstance().getString("resolve_external_entities_"));
325N/A }
325N/A features.put(name,value);
325N/A
325N/A }
325N/A
325N/A public void checkProperty(String name) {
325N/A if (!features.containsKey(name))
325N/A throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
325N/A }
325N/A
325N/A public String toString(){
325N/A return features.toString();
325N/A }
325N/A
325N/A}