1 16 package org.springframework.webflow.executor.jsf; 17 18 import javax.faces.context.FacesContext; 19 20 import org.springframework.binding.collection.SharedMapDecorator; 21 import org.springframework.core.style.ToStringCreator; 22 import org.springframework.webflow.context.ExternalContext; 23 import org.springframework.webflow.core.collection.LocalAttributeMap; 24 import org.springframework.webflow.core.collection.LocalParameterMap; 25 import org.springframework.webflow.core.collection.LocalSharedAttributeMap; 26 import org.springframework.webflow.core.collection.MutableAttributeMap; 27 import org.springframework.webflow.core.collection.ParameterMap; 28 import org.springframework.webflow.core.collection.SharedAttributeMap; 29 30 36 public class JsfExternalContext implements ExternalContext { 37 38 41 private FacesContext facesContext; 42 43 46 private String actionId; 47 48 51 private String outcome; 52 53 57 public JsfExternalContext(FacesContext facesContext) { 58 this.facesContext = facesContext; 59 } 60 61 67 public JsfExternalContext(FacesContext facesContext, String actionId, String outcome) { 68 this.facesContext = facesContext; 69 this.actionId = actionId; 70 this.outcome = outcome; 71 } 72 73 public String getContextPath() { 74 return facesContext.getExternalContext().getRequestContextPath(); 75 } 76 77 public String getDispatcherPath() { 78 return facesContext.getExternalContext().getRequestServletPath(); 79 } 80 81 public String getRequestPathInfo() { 82 return facesContext.getExternalContext().getRequestPathInfo(); 83 } 84 85 public ParameterMap getRequestParameterMap() { 86 return new LocalParameterMap(facesContext.getExternalContext().getRequestParameterMap()); 87 } 88 89 public MutableAttributeMap getRequestMap() { 90 return new LocalAttributeMap(facesContext.getExternalContext().getRequestMap()); 91 } 92 93 public SharedAttributeMap getSessionMap() { 94 return new LocalSharedAttributeMap(new SessionSharedMap(facesContext)); 95 } 96 97 public SharedAttributeMap getGlobalSessionMap() { 98 return getSessionMap(); 99 } 100 101 public SharedAttributeMap getApplicationMap() { 102 return new LocalSharedAttributeMap(new ApplicationSharedMap(facesContext)); 103 } 104 105 108 public FacesContext getFacesContext() { 109 return facesContext; 110 } 111 112 115 public String getActionId() { 116 return actionId; 117 } 118 119 122 public String getOutcome() { 123 return outcome; 124 } 125 126 private static class SessionSharedMap extends SharedMapDecorator { 127 128 private FacesContext facesContext; 129 130 public SessionSharedMap(FacesContext facesContext) { 131 super(facesContext.getExternalContext().getSessionMap()); 132 this.facesContext = facesContext; 133 } 134 135 public Object getMutex() { 136 return facesContext.getExternalContext().getSession(false); 137 } 138 } 139 140 private static class ApplicationSharedMap extends SharedMapDecorator { 141 142 private FacesContext facesContext; 143 144 public ApplicationSharedMap(FacesContext facesContext) { 145 super(facesContext.getExternalContext().getApplicationMap()); 146 this.facesContext = facesContext; 147 } 148 149 public Object getMutex() { 150 return facesContext.getExternalContext().getContext(); 151 } 152 } 153 154 public String toString() { 155 return new ToStringCreator(this).append("actionId", actionId).append("outcome", outcome).append("facesContext", 156 facesContext).toString(); 157 } 158 } | Popular Tags |