コード例 #1
0
 /**
  * Override SAXParser's setFeature method to track the initial state of features. This keeps us
  * from affecting the performance of the SAXParser when it is created with XMLReaderFactory.
  */
 public synchronized void setFeature(String name, boolean value)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   if (name == null) {
     // TODO: Add localized error message.
     throw new NullPointerException();
   }
   if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
     try {
       fSecurityManager.setSecureProcessing(value);
       setProperty(SECURITY_MANAGER, fSecurityManager);
     } catch (SAXNotRecognizedException exc) {
       // If the property is not supported
       // re-throw the exception if the value is true.
       if (value) {
         throw exc;
       }
     } catch (SAXNotSupportedException exc) {
       // If the property is not supported
       // re-throw the exception if the value is true.
       if (value) {
         throw exc;
       }
     }
     return;
   }
   if (!fInitFeatures.containsKey(name)) {
     boolean current = super.getFeature(name);
     fInitFeatures.put(name, current ? Boolean.TRUE : Boolean.FALSE);
   }
   /** Forward feature to the schema validator if there is one. * */
   if (fSAXParser != null && fSAXParser.fSchemaValidator != null) {
     setSchemaValidatorFeature(name, value);
   }
   super.setFeature(name, value);
 }
コード例 #2
0
 public void parse(String systemId) throws SAXException, IOException {
   if (fSAXParser != null && fSAXParser.fSchemaValidator != null) {
     if (fSAXParser.fSchemaValidationManager != null) {
       fSAXParser.fSchemaValidationManager.reset();
       fSAXParser.fUnparsedEntityHandler.reset();
     }
     resetSchemaValidator();
   }
   super.parse(systemId);
 }
コード例 #3
0
 public void parse(InputSource inputSource) throws SAXException, IOException {
   if (fSAXParser != null && fSAXParser.fSchemaValidator != null) {
     if (fSAXParser.fSchemaValidationManager != null) {
       fSAXParser.fSchemaValidationManager.reset();
       fSAXParser.fUnparsedEntityHandler.reset();
     }
     resetSchemaValidator();
   }
   super.parse(inputSource);
 }
コード例 #4
0
  private RequestDataMeanFree importRequestDataMeanFree(BufferedReader reader) {
    RDImportHandlerMeanFree handler;

    try {
      handler = new RDImportHandlerMeanFree();
      SAXParser parser = new SAXParser();
      parser.setContentHandler(handler);
      parser.parse(new InputSource(reader));
      // new ByteArrayInputStream(data.getBytes())));
      if (handler.getError()
          || handler.getInputImage() == null
          || handler.getInputMaskImage() == null
          || handler.getOutputImagePath() == null) return null;
    } catch (Throwable t) {
      return null;
    }
    return new RequestDataMeanFree(
        handler.getInputImage(),
        handler.getInputMaskImage(),
        handler.getOutputImagePath(),
        handler.getRequestURI());
  }
コード例 #5
0
 synchronized void restoreInitState()
     throws SAXNotRecognizedException, SAXNotSupportedException {
   Iterator iter;
   if (!fInitFeatures.isEmpty()) {
     iter = fInitFeatures.entrySet().iterator();
     while (iter.hasNext()) {
       Map.Entry entry = (Map.Entry) iter.next();
       String name = (String) entry.getKey();
       boolean value = ((Boolean) entry.getValue()).booleanValue();
       super.setFeature(name, value);
     }
     fInitFeatures.clear();
   }
   if (!fInitProperties.isEmpty()) {
     iter = fInitProperties.entrySet().iterator();
     while (iter.hasNext()) {
       Map.Entry entry = (Map.Entry) iter.next();
       String name = (String) entry.getKey();
       Object value = entry.getValue();
       super.setProperty(name, value);
     }
     fInitProperties.clear();
   }
 }
コード例 #6
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);
     }
   }
 }
コード例 #7
0
 void setProperty0(String name, Object value)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   super.setProperty(name, value);
 }
コード例 #8
0
 void setFeature0(String name, boolean value)
     throws SAXNotRecognizedException, SAXNotSupportedException {
   super.setFeature(name, value);
 }
コード例 #9
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);
        }
      }
    }