001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.rest.server.view.thymeleaf;
018
019import org.apache.juneau.rest.server.*;
020import org.apache.juneau.rest.server.view.*;
021
022/**
023 * Child-resource flavor of the {@link ThymeleafMixin} mixin.
024 *
025 * <p>
026 * Mounts as a <b>routed child</b> via {@link Rest#children() @Rest(children=ThymeleafResource.class)}
027 * under a parent at the subtree {@code /thymeleaf} and renders raw Thymeleaf templates by delegating to a
028 * shared {@link ThymeleafDispatcher} worker &mdash; the same flavor-neutral {@link RawTemplateDispatcher}
029 * implementation the {@link ThymeleafMixin mixin} and {@link ThymeleafServlet servlet} flavors hold, so the
030 * three forms cannot drift.
031 *
032 * <h5 class='section'>See Also:</h5><ul>
033 *    <li class='jc'>{@link ThymeleafMixin}
034 *    <li class='jc'>{@link ThymeleafServlet}
035 *    <li class='jc'>{@link ViewResource}
036 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/ThymeleafViewSupport">Thymeleaf View Support</a>
037 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerComposition">REST Server — Mixins and Multi-Mount Paths</a>
038 * </ul>
039 *
040 * @since 10.0.0
041 */
042@Rest(
043   path="/thymeleaf",
044   responseProcessors={ThymeleafViewRenderer.class}
045)
046public class ThymeleafResource extends ViewResource {
047
048   private final ThymeleafDispatcher worker;
049
050   /** No-arg constructor &mdash; uses a default {@link ThymeleafDispatcher} worker. */
051   public ThymeleafResource() {
052      this(ThymeleafDispatcher.create().build());
053   }
054
055   /**
056    * Worker constructor.
057    *
058    * @param worker The shared flavor-neutral Thymeleaf dispatcher this child delegates raw dispatch
059    *    to. Must not be {@code null}.
060    */
061   protected ThymeleafResource(ThymeleafDispatcher worker) {
062      this.worker = worker;
063   }
064
065   @Override /* ViewResource */
066   protected RawTemplateDispatcher dispatcher() {
067      return worker;
068   }
069}