Permalink
Browse files

Merge pull request #21 from vuvarov/master

Fix for file name check for .pdf templates when request.format=pdf
  • Loading branch information...
2 parents 7b1538b + e0c2d42 commit 8df0cc31b8b8d77ac0628e08f5572d910fd6268d @pepite committed May 1, 2012
Showing with 21 additions and 11 deletions.
  1. +21 −11 src/play/modules/pdf/PDF.java
@@ -59,7 +59,7 @@
public String ALL_PAGES = null;
public String EVEN_PAGES = null;
public String ODD_PAGES = null;
-
+
public String filename = null;
public IHtmlToPdfTransformer.PageSize pageSize = IHtmlToPdfTransformer.A4P;
@@ -76,7 +76,7 @@ private PDFDocument(String template, Options options){
this.template = template;
this.options = options;
}
-
+
public PDFDocument(String template, Options options, Object... args) {
this(template, options);
try {
@@ -112,11 +112,11 @@ public PDFDocument(String template, Options options, Map<String,Object> args) {
public PDFDocument() {
}
}
-
+
public static class MultiPDFDocuments {
public List<PDFDocument> documents = new LinkedList<PDFDocument>();
public String filename;
-
+
public MultiPDFDocuments(String filename) {
this.filename = filename;
}
@@ -140,7 +140,7 @@ public MultiPDFDocuments add(String template, Options options, Map<String,Object
return this;
}
}
-
+
/**
* Render the corresponding template
*
@@ -167,7 +167,7 @@ public static void writePDF(File file, Object... args) {
throw new UnexpectedException(e);
}
}
-
+
/**
* Render the corresponding template into a file
* @param out the stream to render to, or null to render to the current Response object
@@ -179,7 +179,7 @@ public static void writePDF(OutputStream out, Object... args) {
PDFDocument singleDoc = new PDFDocument();
MultiPDFDocuments docs = null;
-
+
if(args.length > 0){
boolean firstEmpty = false;
try {
@@ -219,7 +219,7 @@ public static void writePDF(OutputStream out, Object... args) {
else
docs.filename = FilenameUtils.getBaseName(singleDoc.template) + ".pdf";
}
-
+
renderTemplateAsPDF(out, docs, args);
}
@@ -231,8 +231,18 @@ static String resolveTemplateName(String templateName, Request request, String f
}
templateName = templateName.replace(".", "/") + "." + (format == null ? "html" : format);
}
- VirtualFile template = Play.getVirtualFile(templateName);
- if (template == null || !template.exists()) {
+ Boolean templateExists = false;
+ for (VirtualFile vf : Play.templatesPath) {
+ if (vf == null) {
+ continue;
+ }
+ VirtualFile tf = vf.child(templateName);
+ if (tf.exists()) {
+ templateExists = true;
+ break;
+ }
+ }
+ if (!templateExists) {
if (templateName.lastIndexOf("." + format) != -1) {
templateName = templateName.substring(0, templateName.lastIndexOf("." + format)) + ".html";
}
@@ -295,7 +305,7 @@ public static void renderTemplateAsPDF(OutputStream out, MultiPDFDocuments docs,
}
StackTraceElement element = PlayException.getInterestingStrackTraceElement(ex);
if (element != null) {
- throw new TemplateNotFoundException(ex.getPath(),
+ throw new TemplateNotFoundException(ex.getPath(),
Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber());
} else {
throw ex;

0 comments on commit 8df0cc3

Please sign in to comment.