You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2017/11/29 13:30:24 UTC
[myfaces-tobago] 01/07: TOBAGO-1782: Clean up * Remove deprecated
code
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit 2131eb002611c98e056493ba0a2392ac9544cd28
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Wed Nov 29 09:27:43 2017 +0100
TOBAGO-1782: Clean up
* Remove deprecated code
---
tobago-core/src/main/faces-config/faces-config.xml | 1 -
.../internal/ajax/AjaxNavigationListener.java | 77 --------
.../tobago/internal/ajax/AjaxNavigationState.java | 206 ---------------------
3 files changed, 284 deletions(-)
diff --git a/tobago-core/src/main/faces-config/faces-config.xml b/tobago-core/src/main/faces-config/faces-config.xml
index f116a50..52dfa05 100644
--- a/tobago-core/src/main/faces-config/faces-config.xml
+++ b/tobago-core/src/main/faces-config/faces-config.xml
@@ -35,7 +35,6 @@
</application>
<lifecycle>
- <!--<phase-listener>org.apache.myfaces.tobago.internal.ajax.AjaxNavigationListener</phase-listener>-->
<phase-listener>org.apache.myfaces.tobago.lifecycle.SecretPhaseListener</phase-listener>
</lifecycle>
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxNavigationListener.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxNavigationListener.java
deleted file mode 100644
index ead8c5a..0000000
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxNavigationListener.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.myfaces.tobago.internal.ajax;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
-
-/**
- * XXX this must be refactored, because of TOBAGO-1524 (see TOBAGO-1563)
- * @deprecated
- */
-@Deprecated
-public class AjaxNavigationListener implements PhaseListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(AjaxNavigationListener.class);
-
- @Override
- public void afterPhase(final PhaseEvent phaseEvent) {
- final FacesContext facesContext = phaseEvent.getFacesContext();
- debug(facesContext);
- if (!facesContext.getResponseComplete()) {
- if (phaseEvent.getPhaseId() == PhaseId.RESTORE_VIEW) {
- AjaxNavigationState.afterRestoreView(facesContext);
- } else if (phaseEvent.getPhaseId() == PhaseId.INVOKE_APPLICATION) {
- AjaxNavigationState.afterInvokeApplication(facesContext);
- }
- }
- debug(facesContext);
- }
-
- @Override
- public void beforePhase(final PhaseEvent phaseEvent) {
- final FacesContext facesContext = phaseEvent.getFacesContext();
- debug(facesContext);
- if (!facesContext.getResponseComplete() && phaseEvent.getPhaseId() == PhaseId.RESTORE_VIEW) {
- AjaxNavigationState.beforeRestoreView(facesContext);
- }
- debug(facesContext);
- }
-
- private void debug(FacesContext facesContext) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("### debug getRenderResponse = {}", facesContext.getRenderResponse());
- if (facesContext.getViewRoot() != null) {
- LOG.trace("### debug getViewId = {}", facesContext.getViewRoot().getViewId());
- }
- }
- }
-
- @Override
- public PhaseId getPhaseId() {
- return PhaseId.ANY_PHASE;
- }
-
-}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxNavigationState.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxNavigationState.java
deleted file mode 100644
index 6e7bfd9..0000000
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxNavigationState.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.myfaces.tobago.internal.ajax;
-
-import org.apache.myfaces.tobago.util.AjaxUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.application.ViewExpiredException;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.event.ExceptionQueuedEvent;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * XXX this must be refactored, because of TOBAGO-1524 (see TOBAGO-1563)
- * @deprecated
- */
-@Deprecated
-public final class AjaxNavigationState {
-
- private static final Logger LOG = LoggerFactory.getLogger(AjaxNavigationState.class);
-
- private static final String SESSION_KEY = "tobago-AjaxNavigationState";
-
- private static final String VIEW_ROOT_KEY = "tobago-AjaxNavigationState-VIEW_ROOT_KEY";
-
- private UIViewRoot viewRoot;
-
- private Map<String, List<FacesMessage>> messages;
-
- private AjaxNavigationState(final FacesContext facesContext) {
- final ExternalContext externalContext = facesContext.getExternalContext();
- externalContext.getSessionMap().put(SESSION_KEY, this);
- viewRoot = facesContext.getViewRoot();
- messages = new HashMap<>();
- final Iterator<String> iterator = facesContext.getClientIdsWithMessages();
- while (iterator.hasNext()) {
- addFacesMessages(facesContext, iterator.next());
- }
- if (LOG.isTraceEnabled()) {
- LOG.trace("Saved viewRoot.getViewId() = \"{}\"", viewRoot.getViewId());
- for (final Map.Entry<String, List<FacesMessage>> entry : messages.entrySet()) {
- for (final FacesMessage message : entry.getValue()) {
- LOG.trace("Saved message \"{}\" : \"{}\"", entry.getKey(), message);
- }
- }
- }
- }
-
- private void addFacesMessages(final FacesContext facesContext, final String clientId) {
- final Iterator<FacesMessage> facesMessages = facesContext.getMessages(clientId);
- while (facesMessages.hasNext()) {
- addFacesMessage(clientId, facesMessages.next());
- }
- }
-
- private void addFacesMessage(final String clientId, final FacesMessage facesMessage) {
- List<FacesMessage> facesMessages = messages.get(clientId);
- if (facesMessages == null) {
- facesMessages = new ArrayList<>();
- messages.put(clientId, facesMessages);
- }
- facesMessages.add(facesMessage);
- }
-
- private void restoreView(final FacesContext facesContext) {
- facesContext.setViewRoot(viewRoot);
- for (final Map.Entry<String, List<FacesMessage>> entry : messages.entrySet()) {
- for (final FacesMessage facesMessage : entry.getValue()) {
- facesContext.addMessage(entry.getKey(), facesMessage);
- }
- }
- facesContext.renderResponse();
- if (LOG.isTraceEnabled()) {
- LOG.trace("Restored viewRoot.getViewId() = \"{}\"", viewRoot.getViewId());
- for (final Map.Entry<String, List<FacesMessage>> entry : messages.entrySet()) {
- for (final FacesMessage message : entry.getValue()) {
- LOG.trace("Restored message \"{}\" : \"{}\"", entry.getKey(), message);
- }
- }
- }
-
- }
-
- public static void storeIncomingView(final FacesContext facesContext) {
- final UIViewRoot viewRoot = facesContext.getViewRoot();
- if (LOG.isTraceEnabled()) {
- if (viewRoot != null) {
- LOG.trace("incoming viewId = '{}'", viewRoot.getViewId());
- } else {
- LOG.trace("incoming viewRoot is null");
- }
- }
- facesContext.getExternalContext().getRequestMap().put(AjaxNavigationState.VIEW_ROOT_KEY, viewRoot);
- }
-
- public static boolean isNavigation(final FacesContext facesContext) {
-
- final UIViewRoot viewRoot = facesContext.getViewRoot();
- if (viewRoot != null) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("current viewId = '{}'", viewRoot.getViewId());
- }
- } else {
- LOG.warn("current viewRoot is null");
- return false;
- }
-
- final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
- final UIViewRoot incomingViewRoot = (UIViewRoot) requestMap.get(VIEW_ROOT_KEY);
- if (viewRoot != incomingViewRoot) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("requesting full page reload because of navigation to {} from {}",
- viewRoot.getViewId(), incomingViewRoot.getViewId());
- }
- return true;
- }
- return false;
- }
-
- public static void beforeRestoreView(final FacesContext facesContext) {
- if (facesContext.getExternalContext().getSessionMap().get(AjaxNavigationState.SESSION_KEY) != null) {
- // restoreView phase and afterPhaseListener are executed even if renderResponse is set
- // so we can't call navigationState.restoreView(...) here in before Phase
- // set empty UIViewRoot to prevent executing restore state logic
- facesContext.setViewRoot(new UIViewRoot());
- }
- }
-
- public static void afterRestoreView(final FacesContext facesContext) {
- if (isViewExpiredExceptionThrown(facesContext)) {
- try {
- facesContext.getExceptionHandler().handle();
- } catch (ViewExpiredException e) {
- LOG.debug("Caught: " + e.getMessage(), e);
- try {
- final ExternalContext externalContext = facesContext.getExternalContext();
- final String url = externalContext.getRequestContextPath()
- + externalContext.getRequestServletPath() + externalContext.getRequestPathInfo();
- AjaxInternalUtils.redirect(facesContext, url);
- facesContext.responseComplete();
- } catch (IOException e1) {
- LOG.error("Caught: " + e1.getMessage(), e);
- }
- }
- }
-
- final ExternalContext externalContext = facesContext.getExternalContext();
- if (externalContext.getSessionMap().get(AjaxNavigationState.SESSION_KEY) == null) {
- storeIncomingView(facesContext);
- } else {
- final AjaxNavigationState navigationState
- = (AjaxNavigationState) externalContext.getSessionMap().remove(AjaxNavigationState.SESSION_KEY);
- navigationState.restoreView(facesContext);
- LOG.trace("force render requested navigation view");
- }
- }
-
- private static boolean isViewExpiredExceptionThrown(FacesContext facesContext) {
- final Iterator<ExceptionQueuedEvent> eventIterator
- = facesContext.getExceptionHandler().getUnhandledExceptionQueuedEvents().iterator();
- if (eventIterator.hasNext()) {
- Throwable throwable = eventIterator.next().getContext().getException();
- if (throwable instanceof ViewExpiredException) {
- return true;
- }
- }
- return false;
- }
-
- public static void afterInvokeApplication(FacesContext facesContext) {
- if (AjaxUtils.isAjaxRequest(facesContext) && isNavigation(facesContext)) {
- try {
- facesContext.getExternalContext().getSessionMap().put(SESSION_KEY, new AjaxNavigationState(facesContext));
- AjaxInternalUtils.requestNavigationReload(facesContext);
- } catch (IOException e) {
- LOG.error("Caught: " + e.getMessage(), e);
- }
- }
- }
-}
--
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.