Example #1
0
  /**
   * write the descriptor class to a DOM tree and return it
   *
   * @param parent node in the DOM tree
   * @param node name for the root element of this xml fragment
   * @param the descriptor to write
   * @return the DOM tree top node
   */
  public Node writeDescriptor(
      Node parent, String nodeName, ServletFilterMappingDescriptor descriptor) {
    Node myNode = appendChild(parent, nodeName);
    appendTextChild(myNode, WebTagNames.FILTER_NAME, descriptor.getName());
    for (String servletName : descriptor.getServletNames()) {
      appendTextChild(myNode, WebTagNames.SERVLET_NAME, servletName);
    }

    for (String urlPattern : descriptor.getURLPatterns()) {
      appendTextChild(myNode, WebTagNames.URL_PATTERN, urlPattern);
    }

    for (DispatcherType dispatcherType : descriptor.getDispatchers()) {
      appendTextChild(myNode, WebTagNames.DISPATCHER, dispatcherType.name());
    }
    return myNode;
  }
Example #2
0
  /**
   * receives notiification of the value for a particular tag
   *
   * @param element the xml element
   * @param value it's associated value
   */
  public void setElementValue(XMLElement element, String value) {
    if (WebTagNames.SERVLET_NAME.equals(element.getQName())) {
      descriptor.addServletName(value);
    } else if (WebTagNames.URL_PATTERN.equals(element.getQName())) {
      if (!URLPattern.isValid(value)) {
        // try trimming url (in case DD uses extra
        // whitespace for aligning)
        String trimmedUrl = value.trim();

        // If URL Pattern does not start with "/" then
        // prepend it (for Servlet2.2 Web apps)
        Object parent = getParentNode().getDescriptor();
        if (parent instanceof WebBundleDescriptor
            && ((WebBundleDescriptor) parent).getSpecVersion().equals("2.2")) {
          if (!trimmedUrl.startsWith("/") && !trimmedUrl.startsWith("*.")) {
            trimmedUrl = "/" + trimmedUrl;
          }
        }

        if (URLPattern.isValid(trimmedUrl)) {
          // warn user if url included \r or \n
          if (URLPattern.containsCRorLF(value)) {
            DOLUtils.getDefaultLogger()
                .log(
                    Level.WARNING,
                    "enterprise.deployment.backend.urlcontainscrlf",
                    new Object[] {value});
          }
          value = trimmedUrl;
        } else {
          throw new IllegalArgumentException(
              localStrings.getLocalString(
                  "enterprise.deployment.invalidurlpattern",
                  "Invalid URL Pattern: [{0}]",
                  new Object[] {value}));
        }
      }
      descriptor.addURLPattern(value);
    } else if (WebTagNames.DISPATCHER.equals(element.getQName())) {
      descriptor.addDispatcher(value);
    } else super.setElementValue(element, value);
  }