Setup necessary template by string code. Throws validation exception if code is null or template not found
@param templateCode - string code of template
355408
public RunParams templateCode(String templateCode) {
        if (templateCode == null) {
            throw new NullPointerException("\"templateCode\" parameter can not be null");
        }
        this.reportTemplate = report.getReportTemplates().get(templateCode);
        if (reportTemplate == null) {
            throw new NullPointerException(String.format("Report template not found for code [%s]", templateCode));
        }
        return this;
    }
8104
public final void setTemplate() {
        template = new HashMap();
        if (isEventExist()) {
            template.putAll(events.get(next));
        }
        template.put("event", eventType);
    }
646909
public void templateNameVerification(String expectedName)
			throws SyntaxException {

		if (!name.equals(expectedName)) {
			throw SyntaxException.create(null, source, MSG_MISNAMED_TPL,
					expectedName);
		}
	}
1230106
def TemplateValidator(value):
    """"""

    try:
        Template(value)
    except Exception as e:
        raise ValidationError(
            _("Cannot compile template (%(exception)s)"),
            params={"exception": e}
        )
306261
void generateValidationChecks(
            final CtClass ctClass,
            final StringBuilder validationChecksCode,
            final StringBuilder staticInitializerCode,
            final List<String> staticFields) {

        for (final CtField ctField : ctClass.getDeclaredFields()) {
            for (final Object annotationObject : ctField.getAvailableAnnotations()) {
                final Annotation annotation = (Annotation) annotationObject;
                if (ANNOTATIONS.contains(annotation.annotationType())) {
                    final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class);
                    final Class<? extends AnnotationCheck<? extends Annotation>> checkClass = constraint.checkWith();
                    final String checkType = checkClass.getName();
                    final String checkName = getCheckName(ctField.getName(), checkType);
                    final String fieldName = ctField.getName();

                    // Define the member for the check
                    staticFields.add(generateCheckFieldDeclaration(checkType, checkName));

                    // Define the member for the field context
                    staticFields.add(generateFieldContextDeclaration(ctClass.getName(), checkName, fieldName));

                    // Write the check initializer code
                    staticInitializerCode.append(
                            generateCheckInitializer(
                                    ctClass.getName(),
                                    checkName,
                                    fieldName,
                                    annotation.annotationType().getName()));

                    // Write the validation code
                    validationChecksCode.append(generateValidation(
                            annotation,
                            checkType,
                            checkName,
                            fieldName));
                }
            }
        }
    }
1212889
def from_string(self, template_code):
        
        try:
            return self.template_class(self.engine.from_string(template_code))
        except mako_exceptions.SyntaxException as exc:
            raise TemplateSyntaxError(exc.args)
582334
@Override
  public ValidationResult validateCode(String system, String code, String display) {
    Coding c = new Coding(system, code, display);
    return validateCode(c, null);
  }
381328
public void invokeTemplate(int line, String name, ITemplate caller, ITag.__ParameterList params, ITag.__Body body, ITag.__Body context, boolean ignoreNonExistsTag) {
        if (_nonExistsTags.contains(name)) return;

        Sandbox.enterSafeZone(secureCode);
        RythmEvents.ENTER_INVOKE_TEMPLATE.trigger(this, (TemplateBase) caller);
        try {
            // try tag registry first
            ITemplate t = _tags.get(name);
            if (null == t) {
                t = _templates.get(name);
            }
            if (null == t && S.isEqual(name, caller.__getName())) {
                // is calling self
                t = caller;
            }

            if (null == t) {
                // try imported path
                TemplateClass tc = caller.__getTemplateClass(true);
                if (null != tc.importPaths) {
                    for (String s : tc.importPaths) {
                        if (s.startsWith("java")) {
                            continue;
                        }
                        String name0 = s + "." + name;
                        t = _tags.get(name0);
                        if (null == t) t = _templates.get(name0);
                        if (null != t) break;
                    }
                }

                // try relative path
                if (null == t) {
                    String callerName = tc.getTagName();
                    int pos = -1;
                    if (null != callerName) pos = callerName.lastIndexOf(".");
                    if (-1 != pos) {
                        String name0 = callerName.substring(0, pos) + "." + name;
                        t = _tags.get(name0);
                        if (null == t) t = _templates.get(name0);
                    }
                }

                // try load the tag from resource
                if (null == t) {
                    tc = resourceManager().tryLoadTemplate(name, tc, caller.__curCodeType());
                    if (null != tc) t = _templates.get(tc.getTagName());
                    if (null == t) {
                        if (ignoreNonExistsTag) {
                            if (logger.isDebugEnabled()) {
                                logger.debug("cannot find tag: " + name);
                            }
                            _nonExistsTags.add(name);
                            if (isDevMode() && nonExistsTemplatesChecker == null) {
                                nonExistsTemplatesChecker = new NonExistsTemplatesChecker();
                            }
                            return;
                        } else {
                            throw new NullPointerException("cannot find tag: " + name);
                        }
                    }
                    t = t.__cloneMe(this, caller);
                }
            }

            if (!(t instanceof JavaTagBase)) {
                // try refresh the tag loaded from template file under tag root
                // note Java source tags are not reloaded here
                String cn = t.getClass().getName();
                TemplateClass tc0 = classes().getByClassName(cn);
                if (null == tc0) {
                    throw new NullPointerException(String.format("null tc0 found. t.class: %s, name: %s, caller.class: %s", cn, name, caller.getClass()));
                }
                t = tc0.asTemplate(caller, this);
            } else {
                t = t.__cloneMe(this, caller);
            }

            if (null != params) {
                if (t instanceof JavaTagBase) {
                    ((JavaTagBase) t).__setRenderArgs0(params);
                } else {
                    for (int i = 0; i < params.size(); ++i) {
                        ITag.__Parameter param = params.get(i);
                        if (null != param.name) t.__setRenderArg(param.name, param.value);
                        else t.__setRenderArg(i, param.value);
                    }
                }
            }
            if (null == body && null != params) {
                body = (ITag.__Body) params.getByName("__body");
                if (null == body) {
                    body = (ITag.__Body) params.getByName("_body");
                }
            }
            if (null != body) {
                t.__setRenderArg("__body", body);
                t.__setRenderArg("_body", body); // for compatibility
            }
            RythmEvents.ON_TAG_INVOCATION.trigger(this, F.T2((TemplateBase) caller, t));
            try {
                if (null != context) {
                    t.__setBodyContext(context);
                }
                t.__setSecureCode(secureCode).__call(line);
            } finally {
                RythmEvents.TAG_INVOKED.trigger(this, F.T2((TemplateBase) caller, t));
            }
        } finally {
            RythmEvents.EXIT_INVOKE_TEMPLATE.trigger(this, (TemplateBase) caller);
            Sandbox.leaveCurZone(secureCode);
        }
    }
