| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.util; |
| 17 | |
|
| 18 | |
import javax.faces.application.ViewHandler; |
| 19 | |
import javax.faces.context.ExternalContext; |
| 20 | |
import javax.faces.context.FacesContext; |
| 21 | |
|
| 22 | |
import org.seasar.framework.util.AssertionUtil; |
| 23 | |
import org.seasar.teeda.core.portlet.FacesPortlet; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
public class ExternalContextUtil { |
| 30 | |
|
| 31 | 0 | private ExternalContextUtil() { |
| 32 | 0 | } |
| 33 | |
|
| 34 | |
public static String getViewId(ExternalContext externalContext) { |
| 35 | |
|
| 36 | 8 | if (PortletUtil.isPortlet(FacesContext.getCurrentInstance())) { |
| 37 | 0 | String viewId = (String) externalContext.getRequestMap().get( |
| 38 | |
FacesPortlet.VIEW_ID); |
| 39 | 0 | if (viewId == null) { |
| 40 | 0 | viewId = (String) externalContext.getRequestMap().get( |
| 41 | |
FacesPortlet.DEFAULT_PAGE); |
| 42 | |
} |
| 43 | 0 | return viewId; |
| 44 | |
} else { |
| 45 | 8 | String viewId = externalContext.getRequestPathInfo(); |
| 46 | 8 | if (viewId == null) { |
| 47 | 4 | viewId = externalContext.getRequestServletPath(); |
| 48 | 4 | final int dot = viewId.lastIndexOf('.'); |
| 49 | 4 | if (dot >= 0) { |
| 50 | 3 | final String suffix = getSuffix(externalContext); |
| 51 | 3 | viewId = viewId.substring(0, dot) + suffix; |
| 52 | |
} |
| 53 | |
} |
| 54 | 8 | return viewId; |
| 55 | |
} |
| 56 | |
} |
| 57 | |
|
| 58 | |
private static String getSuffix(ExternalContext externalContext) { |
| 59 | 3 | final String defaultSuffix = externalContext |
| 60 | |
.getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME); |
| 61 | 3 | if (defaultSuffix != null) { |
| 62 | 1 | return defaultSuffix; |
| 63 | |
} |
| 64 | 2 | return ViewHandler.DEFAULT_SUFFIX; |
| 65 | |
} |
| 66 | |
|
| 67 | |
public static String encodeActionURL(FacesContext context, String url) { |
| 68 | 1 | AssertionUtil.assertNotNull("FacesContext", context); |
| 69 | 1 | return context.getExternalContext().encodeActionURL(url); |
| 70 | |
} |
| 71 | |
} |