下面列出了org.xml.sax.SAXNotRecognizedException#javax.xml.transform.TransformerConfigurationException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Create a transformer from a stylesheet
*
* @param source DOMSource
*
* @return the Transformer
*/
public static Transformer createTransformer(DOMSource source)
{
if(log.isDebugEnabled())
{
log.debug("createTransformer(DOMSource " + source + ")");
}
Transformer transformer = null;
TransformerFactory transformerFactory = TransformerFactory.newInstance();
URIResolver resolver = new URIResolver();
transformerFactory.setURIResolver(resolver);
try
{
transformer = transformerFactory.newTransformer(source);
}
catch(TransformerConfigurationException e)
{
log.error(e.getMessage(), e);
}
return transformer;
}
/**
* Makes a list of templates from a series of xsltProcessors that applies those xsltProcessors
* in order.
* @param templateList The series of xsltProcessors used to construct the
* filter.
* @throws BuildException If no xsltProcessors are specified.
*/
List<Templates> makeTemplates(List<CCGBankTaskTemplates> templateList)
throws FileNotFoundException,TransformerConfigurationException {
List<Templates> l = new ArrayList<Templates>();
for(CCGBankTaskTemplates taskTemplates : templateList) {
for(File f : taskTemplates) {
StreamSource ss = new StreamSource(
new BufferedInputStream(new FileInputStream(f)));
ss.setSystemId(f);
l.add(transformerFactory.newTemplates(ss));
}
}
return Collections.unmodifiableList(l);
}
/**
* javax.xml.transform.sax.TransformerFactory implementation.
* Create a Transformer object that copies the input document to the result.
*
* @return A Transformer object that simply copies the source to the result.
* @throws TransformerConfigurationException
*/
@Override
public Transformer newTransformer()
throws TransformerConfigurationException
{
TransformerImpl result = new TransformerImpl(new Properties(),
_indentNumber, this);
if (_uriResolver != null) {
result.setURIResolver(_uriResolver);
}
if (!_isNotSecureProcessing) {
result.setSecureProcessing(true);
}
return result;
}
/**
* Returns properly configured (e.g. security features) factory
* - securityProcessing == is set based on security processing property, default is true
*/
public static TransformerFactory createTransformerFactory(boolean disableSecureProcessing) throws IllegalStateException {
try {
TransformerFactory factory = TransformerFactory.newInstance();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "TransformerFactory instance: {0}", factory);
}
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing));
return factory;
} catch (TransformerConfigurationException ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new IllegalStateException( ex);
} catch (AbstractMethodError er) {
LOGGER.log(Level.SEVERE, null, er);
throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er);
}
}
public CejshBuilder(CejshConfig config, ExportOptions options)
throws TransformerConfigurationException, ParserConfigurationException, XPathExpressionException {
this.gcalendar = new GregorianCalendar(UTC);
this.logLevel = config.getLogLevel();
this.options = options;
TransformerFactory xslFactory = TransformerFactory.newInstance();
tranformationErrorHandler = new TransformErrorListener();
bwmetaXsl = xslFactory.newTransformer(new StreamSource(config.getCejshXslUrl()));
if (bwmetaXsl == null) {
throw new TransformerConfigurationException("Cannot load XSL: " + config.getCejshXslUrl());
}
bwmetaXsl.setOutputProperty(OutputKeys.INDENT, "yes");
bwmetaXsl.setErrorListener(tranformationErrorHandler);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
db = dbf.newDocumentBuilder();
XPathFactory xPathFactory = ProarcXmlUtils.defaultXPathFactory();
XPath xpath = xPathFactory.newXPath();
xpath.setNamespaceContext(new SimpleNamespaceContext().add("m", ModsConstants.NS));
issnPath = xpath.compile("m:mods/m:identifier[@type='issn' and not(@invalid)]");
partNumberPath = xpath.compile("m:mods/m:titleInfo/m:partNumber");
dateIssuedPath = xpath.compile("m:mods/m:originInfo/m:dateIssued");
reviewedArticlePath = xpath.compile("m:mods/m:genre[text()='article' and @type='peer-reviewed']");
}
/**
* Create a Transformer object that copies the input document to the
* result. Uses the com.sun.org.apache.xalan.internal.processor.TransformerFactory.
* @return A Transformer object.
*/
public Transformer newTransformer()
throws TransformerConfigurationException
{
if (_xalanFactory == null) {
createXalanTransformerFactory();
}
if (_errorlistener != null) {
_xalanFactory.setErrorListener(_errorlistener);
}
if (_uriresolver != null) {
_xalanFactory.setURIResolver(_uriresolver);
}
_currFactory = _xalanFactory;
return _currFactory.newTransformer();
}
public XMLFilter newXMLFilter(Templates templates)
throws TransformerConfigurationException {
try {
return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
}
catch(TransformerConfigurationException e1) {
if (_xsltcFactory == null) {
createXSLTCTransformerFactory();
}
ErrorListener errorListener = _xsltcFactory.getErrorListener();
if(errorListener != null) {
try {
errorListener.fatalError(e1);
return null;
}
catch( TransformerException e2) {
new TransformerConfigurationException(e2);
}
}
throw e1;
}
}
/**
* Load the {@link Templates} instance for the stylesheet at the configured location.
*/
private Templates loadTemplates() throws ApplicationContextException {
Source stylesheetSource = getStylesheetSource();
try {
Templates templates = this.transformerFactory.newTemplates(stylesheetSource);
if (logger.isDebugEnabled()) {
logger.debug("Loading templates '" + templates + "'");
}
return templates;
}
catch (TransformerConfigurationException ex) {
throw new ApplicationContextException("Can't load stylesheet from '" + getUrl() + "'", ex);
}
finally {
closeSourceIfNecessary(stylesheetSource);
}
}
/** Returns a new transformer for the compiled XSL templates
*/
public static Transformer getTransformer(Templates templates) throws TransformerConfigurationException {
Transformer tf = factory.newTransformerHandler(templates).getTransformer();
// In debug mode, add a TraceListener to log stylesheet execution
if (LOGGER.isDebugEnabled()) {
try {
TraceManager tm = ((org.apache.xalan.transformer.TransformerImpl) tf).getTraceManager();
tm.addTraceListener(new MCRTraceListener());
} catch (Exception ex) {
LOGGER.warn(ex);
}
}
return tf;
}
public Templates parseTemplates(Source source) throws TransformerConfigurationException, SAXException, IOException {
InputSource inputSource = SAXSource.sourceToInputSource(source);
if (inputSource == null) {
throw new RuntimeException("Unable convert to Input Source");
}
SAXTransformerFactory saxTransformerFactory = createFeaturedSaxTransformerFactory();
TemplatesHandler templateHandler = saxTransformerFactory.newTemplatesHandler();
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
if (resolver != null) {
xmlReader.setEntityResolver(resolver);
}
xmlReader.setContentHandler(templateHandler);
xmlReader.parse(inputSource);
Templates templates = templateHandler.getTemplates();
if (templates == null) {
throw new RuntimeException("Unable create templates from given source");
}
return templates;
}
/**
* javax.xml.transform.sax.SAXTransformerFactory implementation.
* Create an XMLFilter that uses the given source as the
* transformation instructions.
*
* @param templates The source of the transformation instructions.
* @return An XMLFilter object, or null if this feature is not supported.
* @throws TransformerConfigurationException
*/
@Override
public XMLFilter newXMLFilter(Templates templates)
throws TransformerConfigurationException
{
try {
return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
}
catch (TransformerConfigurationException e1) {
if (_errorListener != null) {
try {
_errorListener.fatalError(e1);
return null;
}
catch (TransformerException e2) {
new TransformerConfigurationException(e2);
}
}
throw e1;
}
}
/**
* Get a TransformerHandler object that can process SAX ContentHandler
* events based on a copy transformer.
* Uses com.sun.org.apache.xalan.internal.processor.TransformerFactory.
*/
public TransformerHandler newTransformerHandler()
throws TransformerConfigurationException
{
if (_xalanFactory == null) {
createXalanTransformerFactory();
}
if (_errorlistener != null) {
_xalanFactory.setErrorListener(_errorlistener);
}
if (_uriresolver != null) {
_xalanFactory.setURIResolver(_uriresolver);
}
return _xalanFactory.newTransformerHandler();
}
@Override
protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os,
Annotation[] anns, MediaType mt)
throws Exception {
Templates t = createTemplates(getOutTemplates(anns, mt), outParamsMap, outProperties);
if (t == null && supportJaxbOnly) {
super.marshalToOutputStream(ms, obj, os, anns, mt);
return;
}
org.apache.cxf.common.jaxb.JAXBUtils.setMinimumEscapeHandler(ms);
TransformerHandler th = null;
try {
th = factory.newTransformerHandler(t);
} catch (TransformerConfigurationException ex) {
TemplatesImpl ti = (TemplatesImpl)t;
th = factory.newTransformerHandler(ti.getTemplates());
this.trySettingProperties(th, ti);
}
Result result = getStreamResult(os, anns, mt);
if (systemId != null) {
result.setSystemId(systemId);
}
th.setResult(result);
if (getContext() == null) {
th.startDocument();
}
ms.marshal(obj, th);
if (getContext() == null) {
th.endDocument();
}
}
/**
* javax.xml.transform.sax.SAXTransformerFactory implementation.
* Get a TemplatesHandler object that can process SAX ContentHandler
* events into a Templates object.
*
* @return A TemplatesHandler object that can handle SAX events
* @throws TransformerConfigurationException
*/
@Override
public TemplatesHandler newTemplatesHandler()
throws TransformerConfigurationException
{
final TemplatesHandlerImpl handler =
new TemplatesHandlerImpl(_indentNumber, this);
if (_uriResolver != null) {
handler.setURIResolver(_uriResolver);
}
return handler;
}
/**
* Get a TemplatesHandler object that can process SAX ContentHandler
* events into a Templates object. Uses the
* com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
*/
public TemplatesHandler newTemplatesHandler()
throws TransformerConfigurationException
{
if (_xsltcFactory == null) {
createXSLTCTransformerFactory();
}
if (_errorlistener != null) {
_xsltcFactory.setErrorListener(_errorlistener);
}
if (_uriresolver != null) {
_xsltcFactory.setURIResolver(_uriresolver);
}
return _xsltcFactory.newTemplatesHandler();
}
/**
* Get a TransformerHandler object that can process SAX ContentHandler
* events based on a transformer specified by the stylesheet Source.
* Uses com.sun.org.apache.xalan.internal.processor.TransformerFactory.
*/
public TransformerHandler newTransformerHandler(Source src)
throws TransformerConfigurationException
{
if (_xalanFactory == null) {
createXalanTransformerFactory();
}
if (_errorlistener != null) {
_xalanFactory.setErrorListener(_errorlistener);
}
if (_uriresolver != null) {
_xalanFactory.setURIResolver(_uriresolver);
}
return _xalanFactory.newTransformerHandler(src);
}
/**
* Implements JAXP's Templates.getOutputProperties(). We need to
* instanciate a translet to get the output settings, so
* we might as well just instanciate a Transformer and use its
* implementation of this method.
*/
public synchronized Properties getOutputProperties() {
try {
return newTransformer().getOutputProperties();
}
catch (TransformerConfigurationException e) {
return null;
}
}
private static TransformerFactory transformerFactory() throws TransformerConfigurationException {
TransformerFactory factory = TransformerFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
if (factory.getFeature(XMLConstants.ACCESS_EXTERNAL_DTD)) {
factory.setFeature(XMLConstants.ACCESS_EXTERNAL_DTD, false);
}
return factory;
}
private Transformer getTransformer() throws TransformerFactoryConfigurationError, TransformerConfigurationException {
final TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, YES_PROPERTY_VALUE); // insert newlines
transformer.setOutputProperty(OutputKeys.METHOD, METHOD_PROPERTY_VALUE);
transformer.setOutputProperty(OutputKeys.VERSION, VERSION_PROPERTY_VALUE);
transformer.setOutputProperty(OutputKeys.ENCODING, ENCODING_PROPERTY_VALUE);
transformer.setOutputProperty(OutputKeys.STANDALONE, YES_PROPERTY_VALUE);
return transformer;
}
/**
* javax.xml.transform.sax.SAXTransformerFactory implementation.
* Get a TransformerHandler object that can process SAX ContentHandler
* events into a Result, based on the transformation instructions
* specified by the argument.
*
* @param src The source of the transformation instructions.
* @return A TransformerHandler object that can handle SAX events
* @throws TransformerConfigurationException
*/
@Override
public TransformerHandler newTransformerHandler(Source src)
throws TransformerConfigurationException
{
final Transformer transformer = newTransformer(src);
if (_uriResolver != null) {
transformer.setURIResolver(_uriResolver);
}
return new TransformerHandlerImpl((TransformerImpl) transformer);
}
/**
* Helper method to write a pretty-printed build xml file
* @param buildXMLFile
* @param doc
* @throws TransformerFactoryConfigurationError
* @throws TransformerConfigurationException
* @throws TransformerException
*/
private static void writeBuildFile(File buildXMLFile, Document doc) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(buildXMLFile);
transformer.transform(source, result);
}
public TransformerChain buildChain() throws TransformerConfigurationException {
TransformerHandler[] handlers = new TransformerHandler[templates.length];
for (int i = templates.length - 1; i >= 0; i--) {
handlers[i] = factory.newTransformerHandler(templates[i]);
if (i < templates.length - 1)
handlers[i].setResult(new SAXResult(handlers[i + 1]));
}
return new TransformerChain(handlers[0], handlers[handlers.length - 1]);
}
/**
* Implements JAXP's Templates.getOutputProperties(). We need to
* instanciate a translet to get the output settings, so
* we might as well just instanciate a Transformer and use its
* implementation of this method.
*/
public synchronized Properties getOutputProperties() {
try {
return newTransformer().getOutputProperties();
}
catch (TransformerConfigurationException e) {
return null;
}
}
@PostConstruct
private void init() throws IOException, TransformerConfigurationException {
translationTemplateBundleDao = dataStorageService.getDao(TranslationTemplateBundleDto.class);
testObjectTypeDao = dataStorageService.getDao(TestObjectTypeDto.class);
tagDao = dataStorageService.getDao(TagDto.class);
testItemTypeDao = dataStorageService.getDao(TestItemTypeDto.class);
componentDao = dataStorageService.getDao(ComponentDto.class);
streaming.prepareCache(tagDao, new SimpleFilter());
streaming.prepareCache(translationTemplateBundleDao, new SimpleFilter());
logger.info("Meta Type controller initialized");
}
/**
* javax.xml.transform.sax.SAXTransformerFactory implementation.
* Get a TransformerHandler object that can process SAX ContentHandler
* events into a Result. This method will return a pure copy transformer.
*
* @return A TransformerHandler object that can handle SAX events
* @throws TransformerConfigurationException
*/
@Override
public TransformerHandler newTransformerHandler()
throws TransformerConfigurationException
{
final Transformer transformer = newTransformer();
if (_uriResolver != null) {
transformer.setURIResolver(_uriResolver);
}
return new TransformerHandlerImpl((TransformerImpl) transformer);
}
public static String documentToString(Document doc)
throws ParserConfigurationException, TransformerConfigurationException, TransformerException {
StringWriter stringWriter = new StringWriter();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(stringWriter);
Transformer transformer = getTransformerFactory().newTransformer();
transformer.transform(source, result);
return stringWriter.toString();
}
@MCRCommand(syntax = "generate md5 file report in directory {0}",
help = "generates XML a report over all content stores about failed md5 checks and write it in directory {0}")
public static void writeFileMD5Report(String targetDirectory) throws IOException, SAXException,
TransformerConfigurationException {
File targetDir = getDirectory(targetDirectory);
FSNodeChecker checker = new MD5Checker();
writeReport(targetDir, checker);
}
/**
* Get a TransformerHandler object that can process SAX ContentHandler
* events based on a transformer specified by the stylesheet Source.
* Uses com.sun.org.apache.xalan.internal.processor.TransformerFactory.
*/
public TransformerHandler newTransformerHandler(Source src)
throws TransformerConfigurationException
{
if (_xalanFactory == null) {
createXalanTransformerFactory();
}
if (_errorlistener != null) {
_xalanFactory.setErrorListener(_errorlistener);
}
if (_uriresolver != null) {
_xalanFactory.setURIResolver(_uriresolver);
}
return _xalanFactory.newTransformerHandler(src);
}
public void configure() throws ConfigurationException {
super.configure();
if (!isSoap()) {
throw new ConfigurationException(getLogPrefix() + "soap must be true");
}
try {
bisUtils = BisUtils.getInstance();
bisErrorTp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(bisUtils.getSoapNamespaceDefs() + "\n" + bisUtils.getBisNamespaceDefs(), (isResultInPayload() ? bisUtils.getBisErrorXPath() : bisUtils.getOldBisErrorXPath()), "text"));
responseTp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(StringUtils.isNotEmpty(getResponseNamespaceDefs()) ? bisUtils.getSoapNamespaceDefs() + "\n" + getResponseNamespaceDefs() : bisUtils.getSoapNamespaceDefs(), StringUtils.isNotEmpty(getResponseXPath()) ? bisUtils.getSoapBodyXPath() + "/" + getResponseXPath() : bisUtils.getSoapBodyXPath() + "/*", "xml"));
bisErrorListTp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(bisUtils.getSoapNamespaceDefs() + "\n" + bisUtils.getBisNamespaceDefs(), (isResultInPayload() ? bisUtils.getBisErrorListXPath() : bisUtils.getOldBisErrorListXPath()), "xml"));
} catch (TransformerConfigurationException e) {
throw new ConfigurationException(getLogPrefix() + "cannot create transformer", e);
}
}
/**
* This method can be over-ridden by a class that extends this one.
* @param handler The calling StylesheetHandler/TemplatesBuilder.
*/
protected Stylesheet getStylesheetRoot(StylesheetHandler handler) throws TransformerConfigurationException
{
StylesheetRoot stylesheet;
stylesheet = new StylesheetRoot(handler.getSchema(), handler.getStylesheetProcessor().getErrorListener());
if (handler.getStylesheetProcessor().isSecureProcessing())
stylesheet.setSecureProcessing(true);
return stylesheet;
}