From 32bf19f57169fdfebddf5cacf33c5d38a7257fd7 Mon Sep 17 00:00:00 2001 From: Dustin Frisch Date: Thu, 12 Oct 2023 14:28:48 +0200 Subject: [PATCH 1/4] NMS-15790: Transport bootstrap.jsp args in context --- .../java/org/opennms/web/utils/Bootstrap.java | 142 ++++++++++++++++++ .../main/webapp/WEB-INF/jsp/event/detail.jsp | 2 +- .../WEB-INF/jsp/graph/results-error.jsp | 24 +-- .../main/webapp/WEB-INF/jsp/graph/results.jsp | 26 ++-- .../src/main/webapp/includes/bootstrap.jsp | 60 +++----- 5 files changed, 192 insertions(+), 62 deletions(-) create mode 100644 opennms-webapp/src/main/java/org/opennms/web/utils/Bootstrap.java diff --git a/opennms-webapp/src/main/java/org/opennms/web/utils/Bootstrap.java b/opennms-webapp/src/main/java/org/opennms/web/utils/Bootstrap.java new file mode 100644 index 000000000000..b5a67866fefa --- /dev/null +++ b/opennms-webapp/src/main/java/org/opennms/web/utils/Bootstrap.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * This file is part of OpenNMS(R). + * + * Copyright (C) 2023 The OpenNMS Group, Inc. + * OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc. + * + * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. + * + * OpenNMS(R) is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * OpenNMS(R) 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with OpenNMS(R). If not, see: + * http://www.gnu.org/licenses/ + * + * For more information contact: + * OpenNMS(R) Licensing + * http://www.opennms.org/ + * http://www.opennms.com/ + *******************************************************************************/ + +package org.opennms.web.utils; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.PageContext; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Set; + +public class Bootstrap { + + private final PageContext pageContext; + + private final List headTitles = Lists.newArrayList(); + + private final List breadcrumbs = Lists.newArrayList(); + + private String ngApp; + private String scrollSpy; + + private Set flags = Sets.newHashSet(); + + private Bootstrap(final PageContext pageContext) { + this.pageContext = Objects.requireNonNull(pageContext); + } + + private static String eval(final PageContext pageContext, final String attr, final String expr) { + try { + return Objects.toString(ExpressionEvaluatorManager.evaluate(attr, expr, Object.class, pageContext)); + } catch (final JspException e) { + throw new RuntimeException(e); + } + } + + public void build(final HttpServletRequest request) throws JspException { + request.setAttribute("__bs_headTitles", this.headTitles); + request.setAttribute("__bs_ngApp", this.ngApp); + request.setAttribute("__bs_scrollSpy", this.scrollSpy); + request.setAttribute("__bs_breadcrumbs", this.breadcrumbs); + request.setAttribute("__bs_flags", this.flags); + } + + public Bootstrap headTitle(final String headTitle) { + this.headTitles.add(eval(this.pageContext, "headTitle", Objects.requireNonNull(headTitle))); + return this; + } + + private Bootstrap breadcrumb(final Breadcrumb entry) { + this.breadcrumbs.add(Objects.requireNonNull(entry)); + return this; + } + + public Bootstrap breadcrumb(final String title) { + final var breadcrumb = new Breadcrumb(eval(this.pageContext, "breadcrumb.title", title)); + return this.breadcrumb(breadcrumb); + } + + public Bootstrap breadcrumb(final String title, final String link) { + final var breadcrumb = new Breadcrumb(eval(this.pageContext, "breadcrumb.title", title)) + .withLink(eval(this.pageContext, "breadcrumb.link", link)); + + return this.breadcrumb(breadcrumb); + } + + public Bootstrap scrollSpy(final String scrollSpy) { + this.scrollSpy = scrollSpy; + return this; + } + + public Bootstrap ngApp(final String ngApp) { + this.ngApp = ngApp; + return this; + } + + public Bootstrap flags(final String... flags) { + this.flags.addAll(Arrays.asList(flags)); + return this; + } + + public static class Breadcrumb { + public final String title; + public final String link; + + public Breadcrumb(final String title) { + this(title, null); + } + + public Breadcrumb(final String title, final String link) { + this.title = Objects.requireNonNull(title); + this.link = link; + } + + public Breadcrumb withLink(final String link) { + return new Breadcrumb(this.title, link); + } + + public String getTitle() { + return this.title; + } + + public String getLink() { + return this.link; + } + } + + public static Bootstrap with(final PageContext pageContext) { + return new Bootstrap(pageContext); + } +} diff --git a/opennms-webapp/src/main/webapp/WEB-INF/jsp/event/detail.jsp b/opennms-webapp/src/main/webapp/WEB-INF/jsp/event/detail.jsp index 6a569c8e1a0f..0ef472e11ffe 100644 --- a/opennms-webapp/src/main/webapp/WEB-INF/jsp/event/detail.jsp +++ b/opennms-webapp/src/main/webapp/WEB-INF/jsp/event/detail.jsp @@ -107,7 +107,7 @@ - + diff --git a/opennms-webapp/src/main/webapp/WEB-INF/jsp/graph/results-error.jsp b/opennms-webapp/src/main/webapp/WEB-INF/jsp/graph/results-error.jsp index 593412ad9dc6..da6afec3f807 100644 --- a/opennms-webapp/src/main/webapp/WEB-INF/jsp/graph/results-error.jsp +++ b/opennms-webapp/src/main/webapp/WEB-INF/jsp/graph/results-error.jsp @@ -37,18 +37,18 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> - - - - - - - - - - - - + + + + + + + + + + + +
diff --git a/opennms-webapp/src/main/webapp/WEB-INF/jsp/graph/results.jsp b/opennms-webapp/src/main/webapp/WEB-INF/jsp/graph/results.jsp index fb4cf829bb9d..7248b141d3a9 100644 --- a/opennms-webapp/src/main/webapp/WEB-INF/jsp/graph/results.jsp +++ b/opennms-webapp/src/main/webapp/WEB-INF/jsp/graph/results.jsp @@ -37,19 +37,19 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/opennms-webapp/src/main/webapp/includes/bootstrap.jsp b/opennms-webapp/src/main/webapp/includes/bootstrap.jsp index 7b2106888e42..1d4b5a354521 100644 --- a/opennms-webapp/src/main/webapp/includes/bootstrap.jsp +++ b/opennms-webapp/src/main/webapp/includes/bootstrap.jsp @@ -62,8 +62,8 @@ <%= "" %> - <c:forEach var="headTitle" items="${paramValues.headTitle}"> - <c:out value="${headTitle}" escapeXml="false"/> | + <c:forEach var="headTitle" items="${__bs_headTitles}"> + <c:out value="${headTitle}" escapeXml="true"/> | </c:forEach> OpenNMS Web Console @@ -81,10 +81,6 @@ - - - - @@ -116,9 +112,6 @@ - - - @@ -183,18 +176,6 @@ - - - - - - - - - - - -