001: package ru.emdev.EmForge.svn.web;
002:
003: import java.util.Collection;
004: import java.util.Iterator;
005:
006: import org.tmatesoft.svn.core.SVNException;
007: import org.tmatesoft.svn.core.SVNLogEntry;
008: import org.tmatesoft.svn.core.SVNLogEntryPath;
009:
010: import ru.emdev.EmForge.web.bean.MainMenuController.MainMenuItem;
011: import ru.emdev.EmForge.wiki.web.bean.Crumb;
012:
013: /**
014: * Subversion history view (svnhistory.xhtml) backing bean
015: *
016: * @author Walter Mourao
017: *
018: */
019: public class SvnHistoryController extends SvnBaseController {
020:
021: public static final String TITLE = "Resource history";
022:
023: @Override
024: public MainMenuItem getSelectionItemOnMainMenu() {
025: return MainMenuItem.SOURCES;
026: }
027:
028: @Override
029: public String getTitleImpl() {
030: return TITLE;
031: }
032:
033: @Override
034: public Crumb getTrailCrumbInfo() {
035: return null;
036: }
037:
038: @Override
039: protected void init() {
040: super .init();
041:
042: revisionLog = null;
043:
044: loadHistory();
045: }
046:
047: //********* controller code ********//
048:
049: /**
050: * Fills the relevant properties
051: */
052: private void loadHistory() {
053: final Collection<SVNLogEntry> entries;
054: try {
055: // load information - is it directory or no
056: isDirectory = Helper
057: .isDirectory(getSvnRepository(), getPath(), Helper
058: .getCurrentRevision(getRevision()));
059:
060: // load history entries
061: entries = Helper.getLogEntries(getSvnRepository(),
062: getPath(), 0, Helper
063: .getCurrentRevision(getRevision()), true);
064: } catch (SVNException e) {
065: this .addErrorMessage("Subversion error", e
066: .getLocalizedMessage());
067: // isabled extra logging
068: //logger.error(e.getLocalizedMessage(), e);
069: revisionLog = null;
070: return;
071: }
072:
073: revisionLog = new RevisionLogItem[entries.size()];
074: int i = 0;
075: for (Iterator<SVNLogEntry> it = entries.iterator(); it
076: .hasNext();) {
077: SVNLogEntry entry = it.next();
078: revisionLog[i] = new RevisionLogItem();
079: revisionLog[i].setAuthor(entry.getAuthor());
080: revisionLog[i].setChangeSet("["
081: + String.valueOf(entry.getRevision()) + "]");
082: revisionLog[i].setRevision(String.valueOf(entry
083: .getRevision()));
084: if (entry.getChangedPaths().entrySet().size() > 0)
085: revisionLog[i].setChangeKind(((SVNLogEntryPath) entry
086: .getChangedPaths().values().iterator().next())
087: .getType());
088: revisionLog[i].setDate(entry.getDate());
089: revisionLog[i].setLogMessage(entry.getMessage());
090: i++;
091: }
092:
093: java.util.Arrays.sort(revisionLog);
094:
095: }
096:
097: //********* attributes ***********//
098:
099: /**
100: * The revision log items
101: */
102: private RevisionLogItem[] revisionLog;
103: private Boolean isDirectory;
104:
105: public RevisionLogItem[] getRevisionLog() {
106: return revisionLog;
107: }
108:
109: public Boolean getIsDirectory() {
110: return isDirectory;
111: }
112: }
|