1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.myfaces.commons.resourcehandler.application; 20 21 /** 22 * Represents a mapping entry of the FacesServlet in the web.xml 23 * configuration file. 24 */ 25 public class FacesServletMapping 26 { 27 28 /** 29 * The path ("/faces", for example) which has been specified in the 30 * url-pattern of the FacesServlet mapping. 31 */ 32 private String prefix; 33 34 /** 35 * The extension (".jsf", for example) which has been specified in the 36 * url-pattern of the FacesServlet mapping. 37 */ 38 private String extension; 39 40 /** 41 * Creates a new FacesServletMapping object using prefix mapping. 42 * 43 * @param path The path ("/faces", for example) which has been specified 44 * in the url-pattern of the FacesServlet mapping. 45 * @return a newly created FacesServletMapping 46 */ 47 public static FacesServletMapping createPrefixMapping(String path) 48 { 49 FacesServletMapping mapping = new FacesServletMapping(); 50 mapping.setPrefix(path); 51 return mapping; 52 } 53 54 /** 55 * Creates a new FacesServletMapping object using extension mapping. 56 * 57 * @param path The extension (".jsf", for example) which has been 58 * specified in the url-pattern of the FacesServlet mapping. 59 * @return a newly created FacesServletMapping 60 */ 61 public static FacesServletMapping createExtensionMapping( 62 String extension) 63 { 64 FacesServletMapping mapping = new FacesServletMapping(); 65 mapping.setExtension(extension); 66 return mapping; 67 } 68 69 /** 70 * Returns the path ("/faces", for example) which has been specified in 71 * the url-pattern of the FacesServlet mapping. If this mapping is based 72 * on an extension, <code>null</code> will be returned. Note that this 73 * path is not the same as the specified url-pattern as the trailing 74 * "/*" is omitted. 75 * 76 * @return the path which has been specified in the url-pattern 77 */ 78 public String getPrefix() 79 { 80 return prefix; 81 } 82 83 /** 84 * Sets the path ("/faces/", for example) which has been specified in 85 * the url-pattern. 86 * 87 * @param path The path which has been specified in the url-pattern 88 */ 89 public void setPrefix(String path) 90 { 91 this.prefix = path; 92 } 93 94 /** 95 * Returns the extension (".jsf", for example) which has been specified 96 * in the url-pattern of the FacesServlet mapping. If this mapping is 97 * not based on an extension, <code>null</code> will be returned. 98 * 99 * @return the extension which has been specified in the url-pattern 100 */ 101 public String getExtension() 102 { 103 return extension; 104 } 105 106 /** 107 * Sets the extension (".jsf", for example) which has been specified in 108 * the url-pattern of the FacesServlet mapping. 109 * 110 * @param extension The extension which has been specified in the url-pattern 111 */ 112 public void setExtension(String extension) 113 { 114 this.extension = extension; 115 } 116 117 /** 118 * Indicates whether this mapping is based on an extension (e.g. 119 * ".jsp"). 120 * 121 * @return <code>true</code>, if this mapping is based is on an 122 * extension, <code>false</code> otherwise 123 */ 124 public boolean isExtensionMapping() 125 { 126 return extension != null; 127 } 128 129 /** 130 * Indicates whether this mapping is based on a prefix (e.g. 131 * /faces/*"). 132 * 133 * @return <code>true</code>, if this mapping is based is on a 134 * prefix, <code>false</code> otherwise 135 */ 136 public boolean isPrefixMapping() 137 { 138 return prefix != null; 139 } 140 141 /** 142 * Returns the url-pattern entry for this servlet mapping. 143 * 144 * @return the url-pattern entry for this servlet mapping 145 */ 146 public String getUrlPattern() 147 { 148 if (isExtensionMapping()) 149 { 150 return "*" + extension; 151 } 152 else 153 { 154 return prefix + "/*"; 155 } 156 } 157 158 }