javax.servlet.descriptor.JspPropertyGroupDescriptor Java Examples

The following examples show how to use javax.servlet.descriptor.JspPropertyGroupDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestApplicationContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testJspPropertyGroupsAreIsolated() throws Exception {
    Tomcat tomcat = getTomcatInstanceTestWebapp(false, false);

    StandardContext standardContext =
            (StandardContext) tomcat.getHost().findChildren()[0];

    ServletContext servletContext = standardContext.getServletContext();

    Assert.assertNull(servletContext.getJspConfigDescriptor());

    tomcat.start();

    JspConfigDescriptor jspConfigDescriptor =
            servletContext.getJspConfigDescriptor();
    Collection<JspPropertyGroupDescriptor> propertyGroups =
            jspConfigDescriptor.getJspPropertyGroups();
    Assert.assertFalse(propertyGroups.isEmpty());
    propertyGroups.clear();

    jspConfigDescriptor = servletContext.getJspConfigDescriptor();
    propertyGroups = jspConfigDescriptor.getJspPropertyGroups();
    Assert.assertFalse(propertyGroups.isEmpty());
}
 
Example #2
Source File: TestJspConfigDescriptorImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testTaglibsAreIsolate() {
    List<TaglibDescriptor> taglibs = new ArrayList<>();
    taglibs.add(new TaglibDescriptorImpl("location", "uri"));
    List<JspPropertyGroupDescriptor> propertyGroups = Collections.emptyList();
    JspConfigDescriptor descriptor = new JspConfigDescriptorImpl(propertyGroups, taglibs);
    descriptor.getTaglibs().clear();
    Assert.assertEquals(taglibs, descriptor.getTaglibs());
}
 
Example #3
Source File: TestJspConfigDescriptorImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testPropertyGroupsAreIsolate() {
    List<TaglibDescriptor> taglibs = Collections.emptyList();
    List<JspPropertyGroupDescriptor> propertyGroups = new ArrayList<>();
    propertyGroups.add(new JspPropertyGroupDescriptorImpl(new JspPropertyGroup()));
    JspConfigDescriptor descriptor = new JspConfigDescriptorImpl(propertyGroups, taglibs);
    descriptor.getJspPropertyGroups().clear();
    Assert.assertEquals(propertyGroups, descriptor.getJspPropertyGroups());
}
 
Example #4
Source File: JspConfigDescriptorImpl.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public JspConfigDescriptorImpl(Collection<JspPropertyGroupDescriptor> jspPropertyGroups,
                               Collection<TaglibDescriptor> taglibs) {
    this.jspPropertyGroups = jspPropertyGroups;
    this.taglibs = taglibs;
}
 
Example #5
Source File: JspConfigDescriptorImpl.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public Collection<JspPropertyGroupDescriptor> getJspPropertyGroups() {
    return new ArrayList<>(jspPropertyGroups);
}
 
Example #6
Source File: JspConfig.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private void processWebDotXml() {

        // Very, very unlikely but just in case...
        if (ctxt.getEffectiveMajorVersion() < 2) {
            defaultIsELIgnored = "true";
            defaultDeferedSyntaxAllowedAsLiteral = "true";
            return;
        }
        if (ctxt.getEffectiveMajorVersion() == 2) {
            if (ctxt.getEffectiveMinorVersion() < 5) {
                defaultDeferedSyntaxAllowedAsLiteral = "true";
            }
            if (ctxt.getEffectiveMinorVersion() < 4) {
                defaultIsELIgnored = "true";
                return;
            }
        }

        JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();

        if (jspConfig == null) {
            return;
        }

        jspProperties = new Vector<>();
        Collection<JspPropertyGroupDescriptor> jspPropertyGroups =
                jspConfig.getJspPropertyGroups();

        for (JspPropertyGroupDescriptor jspPropertyGroup : jspPropertyGroups) {

            Collection<String> urlPatterns = jspPropertyGroup.getUrlPatterns();

            if (urlPatterns.size() == 0) {
                continue;
            }

            JspProperty property = new JspProperty(jspPropertyGroup.getIsXml(),
                    jspPropertyGroup.getElIgnored(),
                    jspPropertyGroup.getScriptingInvalid(),
                    jspPropertyGroup.getPageEncoding(),
                    jspPropertyGroup.getIncludePreludes(),
                    jspPropertyGroup.getIncludeCodas(),
                    jspPropertyGroup.getDeferredSyntaxAllowedAsLiteral(),
                    jspPropertyGroup.getTrimDirectiveWhitespaces(),
                    jspPropertyGroup.getDefaultContentType(),
                    jspPropertyGroup.getBuffer(),
                    jspPropertyGroup.getErrorOnUndeclaredNamespace());

            // Add one JspPropertyGroup for each URL Pattern.  This makes
            // the matching logic easier.
            for (String urlPattern : urlPatterns) {
                String path = null;
                String extension = null;

                if (urlPattern.indexOf('*') < 0) {
                    // Exact match
                    path = urlPattern;
                } else {
                    int i = urlPattern.lastIndexOf('/');
                    String file;
                    if (i >= 0) {
                        path = urlPattern.substring(0,i+1);
                        file = urlPattern.substring(i+1);
                    } else {
                        file = urlPattern;
                    }

                    // pattern must be "*", or of the form "*.jsp"
                    if (file.equals("*")) {
                        extension = "*";
                    } else if (file.startsWith("*.")) {
                        extension = file.substring(file.indexOf('.')+1);
                    }

                    // The url patterns are reconstructed as the following:
                    // path != null, extension == null:  / or /foo/bar.ext
                    // path == null, extension != null:  *.ext
                    // path != null, extension == "*":   /foo/*
                    boolean isStar = "*".equals(extension);
                    if ((path == null && (extension == null || isStar))
                            || (path != null && !isStar)) {
                        if (log.isWarnEnabled()) {
                            log.warn(Localizer.getMessage(
                                    "jsp.warning.bad.urlpattern.propertygroup",
                                    urlPattern));
                        }
                        continue;
                    }
                }

                JspPropertyGroup propertyGroup =
                    new JspPropertyGroup(path, extension, property);

                jspProperties.addElement(propertyGroup);
            }
        }
    }
 
