javax.mvc.engine.ViewEngine Maven / Gradle / Ivy
Show all versions of javax.mvc-api Show documentation
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package javax.mvc.engine;
/**
* View engines are responsible for processing views and are discovered
* using CDI. Implementations must inject all instances of this interface,
* and process a view as follows:
*
* - Gather the set of candidate view engines by calling {@link #supports(String)}
* and discarding engines that return
false
.
* - Sort the resulting set of candidates using priorities. View engines
* can be decorated with {@link javax.annotation.Priority} to indicate
* their priority; otherwise the priority is assumed to be {@link Priorities#DEFAULT}.
* - If more than one candidate is available, choose one in an
* implementation-defined manner.
* - Fire a {@link javax.mvc.event.BeforeProcessViewEvent} event.
* - Call method {@link #processView(ViewEngineContext)} to process view.
* - Fire a {@link javax.mvc.event.AfterProcessViewEvent} event.
*
* The default view engines for JSPs and Facelets use file extensions to determine
* support. Namely, the default JSP view engine supports views with extensions jsp
* and jspx
, and the one for Facelets supports views with extension
* xhtml
.
*
* @author Santiago Pericas-Geertsen
* @see javax.annotation.Priority
* @see javax.mvc.event.BeforeProcessViewEvent
* @since 1.0
*/
@SuppressWarnings("unused")
public interface ViewEngine {
/**
* Name of property that can be set in an application's {@link javax.ws.rs.core.Configuration}
* to override the root location for views in an archive.
*
* @see javax.ws.rs.core.Application#getProperties()
*/
String VIEW_FOLDER = "javax.mvc.engine.ViewEngine.viewFolder";
/**
* Default value for property {@link #VIEW_FOLDER}.
*/
String DEFAULT_VIEW_FOLDER = "/WEB-INF/views/";
/**
* Returns true
if this engine can process the view or false
* otherwise.
*
* @param view the view.
* @return outcome of supports test.
*/
boolean supports(String view);
/**
* Process a view given a {@link javax.mvc.engine.ViewEngineContext}. Processing
* a view involves merging the model and template data and writing
* the result to an output stream.
*
* Following the Java EE threading model, the underlying view engine implementation
* must support this method being called by different threads. Any resources allocated
* during view processing must be released before the method returns.
*
* @param context the context needed for processing.
* @throws ViewEngineException if an error occurs during processing.
*/
void processView(ViewEngineContext context) throws ViewEngineException;
}