Example usage for org.apache.wicket.util.time Time valueOf

List of usage examples for org.apache.wicket.util.time Time valueOf

Introduction

In this page you can find the example usage for org.apache.wicket.util.time Time valueOf.

Prototype

public static Time valueOf(final TimeOfDay timeOfDay) 

Source Link

Document

Retrieves a Time instance based on the given TimeOfDay object.

Usage

From source file:com.gitblit.wicket.pages.BasePage.java

License:Apache License

/**
 * Sets the last-modified header field and the expires field.
 *
 * @param when//from  w w w.j a v a2 s .co  m
 */
protected final void setLastModified(Date when) {
    if (when == null) {
        return;
    }

    if (when.before(app().getBootDate())) {
        // last-modified can not be before the Gitblit boot date
        // this helps ensure that pages are properly refreshed after a
        // server config change
        when = app().getBootDate();
    }

    int expires = app().settings().getInteger(Keys.web.pageCacheExpires, 0);
    WebResponse response = (WebResponse) getResponse();
    response.setLastModifiedTime(Time.valueOf(when));
    response.addHeader("Expires",
            String.valueOf(System.currentTimeMillis() + Duration.minutes(expires).getMilliseconds()));
}

From source file:com.mastfrog.acteur.wicket.adapters.RequestAdapter.java

License:Open Source License

@Override
public Time getDateHeader(String string) {
    String hdr = getHeader(string);
    if (hdr == null) {
        return null;
    }/*w  w w. j a v a2 s .c  o  m*/
    DateTime dt = Headers.ISO2822DateFormat.parseDateTime(hdr);
    return Time.valueOf(dt.toDate());
}

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

License:Open Source License

/**
 * @see org.apache.wicket.Resource#getResourceStream()
 *//*from  w  w  w  . jav a  2  s  .  c o m*/
@Override
public IResourceStream getResourceStream() {
    String css = "";
    ValueMap params = getParameters();
    Long time = null;
    if (params.size() == 1) {
        Iterator iterator = params.entrySet().iterator();
        if (iterator.hasNext()) {
            Map.Entry entry = (Entry) iterator.next();
            String solutionName = (String) entry.getKey();
            Pair<String, Long> filterTime = filterTime((String) entry.getValue());
            String formInstanceName = filterTime.getLeft();
            time = filterTime.getRight();

            String solutionAndForm = solutionName + "/" + formInstanceName; //$NON-NLS-1$
            String templateDir = "default"; //$NON-NLS-1$
            IServiceProvider sp = null;
            Solution solution = null;
            Form form = null;
            if (Session.exists()) {
                sp = WebClientSession.get().getWebClient();
                if (sp != null) {
                    IForm fc = ((WebClient) sp).getFormManager().getForm(formInstanceName);
                    if (fc instanceof FormController) {
                        FlattenedSolution clientSolution = sp.getFlattenedSolution();
                        form = clientSolution.getForm(((FormController) fc).getForm().getName());
                    }
                }
                templateDir = WebClientSession.get().getTemplateDirectoryName();
            }

            final String fullpath = "/servoy-webclient/templates/" + templateDir + "/" + solutionAndForm
                    + ".css";
            try {
                URL url = context.getResource(fullpath);
                if (url != null) {
                    return new NullUrlResourceStream(url);
                }
            } catch (Exception e) {
                Debug.error(e);
            }

            try {
                IApplicationServerSingleton as = ApplicationServerRegistry.get();
                RootObjectMetaData sd = as.getLocalRepository().getRootObjectMetaData(solutionName,
                        IRepository.SOLUTIONS);
                if (sd != null) {
                    solution = (Solution) as.getLocalRepository().getActiveRootObject(sd.getRootObjectId());
                    if (form == null) {
                        form = solution.getForm(formInstanceName);
                    }
                }
                if (form != null) {
                    Pair<String, String> formHTMLAndCSS = TemplateGenerator.getFormHTMLAndCSS(solution, form,
                            sp, formInstanceName);
                    css = formHTMLAndCSS.getRight();
                }
            } catch (Exception e) {
                Debug.error(e);
            }
        }
    }
    StringResourceStream stream = new StringResourceStream(css, "text/css"); //$NON-NLS-1$
    stream.setLastModified(time != null ? Time.valueOf(time.longValue()) : null);
    return stream;
}

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

License:Open Source License

