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; 018 019import java.io.*; 020 021import org.apache.juneau.http.*; 022import org.apache.juneau.rest.server.*; 023import org.apache.juneau.rest.server.servlet.*; 024 025/** 026 * Abstract base for the child-resource flavors of the view mixin resources. 027 * 028 * <p> 029 * Mirror of {@link ViewServlet} for routed-child deployment: each per-engine bridge module ships a thin 030 * {@code <Engine>Resource} subclass that declares its own subtree mount via 031 * {@link Rest#path() @Rest(path)} (e.g. {@code "/jsp"}) and supplies the per-engine 032 * {@link RawTemplateDispatcher} (the matching flavor-neutral {@code <Engine>Dispatcher} worker) via 033 * {@link #dispatcher()}. 034 * 035 * <p> 036 * The single greedy op declared here ({@code @RestGet(path="/*")}) captures the trailing remainder under 037 * the child's subtree mount and delegates straight to the shared {@link RawTemplateDispatcher}, so the 038 * mixin, servlet, and child forms cannot drift. 039 * 040 * <h5 class='section'>See Also:</h5><ul> 041 * <li class='jic'>{@link RawTemplateDispatcher} 042 * <li class='jc'>{@link ViewServlet} 043 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerComposition">REST Server — Mixins and Multi-Mount Paths</a> 044 * </ul> 045 * 046 * @since 10.0.0 047 */ 048@Rest 049public abstract class ViewResource extends RestResource { 050 051 /** 052 * Returns the per-engine {@link RawTemplateDispatcher} this child delegates raw template dispatch 053 * to. 054 * 055 * <p> 056 * Typically the matching flavor-neutral {@code <Engine>Dispatcher} worker (which implements 057 * {@link RawTemplateDispatcher}). Never {@code null}. 058 * 059 * @return The raw-template dispatcher. Never {@code null}. 060 */ 061 protected abstract RawTemplateDispatcher dispatcher(); 062 063 /** 064 * [GET /*] — render the raw template identified by the trailing path under this child's 065 * subtree mount. 066 * 067 * @param path The trailing path segment after the mount prefix. 068 * @param req The current REST request. 069 * @param res The current REST response. 070 * @throws IOException If the underlying response writer fails. 071 */ 072 @RestGet( 073 path="/*", 074 summary="View", 075 description="Render a raw template under this child's subtree mount.", 076 swagger=@OpSwagger(ignore=true) 077 ) 078 public void render(@Path("/*") String path, RestRequest req, RestResponse res) throws IOException { 079 dispatcher().render(path, req, res); 080 } 081}