本文整理汇总了Java中javax.xml.transform.TransformerFactory.setURIResolver方法的典型用法代码示例。如果您正苦于以下问题:Java TransformerFactory.setURIResolver方法的具体用法?Java TransformerFactory.setURIResolver怎么用?Java TransformerFactory.setURIResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.transform.TransformerFactory
的用法示例。
在下文中一共展示了TransformerFactory.setURIResolver方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransformerFactory
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
* Returns an instance of TransformerFactory with either a custom URIResolver
* or Catalog.
*
* @param setUseCatalog a flag indicates whether USE_CATALOG shall be set
* through the factory
* @param useCatalog the value of USE_CATALOG
* @param catalog a catalog
* @param resolver a custom resolver
* @return an instance of TransformerFactory
* @throws Exception
*/
TransformerFactory getTransformerFactory(boolean setUseCatalog, boolean useCatalog,
String catalog, URIResolver resolver)
throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
if (setUseCatalog) {
factory.setFeature(XMLConstants.USE_CATALOG, useCatalog);
}
if (catalog != null) {
factory.setAttribute(CatalogFeatures.Feature.FILES.getPropertyName(), catalog);
}
// use resolver or catalog if resolver = null
if (resolver != null) {
factory.setURIResolver(resolver);
}
return factory;
}
示例2: supportURIResolver
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
@Test(dataProvider = "supportURIResolver")
public void supportURIResolver(URI catalogFile, Source xsl, Source xml, String expected) throws Exception {
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
TransformerFactory factory = TransformerFactory.newInstance();
factory.setURIResolver(cr);
Transformer transformer = factory.newTransformer(xsl);
StringWriter out = new StringWriter();
transformer.transform(xml, new StreamResult(out));
if (expected != null) {
Assert.assertTrue(out.toString().contains(expected), "supportURIResolver");
}
}
示例3: resolver01
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
* This is to test the URIResolver.resolve() method when a transformer is
* created using StreamSource. style-sheet file has xsl:include in it.
*
* @throws Exception If any errors occur.
*/
@Test
public static void resolver01() throws Exception {
try (FileInputStream fis = new FileInputStream(XSL_INCLUDE_FILE)) {
TransformerFactory tfactory = TransformerFactory.newInstance();
URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID);
tfactory.setURIResolver(resolver);
StreamSource streamSource = new StreamSource(fis);
streamSource.setSystemId(SYSTEM_ID);
assertNotNull(tfactory.newTransformer(streamSource));
}
}
示例4: resolver02
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
* This is to test the URIResolver.resolve() method when a transformer is
* created using DOMSource. style-sheet file has xsl:include in it.
*
* @throws Exception If any errors occur.
*/
@Test
public static void resolver02() throws Exception {
TransformerFactory tfactory = TransformerFactory.newInstance();
URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID);
tfactory.setURIResolver(resolver);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(XSL_INCLUDE_FILE);
DOMSource domSource = new DOMSource(document, SYSTEM_ID);
assertNotNull(tfactory.newTransformer(domSource));
}
示例5: resolver03
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
* This is to test the URIResolver.resolve() method when a transformer is
* created using SAXSource. style-sheet file has xsl:include in it.
*
* @throws Exception If any errors occur.
*/
@Test
public static void resolver03() throws Exception {
try (FileInputStream fis = new FileInputStream(XSL_INCLUDE_FILE)){
URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID);
TransformerFactory tfactory = TransformerFactory.newInstance();
tfactory.setURIResolver(resolver);
InputSource is = new InputSource(fis);
is.setSystemId(SYSTEM_ID);
SAXSource saxSource = new SAXSource(is);
assertNotNull(tfactory.newTransformer(saxSource));
}
}
示例6: resolver04
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
* This is to test the URIResolver.resolve() method when a transformer is
* created using StreamSource. style-sheet file has xsl:import in it.
*
* @throws Exception If any errors occur.
*/
@Test
public static void resolver04() throws Exception {
try (FileInputStream fis = new FileInputStream(XSL_IMPORT_FILE)) {
URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID);
TransformerFactory tfactory = TransformerFactory.newInstance();
tfactory.setURIResolver(resolver);
StreamSource streamSource = new StreamSource(fis);
streamSource.setSystemId(SYSTEM_ID);
assertNotNull(tfactory.newTransformer(streamSource));
}
}
示例7: resolver05
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
* This is to test the URIResolver.resolve() method when a transformer is
* created using DOMSource. style-sheet file has xsl:import in it.
*
* @throws Exception If any errors occur.
*/
@Test
public static void resolver05() throws Exception {
URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID);
TransformerFactory tfactory = TransformerFactory.newInstance();
tfactory.setURIResolver(resolver);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new File(XSL_IMPORT_FILE));
DOMSource domSource = new DOMSource(document, SYSTEM_ID);
assertNotNull(tfactory.newTransformer(domSource));
}
示例8: resolver06
import javax.xml.transform.TransformerFactory; //导入方法依赖的package包/类
/**
* This is to test the URIResolver.resolve() method when a transformer is
* created using SAXSource. style-sheet file has xsl:import in it.
*
* @throws Exception If any errors occur.
*/
@Test
public static void resolver06() throws Exception {
try (FileInputStream fis = new FileInputStream(XSL_IMPORT_FILE)){
URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID);
TransformerFactory tfactory = TransformerFactory.newInstance();
tfactory.setURIResolver(resolver);
InputSource is = new InputSource(fis);
is.setSystemId(SYSTEM_ID);
SAXSource saxSource = new SAXSource(is);
assertNotNull(tfactory.newTransformer(saxSource));
}
}