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


Java SAXResult類代碼示例

本文整理匯總了Java中javax.xml.transform.sax.SAXResult的典型用法代碼示例。如果您正苦於以下問題:Java SAXResult類的具體用法?Java SAXResult怎麽用?Java SAXResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: render

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
protected void render(FopFactory fopFactory, FOUserAgent foUserAgent, String outputFormat, Source foDocumentSrc, PlaceholderReplacementHandler.PlaceholderLookup placeholderLookup, OutputStream outputStream) throws Docx4JException {
	Fop fop = null;
	Result result = null;
	try {
		if (foUserAgent==null) {
			fop = fopFactory.newFop(outputFormat, outputStream);
		} else {
			fop = fopFactory.newFop(outputFormat, foUserAgent, outputStream);				
		}
		result = (placeholderLookup == null ?
				//1 Pass
				new SAXResult(fop.getDefaultHandler()) :
				//2 Pass
				new SAXResult(new PlaceholderReplacementHandler(fop.getDefaultHandler(), placeholderLookup)));
	} catch (FOPException e) {
		throw new Docx4JException("Exception setting up result for fo transformation: " + e.getMessage(), e);
	}
	
	XmlSerializerUtil.serialize(foDocumentSrc, result, false, false);
}
 
開發者ID:plutext,項目名稱:docx4j-export-FO,代碼行數:21,代碼來源:FORendererApacheFOP.java

示例2: export

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
public void export(OutputStream out) throws FOPException, IOException, TransformerException {
    FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());

    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

    // Setup XSLT
    TransformerFactory Factory = TransformerFactory.newInstance();
    Transformer transformer = Factory.newTransformer(xsltSource);

    // Set the value of a <param> in the stylesheet
    transformer.setParameter("versionParam", "2.0");

    // Setup input for XSLT transformation
    Reader reader = composeXml();
    Source src = new StreamSource(reader);

    // Resulting SAX events (the generated FO) must be piped through to
    // FOP
    Result res = new SAXResult(fop.getDefaultHandler());

    // Start XSLT transformation and FOP processing
    transformer.transform(src, res);

    reader.close();
    out.flush();
}
 
開發者ID:ManyDesigns,項目名稱:Portofino,代碼行數:27,代碼來源:FormPdfExporter.java

示例3: render

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
/**
 * <p>render</p>
 *
 * @param in a {@link java.io.Reader} object.
 * @param out a {@link java.io.OutputStream} object.
 * @param xslt a {@link java.io.Reader} object.
 * @throws org.opennms.reporting.availability.render.ReportRenderException if any.
 */
public void render(Reader in, OutputStream out, Reader xslt) throws ReportRenderException {
    try {

        FopFactory fopFactory = FopFactory.newInstance();
        fopFactory.setStrictValidation(false);
        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

        TransformerFactory tfact = TransformerFactory.newInstance();
        Transformer transformer = tfact.newTransformer(new StreamSource(xslt));
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.transform(new StreamSource(in), new SAXResult(fop.getDefaultHandler()));

    } catch (TransformerConfigurationException tce) {
        log.fatal("TransformerConfigurationException", tce);
        throw new ReportRenderException(tce);
    } catch (TransformerException te) {
        log.fatal("TransformerException", te);
        throw new ReportRenderException(te);
    } catch (FOPException e) {
        log.fatal("FOPException", e);
        throw new ReportRenderException(e);
    }
}
 
開發者ID:vishwaabhinav,項目名稱:OpenNMS,代碼行數:32,代碼來源:PDFReportRenderer.java

示例4: export

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
public void export(OutputStream out) throws FOPException, IOException, TransformerException {
    FopFactory fopFactory = FopFactory.newInstance();

    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

    // Setup XSLT
    TransformerFactory Factory = TransformerFactory.newInstance();
    Transformer transformer = Factory.newTransformer(xsltSource);

    // Set the value of a <param> in the stylesheet
    transformer.setParameter("versionParam", "2.0");

    // Setup input for XSLT transformation
    Reader reader = composeXml();
    Source src = new StreamSource(reader);

    // Resulting SAX events (the generated FO) must be piped through to
    // FOP
    Result res = new SAXResult(fop.getDefaultHandler());

    // Start XSLT transformation and FOP processing
    transformer.transform(src, res);

    reader.close();
    out.flush();
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:27,代碼來源:FormPdfExporter.java

示例5: toPDF

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
public void toPDF(OutputStream os) {
    try {
        FOUserAgent userAgent = FopFactory.newInstance().newFOUserAgent();
        Fop fop = FopFactory.newInstance().newFop(MimeConstants.MIME_PDF, userAgent, os);
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();

        Source src = new StreamSource(new StringReader(fo));
        Result res = new SAXResult(fop.getDefaultHandler());

        transformer.transform(src, res);
    }
    catch (FOPException fope) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{fope.getMessage()});
    }
    catch (TransformerConfigurationException tce) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{tce.getMessage()});
    }
    catch (TransformerException te) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{te.getMessage()});
    }
}
 
