org.thymeleaf.templateresource.ITemplateResource Java Examples

The following examples show how to use org.thymeleaf.templateresource.ITemplateResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DomainBasedTemplateResolver.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration, String ownerTemplate, String template, String resourceName, String characterEncoding, Map<String, Object> templateResolutionAttributes) {
    boolean templateFound = templates.containsKey(resourceName);
    String[] templateParts = resourceName.split(Pattern.quote(FormManager.TEMPLATE_NAME_SEPARATOR));

    // template not found for the client, try at domain level
    if (!templateFound && templateParts.length == 2) {
        resourceName = templateParts[0];
        templateFound = templates.containsKey(resourceName);
    }

    if (templateFound) {
        return templates.get(resourceName);
    }

    return null;
}
 
Example #2
Source File: ThymeleafViewResultHandler.java    From oxygen with Apache License 2.0 5 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration,
    String ownerTemplate, String template, Map<String, Object> templateResolutionAttributes) {
  if (isCacheable()) {
    return new StringTemplateResource(Templates.cachedTemplate(prefix + template));
  }
  return new StringTemplateResource(Templates.template(prefix + template));
}
 
Example #3
Source File: JessieFileTemplateResolver.java    From microprofile-starter with Apache License 2.0 5 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration, String ownerTemplate,
                                                    String template, String resourceName, String characterEncoding,
                                                    Map<String, Object> templateResolutionAttributes) {
    return new ClassLoaderTemplateResource(JessieFileTemplateResolver.class.getClassLoader(),
            filesLocator.getTemplateFile(resourceName), characterEncoding);
}
 
Example #4
Source File: CustomClassLoaderTemplateResolver.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration, String ownerTemplate, String template, String resourceName, String characterEncoding, Map<String, Object> templateResolutionAttributes) {
    if (resourceName.contains(FormManager.TEMPLATE_NAME_SEPARATOR)) {
        resourceName = resourceName.split(Pattern.quote(FormManager.TEMPLATE_NAME_SEPARATOR))[0] + ".html";
    }
    return super.computeTemplateResource(configuration, ownerTemplate, template, resourceName, characterEncoding, templateResolutionAttributes);
}
 
Example #5
Source File: TemplateResolver.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration, String ownerTemplate, String template, String resourceName, String characterEncoding, Map<String, Object> templateResolutionAttributes) {
    if (templates.containsKey(resourceName)) {
        return templates.get(resourceName);
    }
    return null;
}
 
Example #6
Source File: TemplateResolverImpl.java    From purplejs with Apache License 2.0 5 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource( final IEngineConfiguration configuration, final String ownerTemplate,
                                                     final String template, final String resourceName, final String characterEncoding,
                                                     final Map<String, Object> templateResolutionAttributes )
{
    return resolve( null, ownerTemplate, resourceName );
}
 
Example #7
Source File: TemplateResolverImpl.java    From purplejs with Apache License 2.0 5 votes vote down vote up
@Override
public ITemplateResource resolve( final ResourcePath base, final String location )
{
    final ResourcePath resolved = resolvePath( base, location );
    final Resource resource = this.loader.loadOrNull( resolved );
    return resource != null ? new TemplateResourceImpl( resource, this ) : null;
}
 
Example #8
Source File: WallRideResourceTemplateResource.java    From wallride with Apache License 2.0 5 votes vote down vote up
public ITemplateResource relative(final String relativeLocation) {
	final Resource relativeResource;
	try {
		relativeResource = this.resource.createRelative(relativeLocation);
	} catch (final IOException e) {
		// Given we have delegated the createRelative(...) mechanism to Spring, it's better if we don't do
		// any assumptions on what this IOException means and simply return a resource object that returns
		// no reader and exists() == false.
		return new WallRideResourceInvalidRelativeTemplateResource(getDescription(), relativeLocation, e);
	}
	return new SpringResourceTemplateResource(relativeResource, this.characterEncoding);
}
 
Example #9
Source File: ThymeleafTemplateEngineImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration, String ownerTemplate, String template, Map<String, Object> templateResolutionAttributes) {
  return new StringTemplateResource(
    vertx.fileSystem()
      .readFileBlocking(template)
      .toString(Charset.defaultCharset()));
}
 
Example #10
Source File: PortletMessageResolver.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<String, String> resolveMessagesForTemplate(String template, ITemplateResource templateResource,
	Locale locale) {

	Map<String, String> messages = super.resolveMessagesForTemplate(template, templateResource, locale);

	if (messages.isEmpty()) {

		ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);

		if (resourceBundle != null) {
			messages = new HashMap<>();

			Enumeration<String> resourceBundleKeys = resourceBundle.getKeys();

			while (resourceBundleKeys.hasMoreElements()) {
				String key = resourceBundleKeys.nextElement();
				Object value = resourceBundle.getObject(key);

				if ((key != null) && (value != null)) {
					messages.put(key, value.toString());
				}
			}
		}
	}

	return messages;
}
 
Example #11
Source File: TdsExtensibleTemplateResolver.java    From tds with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource(final IEngineConfiguration configuration,
    final String ownerTemplate, final String template, final String resourceName, final String characterEncoding,
    final Map<String, Object> templateResolutionAttributes) {
  return new FileTemplateResource(resourceName, characterEncoding);
}
 
Example #12
Source File: TemplateResolverImpl.java    From purplejs with Apache License 2.0 4 votes vote down vote up
private ITemplateResource resolve( final ResourcePath base, final String ownerTemplate, final String location )
{
    final ResourcePath parent = findParent( base, ownerTemplate );
    return resolve( parent, location );
}
 
Example #13
Source File: TemplateResourceImpl.java    From purplejs with Apache License 2.0 4 votes vote down vote up
@Override
public ITemplateResource relative( final String relativeLocation )
{
    return this.resolver.resolve( this.path, relativeLocation );
}
 
Example #14
Source File: WallRideResourceTemplateResource.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Override
public ITemplateResource relative(final String relativeLocation) {
	return this;
}
 
Example #15
Source File: WallRideResourceTemplateResolver.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Override
protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration, String ownerTemplate, String template, String resourceName, String characterEncoding, Map<String, Object> templateResolutionAttributes) {
	return new WallRideResourceTemplateResource(this.applicationContext, resourceName, characterEncoding);
}
 
Example #16
Source File: TemplateResourceResolver.java    From purplejs with Apache License 2.0 votes vote down vote up
ITemplateResource resolve( ResourcePath base, String location );