001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.devutils.pagestore; 018 019import org.apache.wicket.Session; 020import org.apache.wicket.devutils.DevUtilsPage; 021import org.apache.wicket.devutils.inspector.InspectorPage; 022import org.apache.wicket.devutils.pagestore.browser.PersistedPanel; 023import org.apache.wicket.markup.html.image.Image; 024import org.apache.wicket.pageStore.DelegatingPageStore; 025import org.apache.wicket.pageStore.IPageStore; 026import org.apache.wicket.pageStore.IPersistentPageStore; 027import org.apache.wicket.request.mapper.parameter.PageParameters; 028import org.apache.wicket.request.resource.PackageResourceReference; 029 030/** 031 * A page that shows the attributes (id, name, size) of the pages stored in the data stores. 032 */ 033public class PageStorePage extends DevUtilsPage 034{ 035 036 /** 037 * Construct. 038 * 039 * @param parameters 040 * the request parameters 041 */ 042 public PageStorePage(final PageParameters parameters) 043 { 044 super(parameters); 045 046 add(new Image("bug", new PackageResourceReference(InspectorPage.class, "bug.png"))); 047 048 add(new PersistedPanel("persisted", PageStorePage::getPersistentPageStore)); 049 } 050 051 @Override 052 public boolean isVersioned() 053 { 054 return false; 055 } 056 057 /** 058 * Helper to find the {@link IPersistentPageStore} of the application. 059 * 060 * @return store or <code>null</code> if not available 061 */ 062 public static IPersistentPageStore getPersistentPageStore() { 063 try { 064 IPageStore store = Session.get().getPageManager().getPageStore(); 065 while (true) { 066 if (store instanceof IPersistentPageStore) { 067 return (IPersistentPageStore)store; 068 } 069 070 if (store instanceof DelegatingPageStore) { 071 store = ((DelegatingPageStore)store).getDelegate(); 072 } else { 073 break; 074 } 075 } 076 } catch (UnsupportedOperationException ex) { 077 // no page store 078 } 079 080 return null; 081 } 082}