Example usage for org.apache.wicket.protocol.http.request WebClientInfo getUserAgent

List of usage examples for org.apache.wicket.protocol.http.request WebClientInfo getUserAgent

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http.request WebClientInfo getUserAgent.

Prototype

public final String getUserAgent() 

Source Link

Document

returns the user agent string.

Usage

From source file:at.molindo.wicketutils.utils.WicketUtils.java

License:Apache License

public static String getUserAgent() {
    final WebClientInfo info = getClientInfo();
    return info == null ? null : info.getUserAgent();
}

From source file:at.molindo.wicketutils.utils.WicketUtils.java

License:Apache License

public static String getClientInfoString() {
    final WebClientInfo info = getClientInfo();
    return info == null ? null : info.getUserAgent() + " (" + info.getProperties().getRemoteAddress() + ")";
}

From source file:com.przemo.projectmanagementweb.controls.LoginPanel.java

public LoginPanel(String id) {
    super(id);//from   w  ww.  ja v  a2s.  c o  m
    Form form = new Form("loginPanel") {
        @Override
        protected void onSubmit() {
            WebClientInfo info = (WebClientInfo) Session.get().getClientInfo();
            if (loginService.login(username, password, info.getProperties().getRemoteAddress(),
                    info.getUserAgent())) {
                setResponsePage(SprintsListPage.class);
            }
        }
    };
    form.add(new TextField("username", new PropertyModel(this, "username")));
    form.add(new PasswordTextField("password", new PropertyModel<>(this, "password")));
    add(form);
}

From source file:com.servoy.j2db.server.headlessclient.WebClient.java

License:Open Source License

@Override
@SuppressWarnings("nls")
public String getClientOSName() {
    if (Session.exists()) {
        Session webClientSession = Session.get();
        if (webClientSession != null) {
            WebClientInfo clientInfo = (WebClientInfo) webClientSession.getClientInfo();
            if (clientInfo != null && clientInfo.getProperties() != null) {
                String userAgent = clientInfo.getUserAgent();
                if (userAgent != null) {
                    if (userAgent.indexOf("NT 6.1") != -1)
                        return "Windows 7";
                    if (userAgent.indexOf("NT 6.0") != -1)
                        return "Windows Vista";
                    if (userAgent.indexOf("NT 5.1") != -1 || userAgent.indexOf("Windows XP") != -1)
                        return "Windows XP";
                    if (userAgent.indexOf("Linux") != -1)
                        return "Linux";
                    if (userAgent.indexOf("Mac") != -1)
                        return "Mac OS";
                }//from  w  ww. j av  a 2 s .com
                return clientInfo.getProperties().getNavigatorPlatform();
            }
        }
    }
    return System.getProperty("os.name");
}

From source file:com.tysanclan.site.projectewok.event.handlers.CheckUserAgentOnLogin.java

License:Open Source License

@Override
public EventResult onEvent(LoginEvent event) {
    WebClientInfo info = TysanSession.get().getClientInfo();

    String userAgent = info.getUserAgent();

    if (userAgent.length() > 255) {
        userAgent = userAgent.substring(0, 255);
    }/* www . j  a  v  a  2 s.  c o  m*/

    MobileUserAgentFilter filter = new MobileUserAgentFilter();

    filter.setIdentifier(userAgent);

    if (userAgentDAO.countByFilter(filter) == 0) {
        MobileUserAgent agent = new MobileUserAgent();
        agent.setIdentifier(userAgent);
        switch (guessStatus(userAgent)) {
        case MOBILE:
            agent.setMobile(true);
            break;
        case PC:
            agent.setMobile(false);
            break;
        case UNKNOWN:
            agent.setMobile(null);
            break;

        }

        userAgentDAO.save(agent);
        log.info("Added new user agent: " + userAgent);

    }

    return EventResult.ok();
}

From source file:com.tysanclan.site.projectewok.pages.member.AbstractElectionPage.java

License:Open Source License

/**
 * //from  w ww .  j av  a 2s  . co  m
 */
