1 23 24 package com.sun.enterprise.deployment.node.web; 25 26 import java.util.Map ; 27 import java.util.Enumeration ; 28 import org.w3c.dom.Node ; 29 30 import com.sun.enterprise.deployment.WebResourceCollectionImpl; 31 import com.sun.enterprise.deployment.WebBundleDescriptor; 32 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode; 33 import com.sun.enterprise.deployment.node.DescriptorFactory; 34 import com.sun.enterprise.deployment.node.XMLElement; 35 import com.sun.enterprise.deployment.xml.WebTagNames; 36 import com.sun.enterprise.util.web.URLPattern; 37 import com.sun.enterprise.util.LocalStringManagerImpl; 38 39 45 public class WebResourceCollectionNode extends DeploymentDescriptorNode { 46 47 private WebResourceCollectionImpl descriptor; 48 private static LocalStringManagerImpl localStrings = 49 new LocalStringManagerImpl(ServletMappingNode.class); 50 51 54 public Object getDescriptor() { 55 if (descriptor==null) { 56 descriptor = (WebResourceCollectionImpl) DescriptorFactory.getDescriptor(getXMLPath()); 57 } 58 return descriptor; 59 } 60 61 64 protected XMLElement getXMLRootTag() { 65 return new XMLElement(WebTagNames.WEB_RESOURCE_COLLECTION); 66 } 67 68 74 protected Map getDispatchTable() { 75 Map table = super.getDispatchTable(); 76 table.put(WebTagNames.WEB_RESOURCE_NAME, "setName"); 77 table.put(WebTagNames.HTTP_METHOD, "addHttpMethod"); 78 return table; 79 } 80 81 87 public void setElementValue(XMLElement element, String value) { 88 if (WebTagNames.URL_PATTERN.equals(element.getQName())) { 89 Object parent = getParentNode().getParentNode().getDescriptor(); 92 if (parent instanceof WebBundleDescriptor && 93 ((WebBundleDescriptor) parent).getSpecVersion().equals("2.2")) 94 { 95 if(!value.startsWith("/") && !value.startsWith("*.")) { 96 value = "/" + value; 97 } 98 } 99 if (!URLPattern.isValid(value)) { 100 throw new IllegalArgumentException (localStrings.getLocalString( 101 "enterprise.deployment.invalidurlpattern", 102 "Invalid URL Pattern: [{0}]", 103 new Object [] {value})); 104 } 105 descriptor.addUrlPattern(value); 106 } else super.setElementValue(element, value); 107 } 108 109 117 public Node writeDescriptor(Node parent, String nodeName, WebResourceCollectionImpl descriptor) { 118 Node myNode = appendChild(parent, nodeName); 119 appendTextChild(myNode, WebTagNames.WEB_RESOURCE_NAME, descriptor.getName()); 120 writeLocalizedDescriptions(myNode, descriptor); 121 122 for (Enumeration urlPatterns = descriptor.getUrlPatterns();urlPatterns.hasMoreElements();) { 124 appendTextChild(myNode, WebTagNames.URL_PATTERN, (String ) urlPatterns.nextElement()); 125 } 126 127 for (Enumeration httpMethods = descriptor.getHttpMethods();httpMethods.hasMoreElements();) { 129 appendTextChild(myNode, WebTagNames.HTTP_METHOD, (String ) httpMethods.nextElement()); 130 } 131 return myNode; 132 } 133 } 134 | Popular Tags |