渲染模板

@param templateContent {@link Template}
@param bindingMap 绑定参数
@param writer {@link Writer} 渲染后写入的目标Writer
@return {@link Writer}
187151
public static Writer render(Template templateContent, Map<String, Object> bindingMap, Writer writer) {
		templateContent.binding(bindingMap);
		templateContent.renderTo(writer);
		return writer;
	}
1218659
public static <T> Writer<Params<T>> writer(final Writer<? super T> writer) {
		return elem(
			"params",
			attr("name").map(Params::getName),
			elems("param", writer)
		);
	}
642156
public static String renderTemplate(
        CmsObject cms,
        String template,
        CmsJspContentAccessBean content,
        Map<String, Object> contextObjects) {

        STGroup group = new STGroup('%', '%');
        group.registerRenderer(Date.class, new DateRenderer());
        CompiledST cST = group.defineTemplate("main", template);
        cST.addArg(new FormalArgument("content"));
        if (contextObjects != null) {
            for (Entry<String, Object> entry : contextObjects.entrySet()) {
                cST.addArg(new FormalArgument(entry.getKey()));
            }
        }
        ST st = group.getInstanceOf("main");
        st.add("content", content);
        if (contextObjects != null) {
            for (Entry<String, Object> entry : contextObjects.entrySet()) {
                st.add(entry.getKey(), entry.getValue());
            }
        }
        return st.render(cms.getRequestContext().getLocale());
    }
1213359
public static String get(final String templateName, final Map<String, Object> data) {
        StringWriter writer = new StringWriter();
        write(templateName, data, writer);
        return writer.toString();
    }
1238746
public int writeTemplateEntry(String template, Object entry) {
        int returnCode = htod.writeTemplateEntry(template, entry);
        if (returnCode == HTODDynacache.DISK_EXCEPTION) {
            stopOnError(this.htod.diskCacheException);
        }
        return returnCode;
    }
