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.servlet;
037:
038: import java.util.Iterator;
039: import java.util.Map;
040:
041: import net.sourceforge.cruisecontrol.Configuration;
042: import net.sourceforge.cruisecontrol.PluginConfiguration;
043: import net.sourceforge.cruisecontrol.interceptor.ConfigurationAware;
044: import net.sourceforge.cruisecontrol.interceptor.DetailsAware;
045:
046: import com.opensymphony.webwork.interceptor.ParameterAware;
047: import com.opensymphony.xwork.ActionSupport;
048:
049: /**
050: * Understands how to edit plugin details via a web interface.
051: */
052: public class PluginDetailsServlet extends ActionSupport implements
053: ConfigurationAware, DetailsAware, ParameterAware {
054: private Configuration configuration;
055: private Map parameters;
056: private PluginConfiguration pluginConfiguration;
057:
058: public String execute() throws Exception {
059: setDetails();
060: configuration.updatePluginConfiguration(pluginConfiguration);
061: addActionMessage("Updated configuration.");
062: return SUCCESS;
063: }
064:
065: public String load() {
066: return INPUT;
067: }
068:
069: public String getName() {
070: return this .pluginConfiguration.getName();
071: }
072:
073: public String getType() {
074: return this .pluginConfiguration.getType();
075: }
076:
077: public Map getDetails() {
078: return this .pluginConfiguration.getDetails();
079: }
080:
081: public void setConfiguration(Configuration configuration) {
082: this .configuration = configuration;
083: }
084:
085: public void setDetails(PluginConfiguration pluginConfiguration) {
086: this .pluginConfiguration = pluginConfiguration;
087: }
088:
089: private void setDetails() {
090: for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) {
091: Map.Entry entry = (Map.Entry) i.next();
092: this .pluginConfiguration.setDetail((String) entry.getKey(),
093: ((String[]) entry.getValue())[0]);
094: }
095: }
096:
097: public void setParameters(Map parameters) {
098: this.parameters = parameters;
099: }
100: }
|