TemplateUtils

Utility methods to handle templates. For example, replace a text in a template. 

Methods

templateExists

Description:

MethodReturn valuesDescription

templateExists(String name)

boolean

Check for template existence.

name: The name of the template.

Example:

package com.openkm;

import com.openkm.util.TemplateUtils;

public class Test {
	public static void main(String[] args) {
		try {
			System.out.println("Exist template: " + TemplateUtils.templateExists("OpenKM - NOTIFICATION"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

replace

Description:

MethodReturn valuesDescription

replace(String name, String template, Map<String, Object> model)

String

Quick replace utility function.

name: The name of the template.

template:  A text whith the template definition.

model: A map use to reaplace elements in the template.

Example:

package com.openkm;

import java.io.File;
import java.util.HashMap;

import com.openkm.core.Config;
import com.openkm.util.FileUtils;
import com.openkm.util.TemplateUtils;

public class Test {
	public static void main(String[] args) {
		try {
			HashMap<String, Object> hm = new HashMap<String, Object>();
			File tmpFileIn = FileUtils.createTempFileFromMime("text/plain");
			hm.put("fileIn", tmpFileIn.getPath());
			String cmd = TemplateUtils.replace("SYSTEM_XLS2CSV", Config.SYSTEM_CATDOC_XLS2CSV, hm);
			System.out.println("cmd template: " + cmd);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}