***********************************************************************
getTemplatesSize()
This method is used by CacheMonitor to get the number of templates from the disk.
***********************************************************************
551749
public int getTemplatesSize() {
        int length = 0;
        if (!this.disableTemplatesSupport) {
            try {
                rwLock.readLock().lock();
                length = template_cache.size();
            } finally {
                rwLock.readLock().unlock();
            }
            if (length < 0) {
                length = 0;
            }
        }
        return length;
    }
1172279
private void checkTemplate(TemplateNode node, TemplateRegistry templateRegistry) {
    ListMultimap<String, SourceLocation> dataKeys = ArrayListMultimap.create();

    for (VarRefNode varRefNode : SoyTreeUtils.getAllNodesOfType(node, VarRefNode.class)) {
      if (varRefNode.isPossibleHeaderVar()) {
        dataKeys.put(varRefNode.getName(), varRefNode.getSourceLocation());
      }
    }

    IndirectParamsInfo ipi =
        new IndirectParamsCalculator(templateRegistry)
            .calculateIndirectParams(templateRegistry.getMetadata(node));

    Set<String> allHeaderVarNames = new HashSet<>();
    List<TemplateHeaderVarDefn> unusedParams = new ArrayList<>();
    // Process @param header variables.
    for (TemplateParam param : node.getAllParams()) {
      allHeaderVarNames.add(param.name());
      if (dataKeys.containsKey(param.name())) {
        // Good: Declared and referenced in template. We remove these from dataKeys so
        // that at the end of the for-loop, dataKeys will only contain the keys that are referenced
        // but not declared in SoyDoc.
        dataKeys.removeAll(param.name());
      } else if (ipi.paramKeyToCalleesMultimap.containsKey(param.name())
          || ipi.mayHaveIndirectParamsInExternalCalls
          || ipi.mayHaveIndirectParamsInExternalDelCalls) {
        // Good: Declared in SoyDoc and either (a) used in a call that passes all data or (b) used
        // in an external call or delcall that passes all data, which may need the param (we can't
        // verify).
      } else {
        // Bad: Declared in SoyDoc but not referenced in template.
        unusedParams.add(param);
      }
    }

    List<TemplateHeaderVarDefn> unusedStateVars = new ArrayList<>();
    // Process @state header variables.
    if (node instanceof TemplateElementNode) {
      TemplateElementNode el = (TemplateElementNode) node;
      for (TemplateStateVar stateVar : el.getStateVars()) {
        allHeaderVarNames.add(stateVar.name());
        if (dataKeys.containsKey(stateVar.name())) {
          // Good: declared and referenced in the template.
          dataKeys.removeAll(stateVar.name());
        } else {
          // Bad: declared in the header, but not used.
          unusedStateVars.add(stateVar);
        }
      }
    }
    // At this point, the only keys left in dataKeys are undeclared.
    for (Entry<String, SourceLocation> undeclared : dataKeys.entries()) {
      String extraErrorMessage =
          SoyErrors.getDidYouMeanMessage(allHeaderVarNames, undeclared.getKey());
      errorReporter.report(
          undeclared.getValue(), UNDECLARED_DATA_KEY, undeclared.getKey(), extraErrorMessage);
    }

    // Delegate templates can declare unused params because other implementations
    // of the same delegate may need to use those params.
    if (node instanceof TemplateBasicNode) {
      reportUnusedHeaderVars(errorReporter, unusedParams, UNUSED_PARAM);
    }
    if (node instanceof TemplateElementNode) {
      reportUnusedHeaderVars(errorReporter, unusedStateVars, UNUSED_STATE);
    }
  }
220883
function getTemplate (templates, fileName) {
  var extMatch = fileName.match(/\.([^\.]*)$/);
  if (extMatch && extMatch.length > 1)
    return templates[extMatch[1]];
  return null;
}
550145
public static synchronized int getPageSize() throws OperatingSystemException {
        if (cachedPageSize == -1) {
            switch (instance().getOperatingSystemType()) {
                case AIX:
                case HPUX:
                case IBMi:
                case Linux:
                case Mac:
                case Solaris:
                case zOS:
                    cachedPageSize = getPageSizePOSIX();
                    break;
                default:
                    throw new OperatingSystemException(Tr.formatMessage(tc, "os.pagesize.unavailable"));
            }
        }
        return cachedPageSize;
    }