public AbstractElectionPage(String title, T election) {
    super(title);

    final boolean isNominationOpen = election.isNominationOpen();

    WebClientInfo clientInfo = TysanSession.get().getClientInfo();

    // If user is using IE7, offer him an alternative
    if (!isNominationOpen
            && (clientInfo.getUserAgent().contains("MSIE") || clientInfo.getUserAgent().contains("Trident"))) {
        throw new RestartResponseAtInterceptPageException(getInternetExplorerAlternativePage(election));
    }

    votes = new TreeMap<Integer, Long>();
    candidates = election.getCandidates().size();

    List<User> users = new LinkedList<User>();
    users.addAll(election.getCandidates());

    ListView<User> candidateView = new ListView<User>("candidates", ModelMaker.wrap(users)) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<User> item) {
            MemberListItem mitem = new MemberListItem("candidate", item.getModelObject());

            if (!isNominationOpen) {
                mitem.add(new DraggableBehavior() {
                    private static final long serialVersionUID = 1L;

                    /**
                     * @see org.odlabs.wiquery.ui.draggable.DraggableBehavior#statement()
                     */
                    @Override
                    public JsStatement statement() {
                        return new JsQuery(getComponent()).$().chain("draggable", "{ revert: true }");

                    }
                });
                mitem.setOutputMarkupId(true);
            }

            item.add(mitem);

        }

    };

    add(new Label("label", isNominationOpen ? "Candidates" : "Cast your vote!"));

    TimeZone tz = getUser().getTimezone() != null ? TimeZone.getTimeZone(getUser().getTimezone())
            : DateUtil.NEW_YORK;

    Calendar cal = Calendar.getInstance(tz, Locale.US);
    cal.setTime(election.getStart());
    cal.add(Calendar.WEEK_OF_YEAR, 1);

    Label explanation = new Label("explanation", isNominationOpen
            ? "Voting will commence " + DateUtil.getTimezoneFormattedString(cal.getTime(), tz.getID())
            : "Drag and drop the candidates of your choice to cast your vote. Place your favorites at the top and your least favorites at the bottom. The order you give them will determine their score. The higher their position the higher the score");

    Form<Void> castVoteForm = new Form<Void>("voteform") {
        private static final long serialVersionUID = 1L;

        @SpringBean
        private UserDAO userDAO;

        /**
         * @see org.apache.wicket.markup.html.form.Form#onSubmit()
         */
        @Override
        protected void onSubmit() {
            List<User> userList = new LinkedList<User>();

            for (Integer position : getVotes().keySet()) {
                userList.add(userDAO.load(getVotes().get(position)));
            }

            onVoteSubmit(userList);
        }

    };

    castVoteForm.add(candidateView);

    List<Integer> positions = new LinkedList<Integer>();
    for (int i = 0; i < users.size(); i++) {
        positions.add(users.size() - (i + 1));
    }

    castVoteForm.add(new ListView<Integer>("slots", positions) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<Integer> item) {
            item.add(new Label("position", new Model<Integer>(item.getIndex() + 1)));

            final int index = item.getIndex();

            item.add(new Label("score", new Model<Integer>(item.getModelObject())));
            WebMarkupContainer container = new WebMarkupContainer("target");
            container.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true);

            if (!isNominationOpen) {
                DroppableAjaxBehavior behavior = new DroppableAjaxBehavior() {
                    private static final long serialVersionUID = 1L;

                    protected void drop(AjaxRequestTarget target, Component source, Component dropped) {

                        if (dropped instanceof MemberListItem) {
                            MemberListItem mli = (MemberListItem) dropped;

                            MemberListItem item2 = new MemberListItem("target", mli.getUser());
                            item2.setOutputMarkupId(true);
                            getComponent().replaceWith(item2);
                            mli.setVisible(false);

                            getVotes().put(index, mli.getUser().getId());

                            if (votes.size() == AbstractElectionPage.this.candidates) {
                                submitButton.setVisible(true);
                                if (target != null) {
                                    target.add(submitButton);
                                }
                            }

                            if (target != null) {

                                target.add(mli);
                                target.add(item2);
                            }
                        }

                    }
                };

                behavior.setHoverClass("election-hover");

                container.add(behavior);
            }

            item.add(container

            );
        }

    });

    add(explanation);
    add(castVoteForm);
    submitButton = new WebMarkupContainer("submit").setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true)
            .setVisible(false);

    castVoteForm.add(submitButton);
}

From source file:com.userweave.components.customModalWindow.SurveyModalWindow.java

License:Open Source License

private boolean isIe7Or8() {
    WebClientInfo clientInfo = (WebClientInfo) Session.get().getClientInfo();

    if (clientInfo == null || clientInfo.getUserAgent() == null) {
        return false;
    } else {/*ww w.ja  va 2 s  .  c  o m*/
        return clientInfo.getUserAgent().contains("MSIE 7.0") || clientInfo.getUserAgent().contains("MSIE 8.0");
    }
}

