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