public static Document transform(Map<String, Object> context, Map<String, Object> params)
throws GeneralException, IOException, TransformerConfigurationException, TransformerException {
Document outputDocument = null;
TransformerFactory tFactory = TransformerFactory.newInstance();
Templates translet = null;
String templateName = (String)context.get("templateName");
if (UtilValidate.isNotEmpty(templateName)) {
translet = xslTemplatesCache.get(templateName);
}
if (translet == null ) {
String templateUrl = (String)context.get("templateUrl");
String templateString = (String)context.get("templateString");
Document templateDocument = (Document)context.get("templateDocument");
Source templateSource = getSource(templateDocument, templateUrl, templateString);
translet = tFactory.newTemplates(templateSource);
if (UtilValidate.isNotEmpty(templateName)) {
xslTemplatesCache.put(templateName, translet);
}
}
if (translet != null ) {
Transformer transformer = translet.newTransformer();
if (params != null) {
for (Map.Entry<String, Object> entry: params.entrySet()) {
String key = (String)entry.getKey();
Object val = entry.getValue();
transformer.setParameter(key, val);