private ResourceState getResource(final String iconId, final String solutionName) {
    return new ResourceState() {
        private String contentType;
        private int length;
        byte[] array = null;

        @Override//  w ww  .  j  ava  2  s.  co m
        public Time lastModifiedTime() {
            try {
                IRootObject solution = ApplicationServerRegistry.get().getLocalRepository()
                        .getActiveRootObject(solutionName, IRepository.SOLUTIONS);
                if (solution != null)
                    return Time.valueOf(solution.getLastModifiedTime());
            } catch (Exception e) {
                Debug.trace(e);
            }
            return time;
        }

        @Override
        public byte[] getData() {
            if (array == null) {
                boolean closeFS = false;
                try {
                    final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
                    FlattenedSolution fs = null;
                    try {
                        if (Session.exists() && ((WebClientSession) Session.get()).getWebClient() != null) {
                            fs = ((WebClientSession) Session.get()).getWebClient().getFlattenedSolution();
                        }

                        if (fs == null) {
                            SolutionMetaData solutionMetaData = (SolutionMetaData) repository
                                    .getRootObjectMetaData(solutionName, IRepository.SOLUTIONS);
                            if (solutionMetaData == null)
                                return new byte[0];
                            closeFS = true;
                            IApplicationServer as = ApplicationServerRegistry
                                    .getService(IApplicationServer.class);
                            fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {
                                @Override
                                public IRepository getRepository() {
                                    return repository;
                                }

                            });
                        }

                        Media m = fs.getMedia(iconId);
                        if (m == null) {
                            try {
                                Integer iIconID = new Integer(iconId);
                                m = fs.getMedia(iIconID.intValue());
                            } catch (NumberFormatException ex) {
                                Debug.error("no media found for: " + iconId);
                            }
                        }
                        if (m != null) {
                            array = m.getMediaData();
                            contentType = m.getMimeType();
                        }
                    } finally {
                        if (closeFS && fs != null) {
                            fs.close(null);
                        }
                    }
                    if (array != null) {
                        if (contentType == null) {
                            contentType = MimeTypes.getContentType(array);
                        }
                        length = array.length;
                    }
                } catch (Exception ex) {
                    Debug.error(ex);
                }
            }
            return array == null ? new byte[0] : array;
        }

        /**
         * @see wicket.markup.html.DynamicWebResource.ResourceState#getLength()
         */
        @Override
        public int getLength() {
            return length;
        }

        @Override
        public String getContentType() {
            return contentType;
        }
    };
}

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

License:Open Source License

public void touchTime() {
    time = Time.valueOf(System.currentTimeMillis());
}

From source file:com.socialsite.image.AbstractImageResource.java

License:Open Source License

@Override
protected ResourceState getResourceState() {
    // parameters
    final ValueMap params = getParameters();
    final long id = params.getAsLong("id");
    final Date lastModified = getImageDao().getLastModifiedTime(id);
    // load the image from the database
    final ImageResourceState imageResourceState = new ImageResourceState(Time.valueOf(lastModified));
    try {/*w  ww .j ava  2  s  .  c o  m*/

        imageResourceState.setContentType("image/jpeg");

        // Check for 304 request
        final ServletWebRequest request = (ServletWebRequest) RequestCycle.get().getRequest();
        final String ifModifiedSince = request.getHttpServletRequest().getHeader("If-Modified-Since");
        if (ifModifiedSince != null) {
            final SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
            final Date date = format.parse(ifModifiedSince);
            if (date != null) {
                if (lastModified.compareTo(date) < 0 || lastModified.compareTo(date) == 0) {
                    // this is a 304 not modified response.so no need to
                    // fetch the image from the database
                    return imageResourceState;
                }
            }
        }

        // normal request
        if (params.containsKey("thumb")) {
            imageResourceState.setData(getImageDao().getThumb(id));
        } else {
            imageResourceState.setData(getImageDao().getImage(id));
        }
    } catch (final Exception e) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
        return new EmptyResourceState();
    }
    return imageResourceState;
}

From source file:de.alpharogroup.wicket.base.application.BaseWebApplication.java

License:Apache License

/**
 * Gets the elapsed duration since this application was initialized.
 *
 * @return the uptime/*  ww w .  j  a va2  s .c om*/
 */
public Duration getUptime() {
    final DateTime startup = getStartupDate();
    if (null != startup) {
        return Duration.elapsed(Time.valueOf(startup.toDate()));
    }
    return Duration.NONE;
}

From source file:de.inren.service.picture.PictureResource.java

License:Apache License

protected Time getImageLastModified() {
    IRequestParameters params = RequestCycle.get().getRequest().getRequestParameters();
    File file = getImageFile(params);
    if (file != null) {
        return Time.valueOf(new Date(file.lastModified()));
    }/*  w  w  w  .jav a  2s.c  om*/
    return null;
}

From source file:fiftyfive.wicket.FoundationApplication.java

License:Apache License

/**
 * Returns the amount of time elapsed since this application was
 * initialized by the Wicket framework./*w w w .  ja v  a  2  s  .c  o m*/
 * 
 * @since 2.0
 */
public Duration getUptime() {
    Date start = getStartupDate();
    if (null == start) {
        return Duration.milliseconds(0);
    }
    return Duration.elapsed(Time.valueOf(start));
}

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

License:Apache License

/**
 * Returns a Duration of time elapsed since the specified date, or
 * {@code null} or the date is {@code null}.
 *///from ww  w  .j ava  2 s .c o m
private static Duration nullSafeElapsed(Date since) {
    return null == since ? null : Duration.elapsed(Time.valueOf(since));
}