Java Code Examples for org.apache.jasper.JspCompilationContext#resolveRelativeUri()

The following examples show how to use org.apache.jasper.JspCompilationContext#resolveRelativeUri() . 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: TagLibraryInfoImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private TldLocation generateTLDLocation(String uri, JspCompilationContext ctxt)
        throws JasperException {

    int uriType = TldLocationsCache.uriType(uri);
    if (uriType == TldLocationsCache.ABS_URI) {
        err.jspError("jsp.error.taglibDirective.absUriCannotBeResolved",
                uri);
    } else if (uriType == TldLocationsCache.NOROOT_REL_URI) {
        uri = ctxt.resolveRelativeUri(uri);
    }

    if (uri.endsWith(".jar")) {
        URL url = null;
        try {
            url = ctxt.getResource(uri);
        } catch (Exception ex) {
            err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex
                    .toString());
        }
        if (url == null) {
            err.jspError("jsp.error.tld.missing_jar", uri);
        }
        return new TldLocation("META-INF/taglib.tld", url.toString());
    } else {
        return new TldLocation(uri);
    }
}
 
Example 2
Source File: TagLibraryInfoImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private TldLocation generateTLDLocation(String uri, JspCompilationContext ctxt)
        throws JasperException {

    int uriType = TldLocationsCache.uriType(uri);
    if (uriType == TldLocationsCache.ABS_URI) {
        err.jspError("jsp.error.taglibDirective.absUriCannotBeResolved",
                uri);
    } else if (uriType == TldLocationsCache.NOROOT_REL_URI) {
        uri = ctxt.resolveRelativeUri(uri);
    }

    if (uri.endsWith(".jar")) {
        URL url = null;
        try {
            url = ctxt.getResource(uri);
        } catch (Exception ex) {
            err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex
                    .toString());
        }
        if (url == null) {
            err.jspError("jsp.error.tld.missing_jar", uri);
        }
        return new TldLocation("META-INF/taglib.tld", url.toString());
    } else if (uri.startsWith("/WEB-INF/lib/")
            || uri.startsWith("/WEB-INF/classes/") ||
            (uri.startsWith("/WEB-INF/tags/") && uri.endsWith(".tld")
                    && !uri.endsWith("implicit.tld"))) {
        err.jspError("jsp.error.tld.invalid_tld_file", uri);
    }

    return new TldLocation(uri);
}
 
Example 3
Source File: TagLibraryInfoImpl.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private String[] generateTLDLocation(String uri,
				 JspCompilationContext ctxt)
               throws JasperException {

int uriType = TldScanner.uriType(uri);
if (uriType == TldScanner.ABS_URI) {
    err.jspError("jsp.error.taglibDirective.absUriCannotBeResolved",
		 uri);
} else if (uriType == TldScanner.NOROOT_REL_URI) {
    uri = ctxt.resolveRelativeUri(uri);
}

String[] location = new String[2];
location[0] = uri;
if (location[0].endsWith("jar")) {
    URL url = null;
    try {
	url = ctxt.getResource(location[0]);
    } catch (Exception ex) {
	err.jspError("jsp.error.tld.unable_to_get_jar", location[0],
		     ex.toString());
    }
    if (url == null) {
	err.jspError("jsp.error.tld.missing_jar", location[0]);
    }
    location[0] = url.toString();
    location[1] = "META-INF/taglib.tld";
}

return location;
   }
 
Example 4
Source File: TagLibraryInfoImpl.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private TldResourcePath generateTldResourcePath(String uri,
        JspCompilationContext ctxt) throws JasperException {

    // TODO: this matches the current implementation but the URL logic looks fishy
    // map URI to location per JSP 7.3.6.2
    if (uri.indexOf(':') != -1) {
        // abs_uri, this was not found in the taglibMap so raise an error
        err.jspError("jsp.error.taglibDirective.absUriCannotBeResolved", uri);
    } else if (uri.charAt(0) != '/') {
        // noroot_rel_uri, resolve against the current JSP page
        uri = ctxt.resolveRelativeUri(uri);
        try {
            // Can't use RequestUtils.normalize since that package is not
            // available to Jasper.
            uri = (new URI(uri)).normalize().toString();
            if (uri.startsWith("../")) {
                // Trying to go outside context root
                err.jspError("jsp.error.taglibDirective.uriInvalid", uri);
            }
        } catch (URISyntaxException e) {
            err.jspError("jsp.error.taglibDirective.uriInvalid", uri);
        }
    }

    URL url = null;
    try {
        url = ctxt.getResource(uri);
    } catch (Exception ex) {
        err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex.toString());
    }
    if (uri.endsWith(".jar")) {
        if (url == null) {
            err.jspError("jsp.error.tld.missing_jar", uri);
        }
        return new TldResourcePath(url, uri, "META-INF/taglib.tld");
    } else if (uri.startsWith("/WEB-INF/lib/") || uri.startsWith("/WEB-INF/classes/") ||
            (uri.startsWith("/WEB-INF/tags/") && uri.endsWith(".tld")&& !uri.endsWith("implicit.tld"))) {
        err.jspError("jsp.error.tld.invalid_tld_file", uri);
    }
    return new TldResourcePath(url, uri);
}