001: package ru.emdev.EmForge.svn.web;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006:
007: import org.tmatesoft.svn.core.SVNDirEntry;
008: import org.tmatesoft.svn.core.SVNException;
009:
010: import ru.emdev.EmForge.web.bean.MainMenuController.MainMenuItem;
011: import ru.emdev.EmForge.wiki.web.bean.Crumb;
012:
013: /**
014: * Subversion directory browser backing bean
015: *
016: * @author Walter Mourao, 20.06.2007: created to browse Subversion repository
017: */
018: public class SvnBrowserController extends SvnBaseController {
019:
020: public static final String PAGE_NAME = "browser";
021: public static final String TITLE = "Source navigation";
022:
023: /** Subversion entries */
024: private SvnDataVO[] svnData;
025:
026: /** User properties */
027: private Collection<String[]> resourceProperties;
028:
029: /**
030: * @see ru.emdev.EmForge.web.bean.BaseControllerImpl#getSelectionItemOnMainMenu()
031: */
032: @Override
033: public MainMenuItem getSelectionItemOnMainMenu() {
034:
035: return MainMenuItem.SOURCES;
036: }
037:
038: /**
039: * @see ru.emdev.EmForge.web.bean.BaseControllerImpl#getTitleImpl()
040: */
041: @Override
042: public String getTitleImpl() {
043:
044: return TITLE;
045: }
046:
047: /**
048: * @see ru.emdev.EmForge.web.bean.BaseControllerImpl#getTrailCrumbInfo()
049: */
050: @Override
051: public Crumb getTrailCrumbInfo() {
052:
053: final String crumbPath;
054: if (getPath() == null || getPath().equals(""))
055: crumbPath = "root";
056: else
057: crumbPath = Helper.fileNameFromFilePath(getPath());
058: return new Crumb(crumbPath, PAGE_NAME + "/" + getLinkRevision()
059: + getLinkPath());
060: }
061:
062: /**
063: * @see ru.emdev.EmForge.svn.web.SvnBaseController#init()
064: */
065: @Override
066: protected void init() {
067:
068: super .init();
069:
070: resourceProperties = null;
071: svnData = null;
072:
073: getData();
074: }
075:
076: /**
077: * Fills the svnData and resourceProperty properties
078: */
079: public void getData() {
080:
081: final String currentPath;
082: if (this .getPath().endsWith("/"))
083: currentPath = this .getPath();
084: else
085: currentPath = this .getPath() + "/";
086:
087: java.util.Map<String, String> properties = new java.util.HashMap<String, String>();
088: try {
089: svnData = Helper.listEntries(getSvnRepository(),
090: currentPath, Helper
091: .getCurrentRevision(getRevision()));
092: getSvnRepository().getDir(currentPath, -1, properties,
093: (Collection<SVNDirEntry>) null);
094:
095: } catch (SVNException e) {
096: this .addErrorMessage("Subversion error", e
097: .getLocalizedMessage());
098: logger.error(e.getLocalizedMessage(), e);
099: svnData = null;
100: return;
101:
102: } catch (Exception ex) {
103: this .addErrorMessage("Cannot display path for "
104: + currentPath, ex.getLocalizedMessage());
105: logger.error(ex.getLocalizedMessage(), ex);
106: svnData = null;
107: return;
108: }
109:
110: java.util.Arrays.sort(svnData);
111:
112: // filling the properties
113: resourceProperties = new ArrayList<String[]>();
114: for (Iterator<String> it = properties.keySet().iterator(); it
115: .hasNext();) {
116: final String key = (String) it.next();
117:
118: if (Helper.isUserProperty(key))// filters only user properties.
119: resourceProperties.add(new String[] { key,
120: properties.get(key) });
121: }
122:
123: }
124:
125: /**
126: * @return
127: */
128: public SvnDataVO[] getSvnData() {
129:
130: return svnData;
131: }
132:
133: /**
134: * @return
135: */
136: public Collection<String[]> getResourceProperties() {
137:
138: return resourceProperties;
139: }
140: }
|