CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-liferay-portal--com-liferay-portal-impl

Core implementation module containing the fundamental services, utilities, and infrastructure components for the Liferay Digital Experience Platform.

Pending
Overview
Eval results
Files

template-processing.mddocs/

Template Processing

Template engine integrations including FreeMarker support and generic template processing utilities for dynamic content generation in the Liferay portal framework.

Capabilities

FreeMarker Integration

Comprehensive FreeMarker template engine integration providing dynamic content generation capabilities.

/**
 * FreeMarker template engine integration for portal content
 */
public class FreeMarkerEngine implements TemplateEngine {
    
    /**
     * Processes FreeMarker template with provided context
     * @param templateName template name or path
     * @param templateContext context variables for template
     * @return processed template output
     * @throws TemplateException if template processing fails
     */
    public String processTemplate(String templateName, Map<String, Object> templateContext)
        throws TemplateException;
    
    /**
     * Processes FreeMarker template from string content
     * @param templateContent template source content
     * @param templateContext context variables
     * @return processed template output
     * @throws TemplateException if processing fails
     */
    public String processTemplateContent(String templateContent, Map<String, Object> templateContext)
        throws TemplateException;
    
    /**
     * Gets FreeMarker configuration
     * @return Configuration instance
     */
    public Configuration getConfiguration();
    
    /**
     * Sets custom FreeMarker configuration
     * @param configuration FreeMarker configuration
     */
    public void setConfiguration(Configuration configuration);
}

/**
 * FreeMarker template context manager
 */
public class FreeMarkerContext {
    
    /**
     * Creates template context with portal variables
     * @param request HTTP servlet request
     * @param response HTTP servlet response
     * @return Map containing context variables
     */
    public static Map<String, Object> createContext(HttpServletRequest request, 
        HttpServletResponse response);
    
    /**
     * Adds portal-specific variables to context
     * @param context template context map
     * @param request HTTP servlet request
     */
    public static void addPortalVariables(Map<String, Object> context, 
        HttpServletRequest request);
    
    /**
     * Adds user-specific variables to context
     * @param context template context map
     * @param user current user
     */
    public static void addUserVariables(Map<String, Object> context, User user);
}

Generic Template Processing

Generic template processing utilities supporting multiple template engines and formats.

/**
 * Generic template manager supporting multiple template engines
 */
public class TemplateManager {
    
    /**
     * Processes template using specified engine
     * @param templateId template identifier
     * @param engineType template engine type
     * @param context template context variables
     * @return processed template output
     * @throws TemplateException if processing fails
     */
    public String processTemplate(String templateId, String engineType, 
        Map<String, Object> context) throws TemplateException;
    
    /**
     * Registers template engine implementation
     * @param engineType engine type identifier
     * @param engine template engine implementation
     */
    public void registerEngine(String engineType, TemplateEngine engine);
    
    /**
     * Gets available template engines
     * @return Set of available engine types
     */
    public Set<String> getAvailableEngines();
}

/**
 * Template resource manager for loading templates from various sources
 */
public class TemplateResourceManager {
    
    /**
     * Loads template from file system
     * @param templatePath path to template file
     * @return template content as string
     * @throws IOException if template cannot be loaded
     */
    public String loadTemplate(String templatePath) throws IOException;
    
    /**
     * Loads template from classpath resource
     * @param resourcePath classpath resource path
     * @return template content as string
     * @throws IOException if resource cannot be loaded
     */
    public String loadTemplateFromClasspath(String resourcePath) throws IOException;
    
    /**
     * Loads template from database
     * @param templateId database template identifier
     * @return template content as string
     * @throws SystemException if database access fails
     */
    public String loadTemplateFromDatabase(long templateId) throws SystemException;
    
    /**
     * Caches template content for performance
     * @param templateId template identifier
     * @param content template content
     */
    public void cacheTemplate(String templateId, String content);
}

Usage Examples

FreeMarker Template Processing:

// Create FreeMarker engine
FreeMarkerEngine engine = new FreeMarkerEngine();

// Create template context
Map<String, Object> context = FreeMarkerContext.createContext(request, response);
context.put("pageTitle", "Welcome to Portal");
context.put("userList", userService.getActiveUsers());

// Process template
String output = engine.processTemplate("welcome.ftl", context);

// Write to response
response.getWriter().write(output);

Template Content Processing:

// Template content as string
String templateContent = """
    <html>
    <head><title>${pageTitle}</title></head>
    <body>
        <h1>Welcome ${user.firstName}!</h1>
        <p>You have ${messageCount} messages.</p>
    </body>
    </html>
    """;

// Process template content
Map<String, Object> context = new HashMap<>();
context.put("pageTitle", "User Dashboard");
context.put("user", getCurrentUser());
context.put("messageCount", getMessageCount());

String result = engine.processTemplateContent(templateContent, context);

Integration with Portal Framework

Template processing integrates with:

  • Portlet Rendering - Dynamic portlet content generation
  • Email Templates - Personalized email content
  • Web Content - CMS template processing
  • Theme Integration - Dynamic theme customization
  • Workflow Templates - Business process templates

Error Handling

  • TemplateException - Template processing errors
  • TemplateNotFoundException - Missing template files
  • TemplateParseException - Template syntax errors
  • ContextException - Template context issues

Install with Tessl CLI

npx tessl i tessl/maven-com-liferay-portal--com-liferay-portal-impl

docs

bean-management.md

database-orm.md

database-upgrades.md

framework-integration.md

index.md

lifecycle-events.md

portlet-framework.md

service-layer.md

template-processing.md

utility-services.md

web-security.md

tile.json