From 1a9d710892e519d2e48557d69656570377083376 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 4 Sep 2019 12:21:29 +0200 Subject: [PATCH] made imprint, about and help configurable --- .../service/page/impl/DefaultPageLayout.java | 66 ++++++++++++++++--- .../service/page/impl/PageContextImpl.java | 6 +- src/main/resources/messages.properties | 6 +- src/main/resources/messages_de.properties | 8 ++- src/main/resources/messages_en.properties | 6 +- 5 files changed, 79 insertions(+), 13 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java index 1d232216..334f0052 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java @@ -15,6 +15,7 @@ import org.apache.commons.codec.binary.Base64InputStream; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.rap.rwt.RWT; +import org.eclipse.rap.rwt.client.service.UrlLauncher; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; @@ -35,6 +36,7 @@ import org.springframework.stereotype.Component; import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.api.API; +import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService; import ch.ethz.seb.sebserver.gui.service.page.PageContext; @@ -52,6 +54,14 @@ public class DefaultPageLayout implements TemplateComposer { private static final Logger log = LoggerFactory.getLogger(DefaultPageLayout.class); + private static final LocTextKey ABOUT_TEXT_KEY = new LocTextKey("sebserver.overall.about"); + private static final LocTextKey IMPRINT_TEXT_KEY = new LocTextKey("sebserver.overall.imprint"); + private static final LocTextKey HELP_TEXT_KEY = new LocTextKey("sebserver.overall.help"); + + private static final LocTextKey ABOUT_MARKUP_TEXT_KEY = new LocTextKey("sebserver.overall.about.markup"); + private static final LocTextKey IMPRINT_MARKUP_TEXT_KEY = new LocTextKey("sebserver.overall.imprint.markup"); + private static final LocTextKey HELP_LINK_TEXT_KEY = new LocTextKey("sebserver.overall.help.link"); + public static final int LOGO_IMAGE_MAX_WIDTH = 400; public static final int LOGO_IMAGE_MAX_HEIGHT = 80; @@ -259,14 +269,54 @@ public class DefaultPageLayout implements TemplateComposer { rowLayout.marginRight = 20; footerRight.setLayout(rowLayout); - this.widgetFactory.labelLocalized( - footerLeft, - CustomVariant.FOOTER, - new LocTextKey("sebserver.overall.imprint")); - this.widgetFactory.labelLocalized( - footerLeft, - CustomVariant.FOOTER, - new LocTextKey("sebserver.overall.about")); + final I18nSupport i18nSupport = this.widgetFactory.getI18nSupport(); + if (StringUtils.isNoneBlank(i18nSupport.getText(IMPRINT_TEXT_KEY, ""))) { + final Label imprint = this.widgetFactory.labelLocalized( + footerLeft, + CustomVariant.FOOTER, + IMPRINT_TEXT_KEY); + + imprint.addListener(SWT.MouseUp, event -> { + try { + pageContext.publishPageMessage(IMPRINT_TEXT_KEY, IMPRINT_MARKUP_TEXT_KEY); + } catch (final Exception e) { + log.error("Invalid markup for 'Imprint'", e); + } + }); + } + if (StringUtils.isNoneBlank(i18nSupport.getText(ABOUT_TEXT_KEY, ""))) { + final Label about = this.widgetFactory.labelLocalized( + footerLeft, + CustomVariant.FOOTER, + ABOUT_TEXT_KEY); + + about.addListener(SWT.MouseUp, event -> { + try { + pageContext.publishPageMessage(ABOUT_TEXT_KEY, ABOUT_MARKUP_TEXT_KEY); + } catch (final Exception e) { + log.error("Invalid markup for 'About'", e); + } + }); + } + if (StringUtils.isNoneBlank(i18nSupport.getText(HELP_TEXT_KEY, ""))) { + final Label help = this.widgetFactory.labelLocalized( + footerLeft, + CustomVariant.FOOTER, + HELP_TEXT_KEY); + + help.addListener(SWT.MouseUp, event -> { + try { + final String link = i18nSupport.getText(HELP_LINK_TEXT_KEY, ""); + if (StringUtils.isNoneBlank(link)) { + final UrlLauncher urlLauncher = RWT.getClient().getService(UrlLauncher.class); + urlLauncher.openURL(link); + } + } catch (final Exception e) { + + } + }); + + } this.widgetFactory.labelLocalized( footerRight, CustomVariant.FOOTER, diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java index b0fc28bd..1673a4cb 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java @@ -258,9 +258,12 @@ public class PageContextImpl implements PageContext { public void publishPageMessage(final LocTextKey title, final LocTextKey message) { final MessageBox messageBox = new Message( getShell(), - this.i18nSupport.getText(title), + (title != null) + ? this.i18nSupport.getText(title) + : "", this.i18nSupport.getText(message), SWT.NONE); + messageBox.setMarkupEnabled(true); messageBox.open(null); } @@ -334,4 +337,5 @@ public class PageContextImpl implements PageContext { this.onOK.accept(false); } } + } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 544faed8..834ebad8 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -3,8 +3,12 @@ ################################ sebserver.overall.version=SEB Server Version : {0} -sebserver.overall.imprint=Imprint +sebserver.overall.imprint= +sebserver.overall.imprint.markup= sebserver.overall.about=About +sebserver.overall.about.markup=SEB Server About Example

This is an example how an About-Page can look like.


By simply define the markup HTML content within the message.propertie configuration of specified language +sebserver.overall.help=Documentation +sebserver.overall.help.link=https://www.safeexambrowser.org/news_en.html sebserver.overall.message.leave.without.save=You are leaving this page without saved changes!\nThe unsaved changes will be lost.\Are you sure to leave the page? sebserver.overall.upload=Please Select diff --git a/src/main/resources/messages_de.properties b/src/main/resources/messages_de.properties index d656e88c..49642d94 100644 --- a/src/main/resources/messages_de.properties +++ b/src/main/resources/messages_de.properties @@ -3,8 +3,12 @@ ################################ sebserver.overall.version=SEB Server Version : {0} -sebserver.overall.imprint=Imprint -sebserver.overall.about=About +sebserver.overall.imprint= +sebserver.overall.imprint.markup= +sebserver.overall.about= +sebserver.overall.about.markup= +sebserver.overall.help=Dokumentation +sebserver.overall.help.link=https://www.safeexambrowser.org/news_de.html sebserver.overall.message.leave.without.save=You are leaving this page without saved changes!\nThe unsaved changes will be lost.\Are you sure to leave the page? sebserver.overall.upload=Bitte Ausw\u00E4hlen diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index c8ffa1a5..f9653972 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -3,8 +3,12 @@ ################################ sebserver.overall.version=SEB Server Version : {0} -sebserver.overall.imprint=Imprint +sebserver.overall.imprint= +sebserver.overall.imprint.markup= sebserver.overall.about=About +sebserver.overall.about.markup=SEB Server About Example

1. This is an example of how an About-Page can look like.

By simply define the markup HTML content within the message.propertie configuration of specified language +sebserver.overall.help=Documentation +sebserver.overall.help.link=https://www.safeexambrowser.org/news_en.html sebserver.overall.message.leave.without.save=You have unsaved changes!\nAre you sure you want to leave the page?\The changes will be lost. sebserver.overall.upload=Please Select