当前位置: 首页>>代码示例>>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;未经允许,请勿转载。