642288
public int getSize() {
		if (size < 0) {
			size = 0;
			for (byte[] cache: start) {
				size += new RemoteOneFileCache(cache).getSize();
			}
			for (byte[] cache: end) {
				size += new RemoteOneFileCache(cache).getSize();
			}
		}
		return size;
	}
53121
def getTemplate(self, uri, meta=None):
        """"""

        if not meta:

            metaKey = self.cacheKey + '_templatesmeta_cache_' + uri

            meta = cache.get(metaKey, None)

            if not meta:
                meta = self.getMeta(uri)
                cache.set(metaKey, meta, 15)

        if not meta:  # No meta, can return a template
            return None

        # Let's find the template in the cache
        action = urlparse(uri).path

        templateKey = self.cacheKey + '_templates_' + action + '_' + meta['template_tag']
        template = cache.get(templateKey, None)

        # Nothing found -> Retrieve it from the server and cache it
        if not template:

            r = self.doQuery('template/' + uri)

            if r.status_code == 200:  # Get the content if there is not problem. If there is, template will stay to None
                template = r.content

            cache.set(templateKey, template, None)  # None = Cache forever

        return template
869096
private static MethodInfo getTemplateSubstituteMethod(InputStream in) throws IOException {

        ClassFile classFile = ClassFile.readFrom(in);

        MethodInfo substituteMethod = null;
        MethodInfo[] all = classFile.getMethods();

        // find the execute method on this template
        for (int i = 0; i < all.length; i++) {

            if ("substitute".equals(
                all[i].getName()) &&
                all[i].getMethodDescriptor().getParameterCount() == 1) {
                substituteMethod = all[i];
                break;
            }
        }
        in.close();
        return substituteMethod;
    }
824742
function getTemplates(config) {

  var templates = {};

  Object.keys(templatePaths).forEach(function(key) {
      if (config.templates && (config.templates[key] && config.templates[key] !== true)) {
        templates[key] = config.templates[key];
      } else {
        templates[key] = fs.readFileSync(__dirname + templatePaths[key], "utf-8");
      }
    });

  return templates;
}
224623
public void delTemplate(String template) {
        if (htod.delTemplate(template) == HTODDynacache.DISK_EXCEPTION) {
            stopOnError(this.htod.diskCacheException);
        }
    }
419681
public void loadTemplates() throws TemplateException {
        loadStrategyI.loadTemplates();
        this.templateSet = loadStrategyI.getTemplates();
        this.templateOrders = loadStrategyI.getOrders();
    }
459291
private void generateTemplateMetadata() {
    SanitizedContentKind contentKind = templateNode.getContentKind();
    String kind = contentKind == null ? "" : contentKind.name();

    // using linked hash sets below for determinism
    Set<String> uniqueIjs = new LinkedHashSet<>();
    for (VarRefNode var : getAllNodesOfType(templateNode, VarRefNode.class)) {
      if (var.isInjected()) {
        uniqueIjs.add(var.getName());
      }
    }

    Set<String> callees = new LinkedHashSet<>();
    for (CallBasicNode call : getAllNodesOfType(templateNode, CallBasicNode.class)) {
      callees.add(call.getCalleeName());
    }

    Set<String> delCallees = new LinkedHashSet<>();
    for (CallDelegateNode call : getAllNodesOfType(templateNode, CallDelegateNode.class)) {
      delCallees.add(call.getDelCalleeName());
    }

    TemplateMetadata.DelTemplateMetadata deltemplateMetadata;
    if (templateNode.getKind() == SoyNode.Kind.TEMPLATE_DELEGATE_NODE) {
      TemplateDelegateNode delegateNode = (TemplateDelegateNode) templateNode;
      deltemplateMetadata =
          createDelTemplateMetadata(
              delegateNode.getDelPackageName() == null ? "" : delegateNode.getDelPackageName(),
              delegateNode.getDelTemplateName(),
              delegateNode.getDelTemplateVariant());
    } else {
      deltemplateMetadata = createDefaultDelTemplateMetadata();
    }
    TemplateMetadata metadata =
        createTemplateMetadata(kind, uniqueIjs, callees, delCallees, deltemplateMetadata);
    TEMPLATE_METADATA_REF.write(metadata, writer);
  }
