List of usage examples for org.apache.wicket.util.time Duration valueOf
public static Duration valueOf(final String string) throws StringValueConversionException
String
to a new Duration
object. From source file:org.efaps.ui.wicket.models.objects.UIProcessInstanceLog.java
License:Apache License
/** * @return the duration as formated string * @throws EFapsException on error//w w w.j ava 2 s . c o m */ public String getDurationTime() throws EFapsException { return Duration.valueOf(getDuration()).toString(Context.getThreadContext().getLocale()); }
From source file:org.hippoecm.frontend.plugins.cms.admin.plugins.ChangePasswordShortcutPlugin.java
License:Apache License
public ChangePasswordShortcutPlugin(final IPluginContext context, final IPluginConfig config) { super(context, config); notificationPeriod = (long) getPluginConfig().getDouble("passwordexpirationnotificationdays", 3) * ONE_DAY_MS;/* w ww . jav a 2s . c o m*/ final UserSession session = UserSession.get(); // password max age is defined on the /hippo:configuration/hippo:security node try { Node securityNode = session.getRootNode().getNode(SECURITY_PATH); if (securityNode.hasProperty(HippoNodeType.HIPPO_PASSWORDMAXAGEDAYS)) { passwordMaxAge = (long) (securityNode.getProperty(HippoNodeType.HIPPO_PASSWORDMAXAGEDAYS) .getDouble() * ONE_DAY_MS); } } catch (RepositoryException e) { log.error("Failed to determine configured password maximum age", e); } username = session.getJcrSession().getUserID(); user = new User(username); AjaxLink link = new AjaxLink("link") { @Override public void onClick(AjaxRequestTarget target) { IDialogService dialogService = getDialogService(); if (user != null && canChangePassword()) { currentPassword = newPassword = checkPassword = ""; dialogService.show(new ChangePasswordDialog()); } else { dialogService.show(new CannotChangePasswordDialog()); } } }; add(link); final IModel<String> labelModel = new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (user.isPasswordExpired()) { return translate("password-is-expired"); } else if (isPasswordAboutToExpire(user)) { final long expirationTime = user.getPasswordExpirationTime(); final Duration expirationDuration = Duration .valueOf(expirationTime - System.currentTimeMillis()); String expiration = expirationDuration.toString(getLocale()); final Matcher matcher = EXPIRATION_PATTERN.matcher(expiration); if (matcher.matches()) { final String expirationMatch = matcher.group(1); expiration = expiration.replace(expirationMatch, translate(expirationMatch)); } final StringResourceModel model = new StringResourceModel("password-about-to-expire", ChangePasswordShortcutPlugin.this, null, null, expiration); return model.getObject(); } return StringUtils.EMPTY; } }; label = new Label("label", labelModel) { @Override public boolean isVisible() { return StringUtils.isNotEmpty(labelModel.getObject()); } }; label.setOutputMarkupId(true); add(label); final HippoIcon icon = HippoIcon.fromSprite("change-password-icon", Icon.PENCIL_SQUARE); link.add(icon); }