開發者ID:akullpp,項目名稱:fopdf,代碼行數:23,代碼來源:Builder.java

示例6: resolveView

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
public void resolveView(ServletRequest request, ServletResponse response, Preferences preferences, Object viewData) throws Exception {
    InputStream is = new ByteArrayInputStream(((String) viewData).getBytes("UTF-8"));
    
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    
    FopFactory fopFactory = FopFactory.newInstance();
    fopFactory.setStrictValidation(false);
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
    
    TransformerFactory tfact = TransformerFactory.newInstance();
    Transformer transformer = tfact.newTransformer();
    Source src = new StreamSource(is);
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(src, res);
    
    byte[] contents = out.toByteArray();
    response.setContentLength(contents.length);
    response.getOutputStream().write(contents);

}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:22,代碼來源:OnmsPdfViewResolver.java

示例7: testFO2RTFWithJAXP

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
/**
 * Tests Fop with JAXP and OutputStream generating RTF.
 * @throws Exception if anything fails
 */
@Test
public void testFO2RTFWithJAXP() throws Exception {
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout);

    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(); //Identity transf.
    Source src = new StreamSource(foFile);
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(src, res);

    assertTrue("Generated RTF has zero length", baout.size() > 0);
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:20,代碼來源:BasicDriverTestCase.java

示例8: buildSingleTransformerPipeline

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
private Result buildSingleTransformerPipeline(Result result)
{
	try
	{
		SAXTransformerFactory saxTransformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
		TransformerHandler transformerHandler = saxTransformerFactory.newTransformerHandler();
		if (result != null)
		{
			transformerHandler.setResult(result);
		}
		return new SAXResult(transformerHandler);
	}
	catch (TransformerConfigurationException ex)
	{
		throw new FluentXmlConfigurationException(ex);
	}
}
 
開發者ID:fluentxml4j,項目名稱:fluentxml4j,代碼行數:18,代碼來源:TransformationChain.java

示例9: setResult

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
@Override
public void setResult(Result result) throws IllegalArgumentException
{
	SAXResult saxResult = toSAXResult(result);

	ContentHandler handler = saxResult.getHandler();
	this.nextContentHandler = handler;
	if (handler instanceof LexicalHandler)
	{
		this.nextLexicalHandler = (LexicalHandler) handler;
	}
	if (handler instanceof DTDHandler)
	{
		this.nextDtdHandler = (DTDHandler) handler;
	}

}
 
開發者ID:fluentxml4j,項目名稱:fluentxml4j,代碼行數:18,代碼來源:AbstractSAXFilter.java

示例10: toSAXResult

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
private SAXResult toSAXResult(Result result)
{
	if (result instanceof SAXResult)
	{
		return (SAXResult) result;
	}

	try
	{
		SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
		TransformerHandler transformerHandler = transformerFactory.newTransformerHandler();
		transformerHandler.setResult(result);
		return new SAXResult(transformerHandler);
	}
	catch (TransformerConfigurationException ex)
	{
		throw new FluentXmlConfigurationException(ex);
	}
}
 
開發者ID:fluentxml4j,項目名稱:fluentxml4j,代碼行數:20,代碼來源:AbstractSAXFilter.java

示例11: delegatesToLexicalHandlerPerDefault

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
@Test
public void delegatesToLexicalHandlerPerDefault() throws SAXException
{
	filter.setResult(new SAXResult(this.contentHandler));

	filter.startDTD("name", "publicId", "systemId");
	verify(contentHandler).startDTD("name", "publicId", "systemId");
	filter.endDTD();
	verify(contentHandler).endDTD();
	filter.startCDATA();
	verify(contentHandler).startCDATA();
	filter.endCDATA();
	verify(contentHandler).endCDATA();
	filter.startEntity("name");
	verify(contentHandler).startEntity("name");
	filter.endEntity("name");
	verify(contentHandler).endEntity("name");
	filter.comment(CHARS, 800, 900);
	verify(contentHandler).comment(CHARS, 800, 900);
}
 
