-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test * settings * version
- Loading branch information
Showing
6 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/stirling/software/SPDF/config/FileFallbackTemplateResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package stirling.software.SPDF.config; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.thymeleaf.IEngineConfiguration; | ||
import org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver; | ||
import org.thymeleaf.templateresource.ClassLoaderTemplateResource; | ||
import org.thymeleaf.templateresource.FileTemplateResource; | ||
import org.thymeleaf.templateresource.ITemplateResource; | ||
|
||
public class FileFallbackTemplateResolver extends AbstractConfigurableTemplateResolver { | ||
|
||
private final ResourceLoader resourceLoader; | ||
|
||
public FileFallbackTemplateResolver(ResourceLoader resourceLoader) { | ||
super(); | ||
this.resourceLoader = resourceLoader; | ||
setSuffix(".html"); | ||
} | ||
|
||
// Note this does not work in local IDE, Prod jar only. | ||
@Override | ||
protected ITemplateResource computeTemplateResource( | ||
IEngineConfiguration configuration, | ||
String ownerTemplate, | ||
String template, | ||
String resourceName, | ||
String characterEncoding, | ||
Map<String, Object> templateResolutionAttributes) { | ||
Resource resource = | ||
resourceLoader.getResource("file:./customFiles/templates/" + resourceName); | ||
try { | ||
if (resource.exists() && resource.isReadable()) { | ||
return new FileTemplateResource(resource.getFile().getPath(), characterEncoding); | ||
} | ||
} catch (IOException e) { | ||
|
||
} | ||
|
||
return new ClassLoaderTemplateResource( | ||
Thread.currentThread().getContextClassLoader(), | ||
"classpath:/templates/" + resourceName, | ||
characterEncoding); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters