+ /**
+ * 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;
+ Template template = templateFactory.createTemplate(templateInputStreamReader = new InputStreamReader(getClass().getResourceAsStream(templateName), utf8Charset));
+ try {
+ template.parse();
+ } catch (TemplateException te1) {
+ logger.log(Level.SEVERE, "Could not parse template “" + templateName + "”!", te1);
+ return null;
+ } finally {
+ Closer.close(templateInputStreamReader);
+ }
+ @SuppressWarnings("unchecked")
+ final Set<String> blockedSoneIds = (Set<String>) soneProperties.get("blockedSoneIds");
+ Collection<Sone> knownSones = Filters.filteredCollection(core.getKnownSones(), new Filter<Sone>() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean filterObject(Sone object) {
+ return !blockedSoneIds.contains(object.getId()) && !object.getId().equals(soneProperties.get("id"));
+ }
+ });
+
+ template.set("currentSone", soneProperties);
+ template.set("knownSones", knownSones);
+ StringWriter writer = new StringWriter();
+ StringBucket bucket = null;
+ try {
+ template.render(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();
+ }
+ }
+ }
+