001: package ru.emdev.EmForge.svn.web;
002:
003: import java.util.Map;
004:
005: import javax.faces.context.FacesContext;
006:
007: import org.apache.commons.logging.Log;
008: import org.apache.commons.logging.LogFactory;
009: import org.tmatesoft.svn.core.io.SVNRepository;
010:
011: import ru.emdev.EmForge.web.bean.BaseControllerImpl;
012:
013: /**
014: * Subversion directory browser backing bean
015: *
016: * @author Walter Mourao, 25.06.2007: created to handle common things (parameters, repository, parse URL)
017: */
018: public abstract class SvnBaseController extends BaseControllerImpl {
019:
020: protected final Log logger = LogFactory.getLog(getClass());
021:
022: /** Current subversion repository. Setted by the Spring request scope initialization. */
023: private SVNRepository svnRepository;
024:
025: /** The request path */
026: private String m_path;
027:
028: /** The request revision */
029: private Long m_revision;
030:
031: /**
032: * @see ru.emdev.EmForge.web.bean.BaseControllerImpl#init()
033: */
034: @Override
035: protected void init() {
036:
037: final Map<String, String> parameters = FacesContext
038: .getCurrentInstance().getExternalContext()
039: .getRequestParameterMap();
040:
041: if (parameters.containsKey("path"))
042: m_path = (String) parameters.get("path");
043: else {
044: m_path = (String) parameters.get("oldpath");
045: }
046:
047: if (m_path == null || m_path.length() == 0
048: || m_path.equals("/") || m_path.equals("root"))
049: m_path = "";
050:
051: final String newRevision = (String) parameters.get("revision");
052: if (newRevision == null || newRevision.equals("-1"))
053: m_revision = null;
054: else {
055: try {
056: m_revision = new Long(Long.parseLong(newRevision));
057: } catch (NumberFormatException e) {
058: m_revision = null;
059: }
060: }
061:
062: }
063:
064: /**
065: * @param svnRepository
066: */
067: public void setSvnRepository(SVNRepository svnRepository) {
068:
069: this .svnRepository = svnRepository;
070: }
071:
072: /**
073: * @return
074: */
075: protected SVNRepository getSvnRepository() {
076:
077: return this .svnRepository;
078: }
079:
080: /**
081: * @return
082: */
083: public Long getRevision() {
084:
085: return m_revision;
086: }
087:
088: /**
089: * @param revision
090: */
091: protected void setRevision(Long revision) {
092:
093: this .m_revision = revision;
094: }
095:
096: /**
097: * @return
098: */
099: public String getLinkRevision() {
100:
101: if (m_revision == null)
102: return "";
103: else
104: return m_revision.toString() + "/";
105: }
106:
107: /**
108: * @return
109: */
110: public String getPath() {
111:
112: return m_path;
113: }
114:
115: /**
116: * @return
117: */
118: public String getLinkPath() {
119:
120: if (m_path == null || m_path.length() == 0)
121: return "root";
122: else
123: return m_path;
124: }
125:
126: }
|