1157173
function View(template) {
  this.context = null;
  if (!template) template = this;
  this.template = template;
  if (!this.template.bindings) this.template.bindings = [];
  this.bindings = this.template.bindings.map(mapBinding.bind(this), this);

  this.firstViewNode = this.firstChild;
  this.lastViewNode = this.lastChild;
  if (this.firstViewNode) {
    this.firstViewNode.view = this;
    this.lastViewNode.view = this;
  }
}
1354037
public void parseAndProcess(
            final TemplateSpec templateSpec,
            final IContext context,
            final Writer writer) {

        Validate.notNull(templateSpec, "Template Specification cannot be null");
        Validate.notNull(context, "Context cannot be null");
        Validate.notNull(writer, "Writer cannot be null");


        // TemplateSpec will already have validated its contents, so need to do it here (template selectors,
        // resolution attributes, etc.)

        final String template = templateSpec.getTemplate();
        final Set<String> templateSelectors = templateSpec.getTemplateSelectors();
        final TemplateMode templateMode = templateSpec.getTemplateMode();
        final Map<String, Object> templateResolutionAttributes = templateSpec.getTemplateResolutionAttributes();

        final TemplateCacheKey cacheKey =
                    new TemplateCacheKey(
                            null, // ownerTemplate
                            template, templateSelectors,
                            0, 0, // lineOffset, colOffset
                            templateMode,
                            templateResolutionAttributes);


        /*
         * First look at the cache - it might be already cached
         */
        if (this.templateCache != null) {

            final TemplateModel cached =  this.templateCache.get(cacheKey);

            if (cached != null) {

                final IEngineContext engineContext =
                        EngineContextManager.prepareEngineContext(this.configuration, cached.getTemplateData(), templateResolutionAttributes, context);

                /*
                 * Create the handler chain to process the data.
                 * This is PARSE + PROCESS, so its called from the TemplateEngine, and the only case in which we should apply
                 * both pre-processors and post-processors (besides creating a last output-to-writer step)
                 */
                final ProcessorTemplateHandler processorTemplateHandler = new ProcessorTemplateHandler();
                final ITemplateHandler processingHandlerChain =
                        createTemplateProcessingHandlerChain(engineContext, true, true, processorTemplateHandler, writer);

                cached.process(processingHandlerChain);

                EngineContextManager.disposeEngineContext(engineContext);

                return;

            }

        }


        /*
         * Resolve the template
         */
        final TemplateResolution templateResolution =
                resolveTemplate(this.configuration, null, template, templateResolutionAttributes, true);


        /*
         * Build the TemplateData object
         */
        final TemplateData templateData =
                buildTemplateData(templateResolution, template, templateSelectors, templateMode, true);


        /*
         * Prepare the context instance that corresponds to this execution of the template engine
         */
        final IEngineContext engineContext =
                EngineContextManager.prepareEngineContext(this.configuration, templateData, templateResolutionAttributes, context);


        /*
         * Create the handler chain to process the data.
         * This is PARSE + PROCESS, so its called from the TemplateEngine, and the only case in which we should apply
         * both pre-processors and post-processors (besides creating a last output-to-writer step)
         */
        final ProcessorTemplateHandler processorTemplateHandler = new ProcessorTemplateHandler();
        final ITemplateHandler processingHandlerChain =
                createTemplateProcessingHandlerChain(engineContext, true, true, processorTemplateHandler, writer);


        /*
         * Obtain the parser
         */
        final ITemplateParser parser = getParserForTemplateMode(engineContext.getTemplateMode());


        /*
         * If the resolved template is cacheable, so we will first read it as an object, cache it, and then process it
         */
        if (templateResolution.getValidity().isCacheable() && this.templateCache != null) {

            // Create the handler chain to create the Template object
            final ModelBuilderTemplateHandler builderHandler = new ModelBuilderTemplateHandler(this.configuration, templateData);

            // Process the template into a TemplateModel
            parser.parseStandalone(
                    this.configuration,
                    null, template, templateSelectors, templateData.getTemplateResource(),
                    engineContext.getTemplateMode(), templateResolution.getUseDecoupledLogic(), builderHandler);

            // Obtain the TemplateModel
            final TemplateModel templateModel = builderHandler.getModel();

            // Put the new template into cache
            this.templateCache.put(cacheKey, templateModel);

            // Process the read (+cached) template itself
            templateModel.process(processingHandlerChain);

        } else {

            //  Process the template, which is not cacheable (so no worry about caching)
            parser.parseStandalone(
                    this.configuration,
                    null, template, templateSelectors, templateData.getTemplateResource(),
                    engineContext.getTemplateMode(), templateResolution.getUseDecoupledLogic(),  processingHandlerChain);

        }


        /*
         * Dispose the engine context now that processing has been done
         */
        EngineContextManager.disposeEngineContext(engineContext);


    }
1235107
public static PredicateTemplate predicateTemplate(String template, Object... args) {
        return predicateTemplate(TemplateFactory.DEFAULT.create(template), ImmutableList.copyOf(args));
    }
1280640
public void render(final Writer writer) throws GitChangelogRepositoryException {
    final MustacheFactory mf = new DefaultMustacheFactory();
    final String templateContent = checkNotNull(getTemplateContent(), "No template!");
    final StringReader reader = new StringReader(templateContent);
    final Mustache mustache = mf.compile(reader, this.settings.getTemplatePath());
    try {
      final boolean useIntegrationIfConfigured = shouldUseIntegrationIfConfigured(templateContent);
      final Changelog changelog = this.getChangelog(useIntegrationIfConfigured);
      mustache
          .execute(
              writer, //
              new Object[] {changelog, this.settings.getExtendedVariables()} //
              )
          .flush();
    } catch (final IOException e) {
      // Should be impossible!
      throw new GitChangelogRepositoryException("", e);
    }
  }
