Create a template source using the composite context passed to
the method.

@param contextSource The composite context source for all the
applications in the ApplicationDepot.

@return A newly created template source.
199147
private TeaServletTemplateSource createTemplateSource(
                                         ContextSource contextSource) {
        return TeaServletTemplateSource.createTemplateSource(
            getServletContext(),
            (TeaServletContextSource) contextSource,
            getProperties().subMap("template"),
            getLog());
    }
159518
public static ProducerTemplate generateTemplete(String contextUri) throws Exception
    {
        String initKey = contextUri.intern();
        synchronized (initKey)
        {
            ProducerTemplate template = templates.get(initKey);

            // 初期化済みの場合は、初期化済みのProducerTemplateを返す。
            if (template != null)
            {
                return template;
            }

            // 初期化を行う
            Main main = new Main();
            main.setApplicationContextUri(contextUri);
            main.enableHangupSupport();

            // run Camel
            CamelInitializeThread initializeThread = new CamelInitializeThread(main);
            initializeThread.start();

            int timeCounter = 0;

            // keep ProducerTemplate
            while (!main.isStarted())
            {
                try
                {
                    TimeUnit.SECONDS.sleep(1);
                }
                catch (InterruptedException ex)
                {
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("Occur interrupt. Ignore interrupt.", ex);
                    }
                }

                timeCounter++;

                if (INITIALIZE_TIMEOUT < timeCounter)
                {
                    logger.error("Timed out to camel initialization. Stop to application start.");
                    throw new Exception("Camel initialization time out.");
                }
            }

            // ProducerTemplateを取得する
            template = main.getCamelTemplate();
            // 初期化済みのProducerTemplateを保持する
            templates.put(initKey, template);

            return template;
        }
    }
24507
public TemplateInstanceExecution templateInstanceExecution(String sourceName, ExpressionEngine expressionEngine) {
        // Transforms each parameter in a name/value pair, using only the source name as input
        Map<String, String> sourceNameInput = Collections.singletonMap("sourceName", sourceName);
        Map<String, String> parameterMap = Maps.transformValues(
                Maps.uniqueIndex(
                        parameters,
                        TemplateParameter::getName
                ),
                parameter -> expressionEngine.render(parameter.getExpression(), sourceNameInput)
        );
        // Concatenates the maps
        Map<String, String> inputMap = new HashMap<>(sourceNameInput);
        inputMap.putAll(parameterMap);
        // Resolves the final expression
        return new TemplateInstanceExecution(
                value -> expressionEngine.render(value, inputMap),
                parameterMap
        );
    }
1245171
public void generate(GenerationContext context) {
    boolean exists = exists(context.getFile());
    if (!context.isOverwrite() && exists) {
      return;
    }
    File dir = context.getFile().getParentFile();
    if (dir != null) {
      mkdirs(dir);
    }
    Writer writer = openWriter(context);
    try {
      Template template = getTemplate(context.getTemplateName());
      process(template, context.getModel(), writer);
    } finally {
      IOUtil.close(writer);
    }
    if (exists) {
      Logger.info(Message.DOMAGEN0020.getMessage(context.getFile().getPath()));
    } else {
      Logger.info(Message.DOMAGEN0019.getMessage(context.getFile().getPath()));
    }
  }
517271
public static ContextLoaderListener createSpringContextLoader(final WebApplicationContext webApplicationContext) {
        return new ContextLoaderListener() {
            @SuppressWarnings("unchecked")
            @Override
            protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
                return webApplicationContext;
            }
        };
    }
226687
protected DataContext createScriptDataContext(
            final Framework framework,
            final String project,
            final Map<String, Map<String, String>> context) {
        BaseDataContext localDataContext = new BaseDataContext();
        localDataContext.merge(ScriptDataContextUtil.createScriptDataContextObjectForProject(framework, project));
        localDataContext.group("plugin").putAll(createPluginData());
        localDataContext.putAll(context);
        return localDataContext;
    }
