1 23 24 29 30 package com.sun.enterprise.deployment.node.web; 31 32 import java.util.Iterator ; 33 import java.util.Map ; 34 import java.util.Set ; 35 import org.w3c.dom.Node ; 36 37 import com.sun.enterprise.deployment.ServletFilterMappingDescriptor; 38 import com.sun.enterprise.deployment.xml.WebTagNames; 39 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode; 40 import com.sun.enterprise.deployment.node.XMLElement; 41 import com.sun.enterprise.deployment.WebBundleDescriptor; 42 import com.sun.enterprise.util.web.URLPattern; 43 import com.sun.enterprise.util.LocalStringManagerImpl; 44 45 46 52 public class FilterMappingNode extends DeploymentDescriptorNode { 53 54 private ServletFilterMappingDescriptor descriptor; 55 private static LocalStringManagerImpl localStrings = 56 new LocalStringManagerImpl(ServletMappingNode.class); 57 58 61 public Object getDescriptor() { 62 63 if (descriptor==null) { 64 descriptor = (ServletFilterMappingDescriptor) super.getDescriptor(); 65 } 66 return descriptor; 67 } 68 69 75 protected Map getDispatchTable() { 76 Map table = super.getDispatchTable(); 77 table.put(WebTagNames.FILTER_NAME, "setName"); 78 return table; 79 } 80 81 87 public void setElementValue(XMLElement element, String value) { 88 if (WebTagNames.SERVLET_NAME.equals(element.getQName())) { 89 descriptor.addServletName(value); 90 } else if (WebTagNames.URL_PATTERN.equals(element.getQName())) { 91 Object parent = getParentNode().getDescriptor(); 94 if (parent instanceof WebBundleDescriptor && 95 ((WebBundleDescriptor) parent).getSpecVersion().equals("2.2")) 96 { 97 if(!value.startsWith("/") && !value.startsWith("*.")) { 98 value = "/" + value; 99 } 100 } 101 102 if (!URLPattern.isValid(value)) { 103 throw new IllegalArgumentException (localStrings.getLocalString( 104 "enterprise.deployment.invalidurlpattern", 105 "Invalid URL Pattern: [{0}]", 106 new Object [] {value})); 107 } 108 descriptor.addURLPattern(value); 109 } else if (WebTagNames.DISPATCHER.equals(element.getQName())) { 110 descriptor.addDispatcher(value); 111 } else super.setElementValue(element, value); 112 } 113 114 122 public Node writeDescriptor(Node parent, String nodeName, ServletFilterMappingDescriptor descriptor) { 123 Node myNode = appendChild(parent, nodeName); 124 appendTextChild(myNode, WebTagNames.FILTER_NAME, descriptor.getName()); 125 for (String servletName : descriptor.getServletNames()) { 126 appendTextChild(myNode, WebTagNames.SERVLET_NAME, servletName); 127 } 128 129 for (String urlPattern : descriptor.getURLPatterns()) { 130 appendTextChild(myNode, WebTagNames.URL_PATTERN, urlPattern); 131 } 132 133 Set dispatchers = descriptor.getDispatchers(); 134 for (Iterator i = dispatchers.iterator(); i.hasNext();) { 135 String dispatcher = (String ) i.next(); 136 appendTextChild(myNode, WebTagNames.DISPATCHER, dispatcher); 137 } 138 return myNode; 139 } 140 } 141 | Popular Tags |