987625
public String process(String templateName, String templateSource, Map<String, Object> params) {
        try {
            Template template = new Template(templateName, templateSource, configuration);
            Writer writer = new StringWriter();
            template.process(params, writer);
            return writer.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
1237232
private boolean isValidElement() {

        boolean validElement = false;
        List elementList = new ArrayList();
        try {
            // get Elements of template stored in Property "template-elements"
            String elements = m_cmsObject.readPropertyObject(
                m_template,
                CmsPropertyDefinition.PROPERTY_TEMPLATE_ELEMENTS,
                false).getValue();
            // template may contain more than one Element
            // Elements are separated by the delimiter ","
            if (elements != null) {
                StringTokenizer T = new StringTokenizer(elements, ",");
                while (T.hasMoreTokens()) {
                    // current element probably looks like "body*|Body" <name><mandatory>|<nicename>
                    String currentElement = T.nextToken();
                    int sepIndex = currentElement.indexOf("|");
                    if (sepIndex != -1) {
                        // current element == "body*"
                        currentElement = currentElement.substring(0, sepIndex);
                    }
                    if (currentElement.endsWith("*")) {
                        // current element == "body"
                        currentElement = currentElement.substring(0, currentElement.length() - 1);
                    }
                    elementList.add(currentElement);
                }
            }
            if (elementList.contains(m_element)) {
                validElement = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return validElement;
    }
221342
function MessageTemplate(messageTemplate) {
        if (messageTemplate === null || !messageTemplate.length) {
            throw new Error('Argument "messageTemplate" is required.');
        }
        this.raw = messageTemplate;
        this.tokens = this.tokenize(messageTemplate);
    }
237601
public final void setTemplateMode(final String templateMode) {
        // Setter overload actually goes against the JavaBeans spec, but having this one is good for legacy
        // compatibility reasons. Besides, given the getter returns TemplateMode, intelligent frameworks like
        // Spring will recognized the property as TemplateMode-typed and simply ignore this setter.
        Validate.notNull(templateMode, "Cannot set a null template mode value");
        this.templateMode = TemplateMode.parse(templateMode);
    }
740122
public static function create($template, array $availableTemplates, $code = 0, \Exception $prev = null)
    {
        return new static(sprintf(
            'Not found template with name "%s". Available templates: "%s"',
            $template,
            implode('", "', $availableTemplates)
        ), $code, $prev);
    }
1356677
public void setErrorCode(String errorCode) {
		if (errorCode != null) {
			NullArgumentException.validateNotEmpty(errorCode, "Error code");
		}
		this.errorCode = errorCode;
	}
1001414
public void addTemplate(String strTemplate, int weight) throws Exception {
		strTemplate = strTemplate.replaceAll("[\\?\\*\\[\\]\\{\\}\\,\\|]", "");
//		if(strTemplate.contains("."))
//			System.out.println(strTemplate);
		strTemplate = strTemplate.replaceAll("\\.", "\\\\.");
		
		Pattern p = Pattern.compile("(#[^#]+#)+");
		Matcher m = p.matcher(strTemplate);
		if(m.matches())
			return;
		
//		strTemplate = "^"+strTemplate;
//		strTemplate += "$";
		
		String str = new String(strTemplate);
		ArrayList<String> matchs = new ArrayList<String>();
		int len = 0;
		int patternNum = 0;
		while(m.find()) {
			patternNum++;
			String target = m.group();
			len+=target.length();
			matchs.add(target);
			str = str.replace(target, "(.{"+minlen+",})");
		}
		len = str.length()-len;
		if(len<2)
			return;
		
		templates.add(strTemplate);
		lens.add(len);
		weights.add((float) (weight*Math.pow(BASE, Math.max(0,2-patternNum))));
		matchGroup.add(matchs);
		//System.out.println(str);
		try {
			patterns.add(Pattern.compile(str));
		} catch (Exception e) {
			System.out.println(str);
			e.printStackTrace();
			throw e;
		}
	}
340274
public int delTemplate(String template) {
        int returnCode = NO_EXCEPTION;
        if (!this.disableTemplatesSupport) {
            if (delayOffload) {
                auxTemplateDependencyTable.removeDependency(template);
            }
            returnCode = delValueSet(TEMPLATE_ID_DATA, template);
        }
        return returnCode;
    }
690450
public static void initServletRequest(ServletRequest servletRequest, URLTemplatesFactory templatesFactory)
    {
        assert servletRequest != null : "The ServletRequest cannot be null.";

        if (servletRequest == null) {
            throw new IllegalArgumentException("The ServletRequest cannot be null.");
        }

        servletRequest.setAttribute(URL_TEMPLATE_FACTORY_ATTR, templatesFactory);
    }