914792
public static DefaultResourceConfig newApplicationConfig(UIContext context)
    {
        final Set<Object> singletons = getSingletons(context);
        final Set<Class<?>> classes = getClasses();

        return new DefaultResourceConfig()
        {
            @Override
            public Set<Class<?>> getClasses()
            {
                return classes;
            }

            @Override
            public Set<Object> getSingletons()
            {
                return singletons;
            }
        };
    }
1035835
public void generate(Context context) {
        Appendable target = context.getTarget();

        for (ProcTemplateElement element : elements) {
            try {
                target.append(element.generate(context));
            } catch (IOException e) {
                // Nothing! Because StringBuilder doesn't catch IOException
            }
        }
    }
1163489
public Template globalLoad(String name, boolean lookupOnly) {

		// If this context was created without a Compiler object specified, then
		// no global lookups can be done. Just return null indicating that the
		// requested template can't be found.
		if (compiler == null) {
			return null;
		}

		// Use the full lookup to find the correct template file. This must
		// always be done on a global load because the actual template file on
		// disk may be different for different object templates. The raw
		// (unduplicated) value of LOADPATH can be used because it will not be
		// changed by the code below.
		SourceRepository repository = compiler.getSourceRepository();
		SourceFile source = repository.retrievePanSource(name,
				relativeLoadpaths);

		if (source.isAbsent()) {
			if (lookupOnly) {

				// Files that were searched for but not found are still
				// dependencies. Keep track of these so that they can be
				// included in the dependency file and checked when trying to
				// see if profiles are up-to-date.
				otherDependencies.add(source);
				return null;
			} else {

				// The lookupOnly flag was not set, so it is an error if the
				// template has not been found.
				throw EvaluationException.create((SourceRange) null,
						(BuildContext) this, MSG_CANNOT_LOCATE_TEMPLATE, name);
			}
		}

		// Now actually retrieve the other object's root, waiting if the
		// result isn't yet available.
		CompileCache ccache = compiler.getCompileCache();
		CompileResult cresult = ccache.waitForResult(source.getPath()
				.getAbsolutePath());

		Template template = null;
		try {
			// Extract the compiled template and ensure that the name is
			// correct. The template must not be null if no exception is thrown.
			template = cresult.template;
			template.templateNameVerification(name);

			// Found the template. Put this into the dependencies only if we're
			// really going to use it. I.e. if the lookupOnly flag is false.
			if (!lookupOnly) {
				dependencies.put(name, template);
				if (template.type == TemplateType.OBJECT) {
					objectDependencies.add(template.name);
				}
			}

		} catch (SyntaxException se) {

			// This can happen if there is a syntax error while including
			// the given template. If this isn't just a lookup, then convert
			// this into an evaluation exception
			// and throw it.
			if (!lookupOnly) {
				throw new EvaluationException(se.getMessage());
			} else {
				template = null;
			}

		} catch (EvaluationException ee) {

			// Eat the exception if we're only doing a lookup; otherwise,
			// rethrow it.
			if (!lookupOnly) {
				throw ee;
			} else {
				template = null;
			}

		}

		return template;
	}
104952
public I_CmsTemplateContextProvider getTemplateContextProvider(String providerName) {

        providerName = providerName.trim();
        providerName = removePropertyPrefix(providerName);
        String providerClassName = providerName;
        String providerConfig = "";

        // get provider configuration string if available
        int separatorIndex = providerName.indexOf(",");
        if (separatorIndex > 0) {
            providerClassName = providerName.substring(0, separatorIndex);
            providerConfig = providerName.substring(separatorIndex + 1);
        }

        I_CmsTemplateContextProvider result = m_providerInstances.get(providerName);
        if (result == null) {
            try {
                Class<?> providerClass = Class.forName(providerClassName);
                if (I_CmsTemplateContextProvider.class.isAssignableFrom(providerClass)) {
                    result = (I_CmsTemplateContextProvider)providerClass.newInstance();
                    result.initialize(m_cms, providerConfig);
                    //note: we use the provider name as a key here, which includes configuration parameters
                    m_providerInstances.put(providerName, result);
                }
            } catch (Throwable t) {
                LOG.error(t.getLocalizedMessage(), t);
            }
        }
        return result;
    }
