Example usage for org.apache.wicket Application get

List of usage examples for org.apache.wicket Application get

Introduction

In this page you can find the example usage for org.apache.wicket Application get.

Prototype

public static Application get() 

Source Link

Document

Get Application for current thread.

Usage

From source file:name.martingeisse.wicket.component.sprite.ApplicationSpriteSupport.java

License:Open Source License

/**
 * Returns the sprite support object for the application of the calling thread,
 * or null if none is associated with that application.
 * /* w w  w . ja  v a  2s.  c o m*/
 * @return the sprite support object
 */
public static ApplicationSpriteSupport get() {
    return get(Application.get());
}

From source file:name.martingeisse.wicket.component.sprite.SpriteAtlas.java

License:Open Source License

/**
 * Constructor. This also registers a shared resource for the atlas using the
 * {@link SpriteAtlas} class and provided name.
 *//*  w ww . java  2 s.  c  om*/
SpriteAtlas(String name, String contentType, byte[] data) {
    this.name = name;
    this.resource = new ByteArrayResource(contentType, data);
    Application.get().getSharedResources().add(SpriteAtlas.class, name, null, null, null, resource);
}

From source file:name.martingeisse.wicket.helpers.Iframe.java

License:Open Source License

@Override
protected void onComponentTag(final ComponentTag tag) {
    super.onComponentTag(tag);
    if (tag.isOpenClose()) {
        tag.setType(TagType.OPEN);//from   w ww  .  j  a v  a  2s .  com
    }
    final Object modelObject = getDefaultModelObject();
    if (modelObject instanceof IResource) {
        tag.put("src", urlFor(IResourceListener.INTERFACE, contentParameters));
    } else if (modelObject instanceof ResourceReference) {
        final ResourceReference resourceReference = (ResourceReference) modelObject;
        if (resourceReference.canBeRegistered() && Application.exists()) {
            Application.get().getResourceReferenceRegistry().registerResourceReference(resourceReference);
        }
        tag.put("src", RequestCycle.get().urlFor(resourceReference, contentParameters));
    } else if (modelObject instanceof IPageProvider) {
        setSrcAttribute(tag, (IPageProvider) modelObject);
    } else if (modelObject instanceof IRequestablePage) {
        setSrcAttribute(tag, new PageProvider((IRequestablePage) modelObject));
    } else if (modelObject instanceof Class<?>) {
        final Class<?> c = (Class<?>) modelObject;
        if (Page.class.isAssignableFrom(c)) {
            setSrcAttribute(tag, new PageProvider(c.asSubclass(Page.class)));
        } else {
            throw new RuntimeException(
                    "cannot handle iframe model object: Class<" + c.getCanonicalName() + ">");
        }
    } else {
        throw new RuntimeException("cannot handle iframe model object: " + modelObject);
    }
}

From source file:net.databinder.auth.AuthDataSessionBase.java

License:Open Source License

protected AuthApplication<T> getApp() {
    return (AuthApplication<T>) Application.get();
}

From source file:net.databinder.auth.AuthDataSessionBase.java

License:Open Source License

public static String getUserCookieName() {
    return Application.get().getClass().getSimpleName() + "_USER";
}

From source file:net.databinder.auth.AuthDataSessionBase.java

License:Open Source License

public static String getAuthCookieName() {
    return Application.get().getClass().getSimpleName() + "_AUTH";
}

From source file:net.databinder.auth.components.DataProfilePanelBase.java

License:Open Source License

/** @return true if username is available (can not load via AuthApplication, or is current user). */
public static boolean isAvailable(String username) {
    AuthApplication authSettings = (AuthApplication) Application.get();

    DataUser found = (DataUser) authSettings.getUser(username),
            current = ((AuthSession) WebSession.get()).getUser();
    return found == null || found.equals(current);
}

From source file:net.databinder.auth.components.DataSignInPageBase.java

License:Open Source License

public DataSignInPageBase(PageParameters params, ReturnPage returnPage) {
    AuthApplication<T> app = null;
    try {//  w  ww.jav a2s. c  om
        app = ((AuthApplication<T>) Application.get());
    } catch (ClassCastException e) {
    }
    // make sure the user is not trying to sign in or register with the wrong page
    if (app == null || !app.getSignInPageClass().isInstance(this))
        throw new UnauthorizedInstantiationException(DataSignInPageBase.class);

    if (params != null) {
        String username = params.get("username").toString();
        String token = params.get("token").toString();
        // e-mail auth, for example
        if (username != null && token != null) {
            T user = app.getUser(username);

            if (user != null && app.getToken(user).equals(token))
                getAuthSession().signIn(user, true);
            setResponsePage(((Application) app).getHomePage());
            RequestCycle.get()
                    .scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler(
                            new PageProvider(((Application) app).getHomePage(), params),
                            RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT));
            return;
        }
    }

    add(new Label("title", new ResourceModel("data.auth.title.sign_in", "Please sign in")));

    sourceList = new SourceList();

    add(profileSocket = profileSocket("profileSocket", returnPage));
    add(new WebMarkupContainer("profileLinkWrapper") {
        public boolean isVisible() {
            return profileLink.isEnabled();
        }
    }.add((profileLink = sourceList.new SourceLink("profileLink", profileSocket))
            .add(new Label("text", getString("data.auth.register_link", null, "Register now"))))
            .add(new Label("text", getString("data.auth.pre_register_link", null, "Don't have an account?"))));

    add(signinSocket = signinSocket("signinSocket", returnPage));
    add(new WebMarkupContainer("signinLinkWrapper") {
        @Override
        public boolean isVisible() {
            return signinLink.isEnabled();
        }
    }.add(new Label("text", getString("data.auth.pre_sign_in_link", null, "Already have an account?")))
            .add((signinLink = sourceList.new SourceLink("signinLink", signinSocket))
                    .add(new Label("text", getString("data.auth.sign_in_link", null, "Sign in")))));
    signinLink.onClick(); // show sign in first
}

From source file:net.databinder.components.RenderedLabel.java

License:Open Source License

/**
 * Utility method to load a specific instance of a the rendering shared resource.
 *///w  ww .  j  a  v  a  2 s .  c  om
protected static void loadSharedResources(RenderedTextImageResource res, String text, Font font, Color color,
        Color backgroundColor, Integer maxWidth) {
    res.setCacheable(true);
    res.backgroundColor = backgroundColor == null ? defaultBackgroundColor : backgroundColor;
    res.color = color == null ? defaultColor : color;
    res.font = font == null ? defaultFont : font;
    res.maxWidth = maxWidth;
    res.text = text;

    String hash = Integer.toHexString(getLabelHash(text, font, color, backgroundColor, maxWidth));
    SharedResources shared = Application.get().getSharedResources();

    shared.add(RenderedLabel.class, hash, null, null, res);
}

From source file:net.databinder.hib.Databinder.java

License:Open Source License

/**
 * @param key object, or null for the default factory
 * @return session factory, as returned by the application
 * @throws WicketRuntimeException if session factory can not be found 
 * @see HibernateApplication/*from  w w w  .j  a  v  a  2s  .  c  o m*/
 */
public static SessionFactory getHibernateSessionFactory(Object key) {
    Application app = Application.get();
    if (app instanceof HibernateApplication)
        return ((HibernateApplication) app).getHibernateSessionFactory(key);
    throw new WicketRuntimeException("Please implement HibernateApplication in your Application subclass.");
}