001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2007, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol.dashboard.web.command;
037:
038: import net.sourceforge.cruisecontrol.Modification;
039: import net.sourceforge.cruisecontrol.dashboard.ModificationKey;
040: import net.sourceforge.cruisecontrol.dashboard.StoryTracker;
041: import org.apache.commons.lang.StringEscapeUtils;
042:
043: import java.util.ArrayList;
044: import java.util.HashMap;
045: import java.util.List;
046: import java.util.Map;
047:
048: public class ModificationCommand {
049: private Modification modification;
050:
051: private final StoryTracker storyTracker;
052:
053: public ModificationCommand(Modification modification,
054: StoryTracker storyTracker) {
055: this .storyTracker = storyTracker;
056: this .modification = modification;
057: }
058:
059: public String getComment() {
060: String comment = StringEscapeUtils
061: .escapeHtml(modification.comment);
062: if (storyTracker == null) {
063: return comment;
064: }
065: return storyTracker.getTextWithUrls(comment);
066: }
067:
068: public ModificationKey getModificationKey() {
069: return new ModificationKey(modification.comment,
070: modification.userName);
071: }
072:
073: public List getModifiedFiles() {
074: return modification.getModifiedFiles();
075: }
076:
077: public String getType() {
078: return modification.type;
079: }
080:
081: public String getUser() {
082: return modification.userName;
083: }
084:
085: public Map toJsonData() {
086: Map data = new HashMap();
087: data.put("type", modification.getType());
088: data.put("user", modification.getUserName());
089: data.put("comment", getComment());
090: data.put("modifiedtime", new Long(modification
091: .getModifiedTime().getTime()));
092: ArrayList files = new ArrayList();
093: for (int i = 0; i < modification.files.size(); i++) {
094: Modification.ModifiedFile file = (Modification.ModifiedFile) modification.files
095: .get(i);
096: Map fileMap = new HashMap();
097: fileMap.put("filename", file.getFileName());
098: fileMap.put("revision", file.getRevision());
099: fileMap.put("folder", file.getFolderName());
100: fileMap.put("action", file.getAction());
101: files.add(fileMap);
102: }
103: data.put("files", files);
104: return data;
105: }
106: }
|