Java 类org.apache.catalina.deploy.WebXml 实例源码

项目:tomcat7    文件:WebRuleSet.java   
@Override
public void begin(String namespace, String name, Attributes attributes)
    throws Exception {
    WebXml webxml = (WebXml) digester.peek(digester.getCount() - 1);
    String value = attributes.getValue("metadata-complete");
    if ("true".equals(value)) {
        webxml.setMetadataComplete(true);
    } else if ("false".equals(value)) {
        webxml.setMetadataComplete(false);
    }
    if (digester.getLogger().isDebugEnabled()) {
        digester.getLogger().debug
            (webxml.getClass().getName() + ".setMetadataComplete( " +
                    webxml.isMetadataComplete() + ")");
    }
}
项目:tomcat7    文件:WebRuleSet.java   
@Override
public void begin(String namespace, String name, Attributes attributes)
        throws Exception {
    if (fragment) {
        digester.getLogger().warn(
                WebRuleSet.sm.getString("webRuleSet.absoluteOrdering"));
    }
    if (isAbsoluteOrderingSet) {
        throw new IllegalArgumentException(WebRuleSet.sm.getString(
                "webRuleSet.absoluteOrderingCount"));
    } else {
        isAbsoluteOrderingSet = true;
        WebXml webXml = (WebXml) digester.peek();
        webXml.createAbsoluteOrdering();
        if (digester.getLogger().isDebugEnabled()) {
            digester.getLogger().debug(
                    webXml.getClass().getName() + ".setAbsoluteOrdering()");
        }
    }
}
项目:tomcat7    文件:WebRuleSet.java   
@Override
public void end(String namespace, String name) throws Exception {
    Object[] params = (Object[]) digester.peekParams();
    if (params != null && params.length == 2) {
        WebXml webXml = (WebXml) digester.peek();
        if (postConstruct) {
            if (webXml.getPostConstructMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(WebRuleSet.sm.getString(
                        "webRuleSet.postconstruct.duplicate", params[0]));
            }
        } else {
            if (webXml.getPreDestroyMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(WebRuleSet.sm.getString(
                        "webRuleSet.predestroy.duplicate", params[0]));
            }
        }
    }
    super.end(namespace, name);
}
项目:tomcat7    文件:ContextConfig.java   
private void convertJsps(WebXml webXml) {
    Map<String,String> jspInitParams;
    ServletDef jspServlet = webXml.getServlets().get("jsp");
    if (jspServlet == null) {
        jspInitParams = new HashMap<String,String>();
        Wrapper w = (Wrapper) context.findChild("jsp");
        if (w != null) {
            String[] params = w.findInitParameters();
            for (String param : params) {
                jspInitParams.put(param, w.findInitParameter(param));
            }
        }
    } else {
        jspInitParams = jspServlet.getParameterMap();
    }
    for (ServletDef servletDef: webXml.getServlets().values()) {
        if (servletDef.getJspFile() != null) {
            convertJsp(servletDef, jspInitParams);
        }
    }
}
项目:tomcat7    文件:ContextConfig.java   
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String,WebXml> processJarsForWebFragments(WebXml application) {

    JarScanner jarScanner = context.getJarScanner();

    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() &&
            !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback =
            new FragmentJarScannerCallback(parseRequired);

    jarScanner.scan(context.getServletContext(),
            context.getLoader().getClassLoader(), callback,
            pluggabilityJarsToSkip);

    return callback.getFragments();
}
项目:tomcat7    文件:ContextConfig.java   
protected void processAnnotationsUrl(URL url, WebXml fragment,
        boolean handlesTypesOnly) {
    if (url == null) {
        // Nothing to do.
        return;
    } else if ("jar".equals(url.getProtocol())) {
        processAnnotationsJar(url, fragment, handlesTypesOnly);
    } else if ("jndi".equals(url.getProtocol())) {
        processAnnotationsJndi(url, fragment, handlesTypesOnly);
    } else if ("file".equals(url.getProtocol())) {
        try {
            processAnnotationsFile(
                    new File(url.toURI()), fragment, handlesTypesOnly);
        } catch (URISyntaxException e) {
            log.error(sm.getString("contextConfig.fileUrl", url), e);
        }
    } else {
        log.error(sm.getString("contextConfig.unknownUrlProtocol",
                url.getProtocol(), url));
    }

}
项目:tomcat7    文件:TestContextConfigAnnotation.java   
@Test
public void testAnnotation() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/ParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    ServletDef servletDef = webxml.getServlets().get("param");
    assertNotNull(servletDef);
    assertEquals("Hello", servletDef.getParameterMap().get("foo"));
    assertEquals("World!", servletDef.getParameterMap().get("bar"));
    assertEquals("param", webxml.getServletMappings().get(
            "/annotation/overwrite"));

    assertEquals("param", servletDef.getDescription());
    assertEquals("param", servletDef.getDisplayName());
    assertEquals("paramLarge.png", servletDef.getLargeIcon());
    assertEquals("paramSmall.png", servletDef.getSmallIcon());
    assertEquals(Boolean.FALSE, servletDef.getAsyncSupported());
    assertEquals(Integer.valueOf(0), servletDef.getLoadOnStartup());
    assertNull(servletDef.getEnabled());
    assertNull(servletDef.getJspFile());

}
项目:tomcat7    文件:TestContextConfigAnnotation.java   
@Test
public void testNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/NoMappingParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    ServletDef servletDef = webxml.getServlets().get("param1");
    assertNull(servletDef);

    webxml.addServletMapping("/param", "param1");
    config.processAnnotationsFile(pFile, webxml, false);
    servletDef = webxml.getServlets().get("param1");
    assertNull(servletDef);

}
项目:tomcat7    文件:TestContextConfigAnnotation.java   
@Test
public void testSetupWebXMLNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    ServletDef servletDef = new ServletDef();
    servletDef.setServletName("param1");
    servletDef.setServletClass(
            "org.apache.catalina.startup.NoMappingParamServlet");
    servletDef.addInitParameter("foo", "tomcat");

    webxml.addServlet(servletDef);
    webxml.addServletMapping("/param", "param1");
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/NoMappingParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
    assertEquals("World!", servletDef.getParameterMap().get("bar"));
    ServletDef servletDef1 = webxml.getServlets().get("param1");
    assertNotNull(servletDef1);
    assertEquals(servletDef, servletDef1);
}
项目:tomcat7    文件:TestContextConfigAnnotation.java   
@Test
public void testDuplicateMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/DuplicateMappingParamServlet");
    assertTrue(pFile.exists());
    try {
        config.processAnnotationsFile(pFile, webxml, false);
        fail();
    } catch (IllegalArgumentException ex) {
        // ignore
    }
    ServletDef servletDef = webxml.getServlets().get("param");
    assertNull(servletDef);
}
项目:tomcat7    文件:TestContextConfigAnnotation.java   
@Test
public void testDuplicateFilterMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/DuplicateMappingParamFilter");
    assertTrue(pFile.exists());
    try {
        config.processAnnotationsFile(pFile, webxml, false);
        fail();
    } catch (IllegalArgumentException ex) {
        // ignore
    }
    FilterDef filterDef = webxml.getFilters().get("paramD");
    assertNull(filterDef);
}
项目:tomcat7    文件:TestWebRuleSet.java   
@Test
    public void testRecycle() throws Exception {
        // Name
        parse(new WebXml(), "web-fragment-2name.xml", true, false);
        parse(new WebXml(), "web-fragment-1name.xml", true, true);
        parse(new WebXml(), "web-fragment-2name.xml", true, false);
        parse(new WebXml(), "web-fragment-1name.xml", true, true);

        // Relative ordering
        parse(new WebXml(), "web-fragment-2ordering.xml", true, false);
        parse(new WebXml(), "web-fragment-1ordering.xml", true, true);
        parse(new WebXml(), "web-fragment-2ordering.xml", true, false);
        parse(new WebXml(), "web-fragment-1ordering.xml", true, true);

        // Absolute ordering
        parse(new WebXml(), "web-2ordering.xml", false, false);
        parse(new WebXml(), "web-1ordering.xml", false, true);
        parse(new WebXml(), "web-2ordering.xml", false, false);
        parse(new WebXml(), "web-1ordering.xml", false, true);
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestContextConfigAnnotation.java   
@Test
public void testAnnotation() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/ParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    ServletDef servletDef = webxml.getServlets().get("param");
    assertNotNull(servletDef);
    assertEquals("Hello", servletDef.getParameterMap().get("foo"));
    assertEquals("World!", servletDef.getParameterMap().get("bar"));
    assertEquals("param", webxml.getServletMappings().get(
            "/annotation/overwrite"));

    assertEquals("param", servletDef.getDescription());
    assertEquals("param", servletDef.getDisplayName());
    assertEquals("paramLarge.png", servletDef.getLargeIcon());
    assertEquals("paramSmall.png", servletDef.getSmallIcon());
    assertEquals(Boolean.FALSE, servletDef.getAsyncSupported());
    assertEquals(Integer.valueOf(0), servletDef.getLoadOnStartup());
    assertNull(servletDef.getEnabled());
    assertNull(servletDef.getJspFile());

}
项目:apache-tomcat-7.0.73-with-comment    文件:TestContextConfigAnnotation.java   
@Test
public void testNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/NoMappingParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    ServletDef servletDef = webxml.getServlets().get("param1");
    assertNull(servletDef);

    webxml.addServletMapping("/param", "param1");
    config.processAnnotationsFile(pFile, webxml, false);
    servletDef = webxml.getServlets().get("param1");
    assertNull(servletDef);

}
项目:apache-tomcat-7.0.73-with-comment    文件:TestContextConfigAnnotation.java   
@Test
public void testSetupWebXMLNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    ServletDef servletDef = new ServletDef();
    servletDef.setServletName("param1");
    servletDef.setServletClass(
            "org.apache.catalina.startup.NoMappingParamServlet");
    servletDef.addInitParameter("foo", "tomcat");

    webxml.addServlet(servletDef);
    webxml.addServletMapping("/param", "param1");
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/NoMappingParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
    assertEquals("World!", servletDef.getParameterMap().get("bar"));
    ServletDef servletDef1 = webxml.getServlets().get("param1");
    assertNotNull(servletDef1);
    assertEquals(servletDef, servletDef1);
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestContextConfigAnnotation.java   
@Test
public void testDuplicateMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/DuplicateMappingParamServlet");
    assertTrue(pFile.exists());
    try {
        config.processAnnotationsFile(pFile, webxml, false);
        fail();
    } catch (IllegalArgumentException ex) {
        // ignore
    }
    ServletDef servletDef = webxml.getServlets().get("param");
    assertNull(servletDef);
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestContextConfigAnnotation.java   
@Test
public void testDuplicateFilterMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/DuplicateMappingParamFilter");
    assertTrue(pFile.exists());
    try {
        config.processAnnotationsFile(pFile, webxml, false);
        fail();
    } catch (IllegalArgumentException ex) {
        // ignore
    }
    FilterDef filterDef = webxml.getFilters().get("paramD");
    assertNull(filterDef);
}
项目:apache-tomcat-7.0.73-with-comment    文件:TestWebRuleSet.java   
@Test
    public void testRecycle() throws Exception {
        // Name
        parse(new WebXml(), "web-fragment-2name.xml", true, false);
        parse(new WebXml(), "web-fragment-1name.xml", true, true);
        parse(new WebXml(), "web-fragment-2name.xml", true, false);
        parse(new WebXml(), "web-fragment-1name.xml", true, true);

        // Relative ordering
        parse(new WebXml(), "web-fragment-2ordering.xml", true, false);
        parse(new WebXml(), "web-fragment-1ordering.xml", true, true);
        parse(new WebXml(), "web-fragment-2ordering.xml", true, false);
        parse(new WebXml(), "web-fragment-1ordering.xml", true, true);

        // Absolute ordering
        parse(new WebXml(), "web-2ordering.xml", false, false);
        parse(new WebXml(), "web-1ordering.xml", false, true);
        parse(new WebXml(), "web-2ordering.xml", false, false);
        parse(new WebXml(), "web-1ordering.xml", false, true);
}
项目:lazycat    文件:WebRuleSet.java   
@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {
    if (fragment) {
        digester.getLogger().warn(WebRuleSet.sm.getString("webRuleSet.absoluteOrdering"));
    }
    if (isAbsoluteOrderingSet) {
        throw new IllegalArgumentException(WebRuleSet.sm.getString("webRuleSet.absoluteOrderingCount"));
    } else {
        isAbsoluteOrderingSet = true;
        WebXml webXml = (WebXml) digester.peek();
        webXml.createAbsoluteOrdering();
        if (digester.getLogger().isDebugEnabled()) {
            digester.getLogger().debug(webXml.getClass().getName() + ".setAbsoluteOrdering()");
        }
    }
}
项目:lazycat    文件:WebRuleSet.java   
@Override
public void end(String namespace, String name) throws Exception {
    Object[] params = (Object[]) digester.peekParams();
    if (params != null && params.length == 2) {
        WebXml webXml = (WebXml) digester.peek();
        if (postConstruct) {
            if (webXml.getPostConstructMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(
                        WebRuleSet.sm.getString("webRuleSet.postconstruct.duplicate", params[0]));
            }
        } else {
            if (webXml.getPreDestroyMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(
                        WebRuleSet.sm.getString("webRuleSet.predestroy.duplicate", params[0]));
            }
        }
    }
    super.end(namespace, name);
}
项目:lazycat    文件:ContextConfig.java   
private void convertJsps(WebXml webXml) {
    Map<String, String> jspInitParams;
    ServletDef jspServlet = webXml.getServlets().get("jsp");
    if (jspServlet == null) {
        jspInitParams = new HashMap<String, String>();
        Wrapper w = (Wrapper) context.findChild("jsp");
        if (w != null) {
            String[] params = w.findInitParameters();
            for (String param : params) {
                jspInitParams.put(param, w.findInitParameter(param));
            }
        }
    } else {
        jspInitParams = jspServlet.getParameterMap();
    }
    for (ServletDef servletDef : webXml.getServlets().values()) {
        if (servletDef.getJspFile() != null) {
            convertJsp(servletDef, jspInitParams);
        }
    }
}
项目:lazycat    文件:ContextConfig.java   
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String, WebXml> processJarsForWebFragments(WebXml application) {

    JarScanner jarScanner = context.getJarScanner();

    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() && !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback = new FragmentJarScannerCallback(parseRequired);

    jarScanner.scan(context.getServletContext(), context.getLoader().getClassLoader(), callback,
            pluggabilityJarsToSkip);

    return callback.getFragments();
}
项目:lazycat    文件:ContextConfig.java   
protected void processAnnotationsUrl(URL url, WebXml fragment, boolean handlesTypesOnly) {
    if (url == null) {
        // Nothing to do.
        return;
    } else if ("jar".equals(url.getProtocol())) {
        processAnnotationsJar(url, fragment, handlesTypesOnly);
    } else if ("jndi".equals(url.getProtocol())) {
        processAnnotationsJndi(url, fragment, handlesTypesOnly);
    } else if ("file".equals(url.getProtocol())) {
        try {
            processAnnotationsFile(new File(url.toURI()), fragment, handlesTypesOnly);
        } catch (URISyntaxException e) {
            log.error(sm.getString("contextConfig.fileUrl", url), e);
        }
    } else {
        log.error(sm.getString("contextConfig.unknownUrlProtocol", url.getProtocol(), url));
    }

}
项目:class-guard    文件:WebRuleSet.java   
@Override
public void begin(String namespace, String name, Attributes attributes)
    throws Exception {
    WebXml webxml = (WebXml) digester.peek(digester.getCount() - 1);
    String value = attributes.getValue("metadata-complete");
    if ("true".equals(value)) {
        webxml.setMetadataComplete(true);
    } else if ("false".equals(value)) {
        webxml.setMetadataComplete(false);
    }
    if (digester.getLogger().isDebugEnabled()) {
        digester.getLogger().debug
            (webxml.getClass().getName() + ".setMetadataComplete( " +
                    webxml.isMetadataComplete() + ")");
    }
}
项目:class-guard    文件:WebRuleSet.java   
@Override
public void begin(String namespace, String name, Attributes attributes)
        throws Exception {
    if (fragment) {
        digester.getLogger().warn(
                WebRuleSet.sm.getString("webRuleSet.absoluteOrdering"));
    }
    if (isAbsoluteOrderingSet) {
        throw new IllegalArgumentException(WebRuleSet.sm.getString(
                "webRuleSet.absoluteOrderingCount"));
    } else {
        isAbsoluteOrderingSet = true;
        WebXml webXml = (WebXml) digester.peek();
        webXml.createAbsoluteOrdering();
        if (digester.getLogger().isDebugEnabled()) {
            digester.getLogger().debug(
                    webXml.getClass().getName() + ".setAbsoluteOrdering()");
        }
    }
}
项目:class-guard    文件:WebRuleSet.java   
@Override
public void end(String namespace, String name) throws Exception {
    Object[] params = (Object[]) digester.peekParams();
    if (params != null && params.length == 2) {
        WebXml webXml = (WebXml) digester.peek();
        if (postConstruct) {
            if (webXml.getPostConstructMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(WebRuleSet.sm.getString(
                        "webRuleSet.postconstruct.duplicate", params[0]));
            }
        } else {
            if (webXml.getPreDestroyMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(WebRuleSet.sm.getString(
                        "webRuleSet.predestroy.duplicate", params[0]));
            }
        }
    }
    super.end(namespace, name);
}
项目:class-guard    文件:ContextConfig.java   
private void convertJsps(WebXml webXml) {
    Map<String,String> jspInitParams;
    ServletDef jspServlet = webXml.getServlets().get("jsp");
    if (jspServlet == null) {
        jspInitParams = new HashMap<String,String>();
        Wrapper w = (Wrapper) context.findChild("jsp");
        if (w != null) {
            String[] params = w.findInitParameters();
            for (String param : params) {
                jspInitParams.put(param, w.findInitParameter(param));
            }
        }
    } else {
        jspInitParams = jspServlet.getParameterMap();
    }
    for (ServletDef servletDef: webXml.getServlets().values()) {
        if (servletDef.getJspFile() != null) {
            convertJsp(servletDef, jspInitParams);
        }
    }
}
项目:class-guard    文件:ContextConfig.java   
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String,WebXml> processJarsForWebFragments(WebXml application) {

    JarScanner jarScanner = context.getJarScanner();

    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() &&
            !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback =
            new FragmentJarScannerCallback(parseRequired);

    jarScanner.scan(context.getServletContext(),
            context.getLoader().getClassLoader(), callback,
            pluggabilityJarsToSkip);

    return callback.getFragments();
}
项目:class-guard    文件:ContextConfig.java   
protected void processAnnotationsUrl(URL url, WebXml fragment,
        boolean handlesTypesOnly) {
    if (url == null) {
        // Nothing to do.
        return;
    } else if ("jar".equals(url.getProtocol())) {
        processAnnotationsJar(url, fragment, handlesTypesOnly);
    } else if ("jndi".equals(url.getProtocol())) {
        processAnnotationsJndi(url, fragment, handlesTypesOnly);
    } else if ("file".equals(url.getProtocol())) {
        try {
            processAnnotationsFile(
                    new File(url.toURI()), fragment, handlesTypesOnly);
        } catch (URISyntaxException e) {
            log.error(sm.getString("contextConfig.fileUrl", url), e);
        }
    } else {
        log.error(sm.getString("contextConfig.unknownUrlProtocol",
                url.getProtocol(), url));
    }

}
项目:apache-tomcat-7.0.57    文件:WebRuleSet.java   
@Override
public void end(String namespace, String name) throws Exception {
    Object[] params = (Object[]) digester.peekParams();
    if (params != null && params.length == 2) {
        WebXml webXml = (WebXml) digester.peek();
        if (postConstruct) {
            if (webXml.getPostConstructMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(WebRuleSet.sm.getString(
                        "webRuleSet.postconstruct.duplicate", params[0]));
            }
        } else {
            if (webXml.getPreDestroyMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(WebRuleSet.sm.getString(
                        "webRuleSet.predestroy.duplicate", params[0]));
            }
        }
    }
    super.end(namespace, name);
}
项目:class-guard    文件:TestContextConfigAnnotation.java   
@Test
public void testAnnotation() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/ParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    ServletDef servletDef = webxml.getServlets().get("param");
    assertNotNull(servletDef);
    assertEquals("Hello", servletDef.getParameterMap().get("foo"));
    assertEquals("World!", servletDef.getParameterMap().get("bar"));
    assertEquals("param", webxml.getServletMappings().get(
            "/annotation/overwrite"));

    assertEquals("param", servletDef.getDescription());
    assertEquals("param", servletDef.getDisplayName());
    assertEquals("paramLarge.png", servletDef.getLargeIcon());
    assertEquals("paramSmall.png", servletDef.getSmallIcon());
    assertEquals(Boolean.FALSE, servletDef.getAsyncSupported());
    assertEquals(Integer.valueOf(0), servletDef.getLoadOnStartup());
    assertNull(servletDef.getEnabled());
    assertNull(servletDef.getJspFile());

}
项目:class-guard    文件:TestContextConfigAnnotation.java   
@Test
public void testNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/NoMappingParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    ServletDef servletDef = webxml.getServlets().get("param1");
    assertNull(servletDef);

    webxml.addServletMapping("/param", "param1");
    config.processAnnotationsFile(pFile, webxml, false);
    servletDef = webxml.getServlets().get("param1");
    assertNull(servletDef);

}
项目:class-guard    文件:TestContextConfigAnnotation.java   
@Test
public void testSetupWebXMLNoMapping() throws Exception {
    WebXml webxml = new WebXml();
    ServletDef servletDef = new ServletDef();
    servletDef.setServletName("param1");
    servletDef.setServletClass(
            "org.apache.catalina.startup.NoMappingParamServlet");
    servletDef.addInitParameter("foo", "tomcat");

    webxml.addServlet(servletDef);
    webxml.addServletMapping("/param", "param1");
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/NoMappingParamServlet");
    assertTrue(pFile.exists());
    config.processAnnotationsFile(pFile, webxml, false);
    assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
    assertEquals("World!", servletDef.getParameterMap().get("bar"));
    ServletDef servletDef1 = webxml.getServlets().get("param1");
    assertNotNull(servletDef1);
    assertEquals(servletDef, servletDef1);
}
项目:class-guard    文件:TestContextConfigAnnotation.java   
@Test
public void testDuplicateMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/DuplicateMappingParamServlet");
    assertTrue(pFile.exists());
    try {
        config.processAnnotationsFile(pFile, webxml, false);
        fail();
    } catch (IllegalArgumentException ex) {
        // ignore
    }
    ServletDef servletDef = webxml.getServlets().get("param");
    assertNull(servletDef);
}
项目:class-guard    文件:TestContextConfigAnnotation.java   
@Test
public void testDuplicateFilterMapping() throws Exception {
    WebXml webxml = new WebXml();
    ContextConfig config = new ContextConfig();
    File pFile = paramClassResource(
            "org/apache/catalina/startup/DuplicateMappingParamFilter");
    assertTrue(pFile.exists());
    try {
        config.processAnnotationsFile(pFile, webxml, false);
        fail();
    } catch (IllegalArgumentException ex) {
        // ignore
    }
    FilterDef filterDef = webxml.getFilters().get("paramD");
    assertNull(filterDef);
}
项目:class-guard    文件:TestWebRuleSet.java   
@Test
    public void testRecycle() throws Exception {
        // Name
        parse(new WebXml(), "web-fragment-2name.xml", true, false);
        parse(new WebXml(), "web-fragment-1name.xml", true, true);
        parse(new WebXml(), "web-fragment-2name.xml", true, false);
        parse(new WebXml(), "web-fragment-1name.xml", true, true);

        // Relative ordering
        parse(new WebXml(), "web-fragment-2ordering.xml", true, false);
        parse(new WebXml(), "web-fragment-1ordering.xml", true, true);
        parse(new WebXml(), "web-fragment-2ordering.xml", true, false);
        parse(new WebXml(), "web-fragment-1ordering.xml", true, true);

        // Absolute ordering
        parse(new WebXml(), "web-2ordering.xml", false, false);
        parse(new WebXml(), "web-1ordering.xml", false, true);
        parse(new WebXml(), "web-2ordering.xml", false, false);
        parse(new WebXml(), "web-1ordering.xml", false, true);
}
项目:apache-tomcat-7.0.57    文件:WebRuleSet.java   
@Override
public void begin(String namespace, String name, Attributes attributes)
    throws Exception {
    WebXml webxml = (WebXml) digester.peek(digester.getCount() - 1);
    String value = attributes.getValue("metadata-complete");
    if ("true".equals(value)) {
        webxml.setMetadataComplete(true);
    } else if ("false".equals(value)) {
        webxml.setMetadataComplete(false);
    }
    if (digester.getLogger().isDebugEnabled()) {
        digester.getLogger().debug
            (webxml.getClass().getName() + ".setMetadataComplete( " +
                    webxml.isMetadataComplete() + ")");
    }
}
项目:apache-tomcat-7.0.57    文件:WebRuleSet.java   
@Override
public void begin(String namespace, String name, Attributes attributes)
        throws Exception {
    if (fragment) {
        digester.getLogger().warn(
                WebRuleSet.sm.getString("webRuleSet.absoluteOrdering"));
    }
    if (isAbsoluteOrderingSet) {
        throw new IllegalArgumentException(WebRuleSet.sm.getString(
                "webRuleSet.absoluteOrderingCount"));
    } else {
        isAbsoluteOrderingSet = true;
        WebXml webXml = (WebXml) digester.peek();
        webXml.createAbsoluteOrdering();
        if (digester.getLogger().isDebugEnabled()) {
            digester.getLogger().debug(
                    webXml.getClass().getName() + ".setAbsoluteOrdering()");
        }
    }
}
项目:apache-tomcat-7.0.57    文件:WebRuleSet.java   
@Override
public void end(String namespace, String name) throws Exception {
    Object[] params = (Object[]) digester.peekParams();
    if (params != null && params.length == 2) {
        WebXml webXml = (WebXml) digester.peek();
        if (postConstruct) {
            if (webXml.getPostConstructMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(WebRuleSet.sm.getString(
                        "webRuleSet.postconstruct.duplicate", params[0]));
            }
        } else {
            if (webXml.getPreDestroyMethods().containsKey(params[0])) {
                throw new IllegalArgumentException(WebRuleSet.sm.getString(
                        "webRuleSet.predestroy.duplicate", params[0]));
            }
        }
    }
    super.end(namespace, name);
}
项目:apache-tomcat-7.0.57    文件:ContextConfig.java   
private void convertJsps(WebXml webXml) {
    Map<String,String> jspInitParams;
    ServletDef jspServlet = webXml.getServlets().get("jsp");
    if (jspServlet == null) {
        jspInitParams = new HashMap<String,String>();
        Wrapper w = (Wrapper) context.findChild("jsp");
        if (w != null) {
            String[] params = w.findInitParameters();
            for (String param : params) {
                jspInitParams.put(param, w.findInitParameter(param));
            }
        }
    } else {
        jspInitParams = jspServlet.getParameterMap();
    }
    for (ServletDef servletDef: webXml.getServlets().values()) {
        if (servletDef.getJspFile() != null) {
            convertJsp(servletDef, jspInitParams);
        }
    }
}