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


Java SAXTransformerFactory.newInstance方法代码示例

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


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

示例1: convertWordDocumentIntoHtml

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Converts a .docx document into HTML markup. This code
 * is based on <a href="http://stackoverflow.com/a/9053258/313554">this StackOverflow</a> answer.
 *
 * @param wordDocument  The converted .docx document.
 * @return
 */
public ConvertedDocumentDTO convertWordDocumentIntoHtml(MultipartFile wordDocument) {
    LOGGER.info("Converting word document: {} into HTML", wordDocument.getOriginalFilename());
    try {
        InputStream input = wordDocument.getInputStream();
        Parser parser = new OOXMLParser();

        StringWriter sw = new StringWriter();
        SAXTransformerFactory factory = (SAXTransformerFactory)
                SAXTransformerFactory.newInstance();
        TransformerHandler handler = factory.newTransformerHandler();
        handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "utf-8");
        handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
        handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
        handler.setResult(new StreamResult(sw));

        Metadata metadata = new Metadata();
        metadata.add(Metadata.CONTENT_TYPE, "text/html;charset=utf-8");
        parser.parse(input, handler, metadata, new ParseContext());
        return new ConvertedDocumentDTO(wordDocument.getOriginalFilename(), sw.toString());
    }
    catch (IOException | SAXException | TransformerException | TikaException ex) {
        LOGGER.error("Conversion failed because an exception was thrown", ex);
        throw new DocumentConversionException(ex.getMessage(), ex);
    }
}
 
开发者ID:Vincit,项目名称:spring-boot-word-to-html-example,代码行数:33,代码来源:WordToHtmlConverter.java

示例2: buildSingleTransformerPipeline

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的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

示例3: toSAXResult

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的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

示例4: test3

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
@Test
public void test3() throws Exception {
    SAXTransformerFactory sf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    Transformer t = sf.newTransformer();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder parser = dbf.newDocumentBuilder();
    Document dom = parser.parse(Bug5072946.class.getResourceAsStream("Bug5072946.xml"));

    DOMResult r = new DOMResult();

    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());

    Node n = r.getNode().getFirstChild();
    r.setNode(n);
    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());
    Assert.assertSame(r.getNode(), n);

    r.setNextSibling(r.getNode().getFirstChild());
    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());
    Assert.assertSame(r.getNode(), n);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:Bug5072946.java

示例5: SimpleXMLWriter

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Builds a {@link SimpleXMLWriter} for the given display.
 *
 * @param display
 *        the display to build the writer for (not null).
 * @throws TransformerConfigurationException
 *         if for some reason the TransformerHandler cannot be created.
 */
public SimpleXMLWriter(final Display display) throws TransformerConfigurationException {
    Check.notNull(display, "display"); //$NON-NLS-1$

    final SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    transformerHandler = transformerFactory.newTransformerHandler();
    transformer = transformerHandler.getTransformer();

    transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); //$NON-NLS-1$
    transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
    transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); //$NON-NLS-1$ //$NON-NLS-2$

    // TODO Reference DTD or schema.

    transformerHandler.setResult(new StreamResult(display.getPrintStream()));
}
 
开发者ID:Microsoft,项目名称:team-explorer-everywhere,代码行数:25,代码来源:SimpleXMLWriter.java

示例6: JDependProcessorXML2

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Constructs a <code>JDepend</code> instance with the specified writer.
 * Creates a new instance of JDependProcessorXML
 *
 *
 * @param writer Writer.
 */
public JDependProcessorXML2(PrintWriter writer)  {
    super(writer);
    
    formatter = NumberFormat.getInstance(Locale.ENGLISH);
    formatter.setMaximumFractionDigits(2);
    
    try {
        SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        TransformerHandler hd = tf.newTransformerHandler();
        Transformer serializer = hd.getTransformer();
        serializer.setOutputProperty(OutputKeys.INDENT,"yes");
        
        // use getWriter as transform result destination
        hd.setResult(new StreamResult(this.getWriter()) );
        
        // create the XmlEmitter
        this.xmlEmitter = new XmlEmitter( hd );
    } catch (TransformerConfigurationException tce) {
        throw new XmlEmitterException(tce);
    }
}
 
开发者ID:bernhardhuber,项目名称:netbeansplugins,代码行数:29,代码来源:JDependProcessorXML2.java

