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


Java Validator.setResourceResolver方法代碼示例

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


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

示例1: validate

import javax.xml.validation.Validator; //導入方法依賴的package包/類
/**
 * validates <code>doc</code> using XML Schema defined <code>schemaURI</code>
 * @param doc document to be validated
 * @param schemaURI URI of XML Schema document
 * @throws SAXException if validation fails
 * @throws IOException if resolving resources fails
 */
public static void validate(Document doc, String schemaURI) throws SAXException, IOException {
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    sf.setResourceResolver(MCREntityResolver.instance());
    Schema schema;
    try {
        schema = sf.newSchema(MCRURIResolver.instance().resolve(schemaURI, null));
    } catch (TransformerException e) {
        Throwable cause = e.getCause();
        if (cause == null) {
            throw new IOException(e);
        }
        if (cause instanceof SAXException) {
            throw (SAXException) cause;
        }
        if (cause instanceof IOException) {
            throw (IOException) cause;
        }
        throw new IOException(e);
    }
    Validator validator = schema.newValidator();
    validator.setResourceResolver(MCREntityResolver.instance());
    validator.validate(new JDOMSource(doc));
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:31,代碼來源:MCRXMLHelper.java

示例2: supportLSResourceResolver1

import javax.xml.validation.Validator; //導入方法依賴的package包/類
@Test(dataProvider = "supportLSResourceResolver1")
public void supportLSResourceResolver1(URI catalogFile, Source source) throws Exception {

    CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);

    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Validator validator = factory.newSchema().newValidator();
    validator.setResourceResolver(cr);
    validator.validate(source);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:CatalogTest.java

示例3: testValidator

import javax.xml.validation.Validator; //導入方法依賴的package包/類
/**
 * Verifies Catalog Support for the Validator.
 * @param setUseCatalog1 a flag to indicate whether USE_CATALOG shall be set
 * on the factory.
 * @param setUseCatalog2 a flag to indicate whether USE_CATALOG shall be set
 * on the Validator.
 * @param source  the XML source
 * @param resolver1 a resolver to be set on the factory if specified
 * @param resolver2 a resolver to be set on the Validator if specified
 * @param catalog1 a catalog to be set on the factory if specified
 * @param catalog2 a catalog to be set on the Validator if specified
 */
public void testValidator(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
        Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
        String catalog1, String catalog2)
        throws Exception {

        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        if (setUseCatalog1) {
            schemaFactory.setFeature(XMLConstants.USE_CATALOG, useCatalog);
        }
        if (catalog1 != null) {
            schemaFactory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog1);
        }
        if (resolver1 != null) {
            schemaFactory.setResourceResolver(resolver1);
        }

        Schema schema = schemaFactory.newSchema();
        Validator validator = schema.newValidator();
        if (setUseCatalog2) {
            validator.setFeature(XMLConstants.USE_CATALOG, useCatalog);
        }
        if (catalog2 != null) {
            validator.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog2);
        }
        if (resolver2 != null) {
            validator.setResourceResolver(resolver2);
        }
        validator.validate(source);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:42,代碼來源:CatalogSupportBase.java

示例4: test200ExportUsers

import javax.xml.validation.Validator; //導入方法依賴的package包/類
@Test
   public void test200ExportUsers() throws Exception {
	final String TEST_NAME = "test200ExportUsers";
       displayTestTile(TEST_NAME);

       // GIVEN
       Task task = createTask(TEST_NAME);
       OperationResult result = task.getResult();
  
       // WHEN
       displayWhen(TEST_NAME);
       List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, 
       		SelectorOptions.createCollection(ItemPath.EMPTY_PATH, GetOperationOptions.createRaw()), task, result);
       
       // THEN
       displayThen(TEST_NAME);
       assertSuccess(result);

       assertEquals("Unexpected number of users", 5, users.size());
       for (PrismObject<UserType> user: users) {
       	display("Exporting user", user);
       	assertNotNull("Null definition in "+user, user.getDefinition());
       	display("Definition", user.getDefinition());
       	String xmlString = prismContext.serializerFor(PrismContext.LANG_XML).serialize(user);
       	display("Exported user", xmlString);
       	
       	Document xmlDocument = DOMUtil.parseDocument(xmlString);
   		Schema javaxSchema = prismContext.getSchemaRegistry().getJavaxSchema();
   		Validator validator = javaxSchema.newValidator();
   		validator.setResourceResolver(prismContext.getEntityResolver());
   		validator.validate(new DOMSource(xmlDocument));
   		
   		PrismObject<Objectable> parsedUser = prismContext.parseObject(xmlString);
   		assertTrue("Re-parsed user is not equal to original: "+user, user.equals(parsedUser));
   		
       }
       
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:39,代碼來源:TestMisc.java

示例5: serializeAndValidate

import javax.xml.validation.Validator; //導入方法依賴的package包/類
private void serializeAndValidate(PrismObject<UserType> user, PrismContext prismContext) throws SchemaException, SAXException, IOException {
	String xmlString = prismContext.serializeObjectToString(user, PrismContext.LANG_XML);
	System.out.println("Serialized XML");
	System.out.println(xmlString);
	Document xmlDocument = DOMUtil.parseDocument(xmlString);
	Schema javaxSchema = prismContext.getSchemaRegistry().getJavaxSchema();
	Validator validator = javaxSchema.newValidator();
	validator.setResourceResolver(prismContext.getEntityResolver());
	validator.validate(new DOMSource(xmlDocument));
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:11,代碼來源:TestPrismObjectConstruction.java


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