You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/03/18 09:29:49 UTC

[isis] branch master updated: ISIS-2576: let WebPageBase handle the favicon

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new bf00157  ISIS-2576: let WebPageBase handle the favicon
bf00157 is described below

commit bf001571f01518568a0a57e294209620ec5ed3e2
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Mar 18 10:29:36 2021 +0100

    ISIS-2576: let WebPageBase handle the favicon
    
    also removes obsolete config option for favicon mime-type
    
    also uses an svg favicon in the demo, to show we can
---
 .../config/pages/sections/isis.viewer.wicket.adoc  |  9 ---
 .../apache/isis/core/config/IsisConfiguration.java |  5 --
 .../demo/domain/src/main/resources/application.yml |  2 +-
 .../src/main/resources/static/images/gift.svg      | 59 +++++++++++++++++
 .../wicket/ui/components/WebComponentBase.java     |  2 +-
 .../ui/components/widgets/favicon/Favicon.java     | 73 ----------------------
 .../isis/viewer/wicket/ui/pages/PageAbstract.html  |  1 -
 .../isis/viewer/wicket/ui/pages/PageAbstract.java  | 11 ++--
 .../isis/viewer/wicket/ui/pages/WebPageBase.java   | 27 +++++++-
 9 files changed, 89 insertions(+), 100 deletions(-)

diff --git a/core/config/src/main/adoc/modules/config/pages/sections/isis.viewer.wicket.adoc b/core/config/src/main/adoc/modules/config/pages/sections/isis.viewer.wicket.adoc
index 7eb5066..0f85412 100644
--- a/core/config/src/main/adoc/modules/config/pages/sections/isis.viewer.wicket.adoc
+++ b/core/config/src/main/adoc/modules/config/pages/sections/isis.viewer.wicket.adoc
@@ -73,15 +73,6 @@ A typical value is ``css``. This will result in this file being read from the ``
 
 
 |
-[[isis.viewer.wicket.application.favicon-content-type]]
-isis.viewer.wicket.application. +
-favicon-content-type
-
-|
-| Specifies the content type of the favIcon, if any.
-
-
-|
 [[isis.viewer.wicket.application.favicon-url]]
 isis.viewer.wicket.application. +
 favicon-url
