use of javax.xml.transform.TransformerConfigurationException in project winery by eclipse.
the class Util method getXMLAsString.
public static String getXMLAsString(Element el) {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t;
try {
t = tf.newTransformer();
} catch (TransformerConfigurationException e) {
throw new IllegalStateException("Could not instantiate Transformer", e);
}
t.setOutputProperty(OutputKeys.INDENT, "yes");
Source source = new DOMSource(el);
ByteArrayOutputStream os = new ByteArrayOutputStream();
Result target = new StreamResult(os);
try {
t.transform(source, target);
} catch (TransformerException e) {
Util.LOGGER.debug(e.getMessage(), e);
throw new IllegalStateException("Could not transform dom node to string", e);
}
return os.toString();
}
use of javax.xml.transform.TransformerConfigurationException in project winery by eclipse.
the class CsarExporter method writeCsar.
/**
* Writes a complete CSAR containing all necessary things reachable from the given service template
*
* @param entryId the id of the service template to export
* @param out the output stream to write to
*/
public void writeCsar(IRepository repository, DefinitionsChildId entryId, OutputStream out) throws ArchiveException, IOException, JAXBException, RepositoryCorruptException {
CsarExporter.LOGGER.trace("Starting CSAR export with {}", entryId.toString());
Map<RepositoryFileReference, String> refMap = new HashMap<>();
Collection<String> definitionNames = new ArrayList<>();
try (final ArchiveOutputStream zos = new ArchiveStreamFactory().createArchiveOutputStream("zip", out)) {
ToscaExportUtil exporter = new ToscaExportUtil();
Map<String, Object> conf = new HashMap<>();
ExportedState exportedState = new ExportedState();
DefinitionsChildId currentId = entryId;
do {
String defName = CsarExporter.getDefinitionsPathInsideCSAR(repository, currentId);
definitionNames.add(defName);
zos.putArchiveEntry(new ZipArchiveEntry(defName));
Collection<DefinitionsChildId> referencedIds;
referencedIds = exporter.exportTOSCA(repository, currentId, zos, refMap, conf);
zos.closeArchiveEntry();
exportedState.flagAsExported(currentId);
exportedState.flagAsExportRequired(referencedIds);
currentId = exportedState.pop();
} while (currentId != null);
// if we export a ServiceTemplate, data for the self-service portal might exist
if (entryId instanceof ServiceTemplateId) {
ServiceTemplateId serviceTemplateId = (ServiceTemplateId) entryId;
this.addSelfServiceMetaData(repository, serviceTemplateId, refMap);
this.addSelfServiceFiles(repository, serviceTemplateId, refMap, zos);
}
// now, refMap contains all files to be added to the CSAR
// write manifest directly after the definitions to have it more at the beginning of the ZIP rather than having it at the very end
this.addManifest(repository, entryId, definitionNames, refMap, zos);
// used for generated XSD schemas
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tFactory.newTransformer();
} catch (TransformerConfigurationException e1) {
CsarExporter.LOGGER.debug(e1.getMessage(), e1);
throw new IllegalStateException("Could not instantiate transformer", e1);
}
// write all referenced files
for (RepositoryFileReference ref : refMap.keySet()) {
String archivePath = refMap.get(ref);
CsarExporter.LOGGER.trace("Creating {}", archivePath);
if (ref instanceof DummyRepositoryFileReferenceForGeneratedXSD) {
addDummyRepositoryFileReferenceForGeneratedXSD(zos, transformer, (DummyRepositoryFileReferenceForGeneratedXSD) ref, archivePath);
} else {
if (ref.getParent() instanceof DirectoryId) {
// special handling for artifact template directories "source" and "files"
addArtifactTemplateToZipFile(zos, repository, ref, archivePath);
} else {
addFileToZipArchive(zos, repository, ref, archivePath);
zos.closeArchiveEntry();
}
}
}
this.addNamespacePrefixes(zos, repository);
}
}
use of javax.xml.transform.TransformerConfigurationException in project wcomponents by BorderTech.
the class TransformXMLInterceptor method initTemplates.
/**
* Statically initialize the XSLT templates that are cached for all future transforms.
*
* @return the XSLT Templates.
*/
private static Templates initTemplates() {
try {
URL xsltURL = ThemeUtil.class.getResource(RESOURCE_NAME);
if (xsltURL != null) {
Source xsltSource = new StreamSource(xsltURL.openStream(), xsltURL.toExternalForm());
TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
Templates templates = factory.newTemplates(xsltSource);
LOG.debug("Generated XSLT templates for: " + RESOURCE_NAME);
return templates;
} else {
// Server-side XSLT enabled but theme resource not on classpath.
throw new IllegalStateException(RESOURCE_NAME + " not on classpath");
}
} catch (IOException | TransformerConfigurationException ex) {
throw new SystemException("Could not create transformer for " + RESOURCE_NAME, ex);
}
}
Aggregations