15783
private TemplateClass tryLoadTemplate(String tmplName, RythmEngine engine, TemplateClass callerClass, ICodeType codeType, boolean processTagName) {
        //logger.info(">>> try load %s on [%s] with processTagName: %s", tmplName, callerClass.getKey(), processTagName);
        if (null == engine) {
            engine = getDefaultEngine();
        }
        if (engine.templateRegistered(tmplName)) {
            return null;
        }
        String rythmSuffix = engine.conf().resourceNameSuffix();
        final List<String> suffixes = new ArrayList<String>(Arrays.asList(RythmEngine.VALID_SUFFIXES));
        if (null == codeType) {
            codeType = TemplateResourceBase.getTypeOfPath(engine, tmplName);
        }
        if (ICodeType.DefImpl.RAW == codeType) {
            // use caller's code type
            codeType = callerClass.codeType;
        }
        final String tagNameOrigin = tmplName;
        boolean hasSuffix = false;
        String suffix = "";
        if (processTagName) {
            boolean withRythmSuffix = S.notEmpty(rythmSuffix);
            for (String s : suffixes) {
                if (tmplName.endsWith(s)) {
                    tmplName = tmplName.substring(0, tmplName.lastIndexOf(s));
                    suffix = s;
                    hasSuffix = true;
                    break;
                }
                if (withRythmSuffix && (tmplName.endsWith(s) || tmplName.endsWith(s + rythmSuffix))) {
                    tmplName = tmplName.substring(0, tmplName.lastIndexOf(s));
                    suffix = s + rythmSuffix;
                    hasSuffix = true;
                    break;
                }
            }
        }
        tmplName = tmplName.replace('.', '/');
        String sfx = codeType.resourceNameSuffix();
        if (S.notEmpty(sfx) && !suffixes.get(0).equals(sfx)) {
            suffixes.remove(sfx);
            suffixes.add(0, sfx);
        }

        final List<String> roots = new ArrayList<String>();
        String root0 = this.getResourceLoaderRoot().replace('\\', '/');
        if (root0.endsWith("/")) {
            root0 = root0.substring(0, root0.length() - 1);
        }

        roots.add(root0);

        // call template using relative path
        String currentPath = callerClass.getKey().toString();
        int pos = currentPath.lastIndexOf("/");
        if (-1 != pos) {
            currentPath = currentPath.substring(0, pos);
            if (currentPath.startsWith(root0)) {
                if (currentPath.length() > root0.length()) {
                    roots.add(0, currentPath);
                }
            } else {
                if (currentPath.startsWith("/")) {
                    currentPath = currentPath.substring(1);
                }
                if (!currentPath.startsWith(root0)) currentPath = root0 + "/" + currentPath;
                roots.add(0, currentPath);
            }
        }
        
        // call tag with import path
        if (null != callerClass.importPaths) {
            for (String s: callerClass.importPaths) {
                if (s.startsWith("java")) {
                    continue;
                }
                roots.add(0, root0 + "/" + s.replace('.', '/'));
            }
        }

        String tmplName0 = tmplName;
        for (String root : roots) {
            String tmplName1 = tmplName0;
            if (root.startsWith("/") && !tmplName1.startsWith("/")) {
                tmplName1 = "/" + tmplName0;
            }
            tmplName = tmplName1.startsWith(root) ? tmplName1 : root + "/" + tmplName0;
            if (hasSuffix) {
                ITemplateResource resource = load(tmplName + suffix);
                if (null == resource || !resource.isValid()) {
                    continue;
                }
                TemplateClass tc = engine.resourceManager().resourceLoaded(resource, false);
                return tc;
            } else {
                for (String suffix0 : suffixes) {
                    String path = tmplName + suffix0;
                    ITemplateResource resource = load(path);
                    if (null == resource || !resource.isValid()) {
                        continue;
                    }
                    TemplateClass tc = engine.resourceManager().resourceLoaded(resource, false);
                    return tc;
                }
            }
        }
        TemplateClass tc = processTagName ? tryLoadTemplate(tagNameOrigin, engine, callerClass, codeType, false) : null;
        if (null == tc) {
            TemplateResourceManager.reportNonResource(tmplName);
        }
        return tc;
    }
