/*
* @(#)VirtualHostBean.java
*
* Copyright 2009 Instituto Superior Tecnico
* Founding Authors: João Figueiredo, Luis Cruz, Paulo Abrantes, Susana Fernandes
*
* https://fenix-ashes.ist.utl.pt/
*
* This file is part of the Bennu Web Application Infrastructure.
*
* The Bennu Web Application Infrastructure is free software: you can
* redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* Bennu 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Bennu. If not, see .
*
*/
package pt.ist.bennu.manager.presentation.actions;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import pt.ist.bennu.core.domain.MyOrg;
import pt.ist.bennu.core.domain.VirtualHost;
import pt.ist.bennu.core.util.ConfigurationManager;
import pt.ist.fenixframework.services.Service;
import pt.utl.ist.fenix.tools.util.ByteArray;
import pt.utl.ist.fenix.tools.util.i18n.Language;
import pt.utl.ist.fenix.tools.util.i18n.MultiLanguageString;
/**
*
* @author Pedro Santos
* @author Sérgio Silva
* @author Paulo Abrantes
* @author Luis Cruz
*
*/
public class VirtualHostBean implements Serializable {
private static final long serialVersionUID = -1296421091913208039L;
private VirtualHost virtualHost;
private String hostname;
private String supportEmailAddress;
private String systemEmailAddress;
private MultiLanguageString applicationTitle;
private MultiLanguageString htmlTitle;
private MultiLanguageString applicationSubTitle;
private MultiLanguageString applicationCopyright;
private Boolean googleSearchEnabled;
private Boolean languageSelectionEnabled;
private Boolean breadCrumbsEnabled;
private String theme;
private String layout;
private String helpLink;
private String errorPage;
private ByteArray logo;
private transient InputStream logoInputStream;
private String logoFilename;
private String logoDisplayName;
private ByteArray favicon;
private transient InputStream faviconInputStream;
private String faviconFilename;
private String faviconDisplayName;
private List supportedLanguages;
private Set themes;
private Set layouts;
public VirtualHostBean(HttpServletRequest request) {
setErrorPage(ConfigurationManager.getProperty("errorPage"));
ServletContext context = request.getServletContext();
Set themeFolders = context.getResourcePaths("/theme/");
themes = new HashSet<>();
for (String folder : themeFolders) {
themes.add(folder.substring("/theme/".length(), folder.length() - 1));
}
Set layoutFolders = context.getResourcePaths("/layout/");
layouts = new HashSet<>();
for (String folder : layoutFolders) {
layouts.add(folder.substring("/layout/".length(), folder.length() - 1));
}
request.setAttribute("layouts", layouts);
}
public VirtualHostBean(VirtualHost virtualHost, HttpServletRequest request) {
this(request);
this.virtualHost = virtualHost;
setHostname(virtualHost.getHostname());
setApplicationTitle(virtualHost.getApplicationTitle());
setApplicationSubTitle(virtualHost.getApplicationSubTitle());
setHtmlTitle(virtualHost.getHtmlTitle());
setApplicationCopyright(virtualHost.getApplicationCopyright());
setGoogleSearchEnabled(virtualHost.getGoogleSearchEnabled());
setLanguageSelectionEnabled(virtualHost.getLanguageSelectionEnabled());
setSupportedLanguages(virtualHost.getLanguages());
setTheme(virtualHost.getTheme());
setLayout(virtualHost.getLayout());
setHelpLink(virtualHost.getHelpLink());
setErrorPage(virtualHost.getErrorPage());
setBreadCrumbsEnabled(virtualHost.getBreadCrumbsEnabled());
setSupportEmailAddress(virtualHost.getSupportEmailAddress());
setSystemEmailAddress(virtualHost.getSystemEmailAddress());
}
@Service
public void save() {
if (virtualHost == null) {
virtualHost = new VirtualHost(MyOrg.getInstance());
}
virtualHost.setHostname(getHostname());
virtualHost.setApplicationTitle(getApplicationTitle());
virtualHost.setApplicationSubTitle(getApplicationSubTitle());
virtualHost.setApplicationCopyright(getApplicationCopyright());
virtualHost.setHtmlTitle(getHtmlTitle());
virtualHost.setGoogleSearchEnabled(getGoogleSearchEnabled());
virtualHost.setLanguageSelectionEnabled(getLanguageSelectionEnabled());
virtualHost.setLanguages(getSupportedLanguages());
virtualHost.setHelpLink(getHelpLink());
virtualHost.setErrorPage(getErrorPage());
virtualHost.setLayout(getLayout());
virtualHost.setLayout(getLayout());
virtualHost.setTheme(getTheme());
if (getLogo() != null) {
virtualHost.setLogo(getLogo());
}
if (getFavicon() != null) {
virtualHost.setFavicon(getFavicon());
}
virtualHost.setBreadCrumbsEnabled(getBreadCrumbsEnabled());
virtualHost.setSupportEmailAddress(getSupportEmailAddress());
virtualHost.setSystemEmailAddress(getSystemEmailAddress());
}
public VirtualHost getVirtualHost() {
return virtualHost;
}
public String getSystemEmailAddress() {
return systemEmailAddress;
}
public void setSystemEmailAddress(String systemEmailAddress) {
this.systemEmailAddress = systemEmailAddress;
}
public String getHelpLink() {
return helpLink;
}
public void setHelpLink(String helpLink) {
this.helpLink = helpLink;
}
public String getErrorPage() {
return errorPage;
}
public void setErrorPage(String errorPage) {
this.errorPage = errorPage;
}
public Boolean getGoogleSearchEnabled() {
return googleSearchEnabled;
}
public void setGoogleSearchEnabled(Boolean googleSearchEnabled) {
this.googleSearchEnabled = googleSearchEnabled;
}
public Boolean getLanguageSelectionEnabled() {
return languageSelectionEnabled;
}
public void setLanguageSelectionEnabled(Boolean languageSelectionEnabled) {
this.languageSelectionEnabled = languageSelectionEnabled;
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public MultiLanguageString getApplicationTitle() {
return applicationTitle;
}
public void setApplicationTitle(MultiLanguageString applicationTitle) {
this.applicationTitle = applicationTitle;
}
public MultiLanguageString getApplicationSubTitle() {
return applicationSubTitle;
}
public void setApplicationSubTitle(MultiLanguageString applicationSubTitle) {
this.applicationSubTitle = applicationSubTitle;
}
public MultiLanguageString getApplicationCopyright() {
return applicationCopyright;
}
public void setApplicationCopyright(MultiLanguageString applicationCopyright) {
this.applicationCopyright = applicationCopyright;
}
public void setTheme(String theme) {
this.theme = theme;
}
public String getTheme() {
return theme;
}
public ByteArray getLogo() {
return logo;
}
public void setLogo(ByteArray logo) {
this.logo = logo;
}
public ByteArray getFavicon() {
return favicon;
}
public void setFavicon(ByteArray favicon) {
this.favicon = favicon;
}
public InputStream getLogoInputStream() {
return logoInputStream;
}
public void setLogoInputStream(InputStream logoInputStream) {
this.logoInputStream = logoInputStream;
}
public String getLogoFilename() {
return logoFilename;
}
public void setLogoFilename(String logoFilename) {
this.logoFilename = logoFilename;
}
public String getLogoDisplayName() {
return logoDisplayName;
}
public void setLogoDisplayName(String logoDisplayName) {
this.logoDisplayName = logoDisplayName;
}
public InputStream getFaviconInputStream() {
return faviconInputStream;
}
public void setFaviconInputStream(InputStream faviconInputStream) {
this.faviconInputStream = faviconInputStream;
}
public String getFaviconFilename() {
return faviconFilename;
}
public void setFaviconFilename(String faviconFilename) {
this.faviconFilename = faviconFilename;
}
public String getFaviconDisplayName() {
return faviconDisplayName;
}
public void setFaviconDisplayName(String faviconDisplayName) {
this.faviconDisplayName = faviconDisplayName;
}
public Boolean getBreadCrumbsEnabled() {
return breadCrumbsEnabled;
}
public void setBreadCrumbsEnabled(Boolean breadCrumbsEnabled) {
this.breadCrumbsEnabled = breadCrumbsEnabled;
}
public MultiLanguageString getHtmlTitle() {
return htmlTitle;
}
public void setHtmlTitle(MultiLanguageString htmlTitle) {
this.htmlTitle = htmlTitle;
}
public String getSupportEmailAddress() {
return supportEmailAddress;
}
public void setSupportEmailAddress(String supportEmailAddress) {
this.supportEmailAddress = supportEmailAddress;
}
public String getLayout() {
return layout;
}
public void setLayout(String layout) {
this.layout = layout;
}
public Set getLayouts() {
return layouts;
}
public Set getThemes() {
return themes;
}
public void setSupportedLanguages(List supportedLanguages) {
this.supportedLanguages = supportedLanguages;
}
public List getSupportedLanguages() {
return supportedLanguages;
}
public List getAvailableLanguages() {
return Arrays.asList(Language.values());
}
}