Advertisement
vangop

FacesImpl-viewhandlerImpl

Mar 14th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1.     public String getActionURL(FacesContext context, String viewId) {
  2.  
  3.         if (context == null) {
  4.             String message = MessageUtils.getExceptionMessageString
  5.                 (MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context");
  6.             throw new NullPointerException(message);
  7.         }
  8.         if (viewId == null) {
  9.             String message = MessageUtils.getExceptionMessageString
  10.                 (MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "viewId");
  11.             throw new NullPointerException(message);
  12.         }
  13.  
  14.         if (viewId.charAt(0) != '/') {
  15.             String message =
  16.                   MessageUtils.getExceptionMessageString(
  17.                         MessageUtils.ILLEGAL_VIEW_ID_ID,
  18.                         viewId);
  19.             if (logger.isLoggable(Level.SEVERE)) {
  20.                 logger.log(Level.SEVERE, "jsf.illegal_view_id_error", viewId);
  21.             }
  22.         throw new IllegalArgumentException(message);
  23.         }
  24.  
  25.         // Acquire the context path, which we will prefix on all results
  26.         ExternalContext extContext = context.getExternalContext();
  27.         String contextPath = extContext.getRequestContextPath();
  28.  
  29.         // Acquire the mapping used to execute this request (if any)
  30.         String mapping = Util.getFacesMapping(context);
  31.  
  32.         // If no mapping can be identified, just return a server-relative path
  33.         if (mapping == null) {
  34.             return (contextPath + viewId);
  35.         }
  36.  
  37.         // Deal with prefix mapping
  38.         if (Util.isPrefixMapped(mapping)) {
  39.             if (mapping.equals("/*")) {
  40.                 return (contextPath + viewId);
  41.             } else {
  42.                 return (contextPath + mapping + viewId);
  43.             }
  44.         }
  45.  
  46.         // Deal with extension mapping
  47.         int period = viewId.lastIndexOf('.');
  48.         if (period < 0) {
  49.             return (contextPath + viewId + mapping);
  50.         } else if (!viewId.endsWith(mapping)) {
  51.             return (contextPath + viewId.substring(0, period) + mapping);
  52.         } else {
  53.             return (contextPath + viewId);
  54.         }
  55.  
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement