resolve #1386
This commit is contained in:
parent
0b449af9ba
commit
6c09bcf23c
2 changed files with 53 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
package stirling.software.SPDF.config;
|
package stirling.software.SPDF.config;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
@ -11,6 +12,8 @@ import org.thymeleaf.templateresource.ClassLoaderTemplateResource;
|
||||||
import org.thymeleaf.templateresource.FileTemplateResource;
|
import org.thymeleaf.templateresource.FileTemplateResource;
|
||||||
import org.thymeleaf.templateresource.ITemplateResource;
|
import org.thymeleaf.templateresource.ITemplateResource;
|
||||||
|
|
||||||
|
import stirling.software.SPDF.model.InputStreamTemplateResource;
|
||||||
|
|
||||||
public class FileFallbackTemplateResolver extends AbstractConfigurableTemplateResolver {
|
public class FileFallbackTemplateResolver extends AbstractConfigurableTemplateResolver {
|
||||||
|
|
||||||
private final ResourceLoader resourceLoader;
|
private final ResourceLoader resourceLoader;
|
||||||
|
@ -40,9 +43,10 @@ public class FileFallbackTemplateResolver extends AbstractConfigurableTemplateRe
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ClassLoaderTemplateResource(
|
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("templates/" + resourceName);
|
||||||
Thread.currentThread().getContextClassLoader(),
|
if (inputStream != null) {
|
||||||
"classpath:/templates/" + resourceName,
|
return new InputStreamTemplateResource(inputStream, "UTF-8");
|
||||||
characterEncoding);
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package stirling.software.SPDF.model;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
|
import org.thymeleaf.templateresource.ITemplateResource;
|
||||||
|
|
||||||
|
public class InputStreamTemplateResource implements ITemplateResource {
|
||||||
|
private InputStream inputStream;
|
||||||
|
private String characterEncoding;
|
||||||
|
|
||||||
|
public InputStreamTemplateResource(InputStream inputStream, String characterEncoding) {
|
||||||
|
this.inputStream = inputStream;
|
||||||
|
this.characterEncoding = characterEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Reader reader() throws IOException {
|
||||||
|
return new InputStreamReader(inputStream, characterEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITemplateResource relative(String relativeLocation) {
|
||||||
|
// Implement logic for relative resources, if needed
|
||||||
|
throw new UnsupportedOperationException("Relative resources not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "InputStream resource [Stream]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBaseName() {
|
||||||
|
return "streamResource";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean exists() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue