001: package ru.emdev.EmForge.wiki.web.bean;
002:
003: import org.apache.commons.lang.StringUtils;
004: import org.apache.commons.logging.Log;
005: import org.apache.commons.logging.LogFactory;
006: import org.emforge.CommentService;
007: import org.emforge.EmForgeException;
008: import org.emforge.xfer.CommentTO;
009:
010: import ru.emdev.EmForge.util.Helper;
011: import ru.emdev.EmForge.web.bean.EditTextController;
012: import ru.emdev.EmForge.web.bean.MainMenuController.MainMenuItem;
013:
014: import com.ecyrd.jspwiki.WikiContext;
015: import com.ecyrd.jspwiki.WikiPage;
016:
017: /** Controller for Wiki pages
018: *
019: * @author spopov
020: *
021: */
022: public class WikiTextViewController extends BaseWikiControllerImpl {
023: protected final Log logger = LogFactory.getLog(getClass());
024:
025: public static String WIKIVIEW_PAGE = "wiki.faces";
026: public static String MAIN_PAGE = "Main";
027:
028: private EditTextController m_editTextController;
029:
030: private CommentService m_commentService;
031:
032: public void setEditTextController(
033: EditTextController editTextController) {
034: m_editTextController = editTextController;
035: }
036:
037: public void setCommentService(CommentService service) {
038: m_commentService = service;
039: }
040:
041: @Override
042: protected void init() {
043:
044: String pageName = getPageParam();
045: String version = getParam("version");
046:
047: // set default param page "Main" in case pagename equals null
048: if (StringUtils.isEmpty(pageName) /*
049: && StringUtils.equals(m_econtext.getRequestServletPath().substring(1), WIKIVIEW_PAGE)*/) {
050: pageName = "Main";
051: }
052:
053: setPageName(pageName);
054: setVersion(Helper.isNumber(version) ? Integer.valueOf(version)
055: : -1);
056: }
057:
058: @Override
059: public Crumb getTrailCrumbInfo() {
060: Crumb res = null;
061: /* ???
062: String view = m_econtext.getRequestServletPath().substring(1);
063:
064: if (StringUtils.equals(view, WIKIVIEW_PAGE)) {
065: */
066: String pageName = getPageName();
067:
068: // for main page we simple display Wiki and link to /wiki
069: if (StringUtils.equals(pageName, MAIN_PAGE)) {
070: res = new Crumb("Wiki", "wiki");
071:
072: } else if (StringUtils.isNotEmpty(pageName)) {
073: String params = null;
074: if (getVersion() != -1) {
075: params = "version=" + getVersion();
076: }
077: res = new Crumb(m_pageName, m_urlConstructor.makeURL(
078: WikiContext.VIEW, pageName, false, params));
079: } else {
080: logger.info("requared as a param page name is empty!!!");
081: }
082: /*
083: }
084: */
085: return res;
086: }
087:
088: @Override
089: public MainMenuItem getSelectionItemOnMainMenu() {
090: return MainMenuItem.WIKI;
091: }
092:
093: @Override
094: public String getTitleImpl() {
095: return getPageName();
096: }
097:
098: public String addComment() {
099: String comment = m_editTextController.getWikiText();
100:
101: if (StringUtils.isNotEmpty(comment) && m_pageName != null) {
102: WikiPage wikiPage = m_wikiEngine.getPage(m_pageName,
103: m_version);
104:
105: if (wikiPage != null) {
106: try {
107: m_commentService.addComment(m_pageName, comment);
108: } catch (EmForgeException ex) {
109: logger.error("Cannot add comment for page: "
110: + m_pageName, ex);
111: addErrorMessage("Cannot add comment: "
112: + ex.getMessage(), "Cannot add comment: "
113: + ex.getMessage());
114: }
115: }
116: }
117:
118: return null;
119: }
120:
121: public CommentTO[] getWikiComments() throws EmForgeException {
122: return m_commentService.getComments(m_pageName);
123: }
124: }
|