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.xml.internal.stream;
27
28 import com.sun.org.apache.xerces.internal.impl.Constants;
29 import com.sun.org.apache.xerces.internal.impl.PropertyManager;
30 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
31 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
32 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
33 import com.sun.org.apache.xerces.internal.util.URI;
34 import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;
35 import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
36 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
37 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
38 import java.util.Collections;
39 import java.util.Enumeration;
40 import java.util.HashMap;
41 import java.util.Map;
42
43 /**
44 *
45 * @author K.Venugopal SUN Microsystems
46 * @author Neeraj Bajaj SUN Microsystems
47 * @author Andy Clark, IBM
48 *
49 */
50 public class XMLEntityStorage {
51
52 /** Property identifier: error reporter. */
53 protected static final String ERROR_REPORTER =
54 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
55
56 /** Feature identifier: warn on duplicate EntityDef */
57 protected static final String WARN_ON_DUPLICATE_ENTITYDEF =
58 Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
59
125 fWarnDuplicateEntityDef = componentManager.getFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);
126
127 fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
128
129 fEntities.clear();
130 fCurrentEntity = null;
131
132 } // reset(XMLComponentManager)
133
134 /**
135 * Returns entity declaration.
136 *
137 * @param name The name of the entity.
138 *
139 * @see SymbolTable
140 */
141 public Entity getEntity(String name) {
142 return fEntities.get(name);
143 } // getEntity(String)
144
145 public boolean hasEntities() {
146 return (fEntities!=null);
147 } // getEntity(String)
148
149 public int getEntitySize() {
150 return fEntities.size();
151 } // getEntity(String)
152
153 public Enumeration getEntityKeys() {
154 return Collections.enumeration(fEntities.keySet());
155 }
156 /**
157 * Adds an internal entity declaration.
158 * <p>
159 * <strong>Note:</strong> This method ignores subsequent entity
160 * declarations.
161 * <p>
162 * <strong>Note:</strong> The name should be a unique symbol. The
163 * SymbolTable can be used for this purpose.
164 *
165 * @param name The name of the entity.
166 * @param text The text of the entity.
167 *
168 * @see SymbolTable
169 */
170 public void addInternalEntity(String name, String text) {
171 if (!fEntities.containsKey(name)) {
172 Entity entity = new Entity.InternalEntity(name, text, fInExternalSubset);
173 fEntities.put(name, entity);
174 }
293 * <p>
294 * <strong>Note:</strong> This method ignores subsequent entity
295 * declarations.
296 * <p>
297 * <strong>Note:</strong> The name should be a unique symbol. The
298 * SymbolTable can be used for this purpose.
299 *
300 * @param name The name of the entity.
301 * @param publicId The public identifier of the entity.
302 * @param systemId The system identifier of the entity.
303 * @param notation The name of the notation.
304 *
305 * @see SymbolTable
306 */
307 public void addUnparsedEntity(String name,
308 String publicId, String systemId,
309 String baseSystemId, String notation) {
310
311 fCurrentEntity = fEntityManager.getCurrentEntity();
312 if (!fEntities.containsKey(name)) {
313 Entity entity = new Entity.ExternalEntity(name, new XMLResourceIdentifierImpl(publicId, systemId, baseSystemId, null), notation, fInExternalSubset);
314 // (fCurrentEntity == null) ? fasle : fCurrentEntity.isEntityDeclInExternalSubset());
315 // fCurrentEntity.isEntityDeclInExternalSubset());
316 fEntities.put(name, entity);
317 }
318 else{
319 if(fWarnDuplicateEntityDef){
320 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
321 "MSG_DUPLICATE_ENTITY_DEFINITION",
322 new Object[]{ name },
323 XMLErrorReporter.SEVERITY_WARNING );
324 }
325 }
326 } // addUnparsedEntity(String,String,String,String)
327
328 /**
329 * Checks whether an entity given by name is unparsed.
330 *
331 * @param entityName The name of the entity to check.
332 * @returns True if the entity is unparsed, false otherwise
333 * (including when the entity is not declared).
334 */
335 public boolean isUnparsedEntity(String entityName) {
421 catch (SecurityException se) {
422 }
423
424 // return empty string if property value is empty string.
425 if (userDir.length() == 0)
426 return "";
427
428 // compute the new escaped value if the new property value doesn't
429 // match the previous one
430 if (userDir.equals(gUserDir)) {
431 return gEscapedUserDir;
432 }
433
434 // record the new value as the global property value
435 gUserDir = userDir;
436
437 char separator = java.io.File.separatorChar;
438 userDir = userDir.replace(separator, '/');
439
440 int len = userDir.length(), ch;
441 StringBuffer buffer = new StringBuffer(len*3);
442 // change C:/blah to /C:/blah
443 if (len >= 2 && userDir.charAt(1) == ':') {
444 ch = Character.toUpperCase(userDir.charAt(0));
445 if (ch >= 'A' && ch <= 'Z') {
446 buffer.append('/');
447 }
448 }
449
450 // for each character in the path
451 int i = 0;
452 for (; i < len; i++) {
453 ch = userDir.charAt(i);
454 // if it's not an ASCII character, break here, and use UTF-8 encoding
455 if (ch >= 128)
456 break;
457 if (gNeedEscaping[ch]) {
458 buffer.append('%');
459 buffer.append(gAfterEscaping1[ch]);
460 buffer.append(gAfterEscaping2[ch]);
461 // record the fact that it's escaped
|
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.xml.internal.stream;
27
28 import com.sun.org.apache.xerces.internal.impl.Constants;
29 import com.sun.org.apache.xerces.internal.impl.PropertyManager;
30 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
31 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
32 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
33 import com.sun.org.apache.xerces.internal.util.URI;
34 import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;
35 import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
36 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
37 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
38 import java.util.HashMap;
39 import java.util.Map;
40
41 /**
42 *
43 * @author K.Venugopal SUN Microsystems
44 * @author Neeraj Bajaj SUN Microsystems
45 * @author Andy Clark, IBM
46 *
47 */
48 public class XMLEntityStorage {
49
50 /** Property identifier: error reporter. */
51 protected static final String ERROR_REPORTER =
52 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
53
54 /** Feature identifier: warn on duplicate EntityDef */
55 protected static final String WARN_ON_DUPLICATE_ENTITYDEF =
56 Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
57
123 fWarnDuplicateEntityDef = componentManager.getFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);
124
125 fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
126
127 fEntities.clear();
128 fCurrentEntity = null;
129
130 } // reset(XMLComponentManager)
131
132 /**
133 * Returns entity declaration.
134 *
135 * @param name The name of the entity.
136 *
137 * @see SymbolTable
138 */
139 public Entity getEntity(String name) {
140 return fEntities.get(name);
141 } // getEntity(String)
142
143 public Map<String, Entity> getEntities() {
144 return fEntities;
145 }
146 /**
147 * Adds an internal entity declaration.
148 * <p>
149 * <strong>Note:</strong> This method ignores subsequent entity
150 * declarations.
151 * <p>
152 * <strong>Note:</strong> The name should be a unique symbol. The
153 * SymbolTable can be used for this purpose.
154 *
155 * @param name The name of the entity.
156 * @param text The text of the entity.
157 *
158 * @see SymbolTable
159 */
160 public void addInternalEntity(String name, String text) {
161 if (!fEntities.containsKey(name)) {
162 Entity entity = new Entity.InternalEntity(name, text, fInExternalSubset);
163 fEntities.put(name, entity);
164 }
283 * <p>
284 * <strong>Note:</strong> This method ignores subsequent entity
285 * declarations.
286 * <p>
287 * <strong>Note:</strong> The name should be a unique symbol. The
288 * SymbolTable can be used for this purpose.
289 *
290 * @param name The name of the entity.
291 * @param publicId The public identifier of the entity.
292 * @param systemId The system identifier of the entity.
293 * @param notation The name of the notation.
294 *
295 * @see SymbolTable
296 */
297 public void addUnparsedEntity(String name,
298 String publicId, String systemId,
299 String baseSystemId, String notation) {
300
301 fCurrentEntity = fEntityManager.getCurrentEntity();
302 if (!fEntities.containsKey(name)) {
303 Entity entity = new Entity.ExternalEntity(name,
304 new XMLResourceIdentifierImpl(publicId, systemId, baseSystemId, null),
305 notation, fInExternalSubset);
306 fEntities.put(name, entity);
307 }
308 else{
309 if(fWarnDuplicateEntityDef){
310 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
311 "MSG_DUPLICATE_ENTITY_DEFINITION",
312 new Object[]{ name },
313 XMLErrorReporter.SEVERITY_WARNING );
314 }
315 }
316 } // addUnparsedEntity(String,String,String,String)
317
318 /**
319 * Checks whether an entity given by name is unparsed.
320 *
321 * @param entityName The name of the entity to check.
322 * @returns True if the entity is unparsed, false otherwise
323 * (including when the entity is not declared).
324 */
325 public boolean isUnparsedEntity(String entityName) {
411 catch (SecurityException se) {
412 }
413
414 // return empty string if property value is empty string.
415 if (userDir.length() == 0)
416 return "";
417
418 // compute the new escaped value if the new property value doesn't
419 // match the previous one
420 if (userDir.equals(gUserDir)) {
421 return gEscapedUserDir;
422 }
423
424 // record the new value as the global property value
425 gUserDir = userDir;
426
427 char separator = java.io.File.separatorChar;
428 userDir = userDir.replace(separator, '/');
429
430 int len = userDir.length(), ch;
431 StringBuilder buffer = new StringBuilder(len*3);
432 // change C:/blah to /C:/blah
433 if (len >= 2 && userDir.charAt(1) == ':') {
434 ch = Character.toUpperCase(userDir.charAt(0));
435 if (ch >= 'A' && ch <= 'Z') {
436 buffer.append('/');
437 }
438 }
439
440 // for each character in the path
441 int i = 0;
442 for (; i < len; i++) {
443 ch = userDir.charAt(i);
444 // if it's not an ASCII character, break here, and use UTF-8 encoding
445 if (ch >= 128)
446 break;
447 if (gNeedEscaping[ch]) {
448 buffer.append('%');
449 buffer.append(gAfterEscaping1[ch]);
450 buffer.append(gAfterEscaping2[ch]);
451 // record the fact that it's escaped
|