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.shared.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 private String exact; 41 42 /** 43 * Creates a new FacesServletMapping object using prefix mapping. 44 * 45 * @param path The path ("/faces", for example) which has been specified 46 * in the url-pattern of the FacesServlet mapping. 47 * @return a newly created FacesServletMapping 48 */ 49 public static FacesServletMapping createPrefixMapping(String path) 50 { 51 FacesServletMapping mapping = new FacesServletMapping(); 52 mapping.setPrefix(path); 53 return mapping; 54 } 55 56 /** 57 * Creates a new FacesServletMapping object using extension mapping. 58 * 59 * @param extension The extension (".jsf", for example) which has been 60 * specified in the url-pattern of the FacesServlet mapping. 61 * @return a newly created FacesServletMapping 62 */ 63 public static FacesServletMapping createExtensionMapping( 64 String extension) 65 { 66 FacesServletMapping mapping = new FacesServletMapping(); 67 mapping.setExtension(extension); 68 return mapping; 69 } 70 71 public static FacesServletMapping createExactMapping(String exact) 72 { 73 FacesServletMapping mapping = new FacesServletMapping(); 74 mapping.setExact(exact); 75 return mapping; 76 } 77 78 /** 79 * Returns the path ("/faces", for example) which has been specified in 80 * the url-pattern of the FacesServlet mapping. If this mapping is based 81 * on an extension, <code>null</code> will be returned. Note that this 82 * path is not the same as the specified url-pattern as the trailing 83 * "/*" is omitted. 84 * 85 * @return the path which has been specified in the url-pattern 86 */ 87 public String getPrefix() 88 { 89 return prefix; 90 } 91 92 /** 93 * Sets the path ("/faces/", for example) which has been specified in 94 * the url-pattern. 95 * 96 * @param path The path which has been specified in the url-pattern 97 */ 98 public void setPrefix(String path) 99 { 100 this.prefix = path; 101 } 102 103 /** 104 * Returns the extension (".jsf", for example) which has been specified 105 * in the url-pattern of the FacesServlet mapping. If this mapping is 106 * not based on an extension, <code>null</code> will be returned. 107 * 108 * @return the extension which has been specified in the url-pattern 109 */ 110 public String getExtension() 111 { 112 return extension; 113 } 114 115 /** 116 * Sets the extension (".jsf", for example) which has been specified in 117 * the url-pattern of the FacesServlet mapping. 118 * 119 * @param extension The extension which has been specified in the url-pattern 120 */ 121 public void setExtension(String extension) 122 { 123 this.extension = extension; 124 } 125 126 /** 127 * Indicates whether this mapping is based on an extension (e.g. 128 * ".jsp"). 129 * 130 * @return <code>true</code>, if this mapping is based is on an 131 * extension, <code>false</code> otherwise 132 */ 133 public boolean isExtensionMapping() 134 { 135 return extension != null; 136 } 137 138 /** 139 * Indicates whether this mapping is based on a prefix (e.g. 140 * /faces/*"). 141 * 142 * @return <code>true</code>, if this mapping is based is on a 143 * prefix, <code>false</code> otherwise 144 */ 145 public boolean isPrefixMapping() 146 { 147 return prefix != null; 148 } 149 150 /** 151 * Returns the url-pattern entry for this servlet mapping. 152 * 153 * @return the url-pattern entry for this servlet mapping 154 */ 155 public String getUrlPattern() 156 { 157 if (isExtensionMapping()) 158 { 159 return '*' + extension; 160 } 161 else 162 { 163 return prefix + "/*"; 164 } 165 } 166 167 public String getExact() 168 { 169 return exact; 170 } 171 172 public void setExact(String exact) 173 { 174 this.exact = exact; 175 } 176 177 public boolean isExactMapping() 178 { 179 return exact != null; 180 } 181 182 @Override 183 public String toString() 184 { 185 return "FacesServletMapping{" + 186 "prefix='" + prefix + '\'' + 187 ", extension='" + extension + '\'' + 188 ", exact='" + exact + '\'' + 189 '}'; 190 } 191 }