001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.api.spi; 020 021import org.apache.wiki.api.core.Command; 022import org.apache.wiki.api.core.Context; 023import org.apache.wiki.api.core.Engine; 024import org.apache.wiki.api.core.Page; 025 026import javax.servlet.http.HttpServletRequest; 027 028 029public class ContextDSL { 030 031 private final ContextSPI contextSPI; 032 033 ContextDSL( final ContextSPI contextSPI ) { 034 this.contextSPI = contextSPI; 035 } 036 037 /** 038 * Create a new Context for the given Page. 039 * 040 * @param engine The Engine that is handling the request. 041 * @param page The Page. If you want to create a Context for an older version of a page, you must use this method. 042 */ 043 public Context create( final Engine engine, final Page page ) { 044 return contextSPI.create( engine, page ); 045 } 046 047 /** 048 * <p>Creates a new Context for the given Engine, Command and HttpServletRequest.</p> 049 * <p>This constructor will also look up the HttpSession associated with the request, and determine if a Session object is present. 050 * If not, a new one is created.</p> 051 * 052 * @param engine The Engine that is handling the request 053 * @param request The HttpServletRequest that should be associated with this context. This parameter may be <code>null</code>. 054 * @param command the command 055 */ 056 public Context create( final Engine engine, final HttpServletRequest request, final Command command ) { 057 return contextSPI.create( engine, request, command ); 058 } 059 060 /** 061 * Creates a new Context for the given Engine, Page and HttpServletRequest. 062 * 063 * @param engine The Engine that is handling the request 064 * @param request The HttpServletRequest that should be associated with this context. This parameter may be <code>null</code>. 065 * @param page The WikiPage. If you want to create a WikiContext for an older version of a page, you must supply this parameter 066 */ 067 public Context create( final Engine engine, final HttpServletRequest request, final Page page ) { 068 return contextSPI.create( engine, request, page ); 069 } 070 071 /** 072 * Creates a new Context from a supplied HTTP request, using a default wiki context. 073 * 074 * @param engine The Engine that is handling the request 075 * @param request the HTTP request 076 * @param requestContext the default context to use 077 */ 078 public Context create( final Engine engine, final HttpServletRequest request, final String requestContext ) { 079 return contextSPI.create( engine, request, requestContext ); 080 } 081 082}