예제 #1
0
 public void setFeature(String name, boolean value)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     throw new NullPointerException(
         JAXPValidationMessageFormatter.formatMessage(
             Locale.getDefault(), "FeatureNameNull", null));
   }
   if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
     fSecurityManager = value ? new SecurityManager() : null;
     fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
     return;
   }
   try {
     fXMLSchemaLoader.setFeature(name, value);
   } catch (XMLConfigurationException e) {
     String identifier = e.getIdentifier();
     if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
       throw new SAXNotRecognizedException(
           SAXMessageFormatter.formatMessage(
               Locale.getDefault(), "feature-not-recognized", new Object[] {identifier}));
     } else {
       throw new SAXNotSupportedException(
           SAXMessageFormatter.formatMessage(
               Locale.getDefault(), "feature-not-supported", new Object[] {identifier}));
     }
   }
 }
예제 #2
0
 public void setProperty(String name, Object object)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     throw new NullPointerException(
         JAXPValidationMessageFormatter.formatMessage(
             Locale.getDefault(), "ProperyNameNull", null));
   }
   if (name.equals(SECURITY_MANAGER)) {
     fSecurityManager = (SecurityManager) object;
     fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
     return;
   } else if (name.equals(XMLGRAMMAR_POOL)) {
     throw new SAXNotSupportedException(
         SAXMessageFormatter.formatMessage(
             Locale.getDefault(), "property-not-supported", new Object[] {name}));
   }
   try {
     fXMLSchemaLoader.setProperty(name, object);
   } catch (XMLConfigurationException e) {
     String identifier = e.getIdentifier();
     if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
       throw new SAXNotRecognizedException(
           SAXMessageFormatter.formatMessage(
               Locale.getDefault(), "property-not-recognized", new Object[] {identifier}));
     } else {
       throw new SAXNotSupportedException(
           SAXMessageFormatter.formatMessage(
               Locale.getDefault(), "property-not-supported", new Object[] {identifier}));
     }
   }
 }
  /**
   * Query the state of a feature.
   *
   * <p>Query the current state of any feature in a SAX2 parser. The parser might not recognize the
   * feature.
   *
   * @param featureId The unique identifier (URI) of the feature being set.
   * @return The current state of the feature.
   * @exception org.xml.sax.SAXNotRecognizedException If the requested feature is not known.
   * @exception SAXNotSupportedException If the requested feature is known but not supported.
   */
  public boolean getFeature(String featureId)
      throws SAXNotRecognizedException, SAXNotSupportedException {

    try {

      // http://xml.org/sax/features/use-entity-resolver2
      //   controls whether the methods of an object implementing
      //   org.xml.sax.ext.EntityResolver2 will be used by the parser.
      //
      if (featureId.equals(USE_ENTITY_RESOLVER2)) {
        return fUseEntityResolver2;
      }

      //
      // Default handling
      //

      return fConfiguration.getFeature(featureId);
    } catch (XMLConfigurationException e) {
      String identifier = e.getIdentifier();
      if (e.getType() == Status.NOT_RECOGNIZED) {
        throw new SAXNotRecognizedException(
            SAXMessageFormatter.formatMessage(
                fConfiguration.getLocale(), "feature-not-recognized", new Object[] {identifier}));
      } else {
        throw new SAXNotSupportedException(
            SAXMessageFormatter.formatMessage(
                fConfiguration.getLocale(), "feature-not-supported", new Object[] {identifier}));
      }
    }
  } // getFeature(String):boolean
 public boolean getFeature(String name)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     throw new NullPointerException(
         JAXPValidationMessageFormatter.formatMessage(
             fXMLSchemaLoader.getLocale(), "FeatureNameNull", null));
   }
   if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
     return (fSecurityManager != null);
   }
   try {
     return fXMLSchemaLoader.getFeature(name);
   } catch (XMLConfigurationException e) {
     String identifier = e.getIdentifier();
     if (e.getType() == Status.NOT_RECOGNIZED) {
       throw new SAXNotRecognizedException(
           SAXMessageFormatter.formatMessage(
               fXMLSchemaLoader.getLocale(), "feature-not-recognized", new Object[] {identifier}));
     } else {
       throw new SAXNotSupportedException(
           SAXMessageFormatter.formatMessage(
               fXMLSchemaLoader.getLocale(), "feature-not-supported", new Object[] {identifier}));
     }
   }
 }
 public void setProperty0(String propertyId, Object value)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   try {
     fConfiguration.setProperty(propertyId, value);
   } catch (XMLConfigurationException e) {
     String identifier = e.getIdentifier();
     if (e.getType() == Status.NOT_RECOGNIZED) {
       throw new SAXNotRecognizedException(
           SAXMessageFormatter.formatMessage(
               fConfiguration.getLocale(), "property-not-recognized", new Object[] {identifier}));
     } else {
       throw new SAXNotSupportedException(
           SAXMessageFormatter.formatMessage(
               fConfiguration.getLocale(), "property-not-supported", new Object[] {identifier}));
     }
   }
 } // setProperty(String,Object)