1123975
protected CmsXmlContentProperty createTemplateContextsPropertyDefinition(
        I_CmsTemplateContextProvider contextProvider,
        Locale locale) {

        if (contextProvider == null) {
            return null;
        }
        List<String> contextOptions = new ArrayList<String>();
        for (CmsTemplateContext context : contextProvider.getAllContexts().values()) {
            contextOptions.add(context.getKey() + ":" + context.getLocalizedName(locale));
        }
        String widgetConfig = CmsStringUtil.listAsString(contextOptions, "|");

        String niceName = Messages.get().getBundle(locale).key(Messages.GUI_SETTING_TEMPLATE_CONTEXTS_NAME_0);
        String description = Messages.get().getBundle(locale).key(Messages.GUI_SETTING_TEMPLATE_CONTEXTS_DESCRIPTION_0);
        CmsXmlContentProperty propDef = new CmsXmlContentProperty(
            CmsTemplateContextInfo.SETTING,
            "string",
            "multicheck",
            widgetConfig,
            null,
            null,
            "",
            niceName,
            description,
            "",
            "false");
        return propDef;
    }
336672
protected WebContext createTemplateContext(RequestManager requestManager) {
        final HttpServletRequest request = requestManager.getRequest();
        final HttpServletResponse response = requestManager.getResponseManager().getResponse();
        final ServletContext servletContext = request.getServletContext();
        final Locale locale = requestManager.getUserLocale();
        return new WebContext(request, response, servletContext, locale);
    }
147377
private static void initURLTemplates( ServletContext servletContext )
    {
        TemplatedURLFormatter formatter = TemplatedURLFormatter.getTemplatedURLFormatter( servletContext );
        if ( formatter == null )
        {
            // get the default template formatter class name from the config file
            formatter = getTemplatedURLFormatter();

            assert formatter != null : "Found a non-null URL formatter";

            // set the TemplatedURLFormatter attribute on the context.
            TemplatedURLFormatter.initServletContext( servletContext, formatter );
        }

        URLTemplatesFactory templatesFactory = URLTemplatesFactory.getURLTemplatesFactory( servletContext );
        if ( templatesFactory == null )
        {
            // URLTemplatesFactory has not been initialized,
            // get a URLTemplatesFactory object from the containerAdapter.
            templatesFactory = PageFlowUtils.createURLTemplatesFactory( servletContext );

            // get the known/req tokens from the default formatter for the factory to use to verify templates
            templatesFactory.setKnownTokens( formatter.getKnownTokens() );
            templatesFactory.setRequiredTokens( formatter.getRequiredTokens() );
            templatesFactory.load( servletContext );

            // set the URLTemplatesFactory attribute on the context.
            URLTemplatesFactory.initServletContext( servletContext, templatesFactory );
        }
    }
