当前位置: 首页>>代码示例>>Java>>正文


Java StreamSource.setSystemId方法代码示例

本文整理汇总了Java中javax.xml.transform.stream.StreamSource.setSystemId方法的典型用法代码示例。如果您正苦于以下问题:Java StreamSource.setSystemId方法的具体用法?Java StreamSource.setSystemId怎么用?Java StreamSource.setSystemId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.transform.stream.StreamSource的用法示例。


在下文中一共展示了StreamSource.setSystemId方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: docResolver01

import javax.xml.transform.stream.StreamSource; //导入方法依赖的package包/类
/**
 * This is to test the URIResolver.resolve() method when there is an error
 * in the file.
 *
 * @throws Exception If any errors occur.
 */
@Test
public static void docResolver01() throws Exception {
    try (FileInputStream fis = new FileInputStream(XML_DIR + "doctest.xsl")) {
        URIResolverTest resolver = new URIResolverTest("temp/colors.xml", SYSTEM_ID);
        StreamSource streamSource = new StreamSource(fis);
        streamSource.setSystemId(SYSTEM_ID);

        Transformer transformer = TransformerFactory.newInstance().newTransformer(streamSource);
        transformer.setURIResolver(resolver);

        File f = new File(XML_DIR + "myFake.xml");
        Document document = DocumentBuilderFactory.newInstance().
                newDocumentBuilder().parse(f);

        // Use a Transformer for output
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(System.err);
        // No exception is expected because resolver resolve wrong URI.
        transformer.transform(source, result);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:URIResolverTest.java

示例2: transformFile

import javax.xml.transform.stream.StreamSource; //导入方法依赖的package包/类
/**
 *  Transforms an XML file using a pre-compiled {@link javax.xml.transform.Transformer}. Use {@link
 *  #getTransformer(String xslFilePath)} to produce a reusable {@link javax.xml.transform.Transformer} for a
 *  given XSL stylesheet.
 *
 * @param  inputFile    The XML file to transform.
 * @param  transformer  A pre-compiled {@link javax.xml.transform.Transformer} used to produce transformed
 *      output.
 * @return              A String containing the transformed content.
 */
public final static String transformFile(File inputFile, Transformer transformer) {
	try {
		StringWriter writer = new StringWriter();
		StreamSource ss = new StreamSource(new FileInputStream(inputFile));
		ss.setSystemId(inputFile);
		transformer.transform(ss, new StreamResult(writer));
		return writer.toString();
	} catch (Throwable e) {
		prtlnErr(e);
		return "";
	}
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:23,代码来源:XSLTransformer.java

示例3: newValidator

import javax.xml.transform.stream.StreamSource; //导入方法依赖的package包/类
public ValidatorHandler newValidator() {
    if (schema==null) {
        synchronized (this) {
            if (schema == null) {

                ResourceResolver resourceResolver = null;
                try (InputStream is = clazz.getResourceAsStream(resourceName)) {

                    StreamSource source = new StreamSource(is);
                    source.setSystemId(resourceName);
                    // do not disable secure processing - these are well-known schemas

                    SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
                    SchemaFactory schemaFactory = allowExternalAccess(sf, "file", false);

                    if (createResolver) {
                        resourceResolver = new ResourceResolver(clazz);
                        schemaFactory.setResourceResolver(resourceResolver);
                    }
                    schema = schemaFactory.newSchema(source);

                } catch (IOException | SAXException e) {
                    InternalError ie = new InternalError(e.getMessage());
                    ie.initCause(e);
                    throw ie;
                } finally {
                    if (resourceResolver != null) resourceResolver.closeStreams();
                }
            }
        }
    }
    return schema.newValidatorHandler();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:SchemaCache.java

示例4: resolver01

import javax.xml.transform.stream.StreamSource; //导入方法依赖的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));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:URIResolverTest.java

示例5: resolver04

import javax.xml.transform.stream.StreamSource; //导入方法依赖的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));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:URIResolverTest.java

示例6: resolve

import javax.xml.transform.stream.StreamSource; //导入方法依赖的package包/类
public Source resolve(String href, String base) throws TransformerException {
    if ("http://astro.com/stylesheets/topleveltemplate".equals(href)) {
        StreamSource ss = new StreamSource(TOPTEMPLINCXSL);
        ss.setSystemId(filenameToURL(TOPTEMPLINCXSL));
        return ss;
    } else {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:TemplatesFilterFactoryImpl.java

示例7: getTransformer

import javax.xml.transform.stream.StreamSource; //导入方法依赖的package包/类
/**
 *  Gets a specific {@link javax.xml.transform.Transformer}, used to transform
 *  XML using a given XSL stylesheet.
 *
 * @param  xslFilePath                            A path to an XSL stylesheet
 *      file.
 * @param  transformerFactoryClass                TransformerFactory class
 *      (e.g. "net.sf.saxon.TransformerFactoryImpl")
 * @return                                        A Transformer used to
 *      transform XML using a given stylesheet.
 * @exception  TransformerConfigurationException  If error.
 * @exception  FileNotFoundException              If file can not be found.
 */
public static Transformer getTransformer(String xslFilePath, String transformerFactoryClass)
	 throws TransformerConfigurationException, FileNotFoundException {

	TransformerFactory tFactory = getTransformerFactory(transformerFactoryClass);

	File xslFile = new File(xslFilePath);
	StreamSource stream = new StreamSource(new FileInputStream(xslFile));

	// Set systemId so xsl style sheets can find relative style sheets referenced in include and import directives
	stream.setSystemId(xslFile);
	return tFactory.newTransformer(stream);
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:26,代码来源:XSLTransformer.java


注:本文中的javax.xml.transform.stream.StreamSource.setSystemId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。