예제 #6
0
 private void setSchemaValidatorFeature(String name, boolean value)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   try {
     fSAXParser.fSchemaValidator.setFeature(name, value);
   }
   // This should never be thrown from the schema validator.
   catch (XMLConfigurationException e) {
     String identifier = e.getIdentifier();
     if (e.getType() == Status.NOT_RECOGNIZED) {
       throw new SAXNotRecognizedException(
           SAXMessageFormatter.formatMessage(
               fConfiguration.getLocale(), "feature-not-recognized", new Object[] {identifier}));
     } else {
       throw new SAXNotSupportedException(
           SAXMessageFormatter.formatMessage(
               fConfiguration.getLocale(), "feature-not-supported", new Object[] {identifier}));
     }
   }
 }
  /**
   * Query the value of a property.
   *
   * <p>Return the current value of a property in a SAX2 parser. The parser might not recognize the
   * property.
   *
   * @param propertyId The unique identifier (URI) of the property being set.
   * @return The current value of the property.
   * @exception org.xml.sax.SAXNotRecognizedException If the requested property is not known.
   * @exception SAXNotSupportedException If the requested property is known but not supported.
   */
  public Object getProperty(String propertyId)
      throws SAXNotRecognizedException, SAXNotSupportedException {

    if (propertyId.equals(CURRENT_ELEMENT_NODE)) {
      boolean deferred = false;
      try {
        deferred = getFeature(DEFER_NODE_EXPANSION);
      } catch (XMLConfigurationException e) {
        // ignore
      }
      if (deferred) {
        throw new SAXNotSupportedException(
            "Current element node cannot be queried when node expansion is deferred.");
      }
      return (fCurrentNode != null && fCurrentNode.getNodeType() == Node.ELEMENT_NODE)
          ? fCurrentNode
          : null;
    }

    try {
      XMLSecurityPropertyManager spm =
          (XMLSecurityPropertyManager) fConfiguration.getProperty(XML_SECURITY_PROPERTY_MANAGER);
      int index = spm.getIndex(propertyId);
      if (index > -1) {
        return spm.getValueByIndex(index);
      }

      return fConfiguration.getProperty(propertyId);
    } catch (XMLConfigurationException e) {
      String identifier = e.getIdentifier();
      if (e.getType() == Status.NOT_RECOGNIZED) {
        throw new SAXNotRecognizedException(
            SAXMessageFormatter.formatMessage(
                fConfiguration.getLocale(), "property-not-recognized", new Object[] {identifier}));
      } else {
        throw new SAXNotSupportedException(
            SAXMessageFormatter.formatMessage(
                fConfiguration.getLocale(), "property-not-supported", new Object[] {identifier}));
      }
    }
  } // getProperty(String):Object
