List of usage examples for org.apache.wicket Application get
public static Application get()
From source file:org.apache.isis.viewer.wicket.viewer.services.GuiceBeanProviderWicket.java
License:Apache License
@Programmatic @Override/*w w w.java 2 s . c o m*/ public <T> T lookup(final Class<T> beanType, final Annotation qualifier) { final Application application = Application.get(); final GuiceInjectorHolder injectorHolder = application.getMetaData(GuiceInjectorHolder.INJECTOR_KEY); final Injector injector = injectorHolder.getInjector(); return injector.getInstance(Key.get(beanType, qualifier)); }
From source file:org.apache.oodt.cas.curation.HomePage.java
License:Apache License
public HomePage() { super();// ww w. j av a 2 s .c o m CurationApp app = ((CurationApp) Application.get()); String loggedInLabel; String logoutLabel = "Log Out"; CurationSession session = (CurationSession) getSession(); if (session.isLoggedIn()) { loggedInLabel = "Logged in as " + session.getLoginUsername() + "."; add(new Label("loggedin_label", loggedInLabel)); add(new Label("logout_label", logoutLabel).setVisible(false)); add(new Link<String>("login_link") { @Override public void onClick() { PageParameters params = new PageParameters(); params.add("action", "login"); setResponsePage(LoginPage.class, params); } }.setVisible(false)); add(new Link<String>("logout_link") { @Override public void onClick() { PageParameters params = new PageParameters(); params.add("action", "logout"); setResponsePage(LoginPage.class, params); } }); } else { loggedInLabel = "Not logged in."; add(new Label("loggedin_label", loggedInLabel)); add(new Label("logout_label", logoutLabel).setVisible(false)); add(new Link<String>("login_link") { @Override public void onClick() { PageParameters params = new PageParameters(); params.add("action", "login"); setResponsePage(LoginPage.class, params); } }); add(new Link<String>("logout_link") { @Override public void onClick() { PageParameters params = new PageParameters(); params.add("action", "logout"); setResponsePage(LoginPage.class, params); } }.setVisible(false)); } String projectName = app.getProjectName() + " CAS Curation"; add(new Label("project_name", projectName)); add(new Label("crumb_name", "Main")); add(new Link<String>("home_link") { @Override public void onClick() { setResponsePage(WorkbenchPage.class); } }); }
From source file:org.apache.oodt.cas.curation.login.LoginPage.java
License:Apache License
public LoginPage(PageParameters parameters) { super();//from w w w . j a va 2 s . c o m final CurationApp app = (CurationApp) Application.get(); final CurationSession session = (CurationSession) getSession(); String ssoClass = app.getSSOImplClass(); final AbstractWebBasedSingleSignOn sso = SingleSignOnFactory.getWebBasedSingleSignOn(ssoClass); sso.setReq(((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest()); sso.setRes(((WebResponse) RequestCycle.get().getResponse()).getHttpServletResponse()); String action = parameters.getString("action"); String appNameString = app.getProjectName() + " CAS Curation Interface"; add(new Label("login_project_name", appNameString)); replace(new Label("crumb_name", "Login")); final WebMarkupContainer creds = new WebMarkupContainer("invalid_creds"); final WebMarkupContainer connect = new WebMarkupContainer("connect_error"); creds.setVisible(false); connect.setVisible(false); final TextField<String> loginUser = new TextField<String>("login_username", new Model<String>("")); final PasswordTextField pass = new PasswordTextField("password", new Model<String>("")); Form<?> form = new Form<Void>("login_form") { private static final long serialVersionUID = 1L; @Override protected void onSubmit() { String username = loginUser.getModelObject(); String password = pass.getModelObject(); if (sso.login(username, password)) { session.setLoggedIn(true); session.setLoginUsername(username); setResponsePage(WorkbenchPage.class); } else { session.setLoggedIn(false); if (session.getLoginUsername() == null) { connect.setVisible(true); } else { creds.setVisible(true); } } } }; form.add(loginUser); form.add(pass); form.add(creds); form.add(connect); add(form); if (action.equals("logout")) { sso.logout(); session.setLoginUsername(null); session.setLoggedIn(false); PageParameters params = new PageParameters(); params.add("action", "login"); setResponsePage(LoginPage.class, params); } }
From source file:org.apache.openmeetings.db.util.ApplicationHelper.java
License:Apache License
public static IApplication ensureApplication(Long langId) { IApplication a = null;// w ww . j a va 2 s .co m if (Application.exists()) { a = (IApplication) Application.get(); } else { WebApplication app = (WebApplication) Application.get(wicketApplicationName); LabelDao.initLanguageMap(); if (app == null) { try { app = (WebApplication) LabelDao.getAppClass().newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { log.error("Failed to create Application"); return null; } app.setServletContext(new MockServletContext(app, null)); app.setName(wicketApplicationName); ServletContext sc = app.getServletContext(); OMContextListener omcl = new OMContextListener(); omcl.contextInitialized(new ServletContextEvent(sc)); XmlWebApplicationContext xmlContext = new XmlWebApplicationContext(); xmlContext.setConfigLocation("classpath:openmeetings-applicationContext.xml"); xmlContext.setServletContext(sc); xmlContext.refresh(); sc.setAttribute(ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, xmlContext); app.setConfigurationType(RuntimeConfigurationType.DEPLOYMENT); ThreadContext.setApplication(app); app.initApplication(); } else { ThreadContext.setApplication(app); } a = (IApplication) Application.get(wicketApplicationName); } if (ThreadContext.getRequestCycle() == null) { ServletWebRequest req = new ServletWebRequest(new MockHttpServletRequest((Application) a, new MockHttpSession(a.getServletContext()), a.getServletContext()), ""); RequestCycleContext rctx = new RequestCycleContext(req, new MockWebResponse(), a.getRootRequestMapper(), a.getExceptionMapperProvider().get()); ThreadContext.setRequestCycle(new RequestCycle(rctx)); } if (ThreadContext.getSession() == null) { WebSession s = WebSession.get(); if (langId > 0) { ((IWebSession) s).setLanguage(langId); } } return a; }
From source file:org.artifactory.common.wicket.component.panel.sidemenu.MenuItem.java
License:Open Source License
private Status fetchStatus(MenuNode node, Class<? extends Page> currentPage, boolean enabled) { if (!enabled) { return DISABLED; }// w w w .j ava2s. c om if (currentPage.equals(node.getPageClass())) { return SELECTED; } Boolean opened = node.isOpened(); if (Boolean.TRUE.equals(opened)) { return OPENED; } else if (Boolean.FALSE.equals(opened)) { return ENABLED; } SiteMap siteMap = ((SiteMapAware) Application.get()).getSiteMap(); MenuNode current = siteMap.getPageNode(currentPage); while (current != null) { if (current.equals(node)) { return OPENED; } current = current.getParent(); } return ENABLED; }
From source file:org.artifactory.common.wicket.component.panel.sidemenu.MenuPanel.java
License:Open Source License
public MenuPanel(String id, Class<? extends Page> pageClass) { super(id);/* www.j ava 2s .c o m*/ SiteMap siteMap = ((SiteMapAware) Application.get()).getSiteMap(); List<MenuNode> menuPages = siteMap.getRoot().getChildren(); for (MenuNode pageNode : menuPages) { add(new MenuItem(newChildId(), pageNode, pageClass)); } }
From source file:org.artifactory.common.wicket.contributor.ResourcePackage.java
License:Open Source License
public ResourcePackage addCssTemplate(final String path) { add(new IHeaderContributor() { @Override//w w w.ja v a2s .c o m public void renderHead(IHeaderResponse response) { String script = readInterpolatedString(path); ICssCompressor compressor = Application.get().getResourceSettings().getCssCompressor(); if (compressor != null) { script = compressor.compress(script); } response.renderCSS(script, null); } }); return this; }
From source file:org.artifactory.common.wicket.model.sitemap.MenuNode.java
License:Open Source License
protected IAuthorizationStrategy getAuthorizationStrategy() { return Application.get().getSecuritySettings().getAuthorizationStrategy(); }
From source file:org.artifactory.common.wicket.util.JavaScriptUtils.java
License:Open Source License
public static String compress(String javascript) { IJavaScriptCompressor compressor = Application.get().getResourceSettings().getJavaScriptCompressor(); return compressor == null ? javascript : compressor.compress(javascript); }
From source file:org.artifactory.common.wicket.util.WicketUtils.java
License:Open Source License
private static String readResourceNoCache(Class scope, String file) { InputStream inputStream = null; try {//from ww w .jav a2 s . c om final String path = Packages.absolutePath(scope, file); final IResourceStream resourceStream = Application.get().getResourceSettings() .getResourceStreamLocator().locate(scope, path); inputStream = resourceStream.getInputStream(); return Streams.readString(inputStream, "utf-8"); } catch (ResourceStreamNotFoundException e) { throw new RuntimeException(String.format("Can't find resource \"%s.%s\"", scope.getName(), file), e); } catch (IOException e) { throw new RuntimeException(String.format("Can't read resource \"%s.%s\"", scope.getName(), file), e); } finally { Closeables.closeQuietly(inputStream); } }