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.mustache; 018 019import org.apache.juneau.rest.server.*; 020import org.apache.juneau.rest.server.view.*; 021 022/** 023 * Standalone servlet companion of the {@link MustacheMixin} mixin. 024 * 025 * <p> 026 * Mounts as a <b>sibling top-level servlet</b> at {@code /mustache/*} and renders raw Mustache 027 * templates by delegating to a shared {@link MustacheDispatcher} worker — 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 MustacheMixin} mixin pins its op at {@code /mustache/*} for composition 033 * into a host at {@code /}, this companion declares the mount at the class level 034 * ({@link Rest#paths() @Rest(paths="/mustache/*")}) and inherits the {@code /*} op from 035 * {@link ViewServlet}. 036 * 037 * <h5 class='section'>See Also:</h5><ul> 038 * <li class='jc'>{@link MustacheMixin} 039 * <li class='jc'>{@link ViewServlet} 040 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/MustacheViewSupport">Mustache 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="/mustache/*", 049 responseProcessors={MustacheViewRenderer.class} 050) 051public class MustacheServlet extends ViewServlet { 052 053 private static final long serialVersionUID = 1L; 054 055 private final transient MustacheDispatcher worker; 056 057 /** No-arg constructor — uses a default {@link MustacheDispatcher} worker. */ 058 public MustacheServlet() { 059 this(MustacheDispatcher.create().build()); 060 } 061 062 /** 063 * Worker constructor. 064 * 065 * @param worker The shared flavor-neutral Mustache dispatcher this servlet delegates raw 066 * dispatch to. Must not be {@code null}. 067 */ 068 protected MustacheServlet(MustacheDispatcher worker) { 069 this.worker = worker; 070 } 071 072 @Override /* ViewServlet */ 073 protected RawTemplateDispatcher dispatcher() { 074 return worker; 075 } 076}