Example usage for org.apache.wicket.protocol.http WebSession getClientInfo

List of usage examples for org.apache.wicket.protocol.http WebSession getClientInfo

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http WebSession getClientInfo.

Prototype

@Override
public WebClientInfo getClientInfo() 

Source Link

Document

To gather the client information this implementation redirects temporarily to a special page ( BrowserInfoPage ).

Usage

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.home.page.ApplicationPageBase.java

License:Apache License

@SuppressWarnings({ "serial" })
private void commonInit() {
    //        getSession().setLocale(Locale.ENGLISH);

    logoutPanel = new LogoutPanel("logoutPanel");
    feedbackPanel = new FeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.add(new AttributeModifier("class", "error"));
    feedbackPanel.setFilter(new IFeedbackMessageFilter() {
        @Override/*from   w  w w . j  a v a2  s.co m*/
        public boolean accept(FeedbackMessage aMessage) {
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            String username = auth != null ? auth.getName() : "SYSTEM";
            if (aMessage.isFatal()) {
                LOG.fatal(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;
        }
    });

    versionLabel = new Label("version", SettingsUtil.getVersionString());

    embeddedDbWarning = new Label("embeddedDbWarning", "USE THIS INSTALLATION FOR TESTING ONLY -- "
            + "AN EMBEDDED DATABASE IS NOT RECOMMENDED FOR PRODUCTION USE");
    embeddedDbWarning.setVisible(false);
    try {
        String driver = repository.getDatabaseDriverName();
        embeddedDbWarning.setVisible(StringUtils.contains(driver.toLowerCase(Locale.US), "hsql"));
    } catch (Throwable e) {
        LOG.warn("Unable to determine which database is being used", e);
    }

    // Override warning about embedded database.
    Properties settings = SettingsUtil.getSettings();
    if ("false".equalsIgnoreCase(settings.getProperty("warnings.embeddedDatabase"))) {
        embeddedDbWarning.setVisible(false);
    }

    // Display a warning when using an unsupported browser
    RequestCycle requestCycle = RequestCycle.get();
    WebClientInfo clientInfo;
    if (Session.exists()) {
        WebSession session = WebSession.get();
        clientInfo = session.getClientInfo();
    } else {
        clientInfo = new WebClientInfo(requestCycle);
    }
    ClientProperties clientProperties = clientInfo.getProperties();

    browserWarning = new Label("browserWarning",
            "THIS BROWSER IS NOT SUPPORTED -- " + "PLEASE USE CHROME OR SAFARI");
    browserWarning.setVisible(!clientProperties.isBrowserSafari() && !clientProperties.isBrowserChrome());

    // Override warning about browser.
    if ("false".equalsIgnoreCase(settings.getProperty("warnings.unsupportedBrowser"))) {
        browserWarning.setVisible(false);
    }

    boolean helpAvailable;
    try {
        Application.get().getResourceSettings().getLocalizer().getString("page.help.link", this);
        Application.get().getResourceSettings().getLocalizer().getString("page.help", this);
        helpAvailable = true;
    } catch (MissingResourceException e) {
        helpAvailable = false;
    }

    add(helpLink = new ExternalLink("helpLink", new ResourceModel("page.help.link", ""),
            new ResourceModel("page.help", "")));
    helpLink.setPopupSettings(new PopupSettings("_blank"));
    helpLink.setVisible(helpAvailable);

    add(logoutPanel);
    add(feedbackPanel);
    add(versionLabel);
    add(embeddedDbWarning);
    add(browserWarning);
}

From source file:org.cast.cwm.components.BrowserInfoGatheringForm.java

License:Open Source License

/**
 * @see org.apache.wicket.markup.html.form.Form#onSubmit()
 *//*from ww w .ja v a2s  .c  o  m*/
@Override
protected void onSubmit() {
    RequestCycle requestCycle = getRequestCycle();
    WebSession session = (WebSession) getSession();
    ClientInfo ci = session.getClientInfo();

    if (ci == null) {
        ci = new WebClientInfo(requestCycle);
        getSession().setClientInfo(ci);
    } else {
        if (!(ci instanceof WebClientInfo))
            throw new RuntimeException("ClientInfo is not of expected type");
    }
    WebClientInfo clientInfo = (WebClientInfo) ci;

    ClientProperties properties = clientInfo.getProperties();
    bean.merge(properties);
}