當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。