/*******************************************************************************
* Copyright 2009, 2010 Innovation Gate GmbH. All Rights Reserved.
*
* This file is part of the OpenWGA server platform.
*
* OpenWGA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, a special exception is granted by the copyright holders
* of OpenWGA called "OpenWGA plugin exception". You should have received
* a copy of this exception along with OpenWGA in file COPYING.
* If not, see <http://www.openwga.com/gpl-plugin-exception>.
*
* OpenWGA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenWGA in file COPYING.
* If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package de.innovationgate.wgpublisher.webtml;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringEscapeUtils;
import de.innovationgate.webgate.api.WGAPIException;
import de.innovationgate.wgpublisher.webtml.utils.TMLAction;
import de.innovationgate.wgpublisher.webtml.utils.TMLContext;
import de.innovationgate.wgpublisher.webtml.utils.TMLException;
public class Button extends ActionBase {
private String clickaction = null;
private String param1 = null;
private String param2 = null;
private String param3 = null;
private String param4 = null;
private String param5 = null;
private String cssclass = null;
private String cssstyle = null;
private String confirm = null;
/**
* Returns the clickaction.
* @return String
*/
public String getClickaction() {
return this.getTagAttributeValue("clickaction", clickaction, null);
}
/**
* Sets the clickaction.
* @param clickaction The clickaction to set
*/
public void setClickaction(String clickaction) {
this.clickaction = clickaction;
}
/**
* @throws WGAPIException
* @see de.innovationgate.wgpublisher.webtml.Base#tmlEndTag()
*/
public void tmlEndTag() throws TMLException, WGAPIException {
String tagContent = this.getResultString();
this.clearResult();
this.appendResult("<button type=\"button\" ");
// support id attribute - htmlUnit access for tml:button
String id = this.getId();
if (id != null) {
this.appendResult("id=\"" + id + "\" ");
}
String clickaction = this.getClickaction();
if (clickaction != null) {
List params = new ArrayList();
params.add(this.getParam1());
params.add(this.getParam2());
params.add(this.getParam3());
params.add(this.getParam4());
params.add(this.getParam5());
String actionCallFunction = null;
if (isAjaxCall()) {
// create ajax call
TMLAction action = getTMLContext().getActionByID(clickaction, getDesignDBKey());
if (action == null) {
addWarning("Action of id '" + clickaction + "' is not defined", true);
return;
}
actionCallFunction = getAjaxJSFunction(action, params);
}
else {
// create standard action call
BaseTagStatus form = getStatus().getAncestorTag(Form.class);
String actionLink = buildCallActionLink(clickaction, (form != null ? form.id : null) , params, getPortletmode(), getPortletcontext());
if (actionLink == null) {
addWarning("No action of id '" + clickaction + "' defined", true);
return;
}
actionCallFunction = "callAction('" + actionLink + "')";
}
// Eventually add confirmation functionality
String confirmMessage = getConfirm();
if (confirmMessage != null) {
actionCallFunction = "if (confirm('" + StringEscapeUtils.escapeJavaScript(StringEscapeUtils.unescapeJavaScript(confirmMessage)) + "')) " + actionCallFunction;
}
this.appendResult("onclick=\"" + actionCallFunction + "; return false;\"");
}
String cssclass = this.getCssclass();
if (cssclass != null) {
this.appendResult("class=\"" + cssclass + "\" ");
}
String cssstyle = this.getCssstyle();
if (cssstyle != null) {
this.appendResult("style=\"" + cssstyle + "\" ");
}
this.appendResult(">");
this.appendResult(tagContent);
this.appendResult("</button>");
}
/**
* Returns the param1.
* @return String
*/
public String getParam1() {
return this.getTagAttributeValue("param1", param1, null);
}
/**
* Returns the param2.
* @return String
*/
public String getParam2() {
return this.getTagAttributeValue("param2", param2, null);
}
/**
* Returns the param3.
* @return String
*/
public String getParam3() {
return this.getTagAttributeValue("param3", param3, null);
}
/**
* Returns the param4.
* @return String
*/
public String getParam4() {
return this.getTagAttributeValue("param4", param4, null);
}
/**
* Returns the param5.
* @return String
*/
public String getParam5() {
return this.getTagAttributeValue("param5", param5, null);
}
/**
* Sets the param1.
* @param param1 The param1 to set
*/
public void setParam1(String param1) {
this.param1 = param1;
}
/**
* Sets the param2.
* @param param2 The param2 to set
*/
public void setParam2(String param2) {
this.param2 = param2;
}
/**
* Sets the param3.
* @param param3 The param3 to set
*/
public void setParam3(String param3) {
this.param3 = param3;
}
/**
* Sets the param4.
* @param param4 The param4 to set
*/
public void setParam4(String param4) {
this.param4 = param4;
}
/**
* Sets the param5.
* @param param5 The param5 to set
*/
public void setParam5(String param5) {
this.param5 = param5;
}
/**
* Returns the cssclass.
* @return String
*/
public String getCssclass() {
return this.getTagAttributeValue("cssclass", cssclass, null);
}
/**
* Returns the cssstyle.
* @return String
*/
public String getCssstyle() {
return this.getTagAttributeValue("cssstyle", cssstyle, null);
}
/**
* Sets the cssclass.
* @param cssclass The cssclass to set
*/
public void setCssclass(String cssclass) {
this.cssclass = cssclass;
}
/**
* Sets the cssstyle.
* @param cssstyle The cssstyle to set
*/
public void setCssstyle(String cssstyle) {
this.cssstyle = cssstyle;
}
public String getConfirm() {
return getTagAttributeValue("confirm", confirm, null);
}
public void setConfirm(String confirm) {
this.confirm = confirm;
}
}