/** * The name that was actually used to load this template from the {@link TemplateLoader} (or from other custom * storage mechanism). This is what should be shown in error messages as the error location. This is usually the * same as {@link #getName()}, except when localized lookup, template acquisition ({@code *} step in the name), or * other {@link TemplateLookupStrategy} transforms the requested name ({@link #getName()}) to a different final * {@link TemplateLoader}-level name. For example, when you get a template with name {@code "foo.ftl"} then because * of localized lookup, it's possible that something like {@code "foo_en.ftl"} will be loaded behind the scenes. * While the template name will be still the same as the requested template name ({@code "foo.ftl"}), errors should * point to {@code "foo_de.ftl"}. Note that relative paths are always resolved relatively to the {@code name}, not * to the {@code sourceName}. * * @since 2.3.22 */ public String getSourceName() { return sourceName != null ? sourceName : getName(); }
private static InputSource createInputSource(String publicId, Template raw) throws IOException, SAXException { StringWriter sw = new StringWriter(); try { raw.process(Collections.EMPTY_MAP, sw); } catch (TemplateException e) { throw new SAXException(e); } InputSource is = new InputSource(); is.setPublicId(publicId); is.setSystemId(raw.getName()); is.setCharacterStream(new StringReader(sw.toString())); return is; }
DebugTemplateModel(Template template) { super(template); this.name = new SimpleScalar(template.getName()); }
@Override void registerTemplateSpi(Template template) { String templateName = template.getName(); synchronized (templateDebugInfos) { TemplateDebugInfo tdi = createTemplateDebugInfo(templateName); tdi.templates.add(new TemplateReference(templateName, template, refQueue)); // Inject already defined breakpoints into the template for (Iterator iter = tdi.breakpoints.iterator(); iter.hasNext(); ) { Breakpoint breakpoint = (Breakpoint) iter.next(); insertDebugBreak(template, breakpoint); } } }
public String getAsString() throws TemplateModelException { return resolvePath(getTemplate().getName()); }
if (template == null) return null; String name = template.getName(); if (name == null) return null;
static Template getTemplate(String systemId) throws IOException { Environment env = Environment.getCurrentEnvironment(); String encoding = env.getTemplate().getEncoding(); if (encoding == null) { encoding = env.getConfiguration().getEncoding(env.getLocale()); } String templatePath = env.getTemplate().getName(); int lastSlash = templatePath.lastIndexOf('/'); templatePath = lastSlash == -1 ? "" : templatePath.substring(0, lastSlash + 1); systemId = env.toFullTemplateName(templatePath, systemId); Template raw = env.getConfiguration().getTemplate(systemId, env.getLocale(), encoding, false); return raw; }
private void calculatePosition() { synchronized (lock) { if (!positionsCalculated) { // The expressions is the argument of the template element, so we prefer it as it's more specific. TemplateObject templateObject = blamedExpression != null ? (TemplateObject) blamedExpression : ( ftlInstructionStackSnapshot != null && ftlInstructionStackSnapshot.length != 0 ? ftlInstructionStackSnapshot[0] : null); // Line number blow 0 means no info, negative means position in ?eval-ed value that we won't use here. if (templateObject != null && templateObject.getBeginLine() > 0) { final Template template = templateObject.getTemplate(); templateName = template != null ? template.getName() : null; templateSourceName = template != null ? template.getSourceName() : null; lineNumber = Integer.valueOf(templateObject.getBeginLine()); columnNumber = Integer.valueOf(templateObject.getBeginColumn()); endLineNumber = Integer.valueOf(templateObject.getEndLine()); endColumnNumber = Integer.valueOf(templateObject.getEndColumn()); } positionsCalculated = true; deleteFTLInstructionStackSnapshotIfNotNeeded(); } } }
@Override public void render(final View view, final Renderer.Context ctx) throws Exception { String name = view.name() + suffix; Template template = template(name, ctx.charset()); Map<String, Object> hash = new HashMap<>(); hash.put("_vname", view.name()); hash.put("_vpath", template.getName()); hash.put("xss", xss); // Locale: Locale locale = (Locale) hash.getOrDefault("locale", ctx.locale()); hash.putIfAbsent("locale", locale); // locals Map<String, Object> locals = ctx.locals(); hash.putAll(locals); // model hash.putAll(view.model()); TemplateModel model = new SimpleHash(hash, new FtlWrapper(freemarker.getObjectWrapper())); // TODO: remove string writer StringWriter writer = new StringWriter(); // Locale: template.setLocale(locale); // output template.process(model, writer); ctx.type(MediaType.html) .send(writer.toString()); }
@Advice.OnMethodEnter(inline = false) public static void onBeforeEvaluate(@Advice.Argument(0) Environment env, @Advice.This Expression dot) { Profiler.start(env.getCurrentTemplate().getName() + ':' + dot.getBeginLine() + '#' + dot.toString()); }
templateName = loadedTemplate.getName(); } else { lazyImport = true;
? new SimpleScalar(env.getTemplate230().getName()) : new SimpleScalar(env.getTemplate().getName()); return SimpleScalar.newInstanceOrNull(env.getMainTemplate().getName()); return SimpleScalar.newInstanceOrNull(env.getCurrentTemplate().getName()); String name = callPlace != null ? callPlace.getTemplate().getName() : null; return name != null ? new SimpleScalar(name) : TemplateScalarModel.EMPTY_STRING;
@Override TemplateElement[] accept(Environment env) throws TemplateException, IOException { final String importedTemplateName = importedTemplateNameExp.evalAndCoerceToPlainText(env); final String fullImportedTemplateName; try { fullImportedTemplateName = env.toFullTemplateName(getTemplate().getName(), importedTemplateName); } catch (MalformedTemplateNameException e) { throw new _MiscTemplateException(e, env, "Malformed template name ", new _DelayedJQuote(e.getTemplateName()), ":\n", e.getMalformednessDescription()); } try { env.importLib(fullImportedTemplateName, targetNsVarName); } catch (IOException e) { throw new _MiscTemplateException(e, env, "Template importing failed (for parameter value ", new _DelayedJQuote(importedTemplateName), "):\n", new _DelayedGetMessage(e)); } return null; }
final String fullIncludedTemplateName; try { fullIncludedTemplateName = env.toFullTemplateName(getTemplate().getName(), includedTemplateName); } catch (MalformedTemplateNameException e) { throw new _MiscTemplateException(e, env,
absTemplateName = env.toFullTemplateName(env.getCurrentTemplate().getName(), templateName); } catch (MalformedTemplateNameException e) { throw new _TemplateModelException(
public static void processTemplate(Template template,Object model,Writer out) throws FreemarkerTemplateException { try { template.process(model, out); } catch (IOException e) { throw new FreemarkerTemplateException("process template occer IOException,templateName:"+template.getName(),e); } catch (TemplateException e) { throw new FreemarkerTemplateException("process template occer TemplateException,templateName:"+template.getName(),e); } }
public TemplateDefinition(TemplateDirectiveBody body, Environment env) { this.body = body; this.env = env; this.templateName = env.getTemplate().getName(); }
JAXBContext jaxbContext = JAXBContext.newInstance(UserAgent.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); // pase file, url , inputstream , string whatever you have. UserAgent userAgent = (UserAgent) jaxbUnmarshaller.unmarshal(file); //getting <template> data from last <support> tag List<Template> templates = userAgent.getSupport().get(3).getTemplate(); for (Template template : templates) { String wantToSeeTempalteData = String.format( "Tempalt [name:%s , default:%s content:%s ]", new Object[] { template.getName(),template.getDefault(), template.getContent() }); System.out.println(wantToSeeTempalteData); }
@Advice.OnMethodEnter(inline = false) public static void onBeforeEvaluate(@Advice.Argument(0) Environment env, @Advice.This Expression dot) { Profiler.start(env.getCurrentTemplate().getName() + ':' + dot.getBeginLine() + '#' + dot.toString()); }