開發者ID:fluentxml4j,項目名稱:fluentxml4j,代碼行數:21,代碼來源:AbstractSAXFilterTest.java

示例12: createResult

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
/**
 * Retrieves a new Result for setting the XML value designated by this
 * SQLXML instance.
 *
 * @param resultClass The class of the result, or null.
 * @throws java.sql.SQLException if there is an error processing the XML
 *         value or the state is not writable
 * @return for setting the XML value designated by this SQLXML instance.
 */
protected <T extends Result>T createResult(
        Class<T> resultClass) throws SQLException {

    checkWritable();
    setWritable(false);
    setReadable(true);

    if (JAXBResult.class.isAssignableFrom(resultClass)) {

        // Must go first presently, since JAXBResult extends SAXResult
        // (purely as an implmentation detail) and it's not possible
        // to instantiate a valid JAXBResult with a Zero-Args
        // constructor(or any subclass thereof, due to the finality of
        // its private UnmarshallerHandler)
        // FALL THROUGH... will throw an exception
    } else if ((resultClass == null)
               || StreamResult.class.isAssignableFrom(resultClass)) {
        return createStreamResult(resultClass);
    } else if (DOMResult.class.isAssignableFrom(resultClass)) {
        return createDOMResult(resultClass);
    } else if (SAXResult.class.isAssignableFrom(resultClass)) {
        return createSAXResult(resultClass);
    } else if (StAXResult.class.isAssignableFrom(resultClass)) {
        return createStAXResult(resultClass);
    }

    throw JDBCUtil.invalidArgument("resultClass: " + resultClass);
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:38,代碼來源:JDBCSQLXML.java

示例13: render

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
/**
 * Renders an input file (XML or XSL-FO) into a PDF file. It uses the JAXP
 * transformer given to optionally transform the input document to XSL-FO.
 * The transformer may be an identity transformer in which case the input
 * must already be XSL-FO. The PDF is written to a byte array that is
 * returned as the method's result.
 * @param src Input XML or XSL-FO
 * @param transformer Transformer to use for optional transformation
 * @param response HTTP response object
 * @throws FOPException If an error occurs during the rendering of the
 * XSL-FO
 * @throws TransformerException If an error occurs during XSL
 * transformation
 * @throws IOException In case of an I/O problem
 */
public void render(Source src, Transformer transformer, HttpServletResponse response, String realpath)
            throws FOPException, TransformerException, IOException {

    FOUserAgent foUserAgent = getFOUserAgent(realpath);

    //Setup output
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    //Setup FOP
    fopFactory.setBaseURL(realpath);
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);


    //Make sure the XSL transformation's result is piped through to FOP
    Result res = new SAXResult(fop.getDefaultHandler());

    //Start the transformation and rendering process
    transformer.transform(src, res);

    //Return the result
    sendPDF(out.toByteArray(), response);
}
 
開發者ID:malglam,項目名稱:Lester,代碼行數:38,代碼來源:CreatePDF.java

示例14: testSAXResult

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
@Test
public void testSAXResult() {
    DefaultHandler handler = new DefaultHandler();

    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";
    try {
        SAXResult saxResult = new SAXResult(handler);
        // saxResult.setSystemId("jaxp-ri/unit-test/javax/xml/stream/XMLOutputFactoryTest/cr6846132.xml");
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = ofac.createXMLStreamWriter(saxResult);
        writer.writeStartDocument("1.0");
        writer.writeStartElement("root");
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        writer.close();
    } catch (Exception e) {
        if (e instanceof UnsupportedOperationException) {
            // expected
        } else {
            e.printStackTrace();
            Assert.fail(e.toString());
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:Bug6846132Test.java

示例15: testSAXResult1

import javax.xml.transform.sax.SAXResult; //導入依賴的package包/類
@Test
public void testSAXResult1() {
    DefaultHandler handler = new DefaultHandler();

    try {
        SAXResult saxResult = new SAXResult(handler);
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        XMLEventWriter writer = ofac.createXMLEventWriter(saxResult);
    } catch (Exception e) {
        if (e instanceof UnsupportedOperationException) {
            // expected
        } else {
            e.printStackTrace();
            Assert.fail(e.toString());
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:Bug6846132Test.java


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