All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.infobip.kafkistry.webapp.menu.MenuItemsInjector.kt Maven / Gradle / Ivy

There is a newer version: 0.8.0
Show newest version
package com.infobip.kafkistry.webapp.menu

import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor
import org.springframework.web.servlet.ModelAndView
import java.util.*
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse

@Component
class MenuItemsInjector(
        menuItemsProviders: Optional>
) : HandlerInterceptor {

    private val menuItems: List = menuItemsProviders.orElse(emptyList())
            .map { it.provideMenuItems() }
            .flatten()

    override fun postHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any, modelAndView: ModelAndView?) {
        if (modelAndView == null) {
            return
        }
        injectMenuItems(modelAndView)
    }

    fun injectMenuItems(modelAndView: ModelAndView) {
        modelAndView.addObject("menuItems", menuItems)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy