001package io.jstach.opt.spring.example.hello; 002 003/** 004 * Generated Renderer. 005 */ 006// @javax.annotation.Generated("io.jstach.apt.GenerateRendererProcessor") 007public class HelloModelAndViewView implements io.jstach.jstachio.Template.EncodedTemplate<io.jstach.opt.spring.example.hello.HelloModelAndView>, 008 io.jstach.jstachio.spi.TemplateProvider, 009 io.jstach.jstachio.spi.JStachioFilter.FilterChain { 010 /** 011 * Template path. 012 * @hidden 013 */ 014 public static final String TEMPLATE_PATH = "templates/hello.mustache"; 015 016 /** 017 * Inline template string copied. 018 * @hidden 019 */ 020 021 public static final String TEMPLATE_STRING = ""; 022 023 /** 024 * Template name. Do not rely on this. 025 * @hidden 026 */ 027 public static final String TEMPLATE_NAME = "io.jstach.opt.spring.example.hello.HelloModelAndViewView"; 028 029 /** 030 * Template charset. 031 * @hidden 032 */ 033 public static final java.nio.charset.Charset TEMPLATE_CHARSET = java.nio.charset.StandardCharsets.UTF_8; 034 035 /** 036 * Template mediaType. 037 * @hidden 038 */ 039 public static final String TEMPLATE_MEDIA_TYPE = "text/html"; 040 041 /** 042 * The models class. Use {@link #modelClass()} instead. 043 * @hidden 044 */ 045 public static final Class<?> MODEL_CLASS = io.jstach.opt.spring.example.hello.HelloModelAndView.class; 046 047 /** 048 * The instance. Use {@link {@link #of()} instead. 049 * @hidden 050 */ 051 private static final HelloModelAndViewView INSTANCE = new HelloModelAndViewView(); 052 053 /** 054 * Formatter. 055 * @hidden 056 */ 057 private final io.jstach.jstachio.Formatter formatter; 058 059 /** 060 * Escaper. 061 * @hidden 062 */ 063 private final io.jstach.jstachio.Escaper escaper; 064 065 /** 066 * Renderer constructor for manual wiring. 067 * @param formatter formatter if null the static formatter will be used. 068 * @param escaper escaper if null the static escaper will be used 069 */ 070 public HelloModelAndViewView( 071 java.util.function./* @Nullable */ Function</* @Nullable */ Object, String> formatter, 072 java.util.function./* @Nullable */ Function<String, String> escaper) { 073 super(); 074 this.formatter = __formatter(formatter); 075 this.escaper = __escaper(escaper); 076 } 077 078 private static io.jstach.jstachio.Formatter __formatter(java.util.function./* @Nullable */ Function</* @Nullable */ Object, String> formatter) { 079 return io.jstach.jstachio.Formatter.of(formatter != null ? formatter : io.jstach.jstachio.formatters.DefaultFormatter.provider()); 080 } 081 082 private static io.jstach.jstachio.Escaper __escaper(java.util.function./* @Nullable */ Function<String, String> escaper) { 083 return io.jstach.jstachio.Escaper.of(escaper != null ? escaper : io.jstach.jstachio.escapers.Html.provider()); 084 } 085 086 /** 087 * Renderer constructor for reflection (use of() instead). 088 * For programmatic consider using {@link #of()} for a shared singleton. 089 */ 090 public HelloModelAndViewView() { 091 this(null, null); 092 } 093 094 @Override 095 public StringBuilder execute(io.jstach.opt.spring.example.hello.HelloModelAndView model, StringBuilder sb) { 096 render(model, io.jstach.jstachio.Output.of(sb), this.formatter, this.escaper, templateAppender()); 097 return sb; 098 } 099 100 @Override 101 public <A extends io.jstach.jstachio.Output<E>, E extends Exception> A execute( 102 io.jstach.opt.spring.example.hello.HelloModelAndView model, 103 A a) throws E { 104 render(model, a, this.formatter, this.escaper, templateAppender()); 105 return a; 106 } 107 108 /** 109 * Renders the passed in model. 110 * @param <A> appendable type. 111 * @param <E> error type. 112 * @param model a model assumed never to be <code>null</code>. 113 * @param a appendable to write to. 114 * @param formatter formats variables before they are passed to the escaper 115 * @param escaper used to write escaped variables 116 * @throws E if an error occurs while writing to the appendable 117 */ 118 protected <A extends io.jstach.jstachio.Output<E>, E extends Exception> void execute( 119 io.jstach.opt.spring.example.hello.HelloModelAndView model, 120 A a, 121 io.jstach.jstachio.Formatter formatter, 122 io.jstach.jstachio.Escaper escaper) throws E { 123 render(model, a, formatter, escaper, templateAppender()); 124 } 125 126 @Override 127 public <A extends io.jstach.jstachio.Output.EncodedOutput<E>, E extends Exception> A write( 128 io.jstach.opt.spring.example.hello.HelloModelAndView model, 129 A outputStream) throws E { 130 encode(model, outputStream, this.formatter, this.escaper, templateAppender()); 131 return outputStream; 132 } 133 134 @Override 135 public boolean supportsType(Class<?> type) { 136 return MODEL_CLASS.isAssignableFrom(type); 137 } 138 139 /** 140 * Needed for jstachio runtime. 141 * @hidden 142 */ 143 @Override 144 public java.util.List<io.jstach.jstachio.Template<?>> provideTemplates(io.jstach.jstachio.TemplateConfig templateConfig ) { 145 return java.util.List.of(io.jstach.jstachio.TemplateConfig.empty() == templateConfig ? INSTANCE : new HelloModelAndViewView(templateConfig)); 146 } 147 148 @Override 149 public String templatePath() { 150 return TEMPLATE_PATH; 151 } 152 @Override 153 public String templateName() { 154 return TEMPLATE_NAME; 155 } 156 @Override 157 public java.nio.charset.Charset templateCharset() { 158 return TEMPLATE_CHARSET; 159 } 160 @Override 161 public String templateMediaType() { 162 return TEMPLATE_MEDIA_TYPE; 163 } 164 @Override 165 public String templateString() { 166 return TEMPLATE_STRING; 167 } 168 @Override 169 public Class<?> templateContentType() { 170 return io.jstach.jstachio.escapers.Html.class; 171 } 172 @Override 173 public io.jstach.jstachio.Escaper templateEscaper() { 174 return this.escaper; 175 } 176 177 @Override 178 public io.jstach.jstachio.Formatter templateFormatter() { 179 return this.formatter; 180 } 181 182 /** 183 * Appender. 184 * @return appender for writing unescaped variables. 185 */ 186 public io.jstach.jstachio.Appender templateAppender() { 187 return io.jstach.jstachio.Appender.defaultAppender(); 188 } 189 190 /** 191 * Model class. 192 * @return class used as model (annotated with JStache). 193 */ 194 @Override 195 public Class<?> modelClass() { 196 return MODEL_CLASS; 197 } 198 199 /** 200 * Needed for jstachio runtime. 201 * @hidden 202 */ 203 @Override 204 public void process(Object model, Appendable appendable) throws java.io.IOException { 205 execute( (io.jstach.opt.spring.example.hello.HelloModelAndView) model, appendable); 206 } 207 208 /** 209 * Needed for jstachio runtime. 210 * @hidden 211 */ 212 @Override 213 public boolean isBroken(Object model) { 214 return !supportsType(model.getClass()); 215 } 216 217 /** 218 * Renderer constructor using config. 219 * @param templateConfig config that has collaborators 220 */ 221 public HelloModelAndViewView(io.jstach.jstachio.TemplateConfig templateConfig) { 222 this(templateConfig.formatter(), templateConfig.escaper()); 223 } 224 225 /** 226 * Convience static factory that will reuse the same singleton instance. 227 * @return renderer same as calling no-arg constructor but is cached with singleton instance 228 */ 229 public static HelloModelAndViewView of() { 230 return INSTANCE; 231 } 232 233 /** 234 * Renders the passed in model. 235 * @param <A> appendable type. 236 * @param <E> error type. 237 * @param data model 238 * @param unescapedWriter appendable to write to. 239 * @param formatter formats variables before they are passed to the escaper. 240 * @param escaper used to write escaped variables. 241 * @param appender used to write unescaped variables. 242 * @throws E if an error occurs while writing to the appendable 243 */ 244 public static <A extends io.jstach.jstachio.Output<E>, E extends Exception> void render( 245 io.jstach.opt.spring.example.hello.HelloModelAndView data, 246 A unescapedWriter, 247 io.jstach.jstachio.Formatter formatter, 248 io.jstach.jstachio.Appender escaper, 249 io.jstach.jstachio.Appender appender) throws E { 250 251 unescapedWriter.append( 252 "<!doctype html>\n" + 253 "<html lang=\"en\">\n" + 254 " <head>\n" + 255 " <meta charset=\"utf-8\">\n" + 256 " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" + 257 " <link rel=\"stylesheet\" href=\"https://unpkg.com/@picocss/pico@latest/css/pico.min.css\">\n" + 258 " <title>Hello, "); 259 260 // variable: message 261 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 262 /* TypeMirror: java.lang.String */ 263 formatter.format(escaper, unescapedWriter, "message", data.message()); 264 265 unescapedWriter.append( 266 "!</title>\n" + 267 " </head>\n" + 268 " <body>\n" + 269 " <main class=\"container\">\n" + 270 " <h1>"); 271 272 // variable: message 273 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 274 /* TypeMirror: java.lang.String */ 275 formatter.format(escaper, unescapedWriter, "message", data.message()); 276 277 unescapedWriter.append( 278 "</h1>\n" + 279 " </main>\n" + 280 " </body>\n" + 281 "</html>"); 282 283 284 } 285 286 /** 287 * Renders to an OutputStream use pre-encoded parts of the template. 288 * @param <A> output type. 289 * @param <E> error type. 290 * @param data model 291 * @param unescapedWriter stream to write to. 292 * @param formatter formats variables before they are passed to the escaper. 293 * @param escaper used to write escaped variables. 294 * @param appender used to write unescaped variables. 295 * @throws E if an error occurs while writing to the appendable 296 */ 297 protected static <A extends io.jstach.jstachio.Output.EncodedOutput<E>, E extends Exception> void encode( 298 io.jstach.opt.spring.example.hello.HelloModelAndView data, 299 A unescapedWriter, 300 io.jstach.jstachio.Formatter formatter, 301 io.jstach.jstachio.Escaper escaper, 302 io.jstach.jstachio.Appender appender) throws E { 303 304 unescapedWriter.write(TEXT_0); 305 306 // variable: message 307 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 308 /* TypeMirror: java.lang.String */ 309 formatter.format(escaper, unescapedWriter, "message", data.message()); 310 311 unescapedWriter.write(TEXT_1); 312 313 // variable: message 314 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 315 /* TypeMirror: java.lang.String */ 316 formatter.format(escaper, unescapedWriter, "message", data.message()); 317 318 unescapedWriter.write(TEXT_2); 319 320 321 } 322 private static final byte[] TEXT_0 = ( 323 "<!doctype html>\n" + 324 "<html lang=\"en\">\n" + 325 " <head>\n" + 326 " <meta charset=\"utf-8\">\n" + 327 " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" + 328 " <link rel=\"stylesheet\" href=\"https://unpkg.com/@picocss/pico@latest/css/pico.min.css\">\n" + 329 " <title>Hello, ").getBytes(TEMPLATE_CHARSET); 330 private static final byte[] TEXT_1 = ( 331 "!</title>\n" + 332 " </head>\n" + 333 " <body>\n" + 334 " <main class=\"container\">\n" + 335 " <h1>").getBytes(TEMPLATE_CHARSET); 336 private static final byte[] TEXT_2 = ( 337 "</h1>\n" + 338 " </main>\n" + 339 " </body>\n" + 340 "</html>").getBytes(TEMPLATE_CHARSET); 341}