org.thymeleaf.IEngineConfiguration Java Examples

The following examples show how to use org.thymeleaf.IEngineConfiguration. 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: PortletTemplateResolver.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
@Override
protected String computeResourceName(IEngineConfiguration engineConfiguration, String ownerTemplate,
	String template, String prefix, String suffix, boolean forceSuffix, Map<String, String> templateAliases,
	Map<String, Object> templateResolutionAttributes) {

	String resourceName = super.computeResourceName(engineConfiguration, ownerTemplate, template, prefix, suffix,
			forceSuffix, templateAliases, templateResolutionAttributes);

	if (resourceName.startsWith("/")) {
		return resourceName;
	}

	String templateLocation = templateLocationSupplier.get();

	if (!templateLocation.endsWith("/")) {
		templateLocation = templateLocation.concat("/");
	}

	return templateLocation.concat(resourceName);
}
 
Example #2
Source File: ThymeLeafV3FirstSupportingTemplateResolver.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Override
public TemplateResolution resolveTemplate(IEngineConfiguration configuration, String ownerTemplate, String template, Map<String, Object> templateResolutionAttributes) {
	try {
		ResourceResolver supportingResolver = resolver.getSupportingResolver(new UnresolvedPath(template));
		ITemplateResolver templateResolver = resolverAdapter.adapt(supportingResolver);
		ResolvedPath resourcePath = supportingResolver.resolve(new UnresolvedPath(template));
		String resolvedPath = resourcePath.getResolvedPath();
		TemplateResolution resolution = templateResolver.resolveTemplate(configuration, ownerTemplate, resolvedPath, templateResolutionAttributes);
		if(!templateExists(resolution)) {
			throw new TemplateResolutionException("Failed to find template "+template+" ("+resolvedPath+")", template, resourcePath);
		}
		return resolution;
	} catch (NoResolverAdapterException e) {
		throw new ResolverAdapterNotFoundException("Unable to resolve template cause no adapter supporting template name '" + template + "' was found.", e);

	}
}
 
Example #3
Source File: DictShowProcessor.java    From FEBS-Security with Apache License 2.0 6 votes vote down vote up
@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag,
                         IElementTagStructureHandler structureHandler) {
    String fieldName = tag.getAttribute(FIELD_NAME).getValue();
    String keyy = tag.getAttribute(KEYY).getValue();

    final IEngineConfiguration configuration = context.getConfiguration();
    final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
    final IStandardExpression expression = parser.parseExpression(context, keyy);
    final String realvalue = String.valueOf(expression.execute(context));

    ApplicationContext appCtx = SpringContextUtils.getApplicationContext(context);
    DictService dictService = appCtx.getBean(DictService.class);
    Dict dict = dictService.findDictByFieldNameAndKeyy(fieldName, realvalue);

    if (log.isDebugEnabled()) {
        log.debug("dict== fieldName:{}, keyy:{}, realvalue:{}", fieldName, keyy, realvalue);
    }
    String label = "";
    if (dict != null) {
        label = dict.getValuee();
    }
    structureHandler.replaceWith(label, false);
}
 
Example #4
Source File: TdsExtensibleTemplateResolver.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected String computeResourceName(final IEngineConfiguration configuration, final String ownerTemplate,
    final String template, final String prefix, final String suffix, final Map<String, String> templateAliases,
    final Map<String, Object> templateResolutionAttributes) {

  Validate.notNull(template, "Template name cannot be null");

  // Don't bother computing resource name if template is not extensible
  if (!template.startsWith(EXT_FRAG_PREFIX))
    return template;

  String resourceName = template.substring(PREFIX_LENGTH);
  if (!StringUtils.isEmptyOrWhitespace(prefix))
    resourceName = prefix + resourceName;
  if (!StringUtils.isEmptyOrWhitespace(suffix))
    resourceName = resourceName + suffix;

  TdsContext tdsContext = (TdsContext) applicationContext.getBean("TdsContext");
  resourceName = tdsContext.getThreddsDirectory() + resourceName;


  return resourceName;
}
 
Example #5
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 #6
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 #7
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 #8
Source File: TemplateResolverImpl.java    From purplejs with Apache License 2.0 5 votes vote down vote up
@Override
protected ICacheEntryValidity computeValidity( final IEngineConfiguration configuration, final String ownerTemplate,
                                               final String template, final Map<String, Object> templateResolutionAttributes )
{
    if ( isDisableCache() )
    {
        return new NonCacheableCacheEntryValidity();
    }

    return super.computeValidity( configuration, ownerTemplate, template, templateResolutionAttributes );
}
 