예제 #8
0
 JAXPSAXParser(
     SAXParserImpl saxParser,
     XMLSecurityPropertyManager securityPropertyMgr,
     XMLSecurityManager securityManager) {
   super();
   fSAXParser = saxParser;
   fSecurityManager = securityManager;
   fSecurityPropertyMgr = securityPropertyMgr;
   /** This class may be used directly. So initialize the security manager if it is null. */
   if (fSecurityManager == null) {
     fSecurityManager = new XMLSecurityManager(true);
     try {
       super.setProperty(SECURITY_MANAGER, fSecurityManager);
     } catch (SAXException e) {
       throw new UnsupportedOperationException(
           SAXMessageFormatter.formatMessage(
               fConfiguration.getLocale(),
               "property-not-recognized",
               new Object[] {SECURITY_MANAGER}),
           e);
     }
   }
   if (fSecurityPropertyMgr == null) {
     fSecurityPropertyMgr = new XMLSecurityPropertyManager();
     try {
       super.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
     } catch (SAXException e) {
       throw new UnsupportedOperationException(
           SAXMessageFormatter.formatMessage(
               fConfiguration.getLocale(),
               "property-not-recognized",
               new Object[] {SECURITY_MANAGER}),
           e);
     }
   }
 }
 public void setFeature(String name, boolean value)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     throw new NullPointerException(
         JAXPValidationMessageFormatter.formatMessage(
             fXMLSchemaLoader.getLocale(), "FeatureNameNull", null));
   }
   if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
     if (System.getSecurityManager() != null && (!value)) {
       throw new SAXNotSupportedException(
           SAXMessageFormatter.formatMessage(null, "jaxp-secureprocessing-feature", null));
     }
     fSecurityManager = value ? new SecurityManager() : null;
     fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);
     fXMLSchemaLoader.setProperty(ACCESS_EXTERNAL_DTD, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
     fXMLSchemaLoader.setProperty(ACCESS_EXTERNAL_SCHEMA, Constants.EXTERNAL_ACCESS_DEFAULT_FSP);
     return;
   } else if (name.equals(Constants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
     // in secure mode, let _useServicesMechanism be determined by the constructor
     if (System.getSecurityManager() != null) return;
   }
   try {
     fXMLSchemaLoader.setFeature(name, value);
   } catch (XMLConfigurationException e) {
     String identifier = e.getIdentifier();
     if (e.getType() == Status.NOT_RECOGNIZED) {
       throw new SAXNotRecognizedException(
           SAXMessageFormatter.formatMessage(
               fXMLSchemaLoader.getLocale(), "feature-not-recognized", new Object[] {identifier}));
     } else {
       throw new SAXNotSupportedException(
           SAXMessageFormatter.formatMessage(
               fXMLSchemaLoader.getLocale(), "feature-not-supported", new Object[] {identifier}));
     }
   }
 }
예제 #10
0
 public void setProperty(String name, Object object)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     throw new NullPointerException();
   }
   try {
     fComponentManager.setProperty(name, object);
   } catch (XMLConfigurationException e) {
     final String identifier = e.getIdentifier();
     final String key =
         e.getType() == XMLConfigurationException.NOT_RECOGNIZED
             ? "property-not-recognized"
             : "property-not-supported";
     throw new SAXNotRecognizedException(
         SAXMessageFormatter.formatMessage(Locale.getDefault(), key, new Object[] {identifier}));
   }
 }
예제 #11
0
 public boolean getFeature(String name)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     throw new NullPointerException();
   }
   try {
     return fComponentManager.getFeature(name);
   } catch (XMLConfigurationException e) {
     final String identifier = e.getIdentifier();
     final String key =
         e.getType() == XMLConfigurationException.NOT_RECOGNIZED
             ? "feature-not-recognized"
             : "feature-not-supported";
     throw new SAXNotRecognizedException(
         SAXMessageFormatter.formatMessage(Locale.getDefault(), key, new Object[] {identifier}));
   }
 }
  // XXX Fix message i18n
  public void error(SAXParseException e) throws SAXException {
    if (errorCount >= ERROR_COUNT_LIMIT) {
      // Ignore all errors after reaching the limit
      return;
    } else if (errorCount == 0) {
      // Print a warning before the first error
      System.err.println(
          SAXMessageFormatter.formatMessage(
              locale, "errorHandlerNotSet", new Object[] {errorCount}));
    }

    String systemId = e.getSystemId();
    if (systemId == null) {
      systemId = "null";
    }
    String message =
        "Error: URI=" + systemId + " Line=" + e.getLineNumber() + ": " + e.getMessage();
    System.err.println(message);
    errorCount++;
  }