916481
private void outputInterfaceField(GinjectorBindings bindings, SourceWriteUtil sourceWriteUtil,
      SourceWriter writer) {

    // Only the root injector has an interface binding.
    if (bindings.getParent() != null) {
      return;
    }

    Class<?> boundGinjectorInterface = getBoundGinjector(bindings);

    if (boundGinjectorInterface == null) {
      // Sanity-check: if this fails, then we somehow didn't bind the injector
      // interface in the root module (the root module should always generate a
      // binding for the injector).
      errorManager.logError("Injector interface not bound in the root module.");
      return;
    }

    NameGenerator nameGenerator = bindings.getNameGenerator();
    String fieldName = nameGenerator.getGinjectorInterfaceFieldName();
    String getterName = nameGenerator.getGinjectorInterfaceGetterMethodName();

    writer.beginJavaDocComment();
    writer.print("The implementation of " + boundGinjectorInterface);
    writer.endJavaDocComment();
    writer.println("private final %s %s;", boundGinjectorInterface.getCanonicalName(), fieldName);

    sourceWriteUtil.writeMethod(writer,
        String.format("public %s %s()", boundGinjectorInterface.getCanonicalName(), getterName),
        String.format("return %s;", fieldName));
  }
1108055
private Object writeMapSimple(SerIterator itemIterator) {
        Map<String, Object> result = new LinkedHashMap<>();
        StringConverter<Object> keyConverter = settings.getConverter().findConverterNoGenerics(itemIterator.keyType());
        while (itemIterator.hasNext()) {
            itemIterator.next();
            Object key = itemIterator.key();
            if (key == null) {
                throw new IllegalArgumentException("Unable to write map key as it cannot be null");
            }
            String str = keyConverter.convertToString(itemIterator.key());
            if (str == null) {
                throw new IllegalArgumentException("Unable to write map key as it cannot be a null string");
            }
            result.put(str, writeObject(itemIterator.valueType(), itemIterator.value(), itemIterator));
        }
        return result;
    }
572071
public static String compile(String path, String templateName, Map<String, Object> input) {
		try {
			Template template = getConfig(path).getTemplate(templateName);
			StringWriter writer = new StringWriter();
			template.process(input, writer);
			return writer.toString();
		} catch (Exception e) {
			JK.throww(e);
			return null;
		}

	}
80261
public static String merge(String templateContent, VelocityContext context) {
		final StringWriter writer = new StringWriter();
		try {
			Velocity.evaluate(context, writer, IdUtil.randomUUID(), templateContent);
		} catch (Exception e) {
			throw new UtilException(e);
		}
		return writer.toString();
	}
97745
protected void process(Template template, Object dataModel, Writer writer) {
    try {
      template.process(dataModel, writer);
    } catch (IOException e) {
      throw new GenException(Message.DOMAGEN9001, e, e);
    } catch (TemplateException e) {
      throw new GenException(Message.DOMAGEN9001, e, e);
    }
  }
1328969
public void formatWriter(File templateDir, String templateName,
			Object aBindMap, String dateFormat, Writer writer)
			throws IOException, FormatException
	{
		// TODO Auto-generated method stub

	}
27075
@Override
	public void onEndPage(final PdfWriter writer, final Document document) {
		final int pageN = writer.getPageNumber();
		final String text = pageN + " / ";
		final float len = bf.getWidthPoint(text, 8);
		cb.beginText();
		cb.setFontAndSize(bf, 8);
		final float width = document.getPageSize().getWidth();
		cb.setTextMatrix(width / 2, 30);
		cb.showText(text);
		cb.endText();
		cb.addTemplate(template, width / 2 + len, 30);
	}
536501
@Override
    public void write(final Writer writer) throws ConfigurationException, IOException {
        Preconditions.checkNotNull(writer);

        @SuppressWarnings("unchecked") final
        HashMap<String, Object> settings = (HashMap<String, Object>) fromNode(this.getModel().getInMemoryRepresentation());
        this.mapper.writerWithDefaultPrettyPrinter().writeValue(writer, settings);
    }