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.freemarker;
018
019import org.apache.juneau.rest.server.*;
020import org.apache.juneau.rest.server.view.*;
021
022/**
023 * Child-resource flavor of the {@link FreemarkerMixin} mixin.
024 *
025 * <p>
026 * Mounts as a <b>routed child</b> via {@link Rest#children() @Rest(children=FreemarkerResource.class)}
027 * under a parent at the subtree {@code /freemarker} and renders raw FreeMarker templates by delegating to
028 * a shared {@link FreemarkerDispatcher} worker &mdash; the same flavor-neutral {@link RawTemplateDispatcher}
029 * implementation the {@link FreemarkerMixin mixin} and {@link FreemarkerServlet servlet} flavors hold, so the
030 * three forms cannot drift.
031 *
032 * <h5 class='section'>See Also:</h5><ul>
033 *    <li class='jc'>{@link FreemarkerMixin}
034 *    <li class='jc'>{@link FreemarkerServlet}
035 *    <li class='jc'>{@link ViewResource}
036 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/FreemarkerViewSupport">FreeMarker 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="/freemarker",
044   responseProcessors={FreemarkerViewRenderer.class}
045)
046public class FreemarkerResource extends ViewResource {
047
048   private final FreemarkerDispatcher worker;
049
050   /** No-arg constructor &mdash; uses a default {@link FreemarkerDispatcher} worker. */
051   public FreemarkerResource() {
052      this(FreemarkerDispatcher.create().build());
053   }
054
055   /**
056    * Worker constructor.
057    *
058    * @param worker The shared flavor-neutral FreeMarker dispatcher this child delegates raw dispatch
059    *    to. Must not be {@code null}.
060    */
061   protected FreemarkerResource(FreemarkerDispatcher worker) {
062      this.worker = worker;
063   }
064
065   @Override /* ViewResource */
066   protected RawTemplateDispatcher dispatcher() {
067      return worker;
068   }
069}