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.url;
020
021import java.util.Properties;
022import java.io.IOException;
023import javax.servlet.http.HttpServletRequest;
024
025import org.apache.wiki.WikiEngine;
026
027/**
028 *  Provides an interface through which JSPWiki constructs URLs.
029 *  JSPWiki calls the methods of this interface whenever an URL
030 *  that points to any JSPWiki internals is required.  For example,
031 *  if you need to find an URL to the editor page for page "TextFormattingRules",
032 *  you would call makeURL( WikiContext.EDIT, "TextFormattingRules", false, null );
033 *  
034 *  @since 2.2
035 */
036public interface URLConstructor
037{
038    /**
039     *  Initializes.  Note that the engine is not fully initialized
040     *  at this point, so don't do anything fancy here - use lazy
041     *  init, if you have to.
042     *  
043     *  @param  engine The WikiEngine that this URLConstructor belongs to
044     *  @param properties Properties used to initialize
045     */
046    void initialize( WikiEngine engine,
047                            Properties properties );
048
049    /**
050     *  Constructs the URL with a bunch of parameters.
051     *  
052     *  @param context The request context (@see WikiContext) that you want the URL for
053     *  @param name The page name (or in case of WikiContext.NONE, the auxiliary JSP page 
054     *              or resource you want to point at.  This must be URL encoded.  Null is NOT safe.
055     *  @param absolute True, if you need an absolute URL.  False, if both relative and absolute
056     *                  URLs are fine.
057     *  @param parameters An URL parameter string (these must be URL-encoded, and separated with &)
058     *  @return An URL pointing to the resource.  Must never return null - throw an InternalWikiException
059     *          if something goes wrong.
060     */
061    String makeURL( String context,
062                           String name,
063                           boolean absolute,
064                           String parameters );
065
066    /**
067     *  Should parse the "page" parameter from the actual
068     *  request.  This is essentially the reverse of makeURL() - whenever a request 
069     *  constructed by calls to makeURL() is passed to this routine, it MUST be
070     *  able to parse the resource name (WikiPage, Attachment, other resource) from
071     *  the request.
072     *  
073     *  @param context In which request context the request was made (this should
074     *                 help in parsing)
075     *  @param request The HTTP request that was used when coming here
076     *  @param encoding The encoding with which the request was made (UTF-8 or ISO-8859-1).
077     *  @return This method must return the name of the resource.
078     *  @throws IOException If parsing failes
079     */
080    String parsePage( String context,
081                             HttpServletRequest request,
082                             String encoding )
083        throws IOException;
084    
085    /**
086     *  Returns information which JSP page should continue handling
087     *  this type of request.
088     *  
089     * @param request The HTTP Request that was used to end up in this page.
090     * @return "Wiki.jsp", "PageInfo.jsp", etc.  Just return the name,
091     *         JSPWiki will figure out the page.
092     */
093    String getForwardPage( HttpServletRequest request );
094}