author | joehw |
Tue, 09 Jul 2013 16:34:52 -0700 | |
changeset 18890 | 25bdeca3173b |
parent 17534 | 21dc0b2762da |
child 18891 | be38bcc1d0f3 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
2 |
* Copyright (c) 2005, 2006, 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 |
||
26 |
package com.sun.org.apache.xerces.internal.impl; |
|
27 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
28 |
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; |
17534 | 29 |
import com.sun.xml.internal.stream.StaxEntityResolverWrapper; |
12005 | 30 |
import java.util.HashMap; |
31 |
import javax.xml.stream.XMLInputFactory; |
|
32 |
import javax.xml.stream.XMLOutputFactory; |
|
33 |
import javax.xml.stream.XMLResolver; |
|
34 |
||
35 |
/** |
|
36 |
* This class manages different properties related to Stax specification and its implementation. |
|
37 |
* This class constructor also takes itself (PropertyManager object) as parameter and initializes the |
|
38 |
* object with the property taken from the object passed. |
|
39 |
* |
|
40 |
* @author Neeraj Bajaj, neeraj.bajaj@sun.com |
|
41 |
* @author K.Venugopal@sun.com |
|
42 |
* @author Sunitha Reddy, sunitha.reddy@sun.com |
|
43 |
*/ |
|
44 |
||
45 |
public class PropertyManager { |
|
46 |
||
47 |
||
48 |
public static final String STAX_NOTATIONS = "javax.xml.stream.notations"; |
|
49 |
public static final String STAX_ENTITIES = "javax.xml.stream.entities"; |
|
50 |
||
51 |
private static final String STRING_INTERNING = "http://xml.org/sax/features/string-interning"; |
|
52 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
53 |
/** Property identifier: Security property manager. */ |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
54 |
private static final String XML_SECURITY_PROPERTY_MANAGER = |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
55 |
Constants.XML_SECURITY_PROPERTY_MANAGER; |
17534 | 56 |
|
12005 | 57 |
HashMap supportedProps = new HashMap(); |
58 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
59 |
private XMLSecurityPropertyManager fSecurityPropertyMgr; |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
60 |
|
12005 | 61 |
public static final int CONTEXT_READER = 1; |
62 |
public static final int CONTEXT_WRITER = 2; |
|
63 |
||
64 |
/** Creates a new instance of PropertyManager */ |
|
65 |
public PropertyManager(int context) { |
|
66 |
switch(context){ |
|
67 |
case CONTEXT_READER:{ |
|
68 |
initConfigurableReaderProperties(); |
|
69 |
break; |
|
70 |
} |
|
71 |
case CONTEXT_WRITER:{ |
|
72 |
initWriterProps(); |
|
73 |
break; |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Initialize this object with the properties taken from passed PropertyManager object. |
|
80 |
*/ |
|
81 |
public PropertyManager(PropertyManager propertyManager){ |
|
82 |
||
83 |
HashMap properties = propertyManager.getProperties(); |
|
84 |
supportedProps.putAll(properties); |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
85 |
fSecurityPropertyMgr = (XMLSecurityPropertyManager)getProperty(XML_SECURITY_PROPERTY_MANAGER); |
12005 | 86 |
} |
87 |
||
88 |
private HashMap getProperties(){ |
|
89 |
return supportedProps ; |
|
90 |
} |
|
91 |
||
92 |
||
93 |
/** |
|
94 |
* Important point: |
|
95 |
* 1. We are not exposing Xerces namespace property. Application should configure namespace through |
|
96 |
* Stax specific property. |
|
97 |
* |
|
98 |
*/ |
|
99 |
private void initConfigurableReaderProperties(){ |
|
100 |
//spec default values |
|
101 |
supportedProps.put(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); |
|
102 |
supportedProps.put(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); |
|
103 |
supportedProps.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE); |
|
104 |
supportedProps.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE); |
|
105 |
supportedProps.put(XMLInputFactory.IS_COALESCING, Boolean.FALSE); |
|
106 |
supportedProps.put(XMLInputFactory.SUPPORT_DTD, Boolean.TRUE); |
|
107 |
supportedProps.put(XMLInputFactory.REPORTER, null); |
|
108 |
supportedProps.put(XMLInputFactory.RESOLVER, null); |
|
109 |
supportedProps.put(XMLInputFactory.ALLOCATOR, null); |
|
110 |
supportedProps.put(STAX_NOTATIONS,null ); |
|
111 |
||
112 |
//zephyr (implementation) specific properties which can be set by the application. |
|
113 |
//interning is always done |
|
114 |
supportedProps.put(Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE , new Boolean(true)); |
|
115 |
//recognizing java encoding names by default |
|
116 |
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE, new Boolean(true)) ; |
|
117 |
//in stax mode, namespace declarations are not added as attributes |
|
118 |
supportedProps.put(Constants.ADD_NAMESPACE_DECL_AS_ATTRIBUTE , Boolean.FALSE) ; |
|
119 |
supportedProps.put(Constants.READER_IN_DEFINED_STATE, new Boolean(true)); |
|
120 |
supportedProps.put(Constants.REUSE_INSTANCE, new Boolean(true)); |
|
121 |
supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT , new Boolean(false)); |
|
122 |
supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD, Boolean.FALSE); |
|
123 |
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE, new Boolean(false)); |
|
124 |
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE, new Boolean(false)); |
|
125 |
supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE, new Boolean(false)); |
|
17534 | 126 |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
127 |
fSecurityPropertyMgr = new XMLSecurityPropertyManager(); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
128 |
supportedProps.put(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); |
12005 | 129 |
} |
130 |
||
131 |
private void initWriterProps(){ |
|
132 |
supportedProps.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE); |
|
133 |
//default value of escaping characters is 'true' |
|
134 |
supportedProps.put(Constants.ESCAPE_CHARACTERS , Boolean.TRUE); |
|
135 |
supportedProps.put(Constants.REUSE_INSTANCE, new Boolean(true)); |
|
136 |
} |
|
137 |
||
138 |
/** |
|
139 |
* public void reset(){ |
|
140 |
* supportedProps.clear() ; |
|
141 |
* } |
|
142 |
*/ |
|
143 |
public boolean containsProperty(String property){ |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
144 |
return supportedProps.containsKey(property) || |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
145 |
fSecurityPropertyMgr.getIndex(property) > -1 ; |
12005 | 146 |
} |
147 |
||
148 |
public Object getProperty(String property){ |
|
149 |
return supportedProps.get(property); |
|
150 |
} |
|
151 |
||
152 |
public void setProperty(String property, Object value){ |
|
153 |
String equivalentProperty = null ; |
|
154 |
if(property == XMLInputFactory.IS_NAMESPACE_AWARE || property.equals(XMLInputFactory.IS_NAMESPACE_AWARE)){ |
|
155 |
equivalentProperty = Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE ; |
|
156 |
} |
|
157 |
else if(property == XMLInputFactory.IS_VALIDATING || property.equals(XMLInputFactory.IS_VALIDATING)){ |
|
158 |
if( (value instanceof Boolean) && ((Boolean)value).booleanValue()){ |
|
159 |
throw new java.lang.IllegalArgumentException("true value of isValidating not supported") ; |
|
160 |
} |
|
161 |
} |
|
162 |
else if(property == STRING_INTERNING || property.equals(STRING_INTERNING)){ |
|
163 |
if( (value instanceof Boolean) && !((Boolean)value).booleanValue()){ |
|
164 |
throw new java.lang.IllegalArgumentException("false value of " + STRING_INTERNING + "feature is not supported") ; |
|
165 |
} |
|
166 |
} |
|
167 |
else if(property == XMLInputFactory.RESOLVER || property.equals(XMLInputFactory.RESOLVER)){ |
|
168 |
//add internal stax property |
|
169 |
supportedProps.put( Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY , new StaxEntityResolverWrapper((XMLResolver)value)) ; |
|
170 |
} |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
171 |
|
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
172 |
int index = fSecurityPropertyMgr.getIndex(property); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
173 |
if (index > -1) { |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
174 |
fSecurityPropertyMgr.setValue(index, |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
175 |
XMLSecurityPropertyManager.State.APIPROPERTY, (String)value); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
176 |
} else { |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
177 |
supportedProps.put(property, value); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
178 |
} |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
179 |
|
12005 | 180 |
if(equivalentProperty != null){ |
181 |
supportedProps.put(equivalentProperty, value ) ; |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
public String toString(){ |
|
186 |
return supportedProps.toString(); |
|
187 |
} |
|
188 |
||
189 |
}//PropertyManager |