示例7: getHtmlFromFile

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Ritorna una vista HTML sul file processato. L'estrazione del testo fa
 * perdere di fatto la formattazione contenuta nel word o nel PDF. La
 * versione HTML è una versione processabile ma che mantiene il formato
 *
 * @param file file da parsare
 * @return vista HTML formattato del contenuto del documento (privato delle
 * immagini)
 */
public String getHtmlFromFile(File file) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        TransformerHandler handler = factory.newTransformerHandler();
        handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
        handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
        handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        handler.setResult(new StreamResult(out));
        ExpandedTitleContentHandler handler1 = new ExpandedTitleContentHandler(handler);
        InputStream is = file.toURI().toURL().openStream();
        adp.parse(is, handler1, new Metadata());
        is.close();
        return new String(out.toByteArray(), "UTF-8").replaceAll("<img .*?</img>", "").replaceAll("<img .*?/>", "");
    } catch (TransformerConfigurationException | IllegalArgumentException | IOException | SAXException | TikaException ex) {
        return "!ERROR: " + ex.getLocalizedMessage();
    }
}
 
开发者ID:fiohol,项目名称:theSemProject,代码行数:28,代码来源:DocumentParser.java

示例8: serialize

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Serializes a property list into a Cocoa XML Property List document.
 * @param propertyList property list.
 * @param file destination.
 * @param comments comments to insert into document.
 * @throws SAXException if exception during serialization.
 * @throws TransformerConfigurationException if exception creating serializer.
 */
public static void serialize(final Map propertyList,
                             final List comments,
                             final File file)
       throws IOException, SAXException,
           TransformerConfigurationException {
    SAXTransformerFactory sf = (SAXTransformerFactory)
            SAXTransformerFactory.newInstance();
    TransformerHandler handler = sf.newTransformerHandler();

    FileOutputStream os = new FileOutputStream(file);
    StreamResult result = new StreamResult(os);
    handler.setResult(result);

    handler.startDocument();
    for(Iterator iter = comments.iterator(); iter.hasNext();) {
        char[] comment = String.valueOf(iter.next()).toCharArray();
        handler.comment(comment, 0, comment.length);
    }
    AttributesImpl attributes = new AttributesImpl();
    handler.startElement(null, "plist", "plist", attributes);
    serializeMap(propertyList, handler);
    handler.endElement(null, "plist", "plist");

    handler.endDocument();
}
 
开发者ID:cniweb,项目名称:ant-contrib,代码行数:34,代码来源:PropertyListSerialization.java

示例9: performXslt

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
private static void performXslt(TextFileRepos repos, StringBuilder sb) throws TransformerException {
	
       for(TextFileRepo repo : repos.repos){

       	for(TextFileAndContents xml : repo.getXmlFiles()) {
               SAXSource saxSource = new SAXSource(new InputSource( new StringReader(xml.textFromFile) ));
               StringWriter writer = new StringWriter();
               TransformerFactory factory = SAXTransformerFactory.newInstance();
               Transformer transformer;
   			transformer = factory.newTransformer(new StreamSource(new StringReader(repo.getOnePerFolder().textFromFile)));
   			transformer.transform(saxSource, new StreamResult(writer));
   			sb.append("#Repo:" + repo.directory.getName() + " XMl file:" + xml.file.getName() + " XSL file: " + repo.getOnePerFolder().file.getName() + "\n");
   			sb.append(writer.toString());
   			sb.append("\n");
       	}
       	
       }
	
}
 
开发者ID:eostermueller,项目名称:crazyFastXml,代码行数:20,代码来源:XsltSampler01.java

示例10: PvXMLWriter

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/**
 * Creates a new instance of PvXMLWriter
 */
