List of usage examples for org.apache.wicket.util.time Duration days
public static Duration days(final int days)
Duration
based on days. From source file:com.gitblit.wicket.GitBlitWebApp.java
License:Apache License
@Override public void init() { super.init(); // Setup page authorization mechanism boolean useAuthentication = settings.getBoolean(Keys.web.authenticateViewPages, false) || settings.getBoolean(Keys.web.authenticateAdminPages, false); if (useAuthentication) { AuthorizationStrategy authStrategy = new AuthorizationStrategy(settings, homePageClass); getSecuritySettings().setAuthorizationStrategy(authStrategy); getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy); }/*from w w w . ja v a 2 s . com*/ // Grab Browser info (like timezone, etc) if (settings.getBoolean(Keys.web.useClientTimezone, false)) { getRequestCycleSettings().setGatherExtendedBrowserInfo(true); } // configure the resource cache duration to 90 days for deployment if (!isDebugMode()) { getResourceSettings().setDefaultCacheDuration(Duration.days(90)); } // setup the standard gitweb-ish urls mount("/repositories", RepositoriesPage.class); mount("/overview", OverviewPage.class, "r"); mount("/summary", SummaryPage.class, "r"); mount("/reflog", ReflogPage.class, "r"); mount("/commits", LogPage.class, "r", "h"); mount("/log", LogPage.class, "r", "h"); mount("/tags", TagsPage.class, "r"); mount("/branches", BranchesPage.class, "r"); mount("/commit", CommitPage.class, "r", "h"); mount("/tag", TagPage.class, "r", "h"); mount("/tree", TreePage.class, "r", "h", "f"); mount("/blob", BlobPage.class, "r", "h", "f"); mount("/blobdiff", BlobDiffPage.class, "r", "h", "f"); mount("/commitdiff", CommitDiffPage.class, "r", "h"); mount("/compare", ComparePage.class, "r", "h"); mount("/patch", PatchPage.class, "r", "h", "f"); mount("/history", HistoryPage.class, "r", "h", "f"); mount("/search", GitSearchPage.class); mount("/metrics", MetricsPage.class, "r"); mount("/blame", BlamePage.class, "r", "h", "f"); mount("/users", UsersPage.class); mount("/teams", TeamsPage.class); mount("/logout", LogoutPage.class); // setup ticket urls mount("/tickets", TicketsPage.class, "r", "h"); mount("/tickets/new", NewTicketPage.class, "r"); mount("/tickets/edit", EditTicketPage.class, "r", "h"); mount("/tickets/export", ExportTicketPage.class, "r", "h"); mount("/milestones/new", NewMilestonePage.class, "r"); mount("/milestones/edit", EditMilestonePage.class, "r", "h"); mount("/mytickets", MyTicketsPage.class, "r", "h"); // setup the markup document urls mount("/docs", DocsPage.class, "r", "h"); mount("/doc", DocPage.class, "r", "h", "f"); mount("/editfile", EditFilePage.class, "r", "h", "f"); // federation urls mount("/proposal", ReviewProposalPage.class, "t"); mount("/registration", FederationRegistrationPage.class, "u", "n"); mount("/new", NewRepositoryPage.class); mount("/edit", EditRepositoryPage.class, "r"); mount("/activity", ActivityPage.class, "r", "h"); mount("/lucene", LuceneSearchPage.class); mount("/project", ProjectPage.class, "p"); mount("/projects", ProjectsPage.class); mount("/user", UserPage.class, "user"); mount("/forks", ForksPage.class, "r"); mount("/fork", ForkPage.class, "r"); // filestore URL mount("/filestore", FilestorePage.class); Bootstrap.install(this); FontAwesome.install(this); Octicons.install(this); StaticResources.install(this); // allow started Wicket plugins to initialize for (PluginWrapper pluginWrapper : pluginManager.getPlugins()) { if (PluginState.STARTED != pluginWrapper.getPluginState()) { continue; } if (pluginWrapper.getPlugin() instanceof GitblitWicketPlugin) { GitblitWicketPlugin wicketPlugin = (GitblitWicketPlugin) pluginWrapper.getPlugin(); wicketPlugin.init(this); } } // customize the Wicket class resolver to load from plugins IClassResolver coreResolver = getApplicationSettings().getClassResolver(); PluginClassResolver classResolver = new PluginClassResolver(coreResolver, pluginManager); getApplicationSettings().setClassResolver(classResolver); getMarkupSettings().setDefaultMarkupEncoding(Constants.ENCODING); }
From source file:com.servoy.j2db.server.headlessclient.WebClientsApplication.java
License:Open Source License
/** * @see wicket.protocol.http.WebApplication#init() *//*from w ww . jav a2 s. c om*/ @Override protected void init() { if (ApplicationServerRegistry.get() == null) return; // TODO this is a workaround to allow mobile test client that only starts Tomcat not to give exceptions (please remove if mobile test client initialises a full app. server in the future) getResourceSettings().setResourceWatcher(new ServoyModificationWatcher(Duration.seconds(5))); // getResourceSettings().setResourcePollFrequency(Duration.seconds(5)); getResourceSettings().setAddLastModifiedTimeToResourceReferenceUrl(true); getResourceSettings().setDefaultCacheDuration((int) Duration.days(365).seconds()); getMarkupSettings().setCompressWhitespace(true); getMarkupSettings().setMarkupCache(new ServoyMarkupCache(this)); // getMarkupSettings().setStripWicketTags(true); getResourceSettings().setResourceStreamLocator(new ServoyResourceStreamLocator(this)); getResourceSettings().setPackageResourceGuard(new ServoyPackageResourceGuard()); // getResourceSettings().setResourceFinder(createResourceFinder()); getResourceSettings().setThrowExceptionOnMissingResource(false); getApplicationSettings().setPageExpiredErrorPage(ServoyExpiredPage.class); getApplicationSettings().setClassResolver(new ServoyClassResolver()); getSessionSettings().setMaxPageMaps(15); // getRequestCycleSettings().setGatherExtendedBrowserInfo(true); getSecuritySettings().setCryptFactory(new CachingKeyInSessionSunJceCryptFactory()); Settings settings = Settings.getInstance(); getDebugSettings().setOutputComponentPath( Utils.getAsBoolean(settings.getProperty("servoy.webclient.debug.wicketpath", "false"))); //$NON-NLS-1$ //$NON-NLS-2$ if (Utils.getAsBoolean(settings.getProperty("servoy.webclient.nice.urls", "false"))) //$NON-NLS-1$ //$NON-NLS-2$ { mount(new HybridUrlCodingStrategy("/solutions", SolutionLoader.class)); //$NON-NLS-1$ mount(new HybridUrlCodingStrategy("/application", MainPage.class)); //$NON-NLS-1$ mount(new HybridUrlCodingStrategy("/ss", SolutionLoader.class) //$NON-NLS-1$ { /** * @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget) */ @Override public boolean matches(IRequestTarget requestTarget) { return false; } }); } else { mountBookmarkablePage("/solutions", SolutionLoader.class); //$NON-NLS-1$ mount(new BookmarkablePageRequestTargetUrlCodingStrategy("/ss", SolutionLoader.class, null) //$NON-NLS-1$ { /** * @see wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy#matches(wicket.IRequestTarget) */ @Override public boolean matches(IRequestTarget requestTarget) { return false; } }); } long maxSize = Utils.getAsLong(settings.getProperty("servoy.webclient.maxuploadsize", "0"), false); //$NON-NLS-1$ //$NON-NLS-2$ if (maxSize > 0) { getApplicationSettings().setDefaultMaximumUploadSize(Bytes.kilobytes(maxSize)); } getSharedResources().putClassAlias(IApplication.class, "application"); //$NON-NLS-1$ getSharedResources().putClassAlias(PageContributor.class, "pc"); //$NON-NLS-1$ getSharedResources().putClassAlias(MaskBehavior.class, "mask"); //$NON-NLS-1$ getSharedResources().putClassAlias(Application.class, "servoy"); //$NON-NLS-1$ getSharedResources().putClassAlias(org.wicketstuff.calendar.markup.html.form.DatePicker.class, "datepicker"); //$NON-NLS-1$ getSharedResources().putClassAlias(YUILoader.class, "yui"); //$NON-NLS-1$ getSharedResources().putClassAlias(JQueryLoader.class, "jquery"); //$NON-NLS-1$ getSharedResources().putClassAlias(TinyMCELoader.class, "tinymce"); //$NON-NLS-1$ getSharedResources().putClassAlias(org.apache.wicket.markup.html.WicketEventReference.class, "wicketevent"); //$NON-NLS-1$ getSharedResources().putClassAlias(org.apache.wicket.ajax.WicketAjaxReference.class, "wicketajax"); //$NON-NLS-1$ getSharedResources().putClassAlias(MainPage.class, "servoyjs"); //$NON-NLS-1$ getSharedResources().putClassAlias(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.class, "modalwindow"); //$NON-NLS-1$ PackageResource.bind(this, IApplication.class, "images/open_project.gif"); //$NON-NLS-1$ PackageResource.bind(this, IApplication.class, "images/save.gif"); //$NON-NLS-1$ mountSharedResource("/formcss", "servoy/formcss"); //$NON-NLS-1$//$NON-NLS-2$ sharedMediaResource = new SharedMediaResource(); getSharedResources().add("media", sharedMediaResource); //$NON-NLS-1$ mount(new SharedResourceRequestTargetUrlCodingStrategy("mediafolder", "servoy/media") //$NON-NLS-1$ //$NON-NLS-2$ { @Override protected void appendParameters(AppendingStringBuffer url, Map<String, ?> parameters) { if (parameters != null && parameters.size() > 0) { Object solutionName = parameters.get("s"); //$NON-NLS-1$ if (solutionName != null) appendPathParameter(url, null, solutionName.toString()); Object resourceId = parameters.get("id"); //$NON-NLS-1$ if (resourceId != null) appendPathParameter(url, null, resourceId.toString()); StringBuilder queryParams = new StringBuilder(); for (Entry<?, ?> entry1 : parameters.entrySet()) { Object value = ((Entry<?, ?>) entry1).getValue(); if (value != null) { Object key = ((Entry<?, ?>) entry1).getKey(); if (!"s".equals(key) && !"id".equals(key)) //$NON-NLS-1$ //$NON-NLS-2$ { if (value instanceof String[]) { String[] values = (String[]) value; for (String value1 : values) { if (queryParams.length() > 0) queryParams.append("&"); //$NON-NLS-1$ queryParams.append(key).append("=").append(value1);//$NON-NLS-1$ } } else { if (queryParams.length() > 0) queryParams.append("&"); //$NON-NLS-1$ queryParams.append(key).append("=").append(value);//$NON-NLS-1$ } } } } if (queryParams.length() > 0) { url.append("?").append(queryParams);//$NON-NLS-1$ } } } @Override protected void appendPathParameter(AppendingStringBuffer url, String key, String value) { String escapedValue = value; String[] values = escapedValue.split("/");//$NON-NLS-1$ if (values.length > 1) { StringBuilder sb = new StringBuilder(escapedValue.length()); for (String str : values) { sb.append(urlEncodePathComponent(str)); sb.append('/'); } sb.setLength(sb.length() - 1); escapedValue = sb.toString(); } else { escapedValue = urlEncodePathComponent(escapedValue); } if (!Strings.isEmpty(escapedValue)) { if (!url.endsWith("/"))//$NON-NLS-1$ { url.append("/");//$NON-NLS-1$ } if (key != null) url.append(urlEncodePathComponent(key)).append("/");//$NON-NLS-1$ url.append(escapedValue); } } /* * (non-Javadoc) * * @see org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy#decodeParameters(java.lang.String, java.util.Map) */ @Override protected ValueMap decodeParameters(String urlFragment, Map<String, ?> urlParameters) { ValueMap map = new ValueMap(); final String[] pairs = urlFragment.split("/"); //$NON-NLS-1$ if (pairs.length > 1) { map.add("s", pairs[1]); //$NON-NLS-1$ StringBuffer sb = new StringBuffer(); for (int i = 2; i < pairs.length; i++) { sb.append(pairs[i]); sb.append("/"); //$NON-NLS-1$ } sb.setLength(sb.length() - 1); map.add("id", sb.toString()); //$NON-NLS-1$ } if (urlParameters != null) { map.putAll(urlParameters); } return map; } }); getSharedResources().add("resources", new ServeResources()); //$NON-NLS-1$ getSharedResources().add("formcss", new FormCssResource(this)); //$NON-NLS-1$ if (settings.getProperty("servoy.webclient.error.page", null) != null) //$NON-NLS-1$ { getApplicationSettings().setInternalErrorPage(ServoyErrorPage.class); } if (settings.getProperty("servoy.webclient.pageexpired.page", null) != null) //$NON-NLS-1$ { getApplicationSettings().setPageExpiredErrorPage(ServoyPageExpiredPage.class); } addPreComponentOnBeforeRenderListener(new IComponentOnBeforeRenderListener() { public void onBeforeRender(Component component) { if (component instanceof IServoyAwareBean) { IModel model = component.getInnermostModel(); WebForm webForm = component.findParent(WebForm.class); if (model instanceof RecordItemModel && webForm != null) { IRecord record = (IRecord) ((RecordItemModel) model).getObject(); FormScope fs = webForm.getController().getFormScope(); if (record != null && fs != null) { ((IServoyAwareBean) component).setSelectedRecord(new ServoyBeanState(record, fs)); } } } else { if (!component.isEnabled()) { boolean hasOnRender = (component instanceof IFieldComponent && ((IFieldComponent) component) .getScriptObject() instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) ((IFieldComponent) component).getScriptObject()) .getRenderEventExecutor().hasRenderCallback()); if (!hasOnRender) { // onrender may change the enable state return; } } Component targetComponent = null; boolean hasFocus = false, hasBlur = false; if (component instanceof IFieldComponent && ((IFieldComponent) component).getEventExecutor() != null) { targetComponent = component; if (component instanceof WebBaseSelectBox) { Component[] cs = ((WebBaseSelectBox) component).getFocusChildren(); if (cs != null && cs.length == 1) targetComponent = cs[0]; } if (component instanceof WebDataHtmlArea) hasFocus = true; // always install a focus handler when in a table view to detect change of selectedIndex and test for record validation if (((IFieldComponent) component).getEventExecutor().hasEnterCmds() || component.findParent(WebCellBasedView.class) != null || (((IFieldComponent) component) .getScriptObject() instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) ((IFieldComponent) component) .getScriptObject()).getRenderEventExecutor().hasRenderCallback())) { hasFocus = true; } // Always trigger event on focus lost: // 1) check for new selected index, record validation may have failed preventing a index changed // 2) prevent focus gained to be called when field validation failed // 3) general ondata change hasBlur = true; } else if (component instanceof WebBaseLabel) { targetComponent = component; hasFocus = true; } if (targetComponent != null) { MainPage mainPage = targetComponent.findParent(MainPage.class); if (mainPage.isUsingAjax()) { AbstractAjaxBehavior eventCallback = mainPage.getPageContributor().getEventCallback(); if (eventCallback != null) { String callback = eventCallback.getCallbackUrl().toString(); if (component instanceof WebDataRadioChoice || component instanceof WebDataCheckBoxChoice || component instanceof WebDataLookupField || component instanceof WebDataComboBox || component instanceof WebDataListBox || component instanceof WebDataHtmlArea) { // is updated via ServoyChoiceComponentUpdatingBehavior or ServoyFormComponentUpdatingBehavior, this is just for events callback += "&nopostdata=true"; } for (IBehavior behavior : targetComponent.getBehaviors()) { if (behavior instanceof EventCallbackModifier) { targetComponent.remove(behavior); } } if (hasFocus) { StringBuilder js = new StringBuilder(); js.append("eventCallback(this,'focus','").append(callback).append("',event)"); //$NON-NLS-1$ //$NON-NLS-2$ targetComponent.add(new EventCallbackModifier("onfocus", true, //$NON-NLS-1$ new Model<String>(js.toString()))); targetComponent.add(new EventCallbackModifier("onmousedown", true, //$NON-NLS-1$ new Model<String>("focusMousedownCallback(event)"))); //$NON-NLS-1$ } if (hasBlur) { boolean blockRequest = false; // if component has ondatachange, check for blockrequest if (component instanceof ISupportEventExecutor && ((ISupportEventExecutor) component).getEventExecutor() .hasChangeCmd()) { WebClientSession webClientSession = WebClientSession.get(); blockRequest = webClientSession != null && webClientSession.blockRequest(); } StringBuilder js = new StringBuilder(); js.append("postEventCallback(this,'blur','").append(callback) //$NON-NLS-1$ .append("',event," + blockRequest + ")"); //$NON-NLS-1$ targetComponent.add(new EventCallbackModifier("onblur", true, //$NON-NLS-1$ new Model<String>(js.toString()))); } } } } } } }); }
From source file:fiftyfive.wicket.FoundationApplication.java
License:Apache License
/** * Set the cache duration for resources to zero if in development mode * (discouraging browser cache), or 1 year if in deployment mode. *///from ww w .j av a 2 s .c om protected void initResources() { getResourceSettings().setDefaultCacheDuration(usesDevelopmentConfig() ? Duration.NONE : Duration.days(365)); }
From source file:net.databinder.auth.AuthDataSessionBase.java
License:Open Source License
/** * @return length of time sign-in cookie should persist, defined here as one month */ protected Duration getSignInCookieMaxAge() { return Duration.days(31); }
From source file:org.apache.isis.viewer.wicket.viewer.IsisWicketApplication.java
License:Apache License
/** * Initializes the application; in particular, bootstrapping the Isis * backend, and initializing the {@link ComponentFactoryRegistry} to be used * for rendering./*from w w w. j a v a2s.co m*/ */ @Override protected void init() { try { super.init(); configureWebJars(); configureWicketBootstrap(); configureWicketSelect2(); String isisConfigDir = getServletContext().getInitParameter("isis.config.dir"); configureLogging(isisConfigDir); getRequestCycleSettings().setRenderStrategy(RenderStrategy.REDIRECT_TO_RENDER); getResourceSettings().setParentFolderPlaceholder("$up$"); determineDeploymentTypeIfRequired(); RequestCycleListenerCollection requestCycleListeners = getRequestCycleListeners(); IRequestCycleListener requestCycleListenerForIsis = newWebRequestCycleForIsis(); requestCycleListeners.add(requestCycleListenerForIsis); requestCycleListeners.add(new PageRequestHandlerTracker()); final IsisConfigurationBuilder isisConfigurationBuilder = createConfigBuilder(); final IsisInjectModule isisModule = newIsisModule(deploymentType, isisConfigurationBuilder); final Injector injector = Guice.createInjector(isisModule, newIsisWicketModule()); initWicketComponentInjection(injector); injector.injectMembers(this); if (requestCycleListenerForIsis instanceof WebRequestCycleForIsis) { WebRequestCycleForIsis webRequestCycleForIsis = (WebRequestCycleForIsis) requestCycleListenerForIsis; webRequestCycleForIsis.setPageClassRegistry(pageClassRegistry); } final IsisConfiguration configuration = isisConfigurationBuilder.getConfiguration(); this.getMarkupSettings().setStripWicketTags(determineStripWicketTags(configuration)); getDebugSettings().setAjaxDebugModeEnabled(determineAjaxDebugModeEnabled(configuration)); // must be done after injected componentFactoryRegistry into the app itself buildCssBundle(); filterJavascriptContributions(); configureWicketSourcePluginIfNecessary(configuration); // TODO ISIS-987 Either make the API better (no direct access to the map) or use DB records int maxEntries = 1000; setMetaData(AccountConfirmationMap.KEY, new AccountConfirmationMap(maxEntries, Duration.days(1))); mountPages(); @SuppressWarnings("unused") SharedResources sharedResources = getSharedResources(); } catch (RuntimeException ex) { List<MetaModelInvalidException> mmies = locateMetaModelInvalidExceptions(ex); if (!mmies.isEmpty()) { final MetaModelInvalidException mmie = mmies.get(0); log(""); logBanner(); log(""); validationErrors.addAll(mmie.getValidationErrors()); for (String validationError : validationErrors) { logError(validationError); } log(""); log("Please inspect the above messages and correct your domain model."); log(""); logBanner(); log(""); } else { // because Wicket's handling in its WicketFilter (that calls this method) does not log the exception. LOG.error("Failed to initialize", ex); throw ex; } } }
From source file:org.cast.cwm.data.resource.UploadedFileResource.java
License:Open Source License
@Override protected ResourceResponse newResourceResponse(final Attributes attributes) { final ResourceResponse response = new ResourceResponse(); long id = attributes.getParameters().get("id").toLong(); IModel<BinaryFileData> mBfd = cwmService.getById(BinaryFileData.class, id); if (mBfd == null || mBfd.getObject() == null) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Data not found [id=" + id + "]"); BinaryFileData bfd = mBfd.getObject(); response.setLastModified(Time.valueOf(bfd.getLastModified())); if (response.dataNeedsToBeWritten(attributes)) { final byte[] data = bfd.getData(); if (data == null) throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Data not found [id=" + id + "]"); response.setContentType(bfd.getMimeType()); response.setContentLength(data.length); response.setContentDisposition(ContentDisposition.INLINE); response.setCacheDuration(Duration.days(1)); response.setCacheScope(WebResponse.CacheScope.PUBLIC); response.setWriteCallback(new WriteCallback() { @Override/*from www . j a v a2s. c o m*/ public void writeData(final Attributes attributes) { attributes.getResponse().write(data); } }); } return response; }
From source file:wicketbox.examples.ColResizeExamplePage.java
License:Apache License
public ColResizeExamplePage() { WebMarkupContainer resizable = new WebMarkupContainer("resizable"); resizable.add(new ColResize("table.colresize-header", "table.colresize-body", new WidthsModel()) { protected String getPersist(Component component) { return persistToCookie("colresize:" + component.getPageRelativePath(), Duration.days(1)); }/*from w ww.ja v a2 s .c o m*/ }); add(resizable); resizable.add(new ListView<Foo>("row", new FoosModel()) { @Override protected void populateItem(ListItem<Foo> item) { item.add(new Label("cell1", new PropertyModel<String>(item.getModel(), "name"))); item.add(new Label("cell2", new PropertyModel<String>(item.getModel(), "name"))); item.add(new Label("cell3", new PropertyModel<String>(item.getModel(), "name"))); item.add(new Label("cell4", new PropertyModel<String>(item.getModel(), "name"))); } }); }
From source file:wicketbox.examples.ScrollExamplePage.java
License:Apache License
public ScrollExamplePage() { WebMarkupContainer scroll = new WebMarkupContainer("scroll"); scroll.add(new Scroll(Orientation.VERTICAL, ".scroll") { @Override// w ww .j av a 2 s. c om protected String getPersist(Component component) { return persistToCookie("scroll:" + component.getPageRelativePath(), Duration.days(1)); } }); add(scroll); scroll.add(new Label("left", new StringResourceModel("lorem", null))); scroll.add(new Label("right", new StringResourceModel("lorem", null))); }