From source file:com.userweave.components.navigation.NavigationBorder.java

License:Open Source License

@Override
public void renderHead(IHeaderResponse response) {
    /**/*  w  ww . ja v a2s  . co  m*/
     * @bugfix: Conditinal Comments wont work, so add
     *          IE7 fix by HeaderContributor
     * @author: opr
     */
    WebClientInfo clientInfo = WebSession.get().getClientInfo();

    if (clientInfo.getUserAgent().contains("MSIE 7.0")) {
        response.renderCSSReference(
                new PackageResourceReference(NavigationBorder.class, "NavigationBorder_ie7.css"));
    }
}

From source file:de.inren.frontend.application.InRenApplication.java

License:Apache License

@Override
public void init() {
    super.init();

    /* Spring injection. */
    this.getComponentInstantiationListeners().add(new SpringComponentInjector(this));

    /* Performance measurement */
    if (false) {/*from www .j  a va2 s .c  o m*/
        getComponentInstantiationListeners().add(new RenderPerformanceListener());
    }

    configureBootstrap();

    initializeServices();

    getSecuritySettings().setAuthorizationStrategy(new MetaDataRoleAuthorizationStrategy(this));

    initializeFailSafeLocalize();
    new AnnotatedMountScanner().scanPackage("de.inren").mount(this);

    mountResource("/" + PictureResource.PICTURE_RESOURCE + "/${" + PictureResource.ID + "}/${"
            + PictureResource.SIZE + "}", PictureResource.asReference());

    // Access to Images by url
    // mount(createImageURIRequestTargetUrlCodingStrategy());
    // mount(createLayoutURIRequestTargetUrlCodingStrategy());
    // mount(createThumbnailURIRequestTargetUrlCodingStrategy());

    // Render hints in html to navigate from firebug to eclipse
    // WicketSource.configure(this);

    // TODO gehrt ins codeflower package. => Init fr Wicket
    // module/packages machen.
    final IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard();
    if (packageResourceGuard instanceof SecurePackageResourceGuard) {
        ((SecurePackageResourceGuard) packageResourceGuard).addPattern("+*.json");
        ((SecurePackageResourceGuard) packageResourceGuard).addPattern("+**.ttf");
    }

    /** for ajax progressbar on upload */
    getApplicationSettings().setUploadProgressUpdatesEnabled(true);

    // I don't like messy html code.
    this.getMarkupSettings().setStripWicketTags(true);
    this.getMarkupSettings().setStripComments(true);

    // This application can be reached from internet, but you must know the
    // right port.
    // So I like to know who else besides me tries to connect.

    getRequestCycleListeners().add(new AbstractRequestCycleListener() {
        @Override
        public void onBeginRequest(RequestCycle cycle) {
            WebClientInfo ci = new WebClientInfo(cycle);
            log.debug("Request info: " + ci.getProperties().getRemoteAddress() + ", "
                    + ("".equals(DnsUtil.lookup(ci.getProperties().getRemoteAddress())) ? ""
                            : DnsUtil.lookup(ci.getProperties().getRemoteAddress()) + ", ")
                    + (cycle.getRequest().getUrl().getPath() == null
                            || "".equals(cycle.getRequest().getUrl().getPath()) ? ""
                                    : cycle.getRequest().getUrl().getPath() + ", ")
                    + ci.getUserAgent());
        }
    });

    getSecuritySettings().setAuthorizationStrategy(new InRenAuthorizationStrategy());

    // MetaDataRoleAuthorizationStrategy.authorize(AdminOnlyPage.class,
    // Roles.ADMIN);
    // mountPage("admin", AdminOnlyPage.class);

    // TODO das funzzt nur auf Class

    // LIST<COMPONENTACCESS> COMPONENTACCESS =
    // COMPONENTACCESSSERVICE.GETCOMPONENTACCESSLIST();
    // FOR (COMPONENTACCESS CA : COMPONENTACCESS) {
    // COLLECTION<ROLE> ROLES = CA.GETGRANTEDROLES();
    // STRINGBUFFER ROLESTRING = NEW STRINGBUFFER();
    // FOR (ROLE ROLE : ROLES) {
    // ROLESTRING.APPEND(ROLE);
    // }
    // METADATAROLEAUTHORIZATIONSTRATEGY.AUTHORIZE(CA.GETNAME(),
    // ROLESTRING.TOSTRING());
    // }
}

