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