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 2018/11/20 11:42:48 UTC
[isis] branch v2 updated: ISIS-2042: When PROTOTYPING warn when
menubars.layout.xml is missing
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new c4b2d96 ISIS-2042: When PROTOTYPING warn when menubars.layout.xml is missing
c4b2d96 is described below
commit c4b2d9610fd249f427adbe54590c78b5a7e7f8de
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Nov 20 12:42:31 2018 +0100
ISIS-2042: When PROTOTYPING warn when menubars.layout.xml is missing
Task-Url: https://issues.apache.org/jira/browse/ISIS-2042
---
.../menubars/MenuBarsLoaderServiceDefault.java | 45 +++++++++++++++++++++-
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/menubars/MenuBarsLoaderServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/menubars/MenuBarsLoaderServiceDefault.java
index ecb2c35..c632f71 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/menubars/MenuBarsLoaderServiceDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/menubars/MenuBarsLoaderServiceDefault.java
@@ -20,18 +20,26 @@ package org.apache.isis.core.runtime.services.menubars;
import java.nio.charset.StandardCharsets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.apache.isis.applib.AppManifest;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.NatureOfService;
import org.apache.isis.applib.layout.menubars.bootstrap3.BS3MenuBars;
import org.apache.isis.applib.services.jaxb.JaxbService;
import org.apache.isis.applib.services.menu.MenuBarsLoaderService;
+import org.apache.isis.commons.internal.base._Strings;
import org.apache.isis.commons.internal.context._Context;
-import org.apache.isis.commons.internal.resources._Resources;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
+import static org.apache.isis.commons.internal.resources._Resources.loadAsString;
+
@DomainService(nature = NatureOfService.DOMAIN)
public class MenuBarsLoaderServiceDefault implements MenuBarsLoaderService {
+
+ private final static Logger log = LoggerFactory.getLogger(MenuBarsLoaderServiceDefault.class);
+ private final static String menubarsLayoutResourceName = "menubars.layout.xml";
@Override
public boolean supportsReloading() {
@@ -44,13 +52,46 @@ public class MenuBarsLoaderServiceDefault implements MenuBarsLoaderService {
try {
final String xml =
- _Resources.loadAsString(appManifest.getClass(), "menubars.layout.xml", StandardCharsets.UTF_8);
+ loadAsString(appManifest.getClass(), menubarsLayoutResourceName, StandardCharsets.UTF_8);
+ // if the menubarsLayout resource is not found, print a warning only once and only when PROTOTYPING
+ if(_Strings.isEmpty(xml)) {
+ if(_Context.isPrototyping()) {
+ warnNotFound();
+ }
+ return null;
+ }
+
return jaxbService.fromXml(BS3MenuBars.class, xml);
} catch (Exception e) {
+ severeCannotLoad(e);
return null;
}
}
+
+ // -- HELPER
+
+ private boolean warnedOnce = false;
+
+ private void warnNotFound() {
+ if(warnedOnce) {
+ return;
+ }
+ final AppManifest appManifest = isisSessionFactory.getAppManifest();
+ log.warn(
+ String.format("Failed to locate resource '%s' at class-path relative to '%s'",
+ menubarsLayoutResourceName, appManifest.getClass().getName()));
+
+ warnedOnce = true;
+ }
+
+ private void severeCannotLoad(Exception cause) {
+ final AppManifest appManifest = isisSessionFactory.getAppManifest();
+ log.error(
+ String.format("Failed to load resource '%s' from class-path relative to '%s'",
+ menubarsLayoutResourceName, appManifest.getClass().getName()),
+ cause);
+ }
@javax.inject.Inject
JaxbService jaxbService;