本文整理汇总了Java中javax.xml.transform.TransformerFactoryConfigurationError类的典型用法代码示例。如果您正苦于以下问题:Java TransformerFactoryConfigurationError类的具体用法?Java TransformerFactoryConfigurationError怎么用?Java TransformerFactoryConfigurationError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransformerFactoryConfigurationError类属于javax.xml.transform包,在下文中一共展示了TransformerFactoryConfigurationError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveWithCustomIndetation
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
/**
* Saves the xml, contained by the specified input with the custom indentation.
* If the input is the result of jaxb marshalling, make sure to set
* Marshaller.JAXB_FORMATTED_OUTPUT to false in order for this method to work
* properly.
*
* @param input
* @param fos
* @param indentation
*/
public static void saveWithCustomIndetation(ByteArrayInputStream input, FileOutputStream fos, int indentation) {
try {
Transformer transformer = SAXTransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indentation));
Source xmlSource = new SAXSource(new org.xml.sax.InputSource(input));
StreamResult res = new StreamResult(fos);
transformer.transform(xmlSource, res);
fos.flush();
fos.close();
} catch (TransformerFactoryConfigurationError | TransformerException | IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
示例2: write
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
public static void write(Document doc, OutputStream out) throws IOException {
// XXX note that this may fail to write out namespaces correctly if the document
// is created with namespaces and no explicit prefixes; however no code in
// this package is likely to be doing so
try {
Transformer t = TransformerFactory.newInstance().newTransformer(
new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
DocumentType dt = doc.getDoctype();
if (dt != null) {
String pub = dt.getPublicId();
if (pub != null) {
t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pub);
}
t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dt.getSystemId());
}
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // NOI18N
Source source = new DOMSource(doc);
Result result = new StreamResult(out);
t.transform(source, result);
} catch (Exception | TransformerFactoryConfigurationError e) {
throw new IOException(e);
}
}
示例3: storeXmlDocument
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
protected void storeXmlDocument ( final Document doc, final File file ) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException
{
// create output directory
file.getParentFile ().mkdirs ();
// write out xml
final TransformerFactory transformerFactory = TransformerFactory.newInstance ();
final Transformer transformer = transformerFactory.newTransformer ();
transformer.setOutputProperty ( OutputKeys.INDENT, "yes" ); //$NON-NLS-1$
final DOMSource source = new DOMSource ( doc );
final StreamResult result = new StreamResult ( file );
transformer.transform ( source, result );
}
示例4: generateConverterDoc
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
private static void generateConverterDoc(ModelContext ctx, ConverterModel converter) throws TransformerFactoryConfigurationError, IOException {
String bundleName = converter.getBundleName();
int dot = bundleName.lastIndexOf('.');
String packageName = bundleName.substring(0, dot);
String fileName = bundleName.substring(dot + 1) + ".xml";
FileObject fo;
try {
fo = ctx.getFiler().getResource(StandardLocation.SOURCE_PATH, packageName, fileName);
} catch (IOException ioe) {
fo = ctx.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName);
ctx.note("generating " + fo.getName());
PrintWriter out = new PrintWriter(fo.openOutputStream());
XMLUtils.writeDOMToFile(converter.generateDoc(), null, out);
out.close();
}
}
示例5: generateDocuments
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
private void generateDocuments(Logger logger, EvaluationContext evalCtx, Corpus corpus, Set<String> classes, Document docList) throws XPathExpressionException, IOException, SAXException, TransformerFactoryConfigurationError {
logger.info("generating HTML documents");
Element docListUL = XMLUtils.evaluateElement(XPATH_DOCUMENT_LIST, docList);
Document docSkel = createDocumentSkeleton();
Iterator<fr.inra.maiage.bibliome.alvisnlp.core.corpus.Document> docIt = documentIterator(evalCtx, corpus);
fr.inra.maiage.bibliome.alvisnlp.core.corpus.Document prev = null;
fr.inra.maiage.bibliome.alvisnlp.core.corpus.Document next = docIt.hasNext() ? docIt.next() : null;
while (next != null) {
fr.inra.maiage.bibliome.alvisnlp.core.corpus.Document doc = next;
addDocumentListItem(docList, docListUL, doc);
next = docIt.hasNext() ? docIt.next() : null;
Document xmlDoc = createDocument(docSkel, doc, prev, next);
HTMLBuilderFragmentTagIterator frit = new HTMLBuilderFragmentTagIterator(this, classes);
for (Section sec : Iterators.loop(sectionIterator(evalCtx, doc))) {
createSection(xmlDoc, sec, frit);
}
writeXHTMLDocument(xmlDoc, doc.getId());
prev = doc;
}
}
示例6: backupWsdlTypes
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
protected void backupWsdlTypes(Element element) throws TransformerFactoryConfigurationError, Exception {
if (wsdlType.equals(""))
return;
StringEx sx = new StringEx(wsdlType);
sx.replaceAll("<cdata>","<![CDATA[");
sx.replaceAll("</cdata>","]]>");
String sDom = "<"+fake_root+">\n" + sx.toString() + "</"+fake_root+">";
DocumentBuilder documentBuilder = XMLUtils.getDefaultDocumentBuilder();
Document document = documentBuilder.parse(new InputSource(new StringReader(sDom)));
String wsdlBackupDir = getWsdlBackupDir(element);
File dir = new File(wsdlBackupDir);
if (!dir.exists())
dir.mkdirs();
File file = new File(wsdlBackupDir + "/" + getName() + ".xml");
XMLUtils.saveXml(document, file);
}
示例7: backupWsdlTypes
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
protected void backupWsdlTypes(Element element) throws TransformerFactoryConfigurationError, Exception {
if (wsdlType.equals(""))
return;
StringEx sx = new StringEx(wsdlType);
sx.replaceAll("<cdata>","<![CDATA[");
sx.replaceAll("</cdata>","]]>");
sx.replaceAll("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>", "");
String sDom = sx.toString();
DocumentBuilder documentBuilder = XMLUtils.getDefaultDocumentBuilder();
Document document = documentBuilder.parse(new InputSource(new StringReader(sDom)));
String wsdlBackupDir = getWsdlBackupDir(element);
File dir = new File(wsdlBackupDir);
if (!dir.exists())
dir.mkdirs();
File file = new File(wsdlBackupDir + "/step-" + priority + ".xml");
XMLUtils.saveXml(document, file);
}
示例8: loadXmlDefinition
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
/**
* Used supplied XML {@link Document} to extract the XML for the defined {@link XmlEntity}.
*
* @param document to extract XML from.
* @return XML for {@link XmlEntity} if found, otherwise <code>null</code>.
* @throws XPathExpressionException
* @throws TransformerException
* @throws TransformerFactoryConfigurationError
* @since GemFire 8.1
*/
private final String loadXmlDefinition(final Document document)
throws XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
final Cache cache = CacheFactory.getAnyInstance();
this.searchString = createQueryString(prefix, type, attributes);
logger.info("XmlEntity:searchString: {}", this.searchString);
if (document != null) {
XPathContext xpathContext = new XPathContext();
xpathContext.addNamespace(prefix, namespace);
// Create an XPathContext here
Node element = XmlUtils.querySingleElement(document, this.searchString, xpathContext);
// Must copy to preserve namespaces.
if (null != element) {
return XmlUtils.elementToString(element);
}
}
logger.warn("No XML definition could be found with name={} and attributes={}", type,
attributes);
return null;
}
示例9: readConfiguration
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
/**
* Reads the configuration information from the shared configuration directory and returns a
* {@link Configuration} object
*
* @return {@link Configuration}
*/
private Configuration readConfiguration(File groupConfigDir)
throws SAXException, ParserConfigurationException, TransformerFactoryConfigurationError,
TransformerException, IOException {
Configuration configuration = new Configuration(groupConfigDir.getName());
File cacheXmlFull = new File(groupConfigDir, configuration.getCacheXmlFileName());
File propertiesFull = new File(groupConfigDir, configuration.getPropertiesFileName());
configuration.setCacheXmlFile(cacheXmlFull);
configuration.setPropertiesFile(propertiesFull);
Set<String> jarFileNames = Arrays.stream(groupConfigDir.list())
.filter((String filename) -> filename.endsWith(".jar")).collect(Collectors.toSet());
configuration.addJarNames(jarFileNames);
return configuration;
}
示例10: writeXml
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
/**
* Writes given xmlDocument to xml file.
*
* @param xmlDocument
*/
@SuppressWarnings("unused")
private void writeXml(final Document xmlDocument) {
Transformer transformer;
try {
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
final DOMSource source = new DOMSource(xmlDocument);
// final StreamResult console =
// new StreamResult(new File("C:/Users/emre.kirmizi/Desktop/out.xml"));
final StreamResult console =
new StreamResult(new File("C:/Users/anil.ozturk/Desktop/out.xml"));
transformer.transform(source, console);
} catch (TransformerFactoryConfigurationError | TransformerException e) {
e.printStackTrace();
}
}
示例11: getSoapBodyXMLFromMessage
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
/**
* getSoapBodyXMLFromMessage
*
* @param response
* SOAPMessage response
* @return String representation of the SOAPBody
*/
public String getSoapBodyXMLFromMessage(SOAPMessage response) {
String message = null;
try {
DOMSource source = new DOMSource(response.getSOAPBody());
StringWriter stringResult = new StringWriter();
TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(stringResult));
message = stringResult.toString();
} catch (TransformerException | TransformerFactoryConfigurationError | SOAPException e) {
log.error("Unable to parse body from response.", e);
}
return message;
}
示例12: getTransformer
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
/**
* @param style
* @return
* @throws TransformerFactoryConfigurationError
*/
private static Transformer getTransformer(String style) throws TransformerFactoryConfigurationError {
String xslfile = DEFAULT_TRANSFORMER;
if (style != null && style.trim().length() != 0) {
xslfile = style + "-derivate.xsl";
}
Transformer trans = null;
try {
URL xslURL = MCRDerivateCommands.class.getResource("/" + xslfile);
if (xslURL != null) {
StreamSource source = new StreamSource(xslURL.toURI().toASCIIString());
TransformerFactory transfakt = TransformerFactory.newInstance();
transfakt.setURIResolver(MCRURIResolver.instance());
trans = transfakt.newTransformer(source);
}
} catch (Exception e) {
LOGGER.debug("Cannot build Transformer.", e);
}
return trans;
}
示例13: getTransformer
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
/**
* The method search for a stylesheet mcr_<em>style</em>_object.xsl and
* build the transformer. Default is <em>mcr_save-object.xsl</em>.
*
* @param style
* the style attribute for the transformer stylesheet
* @return the transformer
* @throws TransformerFactoryConfigurationError
* @throws TransformerConfigurationException
*/
private static Transformer getTransformer(String style) throws TransformerFactoryConfigurationError,
TransformerConfigurationException {
String xslfile = DEFAULT_TRANSFORMER;
if (style != null && style.trim().length() != 0) {
xslfile = style + "-classification.xsl";
}
Transformer trans = null;
URL styleURL = MCRClassification2Commands.class.getResource("/" + xslfile);
if (styleURL == null) {
styleURL = MCRClassification2Commands.class.getResource(DEFAULT_TRANSFORMER);
}
if (styleURL != null) {
StreamSource source;
try {
source = new StreamSource(styleURL.toURI().toASCIIString());
} catch (URISyntaxException e) {
throw new TransformerConfigurationException(e);
}
TransformerFactory transfakt = TransformerFactory.newInstance();
transfakt.setURIResolver(MCRURIResolver.instance());
trans = transfakt.newTransformer(source);
}
return trans;
}
示例14: singleTransform
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
@Test
public void singleTransform()
throws JDOMException, IOException, TransformerFactoryConfigurationError, TransformerException {
String testFilePath = "/" + getClass().getSimpleName() + "/oneObj.xml";
InputStream testXMLAsStream = getClass().getResourceAsStream(testFilePath);
JDOMResult jdomResult = xslTransformation(testXMLAsStream);
Document resultXML = jdomResult.getDocument();
// XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
// xmlOutputter.output(resultXML, System.out);
List<Element> mycoreojectTags = XPathFactory.instance()
.compile("/solr-document-container/source/mycoreobject", Filters.element()).evaluate(resultXML);
assertEquals(1, mycoreojectTags.size());
List<Element> userFieldTags = XPathFactory.instance()
.compile("/solr-document-container/source/user", Filters.element()).evaluate(resultXML);
assertEquals(1, userFieldTags.size());
}
示例15: multiTransform
import javax.xml.transform.TransformerFactoryConfigurationError; //导入依赖的package包/类
@Test
public void multiTransform()
throws JDOMException, IOException, TransformerFactoryConfigurationError, TransformerException {
String testFilePath = "/" + getClass().getSimpleName() + "/multiplObj.xml";
InputStream testXMLAsStream = getClass().getResourceAsStream(testFilePath);
JDOMResult jdomResult = xslTransformation(testXMLAsStream);
Document resultXML = jdomResult.getDocument();
// XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
// xmlOutputter.output(resultXML, System.out);
List<Element> mycoreojectTags = XPathFactory.instance()
.compile("/solr-document-container/source/mycoreobject", Filters.element()).evaluate(resultXML);
assertEquals(3, mycoreojectTags.size());
List<Element> userFieldTags = XPathFactory.instance()
.compile("/solr-document-container/source/user", Filters.element()).evaluate(resultXML);
assertEquals(3, userFieldTags.size());
}