public PvXMLWriter()
{
	try
	{
		factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
		handler = factory.newTransformerHandler();
		serializer = handler.getTransformer();
		serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
		serializer.setOutputProperty(OutputKeys.INDENT, "yes");
		serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
	} catch (Exception e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:fr3ts0n,项目名称:AndrOBD,代码行数:19,代码来源:PvXMLWriter.java

示例11: testXMLSerialisation

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
@Test
public void testXMLSerialisation() throws SAXException, IOException {
    FSManifestIterable it = new FSManifestIterable(bundlerepo);
    BundleRepoDescriptor repo = new BundleRepoDescriptor(bundlerepo.toURI(),
            ExecutionEnvironmentProfileProvider.getInstance());
    repo.populate(it.iterator());

    SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler hd;
    try {
        hd = tf.newTransformerHandler();
    } catch (TransformerConfigurationException e) {
        throw new BuildException("Sax configuration error: " + e.getMessage(), e);
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StreamResult stream = new StreamResult(out);
    hd.setResult(stream);

    OBRXMLWriter.writeManifests(it, hd, false);

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    BundleRepoDescriptor repo2 = OBRXMLParser.parse(bundlerepo.toURI(), in);

    assertEquals(repo, repo2);
}
 
开发者ID:apache,项目名称:ant-ivy,代码行数:27,代码来源:BundleRepoTest.java

示例12: gen

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
public String gen(String source, ArrayList<CoveredStatement> entries) throws Exception {
    java.io.StringWriter sw = new StringWriter();
    //PrintWriter out = new PrintWriter(System.out);
    StreamResult streamResult = new StreamResult(sw);
    SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

    TransformerHandler hd = tf.newTransformerHandler();
    Transformer serializer = hd.getTransformer();
    serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
    //serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "users.dtd");
    //serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    hd.setResult(streamResult);
    hd.startDocument();
    AttributesImpl atts = new AttributesImpl();
    hd.startElement("", "", "html", atts);
    hd.startElement("", "", "head", atts);
    hd.endElement("", "", "head");
    hd.startElement("", "", "body", atts);
    hd.startElement("", "", "pre", atts);
    genTree(entries, hd, source);
    hd.endElement("", "", "pre");
    hd.endElement("", "", "body");
    hd.endElement("", "", "html");
    hd.endDocument();
    return sw.toString();
}
 
开发者ID:raverkamp,项目名称:plsql-code-coverage,代码行数:27,代码来源:GenHtml.java

示例13: downgrade

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
static
public byte[] downgrade(byte[] bytes, Version version) throws IOException, TransformerConfigurationException, SAXException {
	ByteArrayOutputStream result = new ByteArrayOutputStream();

	SAXTransformerFactory transformerFactory = (SAXTransformerFactory)SAXTransformerFactory.newInstance();

	TransformerHandler transformer = transformerFactory.newTransformerHandler();
	transformer.setResult(new StreamResult(result));

	ExportFilter exportFilter = new ExportFilter(XMLReaderFactory.createXMLReader(), version);
	exportFilter.setContentHandler(transformer);

	try(InputStream is = new ByteArrayInputStream(bytes)){
		exportFilter.parse(new InputSource(is));
	}

	return result.toByteArray();
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:19,代码来源:VersionUtil.java

示例14: startRenderer

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void startRenderer(OutputStream outputStream)
            throws IOException {
    if (this.handler == null) {
        SAXTransformerFactory factory
            = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
        try {
            TransformerHandler transformerHandler = factory.newTransformerHandler();
            setContentHandler(transformerHandler);
            StreamResult res = new StreamResult(outputStream);
            transformerHandler.setResult(res);
        } catch (TransformerConfigurationException tce) {
            throw new RuntimeException(tce.getMessage());
        }
        this.out = outputStream;
    }

    try {
        handler.startDocument();
    } catch (SAXException saxe) {
        handleSAXException(saxe);
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:24,代码来源:AbstractXMLRenderer.java

示例15: XmlWriter

import javax.xml.transform.sax.SAXTransformerFactory; //导入方法依赖的package包/类
public XmlWriter(PrintWriter out, String encoding) throws TransformerConfigurationException, SAXException {
	StreamResult streamResult = new StreamResult(out);
	SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
	transformerHandler = tf.newTransformerHandler();
	Transformer serializer = transformerHandler.getTransformer();
	serializer.setOutputProperty(OutputKeys.ENCODING, encoding);
	serializer.setOutputProperty(OutputKeys.INDENT, "yes");
	serializer.setOutputProperty(OutputKeys.METHOD, "xml");
	transformerHandler.setResult(streamResult);
	startedElementStack = new Stack<String>();
	transformerHandler.startDocument();
	elementAttributes = new AttributesImpl();
	Pattern p = Pattern.compile("\\p{Cntrl}");
	controlMatcher = p.matcher("");

}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:17,代码来源:XmlWriter.java


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