225631
@Override
	public Template getTemplate(String resource) {
		try {
			return FreemarkerTemplate.wrap(this.cfg.getTemplate(resource));
		} catch(IOException e) {
			throw new IORuntimeException(e);
		}catch (Exception e) {
			throw new TemplateException(e);
		}
	}
193338
@Override
    public int getDepIdsSizeDisk() {
        final String methodName = "getDepIdsSizeDisk()";
        if (this.swapToDisk) {
            // TODO write code to support getDepIdsSizeDisk function
            if (tc.isDebugEnabled()) {
                Tr.debug(tc, methodName + " cacheName=" + cacheName + " ERROR because it is not implemented yet");
            }
        } else {
            if (this.featureSupport.isDiskCacheSupported() == false) {
                Tr.error(tc, "DYNA1064E", new Object[] { methodName, cacheName, this.cacheProviderName });
            } else {
                if (tc.isDebugEnabled()) {
                    Tr.debug(tc, methodName + " cacheName=" + cacheName + " no operation is done because the disk cache offload is not enabled");
                }
            }
        }
        return 0;
    }
442947
function getSourceTemplate(cb) {
    if (options.cache) {
      var info = self.cache[filename];
      if (info) {
        return cb(null, info.source, info.template);
      }
    }

    fs.readFile(filename, 'utf8', function(err, source) {
      if (err) return cb(err);

      var template = self.compile(source, filename);
      if (options.cache) {
        self.cache[filename] = {
          source: source,
          template: template
        };
      }
      return cb(null, source, template);
    });
  }
182278
function SmartTemplateParser ( $template_filename )
		{
			// Load Template
			if ($hd = @fopen($template_filename, "r"))
			{
				if (filesize($template_filename))
				{
					$this->template = fread($hd, filesize($template_filename));
				}
				else
				{
					$this->template = "SmartTemplate Parser Error: File size is zero byte: '$template_filename'";
				}
				fclose($hd);
				// Extract the name of the template directory
				$this->template_dir = dirname($template_filename);
			}
			else
			{
				$this->template = "SmartTemplate Parser Error: File not found: '$template_filename'";
			}
		}
1034086
@SuppressWarnings("unchecked")
    public TemplateWrapper[] getKnownTemplates() {
        if (mTemplateOrdering == null) {
            setTemplateOrdering("name");
        }

        Comparator<TemplateWrapper> comparator = 
            BeanComparator.forClass(TemplateWrapper.class).orderBy("name");
        Set<TemplateWrapper> known = new TreeSet<TemplateWrapper>(comparator);

        TemplateLoader.Template[] loaded = mTeaServletEngine
            .getTemplateSource().getLoadedTemplates();

        if (loaded != null) {
            for (int j = 0; j < loaded.length; j++) {
                TeaServletAdmin.TemplateWrapper wrapper =
                    new TemplateWrapper(loaded[j], TeaServletInvocationStats.getInstance()
                        .getStatistics(loaded[j].getName(), null), TeaServletInvocationStats.getInstance()
                        .getStatistics(loaded[j].getName(), "__substitution"),
                        TeaServletRequestStats.getInstance().getStats(loaded[j].getName()));

                try {
                    known.add(wrapper);
                } catch (ClassCastException cce) {
                    mTeaServletEngine.getLog().warn(cce);
                }
            }
        }

        String[] allNames = mTeaServletEngine.getTemplateSource()
            .getKnownTemplateNames();
        if (allNames != null) {
            for (int j = 0; j < allNames.length; j++) {
                TeaServletAdmin.TemplateWrapper wrapper =
                    new TemplateWrapper(allNames[j], TeaServletInvocationStats.getInstance()
                        .getStatistics(allNames[j], null), TeaServletInvocationStats.getInstance()
                        .getStatistics(allNames[j], "__substitution"),
                        TeaServletRequestStats.getInstance().getStats(allNames[j]));
                try {
                    known.add(wrapper);
                } catch (ClassCastException cce) {
                    mTeaServletEngine.getLog().warn(cce);
                }
            }
        }

        List<TemplateWrapper> v = new ArrayList<TemplateWrapper>(known);
        
        Collections.sort(v, mTemplateOrdering);
        
//        return (TeaServletAdmin.TemplateWrapper[])known.toArray(new TemplateWrapper[known.size()]);
        return v.toArray(new TemplateWrapper[v.size()]);
    }