001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.tags;
021:
022: import java.io.IOException;
023: import javax.servlet.jsp.JspWriter;
024:
025: import com.ecyrd.jspwiki.WikiContext;
026: import com.ecyrd.jspwiki.WikiEngine;
027: import com.ecyrd.jspwiki.WikiPage;
028:
029: /**
030: * Writes an edit link. Body of the link becomes the link text.
031: * <P><B>Attributes</B></P>
032: * <UL>
033: * <LI>page - Page name to refer to. Default is the current page.
034: * <LI>format - Format, either "anchor" or "url".
035: * <LI>version - Version number of the page to refer to. Possible values
036: * are "this", meaning the version of the current page; or a version
037: * number. Default is always to point at the latest version of the page.
038: * </UL>
039: *
040: * @author Janne Jalkanen
041: * @since 2.0
042: */
043: public class EditLinkTag extends WikiLinkTag {
044: public String m_version = null;
045:
046: public void setVersion(String vers) {
047: m_version = vers;
048: }
049:
050: public final int doWikiStartTag() throws IOException {
051: WikiEngine engine = m_wikiContext.getEngine();
052: WikiPage page = null;
053: String versionString = "";
054: String pageName = null;
055:
056: //
057: // Determine the page and the link.
058: //
059: if (m_pageName == null) {
060: page = m_wikiContext.getPage();
061: if (page == null) {
062: // You can't call this on the page itself anyways.
063: return SKIP_BODY;
064: } else {
065: pageName = page.getName();
066: }
067: } else {
068: pageName = m_pageName;
069: }
070:
071: //
072: // Determine the latest version, if the version attribute is "this".
073: //
074: if (m_version != null) {
075: if ("this".equalsIgnoreCase(m_version)) {
076: if (page == null) {
077: // No page, so go fetch according to page name.
078: page = engine.getPage(m_pageName);
079: }
080:
081: if (page != null) {
082: versionString = "version=" + page.getVersion();
083: }
084: } else {
085: versionString = "version=" + m_version;
086: }
087: }
088:
089: //
090: // Finally, print out the correct link, according to what
091: // user commanded.
092: //
093: JspWriter out = pageContext.getOut();
094:
095: pageName = WikiEngine.makeAbsolutePageName(pageName);
096:
097: switch (m_format) {
098: case ANCHOR:
099: out.print("<a href=\""
100: + m_wikiContext.getURL(WikiContext.EDIT, pageName,
101: versionString) + "\">");
102: break;
103:
104: case URL:
105: out.print(m_wikiContext.getURL(WikiContext.EDIT, pageName,
106: versionString));
107: break;
108: }
109:
110: return EVAL_BODY_INCLUDE;
111: }
112: }
|