1 38 39 package com.sun.xml.fastinfoset.stax; 40 41 import java.util.HashMap ; 42 import javax.xml.stream.XMLInputFactory; 43 import javax.xml.stream.XMLOutputFactory; 44 import javax.xml.stream.XMLResolver; 45 import com.sun.xml.fastinfoset.CommonResourceBundle; 46 47 public class StAXManager { 48 protected static final String STAX_NOTATIONS = "javax.xml.stream.notations"; 49 protected static final String STAX_ENTITIES = "javax.xml.stream.entities"; 50 51 HashMap features = new HashMap (); 52 53 public static final int CONTEXT_READER = 1; 54 public static final int CONTEXT_WRITER = 2; 55 56 57 58 public StAXManager() { 59 } 60 61 public StAXManager(int context) { 62 switch(context){ 63 case CONTEXT_READER:{ 64 initConfigurableReaderProperties(); 65 break; 66 } 67 case CONTEXT_WRITER:{ 68 initWriterProps(); 69 break; 70 } 71 } 72 } 73 74 public StAXManager(StAXManager manager){ 75 76 HashMap properties = manager.getProperties(); 77 features.putAll(properties); 78 } 79 80 private HashMap getProperties(){ 81 return features ; 82 } 83 84 private void initConfigurableReaderProperties(){ 85 features.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); 87 features.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); 88 features.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); 89 features.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE); 90 features.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE); 91 features.put(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); 92 features.put(XMLInputFactory.REPORTER, null); 93 features.put(XMLInputFactory.RESOLVER, null); 94 features.put(XMLInputFactory.ALLOCATOR, null); 95 features.put(STAX_NOTATIONS,null ); 96 } 97 98 private void initWriterProps(){ 99 features.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE); 100 } 101 102 107 public boolean containsProperty(String property){ 108 return features.containsKey(property) ; 109 } 110 111 public Object getProperty(String name){ 112 checkProperty(name); 113 return features.get(name); 114 } 115 116 public void setProperty(String name, Object value){ 117 checkProperty(name); 118 if (name.equals(XMLInputFactory.IS_VALIDATING) && 119 Boolean.TRUE.equals(value)){ 120 throw new IllegalArgumentException (CommonResourceBundle.getInstance().getString("message.validationNotSupported") + 121 CommonResourceBundle.getInstance().getString("support_validation")); 122 } else if (name.equals(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES) && 123 Boolean.TRUE.equals(value)) { 124 throw new IllegalArgumentException (CommonResourceBundle.getInstance().getString("message.externalEntities") + 125 CommonResourceBundle.getInstance().getString("resolve_external_entities_")); 126 } 127 features.put(name,value); 128 129 } 130 131 public void checkProperty(String name) { 132 if (!features.containsKey(name)) 133 throw new IllegalArgumentException (CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object []{name})); 134 } 135 136 public String toString(){ 137 return features.toString(); 138 } 139 140 } 141 | Popular Tags |