Example #7
Source File: ApplicationJspConfigDescriptor.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<JspPropertyGroupDescriptor> getJspPropertyGroups() {
    return jspPropertyGroups;
}
 
Example #8
Source File: ApplicationJspConfigDescriptor.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<JspPropertyGroupDescriptor> getJspPropertyGroups() {
    return jspPropertyGroups;
}
 
Example #9
Source File: JspCServletContext.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public JspConfigDescriptorImpl(Collection<TaglibDescriptor> taglibs,
           Collection<JspPropertyGroupDescriptor> jspPropertyGroups) {
   this.taglibs = taglibs;
   this.jspPropertyGroups = jspPropertyGroups;
}
 
Example #10
Source File: JspCServletContext.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public Collection<JspPropertyGroupDescriptor> getJspPropertyGroups() {
    return this.jspPropertyGroups;
}
 
Example #11
Source File: JspConfig.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private void processWebDotXml(ServletContext ctxt) throws JasperException {

        JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
        if (jspConfig == null) {
            return;
        }

        jspProperties = new ArrayList<JspPropertyGroup>();
        for (JspPropertyGroupDescriptor jpg: jspConfig.getJspPropertyGroups()) {

            Collection<String> urlPatterns = jpg.getUrlPatterns();
            String pageEncoding = jpg.getPageEncoding();
            String scriptingInvalid = jpg.getScriptingInvalid();
            String elIgnored = jpg.getElIgnored();
            String isXml = jpg.getIsXml();
            String trimSpaces = jpg.getTrimDirectiveWhitespaces();
            String poundAllowed = jpg.getDeferredSyntaxAllowedAsLiteral();
            String buffer = jpg.getBuffer();
            String defaultContentType = jpg.getDefaultContentType();
            String errorOnUndeclaredNamespace = jpg.getErrorOnUndeclaredNamespace();
            ArrayList<String> includePrelude = new ArrayList<String>();
            includePrelude.addAll(jpg.getIncludePreludes());
            ArrayList<String> includeCoda = new ArrayList<String>();
            includeCoda.addAll(jpg.getIncludeCodas());

            // Creates a JspPropertyGroup for each url pattern in the given
            // urlPatterns, and adds it to the given jspProperties.
            // This simplifies the matching logic.

            for (String urlPattern: urlPatterns) {
                String path = null;
                String extension = null;
 
                if (urlPattern.indexOf('*') < 0) {
                    // Exact match
                    path = urlPattern;
                } else {
                    int i = urlPattern.lastIndexOf('/');
                    String file;
                    if (i >= 0) {
                        path = urlPattern.substring(0,i+1);
                        file = urlPattern.substring(i+1);
                    } else {
                        file = urlPattern;
                    }
 
                    // pattern must be "*", or of the form "*.jsp"
                    if (file.equals("*")) {
                        extension = "*";
                    } else if (file.startsWith("*.")) {
                        extension = file.substring(file.indexOf('.')+1);
                    }

                    // The url patterns are reconstructed as the following:
                    // path != null, extension == null:  / or /foo/bar.ext
                    // path == null, extension != null:  *.ext
                    // path != null, extension == "*":   /foo/*
                    boolean isStar = "*".equals(extension);
                    if ((path == null && (extension == null || isStar))
                            || (path != null && !isStar)) {
                        if (log.isLoggable(Level.WARNING)) {
                            log.warning(Localizer.getMessage(
                                "jsp.warning.bad.urlpattern.propertygroup",
                                urlPattern));
                        }
                        continue;
                    }
                 }
 
                 JspProperty property = new JspProperty(isXml,
                                                    elIgnored,
                                                    scriptingInvalid,
                                                    trimSpaces,
                                                    poundAllowed,
                                                    pageEncoding,
                                                    includePrelude,
                                                    includeCoda,
                                                    defaultContentType,
                                                    buffer,
                                                    errorOnUndeclaredNamespace);
                 JspPropertyGroup propertyGroup =
                     new JspPropertyGroup(path, extension, property);

                 jspProperties.add(propertyGroup);
            }
        }
    }