From source file:org.dcm4chee.web.war.folder.webviewer.Webviewer.java

License:LGPL

@SuppressWarnings("serial")
public static AbstractLink getLink(final AbstractDicomModel model, final WebviewerLinkProvider[] providers,
        final StudyPermissionHelper studyPermissionHelper, TooltipBehaviour tooltip, ModalWindow modalWindow,
        final WebviewerLinkClickedCallback callback) {
    final WebviewerLinkProvider[] p = { null };
    AbstractLink link = null;/*from ww w  .  j  a v  a2s  .c o  m*/
    if (providers != null)
        for (int i = 0; i < providers.length; i++) {
            if (isLevelSupported(model, providers[i])) {
                if (p[0] == null) {
                    p[0] = providers[i];
                } else {
                    link = getWebviewerSelectionPageLink(model, providers, modalWindow, callback);
                    break;
                }
            }
        }
    if (p[0] == null) {
        link = new ExternalLink(WEBVIEW_ID, "http://dummy");
        link.setVisible(false);
    } else {
        if (link == null) {
            if (p[0].hasOwnWindow()) {
                String url = getUrlForModel(model, p[0]);
                link = new ExternalLink(WEBVIEW_ID, url);
                ((ExternalLink) link).setPopupSettings(getPopupSettingsForDirectGET(url));
            } else if (p[0].supportViewingAllSelection()) {
                link = new Link<Object>(WEBVIEW_ID) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick() {
                        try {
                            ExportDicomModel dicomModel = new ExportDicomModel(model);

                            RequestCycle.get().setRequestTarget(EmptyRequestTarget.getInstance());

                            HttpServletRequest request = ((WebRequestCycle) RequestCycle.get()).getWebRequest()
                                    .getHttpServletRequest();
                            HttpServletResponse response = ((WebResponse) getRequestCycle().getResponse())
                                    .getHttpServletResponse();
                            String result = p[0].viewAllSelection(dicomModel.getPatients(), request, response);
                            if (!p[0].notWebPageLinkTarget()) {
                                ViewerPage page = new ViewerPage();
                                page.add(new Label("viewer", new Model<String>(result))
                                        .setEscapeModelStrings(false));
                                this.setResponsePage(page);
                            }
                        } catch (Exception e) {
                            log.error("Cannot view the selection!", e);
                            if (p[0].notWebPageLinkTarget()) {
                                setResponsePage(getPage());
                            }
                        }
                    }
                };

                WebClientInfo clientInfo = (WebClientInfo) WebRequestCycle.get().getClientInfo();
                String browser = clientInfo.getUserAgent();

                if (!p[0].notWebPageLinkTarget() || (browser != null && browser.contains("Firefox"))) {
                    ((Link) link).setPopupSettings(new PopupSettings(PageMap.forName("webviewPage"),
                            PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS));
                }
            } else {
                link = new Link<Object>(WEBVIEW_ID) {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick() {
                        setResponsePage(new WebviewerRedirectPage(model, p[0]));
                    }
                };
                ((Link) link).setPopupSettings(new PopupSettings(PageMap.forName("webviewPage"),
                        PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS));
            }
            if (callback != null) {
                link.add(new AjaxEventBehavior("onclick") {
                    @Override
                    public void onEvent(AjaxRequestTarget target) {
                        callback.linkClicked(target);
                    }

                    // just for the case, if the link is rendered as a <button> element
                    @Override
                    protected void onComponentTag(ComponentTag tag) {
                        String current = tag.getAttribute("onclick");

                        super.onComponentTag(tag);

                        if (current != null) {
                            tag.put("onclick",
                                    new StringBuilder(tag.getAttribute("onclick")).append(";").append(current));
                        }
                    }
                });
            }
        }
        if (model instanceof PatientModel) {
            link.setVisible(studyPermissionHelper.checkPermission(model.getDicomModelsOfNextLevel(),
                    StudyPermission.READ_ACTION, false));
        } else {
            link.setVisible(studyPermissionHelper.checkPermission(model, StudyPermission.READ_ACTION));
        }
    }
    Image image = new Image("webviewImg", ImageManager.IMAGE_FOLDER_VIEWER);
    image.add(new ImageSizeBehaviour("vertical-align: middle;"));
    if (tooltip != null)
        image.add(tooltip);
    link.add(image);
    return link;
}