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:fiftyfive.wicket.shiro.ShiroWicketPlugin.java

License:Apache License

/**
 * Looks up a localized string from the application properties.
 *//*from   www  .j a  va  2  s  .co m*/
protected String getLocalizedMessage(String key, String theDefault) {
    return Application.get().getResourceSettings().getLocalizer().getString(key, null, null, theDefault);
}

From source file:fiftyfive.wicket.util.LoggingUtils.java

License:Apache License

/**
 * Returns a Map with information associated with the following keys:
 * <ul>//w ww. jav  a  2  s.  c o m
 * <li>{@code Active Sessions} (if {@link IRequestLogger} is enabled)</li>
 * <li>{@code Memory Usage}</li>
 * <li>{@code IP Address}</li>
 * <li>{@code Uptime} (if app is a {@link FoundationApplication})</li>
 * </ul>
 */
public static Map<String, Object> getApplicationInfo() {
    Map<String, Object> info = new LinkedHashMap<String, Object>();

    String active = describeActiveSessions();
    if (active != null) {
        info.put("Active Sessions", active);
    }
    info.put("Memory Usage", describeMemoryUsage());
    info.put("IP Address", getHostIpAddress());

    Application app = Application.get();
    if (app instanceof FoundationApplication) {
        info.put("Uptime", ((FoundationApplication) app).getUptime());
    }
    return info;
}

From source file:fiftyfive.wicket.util.LoggingUtils.java

License:Apache License

/**
 * Returns the amount of time the currently session has been active.
 * Depends on Wicket's {@link IRequestLogger} being enabled. If it is not,
 * returns {@code null}./* ww w  .j  a  v  a 2 s  .co  m*/
 */
public static Duration getSessionDuration() {
    Date start = null;
    Session currSession = Session.get();
    IRequestLogger log = Application.get().getRequestLogger();

    if (log != null && currSession != null && currSession.getId() != null) {
        String sessionId = currSession.getId();
        SessionData[] sessions = log.getLiveSessions();
        if (sessions != null) {
            for (SessionData sess : sessions) {
                if (sessionId.equals(sess.getSessionId())) {
                    start = sess.getStartDate();
                    break;
                }
            }
        }
    }
    return nullSafeElapsed(start);
}

From source file:fiftyfive.wicket.util.LoggingUtils.java

License:Apache License

/**
 * Returns a string that describes the active sessions in this format:
 * {@code 5 (16 peak)}. This information comes from the application's
 * {@link IRequestLogger}. If the logger is not enabled, returns
 * {@code null}.//from   w  w w  .  j  a v  a  2 s. c  o m
 */
public static String describeActiveSessions() {
    IRequestLogger log = Application.get().getRequestLogger();
    if (null == log)
        return null;

    SessionData[] sessions = log.getLiveSessions();
    if (null == sessions)
        return null;

    return String.format("%d (%d peak)", sessions.length, log.getPeakSessions());
}

From source file:fiftyfive.wicket.util.LoggingUtils.java

License:Apache License

private static IRequestHandler guessOriginalRequestHandler() {
    IRequestMapper mapper = Application.get().getRootRequestMapper();
    return mapper.mapRequest(RequestCycle.get().getRequest());
}

From source file:fiftyfive.wicket.util.Shortcuts.java

License:Apache License

/**
 * Creates a header contributor that adds a &lt;link&gt; to a CSS file with
 * the specified name and media; the name is resolved relative to the current
 * application class.//w w w  . j  a va2 s. co  m
 * For example:
 * <pre class="example">
 * add(cssResource("application.css", "screen"));</pre>
 * <p>
 * will add a {@code <link media="screen">} to the &lt;head&gt; for {@code application.css},
 * found in the same classpath location as your wicket application class.
 * <p>
 * This is equivalent to overriding {@code renderHead()} with:
 * <pre class="example">
 * response.renderCSSReference(
 *     new PackageResourceReference(Application.get().getClass(), "application.css"),
 *     "screen"
 * );</pre>
 * 
 * @since 3.0
 */
public static Behavior cssResource(String filename, String media) {
    return cssResource(Application.get().getClass(), filename, media);
}

From source file:fiftyfive.wicket.util.Shortcuts.java

License:Apache License

/**
 * Creates a header contributor that adds a &lt;link&gt; to an
 * Internet Explorer conditional stylesheet CSS file with
 * the specified name, relative to the current application class.
 * The stylesheet will apply based on the IE condition argument.
 * For example:/* ww  w  . ja  va  2s .co  m*/
 * <pre class="example">
 * add(cssConditionalResource("IE 7", "ie-7.css"));</pre>
 * <p>
 * will add a &lt;link&gt; to the &lt;head&gt; for {@code ie-7.css},
 * found in the same classpath location as your wicket application class.
 * The stylesheet will only be loaded in IE 7 browsers.
 * <p>
 * This is equivalent to:
 * <pre class="example">
 * InternetExplorerCss.getConditionalHeaderContribution(
 *     "IE 7"
 *     new PackageResourceReference(
 *         Application.get().getClass(), "ie-7.css")
 *     )
 * );</pre>
 * 
 * @since 2.0
 */
public static Behavior cssConditionalResource(String cond, String filename) {
    Args.notNull(cond, "cond");
    Args.notNull(filename, "filename");
    return InternetExplorerCss.getConditionalHeaderContribution(cond,
            new PackageResourceReference(Application.get().getClass(), filename));
}

From source file:fr.openwide.core.wicket.markup.html.model.CountMessageModel.java

License:Apache License

@Override
public String getObject() {
    // this shouldn't be called in the Wicket environment BUT we sometimes use this in Excel exports
    return Application.get().getResourceSettings().getLocalizer().getString(getResourceKey(), null,
            Model.of(getPropertySubstitutionBean()));
}

From source file:fr.xebia.demo.wicket.blog.view.AddCommentForm.java

License:Apache License

private void saveComment(Comment comment) {
    try {/*from   w w w.  j  av  a2 s . com*/
        comment.setDate(new Date());
        comment.setApproved(false);
        logger.debug("Adding comment: " + comment);
        commentService.save(comment);
        setResponsePage(Application.get().getHomePage(),
                PageParametersUtils.fromStringMessage(getString("comment.list.added", new Model(comment))));
    } catch (Exception e) {
        logger.error("Error while saving comment", e);
        PageParameters pageParameters = PageParametersUtils.fromException(e);
        pageParameters.put(AddCommentPage.PARAM_POSTID_KEY, comment.getPostId());
        throw new RestartResponseException(AddCommentPage.class, pageParameters);
    }
}

From source file:fr.xebia.demo.wicket.blog.view.AddCommentPage.java

License:Apache License

private void createComponents(Long postId) {
    add(new AddCommentForm("commentForm", postId));
    add(new PageLink("backToHome", Application.get().getHomePage()));
}