Example #9
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 #10
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 #11
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 #12
Source File: ThSysTagProcessor.java    From mayday with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
		String attributeValue, IElementTagStructureHandler structureHandler) {
	final IEngineConfiguration configuration = context.getConfiguration();
	final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
	final IStandardExpression expression = parser.parseExpression(context, attributeValue);
	final String title = (String) expression.execute(context);
	structureHandler.setBody(title + " - " + MaydayConst.OPTIONS.get("blog_name"), false);
}
 
Example #13
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 #14
Source File: DictSelectProcessor.java    From FEBS-Security with Apache License 2.0 4 votes vote down vote up
@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag,
                         IElementTagStructureHandler structureHandler) {
    String fieldName = tag.getAttribute(FIELD_NAME).getValue();
    IAttribute valueAttr = tag.getAttribute(KEYY);
    IAttribute clsAttr = tag.getAttribute(CLS);
    IAttribute nameAttr = tag.getAttribute(NAME);
    IAttribute idAttr = tag.getAttribute(ID);
    final IEngineConfiguration configuration = context.getConfiguration();
    final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
    String realvalue = "";
    if (valueAttr != null) {
        final IStandardExpression valueexpression = parser.parseExpression(context, valueAttr.getValue());
        realvalue = String.valueOf(valueexpression.execute(context));

        if (log.isDebugEnabled())
            log.debug("dict== fieldName:{}, keyy:{}, realvalue:{}", fieldName, valueAttr.getValue(), realvalue);
    }
    ApplicationContext appCtx = SpringContextUtils.getApplicationContext(context);
    DictService dictService = appCtx.getBean(DictService.class);
    List<Dict> dicts = dictService.findDictByFieldName(fieldName);
    StringBuilder options = new StringBuilder();
    String selected = "";
    for (Dict dict : dicts) {
        if (valueAttr != null && realvalue.equals(dict.getKeyy()))
            selected = " selected=selected ";
        else
            selected = "";
        options.append("<option value=\"").append(dict.getKeyy()).append("\" ").append(selected).append(">").append(dict.getValuee()).append("</option>");
    }
    StringBuilder select = new StringBuilder("<select");
    if (clsAttr != null)
        select.append(" class=\"").append(clsAttr.getValue()).append("\"");
    if (nameAttr != null)
        select.append(" name=\"").append(nameAttr.getValue()).append("\"");
    if (idAttr != null)
        select.append("  id=\"").append(idAttr.getValue()).append("\"");
    select.append(">");
    select.append(options);
    select.append("<select>");

    structureHandler.replaceWith(select.toString(), false);
}
 
Example #15
Source File: WebExpressionContextProvider.java    From ogham with Apache License 2.0 4 votes vote down vote up
@Override
public IContext getWebContext(Context context, IContext base, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext, ApplicationContext applicationContext,
		Map<String, Object> springModel) {
	final IEngineConfiguration configuration = viewTemplateEngine.getConfiguration();
	return new WebExpressionContext(configuration, request, response, servletContext, base.getLocale(), springModel);
}
 
Example #16
Source File: PageUtils.java    From thymeleaf-spring-data-dialect with Apache License 2.0 4 votes vote down vote up
public static Page<?> findPage(final ITemplateContext context) {
    // 1. Get Page object from local variables (defined with sd:page-object)
    // 2. Search Page using ${page} expression
    // 3. Search Page object as request attribute

    final Object pageFromLocalVariable = context.getVariable(Keys.PAGE_VARIABLE_KEY);
    if (isPageInstance(pageFromLocalVariable)) {
        return (Page<?>) pageFromLocalVariable;
    }

    // Check if not null and Page instance available with ${page} expression
    final IEngineConfiguration configuration = context.getConfiguration();
    final IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);
    final IStandardExpression expression = parser.parseExpression(context, Keys.PAGE_EXPRESSION);
    final Object page = expression.execute(context);
    if (isPageInstance(page)) {
        return (Page<?>) page;
    }

    // Search for Page object, and only one instance, as request attribute
    if (context instanceof IWebContext) {
        HttpServletRequest request = ((IWebContext) context).getRequest();
        Enumeration<String> attrNames = request.getAttributeNames();
        Page<?> pageOnRequest = null;
        while (attrNames.hasMoreElements()) {
            String attrName = (String) attrNames.nextElement();
            Object attr = request.getAttribute(attrName);
            if (isPageInstance(attr)) {
                if (pageOnRequest != null) {
                    throw new InvalidObjectParameterException("More than one Page object found on request!");
                }

                pageOnRequest = (Page<?>) attr;
            }
        }

        if (pageOnRequest != null) {
            return pageOnRequest;
        }
    }

    throw new InvalidObjectParameterException("Invalid or not present Page object found on request!");
}
 
Example #17
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 #18
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);
}