本文整理汇总了Java中com.helger.xml.schema.XMLSchemaCache类的典型用法代码示例。如果您正苦于以下问题:Java XMLSchemaCache类的具体用法?Java XMLSchemaCache怎么用?Java XMLSchemaCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XMLSchemaCache类属于com.helger.xml.schema包,在下文中一共展示了XMLSchemaCache类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateDocumentBuilder
import com.helger.xml.schema.XMLSchemaCache; //导入依赖的package包/类
@Test
public void testCreateDocumentBuilder ()
{
final Schema sch = XMLSchemaCache.getInstance ().getSchema (new ClassPathResource ("xml/schema1.xsd"));
assertNotNull (sch);
DocumentBuilder db = XMLFactory.createDocumentBuilder (sch);
assertNotNull (db);
assertNotNull (db.getSchema ());
try
{
XMLFactory.createDocumentBuilder ((Schema) null);
fail ();
}
catch (final NullPointerException ex)
{}
db = XMLFactory.createDocumentBuilder ();
assertNotNull (db);
assertNull (db.getSchema ());
}
示例2: validateXMLSchema
import com.helger.xml.schema.XMLSchemaCache; //导入依赖的package包/类
public static boolean validateXMLSchema (@Nonnull final File xsdPath, @Nonnull final File xmlPath)
{
try
{
System.setProperty ("jdk.xml.maxOccurLimit", "9999999");
final Validator aValidator = XMLSchemaCache.getInstance ().getValidator (new FileSystemResource (xsdPath));
aValidator.validate (TransformSourceFactory.create (xmlPath));
}
catch (final IOException | SAXException e)
{
s_aLogger.info ("Exception: " + e.getMessage ());
return false;
}
return true;
}
示例3: createSchema
import com.helger.xml.schema.XMLSchemaCache; //导入依赖的package包/类
/**
* Create the schema. Overload this method to create the schema differently.
* The result of this call may be cached.
*
* @param aClassLoader
* Optional class loader to use. May be <code>null</code>.
* @return A non-<code>null</code> {@link Schema} instance.
*/
@Nonnull
protected Schema createSchema (@Nullable final ClassLoader aClassLoader)
{
final ICommonsList <? extends IReadableResource> aXSDRes = getAllXSDResources (aClassLoader);
final Schema ret = XMLSchemaCache.getInstanceOfClassLoader (aClassLoader).getSchema (aXSDRes);
if (ret == null)
throw new IllegalStateException ("Failed to create Schema from " +
aXSDRes +
(aClassLoader == null ? " with default class loader"
: " using class loader " + aClassLoader));
return ret;
}
示例4: cleanup
import com.helger.xml.schema.XMLSchemaCache; //导入依赖的package包/类
/**
* Cleanup all custom caches contained in this library. Loaded SPI
* implementations are not affected by this method!
*/
public static void cleanup ()
{
if (MimeTypeInfoManager.isDefaultInstantiated ())
MimeTypeInfoManager.getDefaultInstance ().reinitializeToDefault ();
if (MicroTypeConverterRegistry.isInstantiated ())
MicroTypeConverterRegistry.getInstance ().reinitialize ();
if (XMLSchemaCache.isInstantiated ())
XMLSchemaCache.getInstance ().clearCache ();
XMLSchemaCache.clearPerClassLoaderCache ();
}
示例5: testRead
import com.helger.xml.schema.XMLSchemaCache; //导入依赖的package包/类
@Test
@SuppressFBWarnings (value = "NP_NONNULL_PARAM_VIOLATION")
public void testRead () throws SAXException
{
// Read valid
final ChangeLog aCL = ChangeLogSerializer.readChangeLog (new FileSystemResource ("src/main/resources/" +
CChangeLog.CHANGELOG_XML_FILENAME));
assertNotNull (aCL);
assertEquals (new Version (1, 0), aCL.getVersion ());
assertEquals ("ph-xml", aCL.getComponent ());
assertTrue (aCL.getAllEntries ().size () > 0);
assertTrue (aCL.getAllReleases ().size () > 0);
assertNotNull (aCL.getLatestRelease ());
for (final EChangeLogCategory eCat : EChangeLogCategory.values ())
assertNotNull (aCL.getAllEntriesOfCategory (eCat));
// Read with XML Schema
final Document aW3CDoc = DOMReader.readXMLDOM (new ClassPathResource (CChangeLog.CHANGELOG_XML_FILENAME),
new DOMReaderSettings ().setSchema (XMLSchemaCache.getInstance ()
.getSchema (new ClassPathResource (CChangeLog.CHANGELOG_XSD_10))));
assertNotNull (aW3CDoc);
// Read invalid
assertNull (ChangeLogSerializer.readChangeLog (null));
assertNull (ChangeLogSerializer.readChangeLog (new ClassPathResource ("does-not-exist.xml")));
try
{
aCL.getAllEntriesOfCategory (null);
fail ();
}
catch (final NullPointerException ex)
{}
}
示例6: testWrite
import com.helger.xml.schema.XMLSchemaCache; //导入依赖的package包/类
@Test
public void testWrite () throws SAXException
{
// 1. read a valid one
final ChangeLog aCL = ChangeLogSerializer.readChangeLog (new ClassPathResource (CChangeLog.CHANGELOG_XML_FILENAME));
assertNotNull (aCL);
// 2. write it
final IMicroDocument aDoc = ChangeLogSerializer.writeChangeLog (aCL);
assertNotNull (aDoc);
// 3. read again -> must be equal
final ChangeLog aCL2 = ChangeLogSerializer.readChangeLog (new MicroDOMInputStreamProvider (aDoc,
XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ));
assertNotNull (aCL2);
// 4. read again with XML Schema
final Document aW3CDoc = DOMReader.readXMLDOM (new ReadableResourceSAXInputSource (new MicroDOMInputStreamProvider (aDoc,
XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ),
null),
new DOMReaderSettings ().setSchema (XMLSchemaCache.getInstance ()
.getSchema (new ClassPathResource (CChangeLog.CHANGELOG_XSD_10))));
assertNotNull (aW3CDoc);
CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aCL, aCL2);
try
{
ChangeLogSerializer.writeChangeLog (null);
fail ();
}
catch (final NullPointerException ex)
{}
}
示例7: testFunctXAreDistinctValuesWithXSD
import com.helger.xml.schema.XMLSchemaCache; //导入依赖的package包/类
@Test
public void testFunctXAreDistinctValuesWithXSD () throws Exception
{
final String sTest = "<?xml version='1.0' encoding='iso-8859-1'?>\n" +
"<schema xmlns='http://purl.oclc.org/dsdl/schematron'>\n" +
" <ns prefix=\"xs\" uri=\"http://www.w3.org/2001/XMLSchema\"/>\n" +
" <ns prefix='fn' uri='http://www.w3.org/2005/xpath-functions' />\n" +
" <ns prefix='functx' uri='http://www.functx.com' />\n" +
" <pattern name='toto'>\n" +
" <title>A very simple pattern with a title</title>\n" +
" <rule context='chapter'>\n" +
" <assert test='fn:count(fn:distinct-values(para)) = fn:count(para)'>Should have distinct values</assert>\n" +
" </rule>\n" +
" </pattern>\n" +
"</schema>";
final MapBasedXPathFunctionResolver aFunctionResolver = new XQueryAsXPathFunctionConverter ().loadXQuery (ClassPathResource.getInputStream ("xquery/functx-1.0-nodoc-2007-01.xq"));
final Schema aSchema = XMLSchemaCache.getInstance ()
.getSchema (new ClassPathResource ("issues/20141124/chapter.xsd"));
final Document aTestDoc = DOMReader.readXMLDOM ("<?xml version='1.0'?>" +
"<chapter>" +
" <title />" +
" <para>09</para>" +
" <para>9</para>" +
"</chapter>",
new DOMReaderSettings ().setSchema (aSchema));
final SchematronOutputType aOT = SchematronResourcePure.fromString (sTest, StandardCharsets.UTF_8)
.setFunctionResolver (aFunctionResolver)
.applySchematronValidationToSVRL (aTestDoc, null);
assertNotNull (aOT);
if (SVRLHelper.getAllFailedAssertions (aOT).size () != 0)
{
System.out.println (SVRLHelper.getAllFailedAssertions (aOT).get (0).getText ());
}
assertTrue (SVRLHelper.getAllFailedAssertions (aOT).isEmpty ());
}
示例8: createValidationSchema
import com.helger.xml.schema.XMLSchemaCache; //导入依赖的package包/类
/**
* @return The validation schema to be used. May be <code>null</code>
* indicating that no validation is required.
*/
@Nullable
protected Schema createValidationSchema ()
{
return m_aXSDs.isEmpty () ? null : XMLSchemaCache.getInstanceOfClassLoader (getClassLoader ()).getSchema (m_aXSDs);
}