예제 #13
0
    /**
     * Override SAXParser's setProperty method to track the initial state of properties. This keeps
     * us from affecting the performance of the SAXParser when it is created with XMLReaderFactory.
     */
    public synchronized void setProperty(String name, Object value)
        throws SAXNotRecognizedException, SAXNotSupportedException {
      if (name == null) {
        // TODO: Add localized error message.
        throw new NullPointerException();
      }
      if (fSAXParser != null) {
        // JAXP 1.2 support
        if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
          // The spec says if a schema is given via SAXParserFactory
          // the JAXP 1.2 properties shouldn't be allowed.
          if (fSAXParser.grammar != null) {
            throw new SAXNotSupportedException(
                SAXMessageFormatter.formatMessage(
                    fConfiguration.getLocale(), "schema-already-specified", new Object[] {name}));
          }
          if (W3C_XML_SCHEMA.equals(value)) {
            // None of the properties will take effect till the setValidating(true) has been called
            if (fSAXParser.isValidating()) {
              fSAXParser.schemaLanguage = W3C_XML_SCHEMA;
              setFeature(XMLSCHEMA_VALIDATION_FEATURE, true);
              // this will allow the parser not to emit DTD-related
              // errors, as the spec demands
              if (!fInitProperties.containsKey(JAXP_SCHEMA_LANGUAGE)) {
                fInitProperties.put(JAXP_SCHEMA_LANGUAGE, super.getProperty(JAXP_SCHEMA_LANGUAGE));
              }
              super.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
            }

          } else if (value == null) {
            fSAXParser.schemaLanguage = null;
            setFeature(XMLSCHEMA_VALIDATION_FEATURE, false);
          } else {
            // REVISIT: It would be nice if we could format this message
            // using a user specified locale as we do in the underlying
            // XMLReader -- mrglavas
            throw new SAXNotSupportedException(
                SAXMessageFormatter.formatMessage(
                    fConfiguration.getLocale(), "schema-not-supported", null));
          }
          return;
        } else if (JAXP_SCHEMA_SOURCE.equals(name)) {
          // The spec says if a schema is given via SAXParserFactory
          // the JAXP 1.2 properties shouldn't be allowed.
          if (fSAXParser.grammar != null) {
            throw new SAXNotSupportedException(
                SAXMessageFormatter.formatMessage(
                    fConfiguration.getLocale(), "schema-already-specified", new Object[] {name}));
          }
          String val = (String) getProperty(JAXP_SCHEMA_LANGUAGE);
          if (val != null && W3C_XML_SCHEMA.equals(val)) {
            if (!fInitProperties.containsKey(JAXP_SCHEMA_SOURCE)) {
              fInitProperties.put(JAXP_SCHEMA_SOURCE, super.getProperty(JAXP_SCHEMA_SOURCE));
            }
            super.setProperty(name, value);
          } else {
            throw new SAXNotSupportedException(
                SAXMessageFormatter.formatMessage(
                    fConfiguration.getLocale(),
                    "jaxp-order-not-supported",
                    new Object[] {JAXP_SCHEMA_LANGUAGE, JAXP_SCHEMA_SOURCE}));
          }
          return;
        }
      }
      /** Forward property to the schema validator if there is one. * */
      if (fSAXParser != null && fSAXParser.fSchemaValidator != null) {
        setSchemaValidatorProperty(name, value);
      }

      // check if the property is managed by security manager
      if (fSecurityManager == null
          || !fSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, value)) {
        // check if the property is managed by security property manager
        if (fSecurityPropertyMgr == null
            || !fSecurityPropertyMgr.setValue(
                name, XMLSecurityPropertyManager.State.APIPROPERTY, value)) {
          // fall back to the existing property manager
          if (!fInitProperties.containsKey(name)) {
            fInitProperties.put(name, super.getProperty(name));
          }
          super.setProperty(name, value);
        }
      }
    }