//line 365 of https://github.com/Bombe/Sone/blob/0fde4bc94b71158908f7a1ed16807985628b8619/src/main/java/net/pterodactylus/sone/core/SoneInserter.java /** 366 * Creates a new manifest element. 367 * 368 * @param name 369 * The name of the file 370 * @param contentType 371 * The content type of the file 372 * @param templateName 373 * The name of the template to render 374 * @return The manifest element 375 */ 376 @SuppressWarnings("synthetic-access") 377 private ManifestElement createManifestElement(String name, String contentType, String templateName) { 378 InputStreamReader templateInputStreamReader = null; 379 Template template; 380 try { 381 templateInputStreamReader = new InputStreamReader(getClass().getResourceAsStream(templateName), utf8Charset); 382 template = TemplateParser.parse(templateInputStreamReader); 383 } catch (TemplateException te1) { 384 logger.log(Level.SEVERE, String.format("Could not parse template ā€œ%sā€!", templateName), te1); 385 return null; 386 } finally { 387 Closer.close(templateInputStreamReader); 388 } 389 390 TemplateContext templateContext = templateContextFactory.createTemplateContext(); 391 templateContext.set("core", core); 392 templateContext.set("currentSone", soneProperties); 393 templateContext.set("currentEdition", core.getUpdateChecker().getLatestEdition()); 394 templateContext.set("version", SonePlugin.VERSION); 395 StringWriter writer = new StringWriter(); 396 RandomAccessBucket bucket = null; 397 try { 398 template.render(templateContext, writer); 399 bucket = new ArrayBucket(writer.toString().getBytes(Charsets.UTF_8)); 400 return new ManifestElement(name, bucket, contentType, bucket.size()); 401 } catch (TemplateException te1) { 402 logger.log(Level.SEVERE, String.format("Could not render template ā€œ%sā€!", templateName), te1); 403 return null; 404 } finally { 405 Closer.close(writer); 406 if (bucket != null) { 407 bucket.free(); 408 } 409 } 410 } 411 412 }