Search in sources :

Example 1 with GlobalInterceptor

use of de.tudarmstadt.ukp.clarin.webanno.support.interceptors.GlobalInterceptor in project webanno by webanno.

the class ApplicationPageBase method commonInit.

private void commonInit() {
    for (GlobalInterceptor interceptor : interceptorsRegistry.getInterceptors()) {
        interceptor.intercept(this);
    }
    footerItems = new ListModel<>(new ArrayList<>());
    footerItemRegistry.getFooterItems().stream().map(c -> c.create("item")).forEach(c -> footerItems.getObject().add(c));
    footer = new WebMarkupContainer("footer");
    footer.setOutputMarkupId(true);
    add(footer);
    footer.add(new ListView<Component>("footerItems", footerItems) {

        private static final long serialVersionUID = 5912513189482015963L;

        {
            setReuseItems(true);
        }

        @Override
        protected void populateItem(ListItem<Component> aItem) {
            aItem.setOutputMarkupPlaceholderTag(true);
            aItem.add(aItem.getModelObject());
        }
    });
    Properties settings = SettingsUtil.getSettings();
    // Override locale to be used by application
    String locale = settings.getProperty(SettingsUtil.CFG_LOCALE, "en");
    switch(locale) {
        case "auto":
            // Do nothing - locale is picked up from browser
            break;
        default:
            // Override the locale in the session
            getSession().setLocale(Locale.forLanguageTag(locale));
            break;
    }
    // Add menubar
    try {
        Class<? extends Component> menubarClass = getApplication().getMetaData(MENUBAR_CLASS);
        if (menubarClass == null) {
            menubarClass = MenuBar.class;
        }
        add(ConstructorUtils.invokeConstructor(menubarClass, "menubar"));
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e1) {
        throw new RuntimeException(e1);
    }
    feedbackPanel = new BootstrapFeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.setFilter((IFeedbackMessageFilter) aMessage -> {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String username = auth != null ? auth.getName() : "SYSTEM";
        if (aMessage.isFatal()) {
            LOG.error("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isError()) {
            LOG.error("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isWarning()) {
            LOG.warn("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isInfo()) {
            LOG.info("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isDebug()) {
            LOG.debug("{}: {}", username, aMessage.getMessage());
        }
        return true;
    });
    add(feedbackPanel);
}
Also used : RuntimeConfigurationType(org.apache.wicket.RuntimeConfigurationType) SettingsUtil(de.tudarmstadt.ukp.clarin.webanno.support.SettingsUtil) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) LoggerFactory(org.slf4j.LoggerFactory) IFeedbackMessageFilter(org.apache.wicket.feedback.IFeedbackMessageFilter) GlobalInterceptorsRegistry(de.tudarmstadt.ukp.clarin.webanno.support.interceptors.GlobalInterceptorsRegistry) ArrayList(java.util.ArrayList) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Locale(java.util.Locale) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) NoOpResourceCachingStrategy(org.apache.wicket.request.resource.caching.NoOpResourceCachingStrategy) BootstrapFeedbackPanel(de.tudarmstadt.ukp.clarin.webanno.support.bootstrap.BootstrapFeedbackPanel) IModel(org.apache.wicket.model.IModel) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) ListView(org.apache.wicket.markup.html.list.ListView) ListModel(org.apache.wicket.model.util.ListModel) Properties(java.util.Properties) Logger(org.slf4j.Logger) ListItem(org.apache.wicket.markup.html.list.ListItem) Component(org.apache.wicket.Component) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) MetaDataKey(org.apache.wicket.MetaDataKey) GlobalInterceptor(de.tudarmstadt.ukp.clarin.webanno.support.interceptors.GlobalInterceptor) ConstructorUtils(org.apache.commons.lang3.reflect.ConstructorUtils) WebPage(org.apache.wicket.markup.html.WebPage) Authentication(org.springframework.security.core.Authentication) IPartialPageRequestHandler(org.apache.wicket.core.request.handler.IPartialPageRequestHandler) FooterItemRegistry(de.tudarmstadt.ukp.clarin.webanno.ui.core.footer.FooterItemRegistry) GlobalInterceptor(de.tudarmstadt.ukp.clarin.webanno.support.interceptors.GlobalInterceptor) ArrayList(java.util.ArrayList) Properties(java.util.Properties) BootstrapFeedbackPanel(de.tudarmstadt.ukp.clarin.webanno.support.bootstrap.BootstrapFeedbackPanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) Authentication(org.springframework.security.core.Authentication) Component(org.apache.wicket.Component)

Aggregations

SettingsUtil (de.tudarmstadt.ukp.clarin.webanno.support.SettingsUtil)1 BootstrapFeedbackPanel (de.tudarmstadt.ukp.clarin.webanno.support.bootstrap.BootstrapFeedbackPanel)1 GlobalInterceptor (de.tudarmstadt.ukp.clarin.webanno.support.interceptors.GlobalInterceptor)1 GlobalInterceptorsRegistry (de.tudarmstadt.ukp.clarin.webanno.support.interceptors.GlobalInterceptorsRegistry)1 FooterItemRegistry (de.tudarmstadt.ukp.clarin.webanno.ui.core.footer.FooterItemRegistry)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Properties (java.util.Properties)1 ConstructorUtils (org.apache.commons.lang3.reflect.ConstructorUtils)1 Component (org.apache.wicket.Component)1 MetaDataKey (org.apache.wicket.MetaDataKey)1 RuntimeConfigurationType (org.apache.wicket.RuntimeConfigurationType)1 IPartialPageRequestHandler (org.apache.wicket.core.request.handler.IPartialPageRequestHandler)1 IFeedbackMessageFilter (org.apache.wicket.feedback.IFeedbackMessageFilter)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 WebPage (org.apache.wicket.markup.html.WebPage)1 ListItem (org.apache.wicket.markup.html.list.ListItem)1 ListView (org.apache.wicket.markup.html.list.ListView)1