當前位置: 首頁>>代碼示例>>Java>>正文


Java SchemaFactory.setErrorHandler方法代碼示例

本文整理匯總了Java中javax.xml.validation.SchemaFactory.setErrorHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java SchemaFactory.setErrorHandler方法的具體用法?Java SchemaFactory.setErrorHandler怎麽用?Java SchemaFactory.setErrorHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.validation.SchemaFactory的用法示例。


在下文中一共展示了SchemaFactory.setErrorHandler方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validate

import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
private void validate(WSDLModel model, 
                      Source saxSource, 
                      XsdBasedValidator.Handler handler,
                      LSResourceResolver resolver) {
    try {
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

        if (resolver != null) {
            sf.setResourceResolver(resolver);
        }
        sf.setErrorHandler(handler);

        if (saxSource == null) {
            return;
        }
        sf.newSchema(saxSource);
    } catch(SAXException sax) {
        //already processed by handler
    } catch(Exception ex) {
        handler.logValidationErrors(Validator.ResultType.ERROR, ex.getMessage());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:WSDLInlineSchemaValidator.java

示例2: getCompiledSchema

import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
protected Schema getCompiledSchema(Source[] schemas,
        LSResourceResolver lsResourceResolver,
        ErrorHandler errorHandler) {
    
    Schema schema = null;
    
    // Create a compiled Schema object.
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    schemaFactory.setResourceResolver(lsResourceResolver);
    schemaFactory.setErrorHandler(errorHandler);
    try {
        schema = schemaFactory.newSchema(schemas);            
    } catch(SAXException ex) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "getCompiledSchema", ex);
    } 
    
    return schema;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:XsdBasedValidator.java

示例3: validate

import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Override
  protected void validate(Model model, Schema schema, XsdBasedValidator.Handler handler) {
      try {
          SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          CatalogModel cm = (CatalogModel) model.getModelSource().getLookup()
.lookup(CatalogModel.class);
   if (cm != null) {
              sf.setResourceResolver(cm);
          }
          sf.setErrorHandler(handler);
          Source saxSource = getSource(model, handler);
          if (saxSource == null) {
              return;
          }
          sf.newSchema(saxSource);
      } catch(SAXException sax) {
          //already processed by handler
      } catch(Exception ex) {
          handler.logValidationErrors(Validator.ResultType.ERROR, ex.getMessage());
      }
  }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:SchemaXsdBasedValidator.java

示例4: buildSchema

import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
/**
 * Builds a schema from the given schema sources.
 * 
 * @param lang schema language, must not be null
 * @param schemaSources schema sources, must not be null
 * 
 * @return the constructed schema
 * 
 * @throws SAXException thrown if there is a problem converting the schema sources in to a schema
 */
protected static Schema buildSchema(SchemaLanguage lang, Source[] schemaSources) throws SAXException {
    if(lang == null){
        throw new IllegalArgumentException("Schema language may not be null");
    }
    
    if(schemaSources == null){
        throw new IllegalArgumentException("Schema sources may not be null");
    }
    
    SchemaFactory schemaFactory;

    if (lang == SchemaLanguage.XML) {
        schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    } else {
        schemaFactory = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
    }

    schemaFactory.setErrorHandler(new LoggingErrorHandler(LoggerFactory.getLogger(SchemaBuilder.class)));
    return schemaFactory.newSchema(schemaSources);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:SchemaBuilder.java

示例5: checkSchemaCorrectness

import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
/**
 * Checks the correctness of the XML Schema documents and return true
 * if it's OK.
 *
 * <p>
 * This method performs a weaker version of the tests where error messages
 * are provided without line number information. So whenever possible
 * use {@link SchemaConstraintChecker}.
 *
 * @see SchemaConstraintChecker
 */
public boolean checkSchemaCorrectness(ErrorReceiver errorHandler) {
    try {
        boolean disableXmlSecurity = false;
        if (options != null) {
            disableXmlSecurity = options.disableXmlSecurity;
        }
        SchemaFactory sf = XmlFactory.createSchemaFactory(W3C_XML_SCHEMA_NS_URI, disableXmlSecurity);
        ErrorReceiverFilter filter = new ErrorReceiverFilter(errorHandler);
        sf.setErrorHandler(filter);
        Set<String> roots = getRootDocuments();
        Source[] sources = new Source[roots.size()];
        int i=0;
        for (String root : roots) {
            sources[i++] = new DOMSource(get(root),root);
        }
        sf.newSchema(sources);
        return !filter.hadError();
    } catch (SAXException e) {
        // the errors should have been reported
        return false;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:34,代碼來源:DOMForest.java

示例6: test1

import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test
public void test1() throws Exception {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

    ErrorHandler errorHandler = new ErrorHandler();
    schemaFactory.setErrorHandler(errorHandler);

    try {
        schemaFactory.newSchema(Bug5010072.class.getResource("Bug5010072.xsd"));
        Assert.fail("should fail to compile");
    } catch (SAXException e) {
        ; // as expected
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:Bug5010072.java

示例7: testErrorHandler

import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test
public void testErrorHandler() {
    SchemaFactory sf = newSchemaFactory();
    assertNull(sf.getErrorHandler(), "When SchemaFactory is created, initially ErrorHandler should not be set.");

    ErrorHandler handler = new MyErrorHandler();
    sf.setErrorHandler(handler);
    assertSame(sf.getErrorHandler(), handler);

    sf.setErrorHandler(null);
    assertNull(sf.getErrorHandler());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:SchemaFactoryTest.java


注:本文中的javax.xml.validation.SchemaFactory.setErrorHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。