001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2005, 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.publishers.rss;
037:
038: import java.io.File;
039:
040: /**
041: * The CruiseControlFeed class extends the generic Feed class with
042: * CruiseControl-specific functionality. Specifically, the CruiseControlFeed
043: * class keeps track of how many projects are being published into the feed
044: * and uses this information to generate a default feed title and description.
045: *
046: * Copyright (c) 2005 Hewlett-Packard Development Company, L.P.
047: * @author Patrick Conant
048: */
049: public class CruiseControlFeed extends Feed {
050:
051: /**
052: * Project count indicates how many CC projects are using this feed.
053: * This affects the link URL, title and description of the feed.
054: */
055: private int projectCount;
056:
057: private String projectName;
058:
059: /**
060: * Constructor.
061: */
062: public CruiseControlFeed(File publishToFile) {
063: super (publishToFile);
064: }
065:
066: /**
067: * incrementProjectCount is called by the RSSPublisher when a new project
068: * is feeding into this Feed instance.
069: */
070: public void incrementProjectCount() {
071: this .projectCount++;
072: }
073:
074: /**
075: * getProjectCount is a convenience method used internally to determine
076: * whether multiple projects are publishing into the same feed.
077: */
078: public int getProjectCount() {
079: return this .projectCount;
080: }
081:
082: /**
083: * Set the name of the project being published into this feed.
084: */
085: public void setProjectName(String name) {
086: if (isNotEmpty(this .projectName)) {
087: this .projectName = this .projectName + ", " + name;
088: } else {
089: this .projectName = name;
090: }
091: }
092:
093: /**
094: * Return the name of the project(s) that are publishing into this feed.
095: */
096: public String getProjectName() {
097: return this .projectName;
098: }
099:
100: /**
101: * Generate a description of this feed based on the names of the projects
102: * flowing into the feed. This method over-rides the base Feed class'
103: * getDescription() method.
104: */
105: public String getDescription() {
106: if (isNotEmpty(super .getDescription())) {
107: return super .getDescription();
108: } else if (isNotEmpty(this .projectName)) {
109: return "Automated build results for CruiseControl project(s) "
110: + this .projectName;
111: } else {
112: return "Automated build results for CruiseControl.";
113: }
114: }
115:
116: /**
117: * Generate a title of this feed based on the names of the projects
118: * flowing into the feed.This method over-rides the base Feed class'
119: * getTitle() method.
120: */
121: public String getTitle() {
122: if (isNotEmpty(super .getTitle())) {
123: return super .getTitle();
124: } else {
125: return "CruiseControl Build Results";
126: }
127: }
128:
129: private static boolean isNotEmpty(String string) {
130: return string != null && string.trim().length() > 0;
131: }
132: }
|