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:org.cast.cwm.ResourceDirectory.java

License:Open Source License

/**
 * creates a new resource response based on the request attributes
 * /*ww w .  j  a  v  a  2 s .c  o m*/
 * @param attributes
 *            current request attributes from client
 * @return resource response for answering request
 */
@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
    String relativePath = "";
    PageParameters parameters = attributes.getParameters();
    for (int i = 0; i < parameters.getIndexedCount(); i++) {
        relativePath += parameters.get(i);
        relativePath += '/';
    }
    if (relativePath.endsWith("/"))
        relativePath = relativePath.substring(0, relativePath.length() - 1);
    log.trace("relativePath is {}", relativePath);

    String absolutePath = new File(sourceDirectory, relativePath).getAbsolutePath();

    final ResourceResponse resourceResponse = new ResourceResponse();

    final IResourceStream resourceStream = getResourceStream(absolutePath);

    // bail out if resource stream could not be found
    if (resourceStream == null) {
        return sendResourceError(absolutePath, resourceResponse, HttpServletResponse.SC_NOT_FOUND,
                "Unable to find resource");
    }

    // allow caching
    resourceResponse.setCacheScope(WebResponse.CacheScope.PUBLIC);
    resourceResponse.setCacheDuration(cacheDuration);

    // add Last-Modified header (to support HEAD requests and If-Modified-Since)
    resourceResponse.setLastModified(resourceStream.lastModifiedTime());

    if (resourceResponse.dataNeedsToBeWritten(attributes)) {
        String contentType = resourceStream.getContentType();

        if (contentType == null && Application.exists())
            contentType = Application.get().getMimeType(absolutePath);

        // set Content-Type (may be null)
        resourceResponse.setContentType(contentType);

        try {
            // read resource data
            final byte[] bytes;

            bytes = IOUtils.toByteArray(resourceStream.getInputStream());

            // send Content-Length header
            resourceResponse.setContentLength(bytes.length);

            // send response body with resource data
            resourceResponse.setWriteCallback(new WriteCallback() {
                @Override
                public void writeData(Attributes attributes) {
                    attributes.getResponse().write(bytes);
                }
            });
        } catch (IOException e) {
            log.debug(e.getMessage(), e);
            return sendResourceError(absolutePath, resourceResponse, 500, "Unable to read resource stream");
        } catch (ResourceStreamNotFoundException e) {
            log.debug(e.getMessage(), e);
            return sendResourceError(absolutePath, resourceResponse, 500, "Unable to open resource stream");
        } finally {
            try {
                resourceStream.close();
            } catch (IOException e) {
                log.warn("Unable to close the resource stream", e);
            }
        }
    }

    return resourceResponse;
}

From source file:org.cast.cwm.ResourceDirectory.java

License:Open Source License

/**
 * @param scope/*from w  w  w .j  a va2s  . c  om*/
 *            resource scope
 * @param path
 *            resource path
 * @return <code>true<code> if resource access is granted
 */
private boolean accept(Class<?> scope, String path) {
    IPackageResourceGuard guard = Application.get().getResourceSettings().getPackageResourceGuard();

    return guard.accept(scope, path);
}

From source file:org.cast.cwm.ThemeDirectoryRequestMapper.java

License:Open Source License

/**
 * Determine if this file is OK to send.
 * @param path resource path/*from   w  w w .j  av a 2s  . c  o m*/
 * @return <code>true<code> if resource access is granted
 */
private boolean accessCheck(String path) {
    IPackageResourceGuard guard = Application.get().getResourceSettings().getPackageResourceGuard();
    return guard.accept(Application.class, path);
}

From source file:org.cast.isi.ISIApplication.java

License:Open Source License

public static ISIApplication get() {
    return (ISIApplication) Application.get();
}

From source file:org.cast.isi.page.Login.java

License:Open Source License

@SuppressWarnings("unchecked")
public Login(PageParameters params) {
    super(params);

    pageTitle = (new StringResourceModel("Login.pageTitle", this, null, "Login").getString());
    setPageTitle(pageTitle);//from   w  ww  . j  a v  a2  s  . com
    add(new Label("pageTitle", pageTitle));
    add(new ShyLabel("loginMessage", new ResourceModel("Login.message", "")));
    add(new BookmarkablePageLink<Void>("home", ISIApplication.get().getHomePage())
            .setVisible(ISIApplication.get().isGuestAccessAllowed()));

    addApplicationTitles();

    add(new BookmarkablePageLink<Void>("forgot", ISIApplication.get().getForgotPasswordPageClass())
            .setVisible(ISIApplication.get().isEmailOn()));
    add(new BookmarkablePageLink<Void>("register", ISIApplication.get().getRegisterPageClass())
            .setVisible(ISIApplication.get().isSelfRegisterOn()));

    AuthApplication<User> app = null;
    try {
        app = ((AuthApplication<User>) Application.get());
    } catch (ClassCastException e) {
    }
    if (app == null || !app.getSignInPageClass().isInstance(this))
        throw new UnauthorizedInstantiationException(Login.class);
    if (params != null) {
        String username = params.get("username").toString();
        String token = params.get("token").toString();

        if (username != null && token != null) {
            User user = app.getUser(username);
            if (user != null && app.getToken(user).equals(token)) {
                AuthDataSession.get().signIn(user, true);
            }
            setResponsePage(((Application) app).getHomePage());
            getSession().bind();
            return;
        }
    }
    add(new SignInForm("form"));
    add(ISIApplication.get().getFooterPanel("pageFooter", params));
}

From source file:org.cdlflex.ui.pages.examples.FeedbackPanelPage.java

License:Apache License

public FeedbackPanelPage() {
    stripWicketTags = Application.get().getMarkupSettings().getStripWicketTags();

    add(feedbackPanel = newFeedbackPanel("feedback"));
    feedbackPanel.setOutputMarkupId(true);
    add(new Buttons("buttons"));
}

From source file:org.cdlflex.ui.pages.examples.FeedbackPanelPage.java

License:Apache License

protected FeedbackPanel newFeedbackPanel(String id) {
    return new FeedbackPanel(id) {
        private static final long serialVersionUID = 1L;

        @Override//from  www  .j a va  2s.  co  m
        protected void onBeforeRender() {
            super.onBeforeRender();
            Application.get().getMarkupSettings().setStripWicketTags(true);
        }

        @Override
        protected void onAfterRender() {
            super.onAfterRender();
            Application.get().getMarkupSettings().setStripWicketTags(stripWicketTags);
        }
    };
}

From source file:org.cdlflex.ui.pages.examples.StripTagExamplePage.java

License:Apache License

public StripTagExamplePage() {
    super();
    stripTags = Application.get().getMarkupSettings().getStripWicketTags();
}

From source file:org.cdlflex.ui.pages.examples.StripTagExamplePage.java

License:Apache License

public StripTagExamplePage(IModel<?> model) {
    super(model);
    stripTags = Application.get().getMarkupSettings().getStripWicketTags();
}

From source file:org.cdlflex.ui.pages.examples.StripTagExamplePage.java

License:Apache License

public StripTagExamplePage(PageParameters parameters) {
    super(parameters);
    stripTags = Application.get().getMarkupSettings().getStripWicketTags();
}