+ /**
+ * Creates a new manifest element.
+ *
+ * @param name
+ * The name of the file
+ * @param contentType
+ * The content type of the file
+ * @param templateName
+ * The name of the template to render
+ * @return The manifest element
+ */
+ @SuppressWarnings("synthetic-access")
+ private ManifestElement createManifestElement(String name, String contentType, String templateName) {
+ InputStreamReader templateInputStreamReader = null;
+ Template template;
+ try {
+ templateInputStreamReader = new InputStreamReader(getClass().getResourceAsStream(templateName), utf8Charset);
+ template = TemplateParser.parse(templateInputStreamReader);
+ } catch (TemplateException te1) {
+ logger.log(Level.SEVERE, "Could not parse template “" + templateName + "”!", te1);
+ return null;
+ } finally {
+ Closer.close(templateInputStreamReader);
+ }
+
+ TemplateContext templateContext = templateContextFactory.createTemplateContext();
+ templateContext.set("currentSone", soneProperties);
+ templateContext.set("currentEdition", core.getUpdateChecker().getLatestEdition());
+ templateContext.set("version", SonePlugin.VERSION);
+ StringWriter writer = new StringWriter();
+ StringBucket bucket = null;
+ try {
+ template.render(templateContext, writer);
+ bucket = new StringBucket(writer.toString(), utf8Charset);
+ return new ManifestElement(name, bucket, contentType, bucket.size());
+ } catch (TemplateException te1) {
+ logger.log(Level.SEVERE, "Could not render template “" + templateName + "”!", te1);
+ return null;
+ } finally {
+ Closer.close(writer);
+ if (bucket != null) {
+ bucket.free();
+ }
+ }
+ }
+