From: Erik Brakkee Date: Mon, 26 Jul 2010 17:20:35 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~173 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=4fe80b8d110c4a54793f66d07d80965649e9ab7f;p=utils --- diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/AbstractPageBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/AbstractPageBehavior.java deleted file mode 100644 index 7971e47d..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/AbstractPageBehavior.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.wicket.behavior; - -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.protocol.http.WebResponse; - -/** - * Abstract page behavior to simplify implementations of behaviors thar don't need to - * implement all callbacks. - * - * @author Erik Brakkee - */ -public abstract class AbstractPageBehavior implements PageBehavior { - - /** - * Constructor. - */ - protected AbstractPageBehavior() { - // Empty - } - - @Override - public void onAfterRender(WebPage aPage) { - // Empty - } - - @Override - public void onBeforeRender(WebPage aPage) { - // Empty - } - - @Override - public void setHeaders(WebPage aPage, WebResponse aResponse) { - // Empty - } - -} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/CompositePageBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/CompositePageBehavior.java deleted file mode 100644 index 6cf88854..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/CompositePageBehavior.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.wicket.behavior; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.protocol.http.WebResponse; - -/** - * Implements a composite page behavior which invokes all behaviors in the order they were - * added. - * - * To use this in an arbitrary page, override onBeforeRender(), - * setHeaders() and onAfterRender in the page and delegate to the - * corresponding methods in this class. - * - * @author Erik Brakkee - */ -public class CompositePageBehavior implements PageBehavior { - - private List behaviors; - - /** - * Constructs the compositie. - */ - public CompositePageBehavior() { - behaviors = new ArrayList(); - } - - /** - * Adds a behavior. - * @param aBehavior Behavior - */ - public void add(PageBehavior aBehavior) { - behaviors.add(aBehavior); - } - - @Override - public void onAfterRender(WebPage aPage) { - for (PageBehavior behavior: behaviors) { - behavior.onAfterRender(aPage); - } - } - - @Override - public void onBeforeRender(WebPage aPage) { - for (PageBehavior behavior: behaviors) { - behavior.onBeforeRender(aPage); - } - } - - @Override - public void setHeaders(WebPage aPage, WebResponse aResponse) { - for (PageBehavior behavior: behaviors) { - behavior.setHeaders(aPage, aResponse); - } - } - -} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/DisableCachingBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/DisableCachingBehavior.java deleted file mode 100644 index 18956a6e..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/DisableCachingBehavior.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.wicket.behavior; - -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.protocol.http.WebResponse; - -/** - *

- * Behavior to disable browser caching. This also means that the page - * automatically expires the first time after it is rendered. - *

- * - *

- * Important: To make sure that form data cannot be submitted twice for - * the same data using the back button, it is still necessary to explicitly call - * getPage().getPageMap().remove(getPage()); - * in the onSubmit callback of the form. - *

- * - * @author Erik Brakkee - * - */ -public class DisableCachingBehavior extends ExpirePageImmediatelyBehavior { - - @Override - public void setHeaders(WebPage aPage, WebResponse aResponse) { - aResponse.setHeader("Pragma", "no-cache"); - aResponse.setHeader("Cache-Control", - "no-cache, max-age=0, must-revalidate, no-store"); - } -} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/ExpirePageImmediatelyBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/ExpirePageImmediatelyBehavior.java deleted file mode 100644 index 16e1c9bd..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/ExpirePageImmediatelyBehavior.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.wicket.behavior; - -import org.apache.wicket.markup.html.WebPage; - -/** - * Page which will be removed from the page map after rendering so it can be - * viewed only once. - * - * @author Erik Brakkee - * - */ -public class ExpirePageImmediatelyBehavior extends AbstractPageBehavior { - - @Override - public void onAfterRender(WebPage aPage) { - aPage.getPageMap().remove(aPage); - } - -} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/FlushEntityManagerBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/FlushEntityManagerBehavior.java deleted file mode 100644 index 287bb64c..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/FlushEntityManagerBehavior.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.wicket.behavior; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.annotation.Resource; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceException; -import javax.persistence.TransactionRequiredException; -import javax.transaction.Status; -import javax.transaction.SystemException; -import javax.transaction.UserTransaction; - -import org.apache.wicket.markup.html.WebPage; - -/** - * Behavior to flush the entity manager after rendering of the page. - * - * @author Erik Brakkee - * - */ -public class FlushEntityManagerBehavior extends AbstractPageBehavior { - - private static final Logger LOGGER = Logger - .getLogger(FlushEntityManagerBehavior.class.getName()); - - private EntityManager entityManager; - - /** - * Constructs the behavior. - * - * @param aEntityManager - * Contextual reference to an entitymanager. - */ - public FlushEntityManagerBehavior(EntityManager aEntityManager) { - entityManager = aEntityManager; - } - - @Override - public void onAfterRender(WebPage aPage) { - try { - if (entityManager.isOpen()) { - entityManager.flush(); - } - } catch (TransactionRequiredException e) { - throw e; - } catch (PersistenceException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Could not flush entitymanager", e); - } - } - -} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/PageBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/PageBehavior.java deleted file mode 100644 index 1b7c25ee..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/PageBehavior.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.wicket.behavior; - -import java.io.Serializable; - -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.protocol.http.WebResponse; - -/** - * Page behavior interface. This provides a mechanism to extend page behavior without - * subclassing. - * - * @author Erik Brakkee - */ -public interface PageBehavior extends Serializable { - - /** - * To be called as part of the Page's onBeforeRender - * @param aPage Page this is called for. - */ - void onBeforeRender(WebPage aPage); - - /** - * To be called as part of the Page's setHeaders - * @param aPage Page this is called for. - * @param aResponse Response to set headers for. - */ - void setHeaders(WebPage aPage, WebResponse aResponse); - - /** - * To be called as part of the Page's onAfterRender - * @param aPage Page this is called for. - */ - void onAfterRender(WebPage aPage); -} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/ResetCssBehavior.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/ResetCssBehavior.java deleted file mode 100644 index 5e7bbdc2..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/ResetCssBehavior.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.wicket.behavior; - -import org.apache.wicket.behavior.HeaderContributor; -import org.apache.wicket.markup.html.CSSPackageResource; -import org.apache.wicket.markup.html.JavascriptPackageResource; - -/** - * Reset CSS style to obtain more uniform browser behavior. - * - * @author Erik Brakkee - */ -public class ResetCssBehavior extends HeaderContributor { - - /** - * Constructs the behavior. - */ - public ResetCssBehavior() { - super(CSSPackageResource.getHeaderContribution(ResetCssBehavior.class, "reset.css")); - } - -} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/WebApplicationBasePage.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/WebApplicationBasePage.java deleted file mode 100644 index 387f1931..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/WebApplicationBasePage.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wamblee.wicket.behavior; - -import javax.persistence.EntityManager; -import javax.transaction.UserTransaction; - -import org.apache.wicket.IPageMap; -import org.apache.wicket.PageParameters; -import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.model.IModel; -import org.apache.wicket.protocol.http.WebResponse; - -/** - * Base page for wicket applications that allows customization of various bahaviors of the - * page. This page has no associated markup. - * - * The utility methods {@link #disableCaching()}, {@link #expireImmediately()}, - * and {@link #flushEntityManagerAfterRender(EntityManager)} are provide for quicly adding - * behaviors. Alternatively, the method {@link #addBehavior(PageBehavior)} can be used. - * - * @author Erik Brakkee - * - */ -public class WebApplicationBasePage extends WebPage { - - private CompositePageBehavior behaviors; - - protected WebApplicationBasePage() { - super(); - init(); - } - - protected WebApplicationBasePage(final IModel model) - { - super(model); - init(); - } - - protected WebApplicationBasePage(final IPageMap pageMap) - { - super(pageMap); - init(); - } - - protected WebApplicationBasePage(final IPageMap pageMap, final IModel model) - { - super(pageMap, model); - init(); - } - - protected WebApplicationBasePage(final PageParameters parameters) - { - super(parameters); - init(); - } - - protected WebApplicationBasePage(final IPageMap pageMap, final PageParameters parameters) - { - super(pageMap, parameters); - init(); - } - - private void init() { - behaviors = new CompositePageBehavior(); - } - - /** - * Disables caching. This implies expiry of the page from the page map. - */ - protected void disableCaching() { - addBehavior(new DisableCachingBehavior()); - } - - /** - * Expires the page immediately. Refresh in the browser will lead to an expired page. - */ - protected void expireImmediately() { - addBehavior(new ExpirePageImmediatelyBehavior()); - } - - /** - * Flushes the entitymanager immedately after rendering to make sure that errors are - * caught early. - * @param aEntityManager Contextual reference to an entity manager. - */ - protected void flushEntityManagerAfterRender(EntityManager aEntityManager) { - addBehavior(new FlushEntityManagerBehavior(aEntityManager)); - } - - /** - * Adds a specific behavior to the page. - * @param aBehavior Behavior to add. - */ - public void addBehavior(PageBehavior aBehavior) { - behaviors.add(aBehavior); - } - - @Override - protected void onBeforeRender() { - behaviors.onBeforeRender(this); - super.onBeforeRender(); - } - - @Override - protected void setHeaders(WebResponse aResponse) { - super.setHeaders(aResponse); - behaviors.setHeaders(this, aResponse); - } - - @Override - protected void onAfterRender() { - super.onAfterRender(); - behaviors.onAfterRender(this); - } -} diff --git a/wicket/components/src/main/java/org/wamblee/wicket/behavior/package-info.java b/wicket/components/src/main/java/org/wamblee/wicket/behavior/package-info.java deleted file mode 100644 index 466e04ce..00000000 --- a/wicket/components/src/main/java/org/wamblee/wicket/behavior/package-info.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * This package contains various utilities for behaviors on components and pages. - * - * Entry points to this package are as follows: - *
    - *
  • {@link WebApplicationBasePage}: A generic web page base class to which various - * behaviors can be added. - *
  • - *
  • {@link CompositePageBehavior}: The composite behavior to which the various - * callbacks from wicket to the page can be delegated. Useful in case the inheritance - * approach based on {@link WebApplicationBasePage} canno tbe used. - *
  • - *
  • {@link PageBehavior}: The page behavior interface. - *
  • - *
- */ -package org.wamblee.wicket.behavior; \ No newline at end of file