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