All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.stringtemplate.v4.STRawGroupDir Maven / Gradle / Ivy

Go to download

StringTemplate is a java template engine for generating source code, web pages, emails, or any other formatted text output. StringTemplate is particularly good at multi-targeted code generators, multiple site skins, and internationalization/localization. It evolved over years of effort developing jGuru.com. StringTemplate also powers the ANTLR 3 and 4 code generator. Its distinguishing characteristic is that unlike other engines, it strictly enforces model-view separation. Strict separation makes websites and code generators more flexible and maintainable; it also provides an excellent defense against malicious template authors.

There is a newer version: 4.3.4
Show newest version
package org.stringtemplate.v4;

import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonToken;
import org.stringtemplate.v4.compiler.*;
import org.stringtemplate.v4.compiler.Compiler;
import org.stringtemplate.v4.misc.Misc;

import java.net.URL;

/** A directory of templates without headers like ST v3 had.  Still allows group
 *  files in directory though like {@link STGroupDir} parent.
 */
public class STRawGroupDir extends STGroupDir {
	public STRawGroupDir(String dirName) {
		super(dirName);
	}

	public STRawGroupDir(String dirName, char delimiterStartChar, char delimiterStopChar) {
		super(dirName, delimiterStartChar, delimiterStopChar);
	}

	public STRawGroupDir(String dirName, String encoding) {
		super(dirName, encoding);
	}

	public STRawGroupDir(String dirName, String encoding, char delimiterStartChar, char delimiterStopChar) {
		super(dirName, encoding, delimiterStartChar, delimiterStopChar);
	}

	public STRawGroupDir(URL root, String encoding, char delimiterStartChar, char delimiterStopChar) {
		super(root, encoding, delimiterStartChar, delimiterStopChar);
	}

	@Override
	public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName,
									   CharStream templateStream)
	{
		String template = templateStream.substring(0, templateStream.size() - 1);
		String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
		String fullyQualifiedTemplateName = prefix + templateName;
		CompiledST impl = new Compiler(this).compile(fullyQualifiedTemplateName, template);
		CommonToken nameT = new CommonToken(STLexer.SEMI); // Seems like a hack, best I could come up with.
		nameT.setInputStream(templateStream);
		rawDefineTemplate(fullyQualifiedTemplateName, impl, nameT);
		impl.defineImplicitlyDefinedTemplates(this);
		return impl;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy