|
1 /* |
|
2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 * |
|
25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
|
26 */ |
|
27 |
|
28 package com.sun.xml.internal.fastinfoset.stax; |
|
29 |
|
30 import java.util.HashMap; |
|
31 import javax.xml.stream.XMLInputFactory; |
|
32 import javax.xml.stream.XMLOutputFactory; |
|
33 import com.sun.xml.internal.fastinfoset.CommonResourceBundle; |
|
34 |
|
35 public class StAXManager { |
|
36 protected static final String STAX_NOTATIONS = "javax.xml.stream.notations"; |
|
37 protected static final String STAX_ENTITIES = "javax.xml.stream.entities"; |
|
38 |
|
39 HashMap features = new HashMap(); |
|
40 |
|
41 public static final int CONTEXT_READER = 1; |
|
42 public static final int CONTEXT_WRITER = 2; |
|
43 |
|
44 |
|
45 /** Creates a new instance of StAXManager */ |
|
46 public StAXManager() { |
|
47 } |
|
48 |
|
49 public StAXManager(int context) { |
|
50 switch(context){ |
|
51 case CONTEXT_READER:{ |
|
52 initConfigurableReaderProperties(); |
|
53 break; |
|
54 } |
|
55 case CONTEXT_WRITER:{ |
|
56 initWriterProps(); |
|
57 break; |
|
58 } |
|
59 } |
|
60 } |
|
61 |
|
62 public StAXManager(StAXManager manager){ |
|
63 |
|
64 HashMap properties = manager.getProperties(); |
|
65 features.putAll(properties); |
|
66 } |
|
67 |
|
68 private HashMap getProperties(){ |
|
69 return features ; |
|
70 } |
|
71 |
|
72 private void initConfigurableReaderProperties(){ |
|
73 //spec v1.0 default values |
|
74 features.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); |
|
75 features.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); |
|
76 features.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); |
|
77 features.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE); |
|
78 features.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE); |
|
79 features.put(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); |
|
80 features.put(XMLInputFactory.REPORTER, null); |
|
81 features.put(XMLInputFactory.RESOLVER, null); |
|
82 features.put(XMLInputFactory.ALLOCATOR, null); |
|
83 features.put(STAX_NOTATIONS,null ); |
|
84 } |
|
85 |
|
86 private void initWriterProps(){ |
|
87 features.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE); |
|
88 } |
|
89 |
|
90 /** |
|
91 * public void reset(){ |
|
92 * features.clear() ; |
|
93 * } |
|
94 */ |
|
95 public boolean containsProperty(String property){ |
|
96 return features.containsKey(property) ; |
|
97 } |
|
98 |
|
99 public Object getProperty(String name){ |
|
100 checkProperty(name); |
|
101 return features.get(name); |
|
102 } |
|
103 |
|
104 public void setProperty(String name, Object value){ |
|
105 checkProperty(name); |
|
106 if (name.equals(XMLInputFactory.IS_VALIDATING) && |
|
107 Boolean.TRUE.equals(value)){ |
|
108 throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.validationNotSupported") + |
|
109 CommonResourceBundle.getInstance().getString("support_validation")); |
|
110 } else if (name.equals(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES) && |
|
111 Boolean.TRUE.equals(value)) { |
|
112 throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.externalEntities") + |
|
113 CommonResourceBundle.getInstance().getString("resolve_external_entities_")); |
|
114 } |
|
115 features.put(name,value); |
|
116 |
|
117 } |
|
118 |
|
119 public void checkProperty(String name) { |
|
120 if (!features.containsKey(name)) |
|
121 throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name})); |
|
122 } |
|
123 |
|
124 public String toString(){ |
|
125 return features.toString(); |
|
126 } |
|
127 |
|
128 } |