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