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


Java SAXResult.setHandler方法代碼示例

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


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

示例1: testCheckElementContentWhitespace

import javax.xml.transform.sax.SAXResult; //導入方法依賴的package包/類
/**
 * Test for the isIgnoringElementContentWhitespace and the
 * setIgnoringElementContentWhitespace. The xml file has all kinds of
 * whitespace,tab and newline characters, it uses the MyNSContentHandler
 * which does not invoke the characters callback when this
 * setIgnoringElementContentWhitespace is set to true.
 * @throws Exception If any errors occur.
 */
@Test
public void testCheckElementContentWhitespace() throws Exception {
    String goldFile = GOLDEN_DIR + "dbfactory02GF.out";
    String outputFile = USER_DIR + "dbfactory02.out";
    MyErrorHandler eh = MyErrorHandler.newInstance();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(true);
    assertFalse(dbf.isIgnoringElementContentWhitespace());
    dbf.setIgnoringElementContentWhitespace(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    db.setErrorHandler(eh);
    Document doc = db.parse(new File(XML_DIR, "DocumentBuilderFactory06.xml"));
    assertFalse(eh.isErrorOccured());
    DOMSource domSource = new DOMSource(doc);
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer transformer = tfactory.newTransformer();
    SAXResult saxResult = new SAXResult();
    try(MyCHandler handler = MyCHandler.newInstance(new File(outputFile))) {
        saxResult.setHandler(handler);
        transformer.transform(domSource, saxResult);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:DocumentBuilderFactoryTest.java

示例2: setSAXConsumer

import javax.xml.transform.sax.SAXResult; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected void setSAXConsumer(final SAXConsumer consumer) {
    TransformerHandler transformerHandler;
    try {
        transformerHandler = TRAX_FACTORY.newTransformerHandler(this.templates);
    } catch (Exception e) {
        throw new SetupException("Could not initialize transformer handler.", e);
    }

    if (this.parameters != null) {
        final Transformer transformer = transformerHandler.getTransformer();

        this.parameters.entrySet().forEach(entry -> {
            final String name = entry.getKey();
            // is valid XSLT parameter name
            if (XSLT_PARAMETER_NAME_PATTERN.matcher(name).matches()) {
                transformer.setParameter(name, entry.getValue());
            }
        });
    }

    final SAXResult result = new SAXResult();
    result.setHandler(consumer);
    // According to TrAX specs, all TransformerHandlers are LexicalHandlers
    result.setLexicalHandler(consumer);
    transformerHandler.setResult(result);

    final SAXConsumerAdapter saxConsumerAdapter = new SAXConsumerAdapter();
    saxConsumerAdapter.setContentHandler(transformerHandler);
    super.setSAXConsumer(saxConsumerAdapter);
}
 
開發者ID:apache,項目名稱:syncope,代碼行數:35,代碼來源:XSLTTransformer.java

示例3: transform

import javax.xml.transform.sax.SAXResult; //導入方法依賴的package包/類
@Override
protected String transform(TransformerPool tp, Source source, Map parametervalues) throws TransformerException, IOException {
	SAXResult result = new SAXResult();
	XmlJsonWriter xjw = new XmlJsonWriter();
	result.setHandler(xjw);
	tp.transform(source, result, parametervalues);
	return xjw.toString();
}
 
開發者ID:ibissource,項目名稱:iaf,代碼行數:9,代碼來源:JsonXsltPipe.java

示例4: getSAXResult

import javax.xml.transform.sax.SAXResult; //導入方法依賴的package包/類
private Result getSAXResult() {
    SAXResult saxResult = new SAXResult();
    saxResult.setHandler(new DefaultHandler());
    return saxResult;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:ValidatorTest.java

示例5: getHandlerSAXResult

import javax.xml.transform.sax.SAXResult; //導入方法依賴的package包/類
private SAXResult getHandlerSAXResult() {
    SAXResult res = new SAXResult();
    MyContentHandler myContentHandler = new MyContentHandler(transOutputStream());
    res.setHandler(myContentHandler);
    return res;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:TransformTest.java

示例6: getOutputHandler

import javax.xml.transform.sax.SAXResult; //導入方法依賴的package包/類
public ContentHandler getOutputHandler(OutputStream out) throws IOException
{
	if (!isAvailable()) return null;

	try
	{
		XSLTTransform xsltTransform = (XSLTTransform) transformerHolder.get();
		if (xsltTransform == null)
		{
			xsltTransform = new XSLTTransform();
			xsltTransform.setXslt(new InputSource(this.getClass()
					.getResourceAsStream(xslt)));
			transformerHolder.set(xsltTransform);
		}
		SAXResult sr = new SAXResult();
		
		TransformerHandler th = xsltTransform.getContentHandler();
		
		Transformer transformer = th.getTransformer();
		if (transformParameters != null) {
			for (Map.Entry<String, String> entry: transformParameters.entrySet()) {
				transformer.setParameter(entry.getKey(), entry.getValue());
			}
		}

		Properties p = OutputPropertiesFactory.getDefaultMethodProperties("xml");
	
		// SAK-14388 - use the alternate XHTMLSerializer2 for Websphere environments
		if ("websphere".equals(ServerConfigurationService.getString("servlet.container")))
		{
			// SAK-16712: null in java.util.Properties causes NullPointerException
			if (getXalan270ContentHandler() != null )
			{
				outputProperties.put("{http://xml.apache.org/xalan}content-handler", getXalan270ContentHandler());
			}
		}
		p.putAll(outputProperties);
		
		/*
		S_KEY_CONTENT_HANDLER:{http://xml.apache.org/xalan}content-handler
			S_KEY_ENTITIES:{http://xml.apache.org/xalan}entities
			S_KEY_INDENT_AMOUNT:{http://xml.apache.org/xalan}indent-amount
			S_OMIT_META_TAG:{http://xml.apache.org/xalan}omit-meta-tag
			S_USE_URL_ESCAPING:{http://xml.apache.org/xalan}use-url-escaping
		*/
		
		Serializer s = SerializerFactory.getSerializer(p);
		s.setOutputStream(out);
		sr.setHandler(s.asContentHandler());
		th.setResult(sr);
		return th;
	}
	catch (Exception ex)
	{
		throw new RuntimeException("Failed to create Content Handler", ex); //$NON-NLS-1$
		/*
		 * String stackTrace = null; try { StringWriter exw = new
		 * StringWriter(); PrintWriter pw = new PrintWriter(exw);
		 * log.error(ex.getMessage(), ex); stackTrace = exw.toString(); } catch
		 * (Exception ex2) { stackTrace =
		 * MessageFormat.format(defaultStackTrace, new Object[] {
		 * ex.getMessage() }); } out.write(MessageFormat.format(errorFormat,
		 * new Object[] { ex.getMessage(), stackTrace }));
		 */
	}
}
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:67,代碼來源:XSLTEntityHandler.java


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