001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ui.apps.sitemanager; 029 030import org.opencms.main.CmsLog; 031import org.opencms.main.OpenCms; 032import org.opencms.site.CmsSiteManagerImpl; 033import org.opencms.ui.A_CmsUI; 034import org.opencms.ui.CmsVaadinUtils; 035import org.opencms.ui.components.CmsBasicDialog; 036import org.opencms.ui.report.CmsReportWidget; 037 038import java.util.Map; 039 040import org.apache.commons.logging.Log; 041 042import com.google.common.collect.Maps; 043import com.vaadin.ui.Button; 044import com.vaadin.ui.Button.ClickEvent; 045import com.vaadin.ui.Button.ClickListener; 046import com.vaadin.ui.FormLayout; 047import com.vaadin.ui.Panel; 048import com.vaadin.v7.ui.TextField; 049 050/** 051 * Class for the Web server configuration form and execution of script. 052 */ 053public class CmsWebServerConfigForm extends CmsBasicDialog { 054 055 /**vaadin serial id. */ 056 private static final long serialVersionUID = 6872090597762705805L; 057 058 /** The logger for this class. */ 059 static Log LOG = CmsLog.getLog(CmsWebServerConfigForm.class.getName()); 060 061 /**Vaadin component. */ 062 private Button m_cancel; 063 064 /**Vaadin component. */ 065 private Button m_ok; 066 067 /**Vaadin component. */ 068 private TextField m_fieldConfigTemplate; 069 070 /**Vaadin component. */ 071 private TextField m_fieldLogging; 072 073 /**Vaadin component. */ 074 private TextField m_fieldPrefix; 075 076 /**Vaadin component. */ 077 private TextField m_fieldScript; 078 079 /**Vaadin component. */ 080 private TextField m_fieldSecureTemplate; 081 082 /**Vaadin component. */ 083 private TextField m_fieldTargetPath; 084 085 /**Vaadin component. */ 086 private Panel m_form; 087 088 /**Site Manager instance. */ 089 private CmsSiteManager m_manager; 090 091 /**Vaadin component. */ 092 private Panel m_report; 093 094 /**Vaadin component. */ 095 private FormLayout m_threadReport; 096 097 /** 098 * Public Constructor.<p> 099 * 100 * @param manager sitemanager instance 101 */ 102 public CmsWebServerConfigForm(CmsSiteManager manager) { 103 m_manager = manager; 104 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 105 m_report.setVisible(false); 106 m_cancel.addClickListener(new ClickListener() { 107 108 private static final long serialVersionUID = 5105904639509364528L; 109 110 public void buttonClick(ClickEvent event) { 111 112 cancel(); 113 } 114 }); 115 116 m_ok.addClickListener(new ClickListener() { 117 118 private static final long serialVersionUID = 7862341970072428829L; 119 120 public void buttonClick(ClickEvent event) { 121 122 runScript(); 123 } 124 }); 125 126 Map<String, String> webconfig = OpenCms.getSiteManager().getWebServerConfig(); 127 if (webconfig == null) { 128 webconfig = Maps.newHashMap(); 129 130 } 131 m_fieldConfigTemplate.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_CONFIGTEMPLATE))); 132 m_fieldSecureTemplate.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_SECURETEMPLATE))); 133 m_fieldTargetPath.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_TARGETPATH))); 134 m_fieldScript.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_WEBSERVERSCRIPT))); 135 m_fieldLogging.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_LOGGINGDIR))); 136 m_fieldPrefix.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_FILENAMEPREFIX))); 137 } 138 139 /** 140 * Cancels site edit.<p> 141 */ 142 void cancel() { 143 144 m_manager.closeDialogWindow(false); 145 } 146 147 /** 148 * Converts null to an empty string and returns all other strings unchanged.<p> 149 * 150 * @param s the input string 151 * @return the output string 152 */ 153 String nullToEmpty(String s) { 154 155 if (s == null) { 156 return ""; 157 } 158 return s; 159 160 } 161 162 /** 163 * Executes script.<p> 164 */ 165 void runScript() { 166 167 //Show report field and hide form fields 168 m_report.setVisible(true); 169 m_form.setVisible(false); 170 m_ok.setEnabled(false); 171 172 Map<String, String> webconfig = OpenCms.getSiteManager().getWebServerConfig(); 173 if (webconfig == null) { 174 webconfig = Maps.newHashMap(); 175 } 176 CmsSitesWebserverThread thread = new CmsSitesWebserverThread( 177 A_CmsUI.getCmsObject(), 178 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_TARGETPATH), 179 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_CONFIGTEMPLATE), 180 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_WEBSERVERSCRIPT), 181 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_FILENAMEPREFIX), 182 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_LOGGINGDIR), 183 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_SECURETEMPLATE)); 184 thread.start(); 185 186 CmsReportWidget report = new CmsReportWidget(thread); 187 m_threadReport.addComponent(report); 188 } 189}