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.htmltowiki;
020
021import org.apache.wiki.api.core.Context;
022import org.apache.wiki.api.core.ContextEnum;
023
024
025/**
026 * Defines a Wiki configuration to XHtmlToWikiTranslator, including things like URLs.
027 */
028public class XHtmlToWikiConfig {
029
030    private String m_outlink = "outlink";
031    private String m_pageInfoJsp = "PageInfo.jsp";
032    private String m_wikiJspPage = "Wiki.jsp?page=";
033    private String m_editJspPage = "Edit.jsp?page=";
034    private String m_attachPage = "attach?page=";
035    private String m_pageName;
036
037    /**
038     *  Creates a new, empty config object.
039     */
040    public XHtmlToWikiConfig() {
041    }
042
043    /**
044     * The constructor initializes the different internal fields according to the current URLConstructor.
045     *
046     * @param wikiContext A WikiContext
047     */
048    public XHtmlToWikiConfig( final Context wikiContext ) {
049        setWikiContext( wikiContext );
050
051        //  Figure out the actual URLs.
052        //  NB: The logic here will fail if you add something else after the Wiki page name in VIEW or ATTACH
053        m_wikiJspPage = wikiContext.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), "" );
054        m_editJspPage = wikiContext.getURL( ContextEnum.PAGE_EDIT.getRequestContext(), "" );
055        m_attachPage = wikiContext.getURL( ContextEnum.PAGE_ATTACH.getRequestContext(), "" );
056        m_pageInfoJsp = wikiContext.getURL( ContextEnum.PAGE_INFO.getRequestContext(), "" );
057    }
058
059    private void setWikiContext( final Context wikiContext ) {
060        if( wikiContext.getPage() != null ) {
061            setPageName( wikiContext.getPage().getName() + '/' );
062        }
063    }
064
065    /**
066     * Return the URL for the attachments.
067     *
068     * @return URL for attachments.
069     */
070    public String getAttachPage() {
071        return m_attachPage;
072    }
073
074    /**
075     * Set the URL for attachments.
076     *
077     * @param attachPage The attachment URL.
078     */
079    public void setAttachPage( final String attachPage ) {
080        m_attachPage = attachPage;
081    }
082
083    /**
084     * Gets the URL of the outlink image.
085     *
086     * @return The URL of the outlink image.
087     */
088    public String getOutlink() {
089        return m_outlink;
090    }
091
092    /**
093     * Set the outlink URL.
094     *
095     * @param outlink The outlink URL.
096     */
097    public void setOutlink( final String outlink ) {
098        m_outlink = outlink;
099    }
100
101    /**
102     * Get the PageInfo.jsp URI.
103     *
104     * @return The URI for the page info display.
105     */
106    public String getPageInfoJsp() {
107        return m_pageInfoJsp;
108    }
109
110    /**
111     * Set the URI for the page info display.
112     *
113     * @param pageInfoJsp URI for the page info.
114     */
115    public void setPageInfoJsp( final String pageInfoJsp ) {
116        m_pageInfoJsp = pageInfoJsp;
117    }
118
119    /**
120     * Get the page name.
121     *
122     * @return The Page Name.
123     */
124    public String getPageName() {
125        return m_pageName;
126    }
127
128    /**
129     * Set the page name.
130     *
131     * @param pageName The name of the page.
132     */
133    public void setPageName( final String pageName ) {
134        m_pageName = pageName;
135    }
136
137    /**
138     * Get the URI to the Wiki.jsp view.
139     *
140     * @return The URI to the Wiki.jsp.
141     */
142    public String getWikiJspPage() {
143        return m_wikiJspPage;
144    }
145
146    /**
147     * Set the URI to the Wiki.jsp.
148     *
149     * @param wikiJspPage The URI to the Wiki.jsp.
150     */
151    public void setWikiJspPage( final String wikiJspPage ) {
152        m_wikiJspPage = wikiJspPage;
153    }
154
155    /**
156     * Return the URI to the Edit.jsp page.
157     *
158     * @return The URI to the Edit.jsp page.
159     */
160    public String getEditJspPage() {
161        return m_editJspPage;
162    }
163
164    /**
165     * Set the URI to the Edit.jsp page.
166     *
167     * @param editJspPage The Edit.jsp URI.
168     */
169    public void setEditJspPage( final String editJspPage ) {
170        m_editJspPage = editJspPage;
171    }
172
173}