diff --git a/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java b/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
index 50eb85e..3e7dadd 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
@@ -2184,11 +2184,6 @@ public class IsisConfiguration {
                 private Optional<String> css = Optional.empty();
 
                 /**
-                 * Specifies the content type of the favIcon, if any.
-                 */
-                private Optional<String> faviconContentType = Optional.empty();
-
-                /**
                  * Specifies the URL to use of the favIcon.
                  *
                  * <p>
diff --git a/examples/demo/domain/src/main/resources/application.yml b/examples/demo/domain/src/main/resources/application.yml
index 51bceaf..d2063a7 100644
--- a/examples/demo/domain/src/main/resources/application.yml
+++ b/examples/demo/domain/src/main/resources/application.yml
@@ -69,7 +69,7 @@ isis:
     wicket:
       application:
         menubars-layout-xml: demoapp/dom/menubars.layout.xml
-        favicon-url: images/favicon.png
+        favicon-url: images/gift.svg
         brand-logo-header: images/gift_48.png
         brand-logo-signin: images/gift_256.png
         name: Apache Isis Demo App
diff --git a/examples/demo/domain/src/main/resources/static/images/gift.svg b/examples/demo/domain/src/main/resources/static/images/gift.svg
new file mode 100644
index 0000000..25a35ed
--- /dev/null
+++ b/examples/demo/domain/src/main/resources/static/images/gift.svg
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
+<path style="fill:#4F3F82;" d="M361,195c0,76.8-55.8,105.3-96.599,132.599H263.5c0,0.3-0.3,0.601-0.3,0.601
+	c-2.401,1.199-4.799,1.8-7.2,1.8c-2.701,0-5.099-0.901-7.5-2.401h-0.901C207.4,300.599,151,272.1,151,195c0-8.401,6.599-15,15-15
+	s15,6.599,15,15c0,32.399,16.199,62.699,43.2,80.7l16.8,11.4V165c0-8.401,6.599-15,15-15s15,6.599,15,15v122.1l16.8-11.4
+	c27.001-18.001,43.2-48.301,43.2-80.7c0-8.401,6.599-15,15-15S361,186.599,361,195z"/>
+<path style="fill:#3B2C68;" d="M361,195c0,76.8-55.8,105.3-96.599,132.599H263.5c0,0.3-0.3,0.601-0.3,0.601
+	c-2.401,1.199-4.799,1.8-7.2,1.8V150c8.401,0,15,6.599,15,15v122.1l16.8-11.4c27.001-18.001,43.2-48.301,43.2-80.7
+	c0-8.401,6.599-15,15-15S361,186.599,361,195z"/>
+<path style="fill:#FC1A40;" d="M346,360H166c-8.401,0-15,6.599-15,15v122c0,8.399,6.599,15,15,15h180c8.401,0,15-6.601,15-15V375
+	C361,366.599,354.401,360,346,360z"/>
+<path style="fill:#C60034;" d="M361,375v122c0,8.399-6.599,15-15,15h-90V360h90C354.401,360,361,366.599,361,375z"/>
+<path style="fill:#FF3E75;" d="M376,300H136c-8.401,0-15,6.599-15,15v60c0,8.399,6.599,15,15,15h240c8.401,0,15-6.601,15-15v-60
+	C391,306.599,384.401,300,376,300z"/>
+<path style="fill:#FC1A40;" d="M391,315v60c0,8.399-6.599,15-15,15H256v-90h120C384.401,300,391,306.599,391,315z"/>
+<path style="fill:#FCBF29;" d="M301,300h-90c0,65.204,0,136.894,0,212h90C301,469.966,301,342.439,301,300z"/>
+<path style="fill:#FE9923;" d="M301,300h-45c0,65.204,0,136.894,0,212h45C301,469.966,301,342.439,301,300z"/>
+<path style="fill:#FEDB41;" d="M301,300h-90c0,27.681,0,58.115,0,90h90C301,372.155,301,318.017,301,300z"/>
+<path style="fill:#FCBF29;" d="M301,300h-45c0,27.681,0,58.115,0,90h45C301,372.155,301,318.017,301,300z"/>
+<path style="fill:#FF5FA8;" d="M166,210c-41.353,0-75-40.371-75-90s33.647-90,75-90c16.553,0,32.227,6.284,45.322,18.193
+	c4.703,4.26,26.237,100.077,23.555,107.578C223.026,188.716,196,210,166,210z"/>
+<path style="fill:#FEDB41;" d="M256,0c-41.4,0-75,40.499-75,90c0,49.499,33.6,90,75,90s75-40.501,75-90C331,40.499,297.4,0,256,0z"
+	/>
+<path style="fill:#FF3E75;" d="M346,210c-30,0-57.026-21.284-68.877-54.229c-0.938-2.622-1.128-5.464-0.542-8.203
+	c1.62-7.591,18.367-94.186,24.097-99.375C313.773,36.284,329.447,30,346,30c41.353,0,75,40.371,75,90S387.353,210,346,210z"/>
+<path style="fill:#FCBF29;" d="M331,90c0,49.499-33.6,90-75,90V0C297.4,0,331,40.499,331,90z"/>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+</svg>
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/WebComponentBase.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/WebComponentBase.java
index 02c8e87..805b803 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/WebComponentBase.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/WebComponentBase.java
@@ -68,7 +68,7 @@ implements HasCommonContext {
     private <X> X computeIfAbsent(Class<X> type, X existingIfAny) {
         return existingIfAny!=null
                 ? existingIfAny
-                        : getCommonContext().lookupServiceElseFail(type);
+                : getCommonContext().lookupServiceElseFail(type);
     }
     
 }
\ No newline at end of file
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/favicon/Favicon.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/favicon/Favicon.java
deleted file mode 100644
index 59366ca..0000000
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/favicon/Favicon.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.isis.viewer.wicket.ui.components.widgets.favicon;
-
-import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.util.string.Strings;
-
-import org.apache.isis.viewer.wicket.ui.components.WebComponentBase;
-
-import lombok.val;
-
-/**
- * A component for application favorite icon
- */
-public class Favicon extends WebComponentBase {
-
-    private static final long serialVersionUID = 1L;
-
-    private String url = null;
-    private String contentType = null;
-
-    public Favicon(String id) {
-        super(id);
-    }
-
-    @Override
-    protected void onConfigure() {
-        super.onConfigure();
-        
-        val isisConfiguration = super.getIsisConfiguration();
-        val webAppContextPath = super.getWebAppContextPath();
-        
-        url = isisConfiguration.getViewer().getWicket().getApplication().getFaviconUrl()
-                .filter(x -> !Strings.isEmpty(x))
-                .map(webAppContextPath::prependContextPathIfLocal)
-                .orElse(null);
-
-        contentType = isisConfiguration.getViewer().getWicket().getApplication().getFaviconContentType()
-                .filter(x -> !Strings.isEmpty(x))
-                .orElse(null);;
-
-        setVisible(url != null);
-    }
-
-    @Override
-    protected void onComponentTag(ComponentTag tag) {
-        super.onComponentTag(tag);
-
-        if(url != null) {
-            tag.put("href", url);
-        }
-        if(contentType != null) {
-            tag.put("type", contentType);
-        }
-
-    }
-}
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.html b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.html
index f73406d..0902d5d 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.html
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.html
@@ -27,7 +27,6 @@
         <meta http-equiv="X-UA-COMPATIBLE" content="IE=edge">
         <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
         <title wicket:id="pageTitle"></title>
-        <link rel="icon" wicket:id="favicon">
         <wicket:header-items/>
     </head>
     <body>
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
index bc2a27d..0b20ce7 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/PageAbstract.java
@@ -16,7 +16,6 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-
 package org.apache.isis.viewer.wicket.ui.pages;
 
 import java.util.Arrays;
@@ -77,7 +76,6 @@ import org.apache.isis.viewer.wicket.ui.app.registry.ComponentFactoryRegistry;
 import org.apache.isis.viewer.wicket.ui.app.registry.ComponentFactoryRegistryAccessor;
 import org.apache.isis.viewer.wicket.ui.components.actionprompt.ActionPromptModalWindow;
 import org.apache.isis.viewer.wicket.ui.components.actionpromptsb.ActionPromptSidebar;
-import org.apache.isis.viewer.wicket.ui.components.widgets.favicon.Favicon;
 import org.apache.isis.viewer.wicket.ui.errors.ExceptionModel;
 import org.apache.isis.viewer.wicket.ui.errors.JGrowlBehaviour;
 import org.apache.isis.viewer.wicket.ui.util.CssClassAppender;
@@ -96,7 +94,9 @@ import de.agilecoders.wicket.core.settings.ITheme;
  * Convenience adapter for {@link WebPage}s built up using {@link ComponentType}s.
  */
 @Log4j2
-public abstract class PageAbstract extends WebPageBase implements ActionPromptProvider {
+public abstract class PageAbstract 
+extends WebPageBase 
+implements ActionPromptProvider {
 
     private static final long serialVersionUID = 1L;
     
@@ -113,7 +113,6 @@ public abstract class PageAbstract extends WebPageBase implements ActionPromptPr
     private static final String ID_ACTION_PROMPT_MODAL_WINDOW = "actionPromptModalWindow";
     private static final String ID_ACTION_PROMPT_SIDEBAR = "actionPromptSidebar";
     private static final String ID_PAGE_TITLE = "pageTitle";
-    private static final String ID_FAVICON = "favicon";
     public static final String ID_MENU_LINK = "menuLink";
     public static final String UIHINT_FOCUS = "focus";
 
@@ -148,8 +147,6 @@ public abstract class PageAbstract extends WebPageBase implements ActionPromptPr
 
             setTitle(title);
 
-            add(new Favicon(ID_FAVICON));
-
             themeDiv = new WebMarkupContainer(ID_THEME);
             add(themeDiv);
             String applicationName = getIsisConfiguration().getViewer().getWicket().getApplication().getName();
@@ -240,7 +237,7 @@ public abstract class PageAbstract extends WebPageBase implements ActionPromptPr
     protected void setTitle(final String title) {
         addOrReplace(new Label(ID_PAGE_TITLE, title != null
                 ? title
-                        : getIsisConfiguration().getViewer().getWicket().getApplication().getName()));
+                : getIsisConfiguration().getViewer().getWicket().getApplication().getName()));
     }
 
     private Class<? extends Page> getSignInPage() {
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/WebPageBase.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/WebPageBase.java
index 59c8826..3af58d9 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/WebPageBase.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/WebPageBase.java
@@ -18,10 +18,13 @@
  */
 package org.apache.isis.viewer.wicket.ui.pages;
 
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.MetaDataHeaderItem;
 import org.apache.wicket.markup.html.WebPage;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 
+import org.apache.isis.commons.internal.base._Strings;
 import org.apache.isis.core.config.IsisConfiguration;
 import org.apache.isis.core.config.viewer.wicket.WebAppContextPath;
 import org.apache.isis.core.interaction.session.InteractionFactory;
@@ -48,12 +51,31 @@ implements HasCommonContext {
     protected WebPageBase(PageParameters parameters) {
         super(parameters);
     }
-    
+
     protected WebPageBase(final IModel<?> model) {
         super(model);
     }
     
     @Override
+    public void renderHead(IHeaderResponse response) {
+        super.renderHead(response);
+        renderFavicon(response);
+    }
+
+    // -- FAVICON SUPPORT
+    
+    protected void renderFavicon(IHeaderResponse response) {
+        getIsisConfiguration().getViewer().getWicket().getApplication().getFaviconUrl()
+        .filter(_Strings::isNotEmpty)
+        .map(getWebAppContextPath()::prependContextPathIfLocal)
+        .ifPresent(faviconUrl->{
+            response.render(MetaDataHeaderItem.forLinkTag("icon", faviconUrl));    
+        });
+    }
+    
+    // -- DEPENDENCIES
+    
+    @Override
     public IsisAppCommonContext getCommonContext() {
         return commonContext = CommonContextUtils.computeIfAbsent(commonContext);
     }
@@ -74,13 +96,12 @@ implements HasCommonContext {
         return isisInteractionFactory = computeIfAbsent(InteractionFactory.class, isisInteractionFactory);
     }
     
-    
     // -- HELPER
     
     private <X> X computeIfAbsent(Class<X> type, X existingIfAny) {
         return existingIfAny!=null
                 ? existingIfAny
-                        : getCommonContext().lookupServiceElseFail(type);
+                : getCommonContext().lookupServiceElseFail(type);
     }
     
 }