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 * Standalone servlet companion of the {@link FreemarkerMixin} mixin.
024 *
025 * <p>
026 * Mounts as a <b>sibling top-level servlet</b> at {@code /freemarker/*} and renders raw FreeMarker
027 * templates by delegating to a shared {@link FreemarkerDispatcher} worker &mdash; the same
028 * flavor-neutral {@link RawTemplateDispatcher} implementation the mixin and child flavors hold, so
029 * the forms cannot drift.
030 *
031 * <p>
032 * Whereas the {@link FreemarkerMixin} mixin pins its op at {@code /freemarker/*} for
033 * composition into a host at {@code /}, this companion declares the mount at the class level
034 * ({@link Rest#paths() @Rest(paths="/freemarker/*")}) and inherits the {@code /*} op from
035 * {@link ViewServlet}.
036 *
037 * <h5 class='section'>See Also:</h5><ul>
038 *    <li class='jc'>{@link FreemarkerMixin}
039 *    <li class='jc'>{@link ViewServlet}
040 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/FreemarkerViewSupport">FreeMarker View Support</a>
041 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerComposition">REST Server — Mixins and Multi-Mount Paths</a>
042 * </ul>
043 *
044 * @serial exclude
045 * @since 10.0.0
046 */
047@Rest(
048   paths="/freemarker/*",
049   responseProcessors={FreemarkerViewRenderer.class}
050)
051public class FreemarkerServlet extends ViewServlet {
052
053   private static final long serialVersionUID = 1L;
054
055   private final transient FreemarkerDispatcher worker;
056
057   /** No-arg constructor &mdash; uses a default {@link FreemarkerDispatcher} worker. */
058   public FreemarkerServlet() {
059      this(FreemarkerDispatcher.create().build());
060   }
061
062   /**
063    * Worker constructor.
064    *
065    * @param worker The shared flavor-neutral FreeMarker dispatcher this servlet delegates raw
066    *    dispatch to. Must not be {@code null}.
067    */
068   protected FreemarkerServlet(FreemarkerDispatcher worker) {
069      this.worker = worker;
070   }
071
072   @Override /* ViewServlet */
073   protected RawTemplateDispatcher dispatcher() {
074      return worker;
075   }
076}