605308
protected FaceletFactory createFaceletFactory(FacesContext context, Compiler compiler)
    {
        ExternalContext eContext = context.getExternalContext();

        // refresh period
        long refreshPeriod;
        if (context.isProjectStage(ProjectStage.Production))
        {
            refreshPeriod = WebConfigParamUtils.getLongInitParameter(eContext, PARAMS_REFRESH_PERIOD,
                    DEFAULT_REFRESH_PERIOD_PRODUCTION);
        }
        else
        {
            refreshPeriod = WebConfigParamUtils.getLongInitParameter(eContext, PARAMS_REFRESH_PERIOD,
                    DEFAULT_REFRESH_PERIOD);
        }

        // resource resolver
        ResourceResolver resolver = new DefaultResourceResolver();
        ArrayList<String> classNames = new ArrayList<String>();
        String faceletsResourceResolverClassName = WebConfigParamUtils.getStringInitParameter(eContext,
                PARAMS_RESOURCE_RESOLVER, null);
        List<String> resourceResolversFromAnnotations = RuntimeConfig.getCurrentInstance(
            context.getExternalContext()).getResourceResolvers();
        if (faceletsResourceResolverClassName != null)
        {
            classNames.add(faceletsResourceResolverClassName);
        }
        if (!resourceResolversFromAnnotations.isEmpty())
        {
            classNames.addAll(resourceResolversFromAnnotations);
        }
        if (!classNames.isEmpty())
        {
            resolver = ClassUtils.buildApplicationObject(ResourceResolver.class, classNames, resolver);
        }

        _resourceResolver = resolver;

        return new DefaultFaceletFactory(compiler, resolver, refreshPeriod);
    }
1245457
protected IContext makeContext()
	{
		final HttpCallContext http = HttpCallContext.peek();

		if (http != null)
		{
			return new WebContext(http.getRequest(), http.getResponse(), http.getServletContext(), http.getRequest().getLocale());
		}
		else
		{
			return new Context();
		}
	}
632813
private Node createTemplateNode() {
    // The Node type choice is arbitrary.
    Node templateNode = new Node(Token.SCRIPT);
    templateNode.setStaticSourceFile(sourceFile);
    return templateNode;
  }
314320
@SuppressWarnings("resource")
	@Override
	public Reader createResource(GeneratorContext context) {

		String path = context.getPath();
		StopWatch stopWatch = null;
		if (PERF_LOGGER.isDebugEnabled()) {
			stopWatch = new StopWatch("Generating resource '" + path + "' with " + getName() + " generator");
			stopWatch.start();
		}

		Reader rd = null;
		if (useCache) {
			List<FilePathMapping> fMappings = linkedResourceMap.get(getResourceCacheKey(path, context));
			if (fMappings != null && !checkResourcesModified(context, fMappings)) {
				// Retrieve from cache
				// Checks if temp resource is already created
				if (context.isProcessingBundle()) {

					if (cacheMode.equals(CacheMode.PROD) || cacheMode.equals(CacheMode.ALL)) {
						rd = retrieveFromCache(path, context, CacheMode.PROD);
					}
				} else {
					if (cacheMode.equals(CacheMode.DEBUG) || cacheMode.equals(CacheMode.ALL)) {
						rd = retrieveFromCache(path, context, CacheMode.DEBUG);
					}
				}
				
				// Update the file path mapping
				addLinkedResources(path, context, fMappings);
			}
		}

		if (rd == null) {

			rd = generateResource(path, context);
			if (useCache) {

				if (rd != null) {
					if (cacheMode.equals(CacheMode.PROD) || cacheMode.equals(CacheMode.ALL)) {
						rd = createTempResource(context, CacheMode.PROD, rd);
					}
				}
			}
			if (context.isProcessingBundle()) {
				if (useCache && (cacheMode.equals(CacheMode.DEBUG) || cacheMode.equals(CacheMode.ALL))) {
					// Create debug cache while processing bundle if cache is
					// allowed in debug
					String content = null;
					try {
						content = IOUtils.toString(rd);
					} catch (IOException e) {
						throw new BundlingProcessException(e);
					}
					Reader dRd = generateResourceForDebug(new StringReader(content), context);
					createTempResource(context, CacheMode.DEBUG, dRd);
					rd = new StringReader(content);
				}
			} else {
				rd = generateResourceForDebug(rd, context);
				if (useCache && (cacheMode.equals(CacheMode.DEBUG) || cacheMode.equals(CacheMode.ALL))) {
					rd = createTempResource(context, CacheMode.DEBUG, rd);
				}
			}
		}

		if (PERF_LOGGER.isDebugEnabled()) {
			stopWatch.stop();
			PERF_LOGGER.debug(stopWatch.shortSummary());
		}

		return rd;
	}