当前位置: 首页>>代码示例>>Java>>正文


Java ServletContext.getResourcePaths方法代码示例

本文整理汇总了Java中javax.servlet.ServletContext.getResourcePaths方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContext.getResourcePaths方法的具体用法?Java ServletContext.getResourcePaths怎么用?Java ServletContext.getResourcePaths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletContext的用法示例。


在下文中一共展示了ServletContext.getResourcePaths方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readLangs

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Reads lang_xx.properties into field {@link #langs langs}.
 */
public void readLangs() {
	final ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();

	final Set<String> resourcePaths = servletContext.getResourcePaths("/plugins/" + dirName);

	for (final String resourcePath : resourcePaths) {
		if (resourcePath.contains("lang_") && resourcePath.endsWith(".properties")) {
			final String langFileName = StringUtils.substringAfter(resourcePath, "/plugins/" + dirName + "/");

			final String key = langFileName.substring("lang_".length(), langFileName.lastIndexOf("."));
			final Properties props = new Properties();

			try {
				final File file = Latkes.getWebFile(resourcePath);

				props.load(new FileInputStream(file));

				langs.put(key.toLowerCase(), props);
			} catch (final Exception e) {
				logger.error("Get plugin[name=" + name + "]'s language configuration failed", e);
			}
		}
	}
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:28,代码来源:AbstractPlugin.java

示例2: getSkinDirNames

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Gets all skin directory names. Scans the /skins/ directory, using the
 * subdirectory of it as the skin directory name, for example,
 * 
 * <pre>
 * ${Web root}/skins/
 *     <b>default</b>/
 *     <b>mobile</b>/
 *     <b>classic</b>/
 * </pre>
 * 
 * .
 *
 * @return a set of skin name, returns an empty set if not found
 */
public static Set<String> getSkinDirNames() {
	final ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();

	final Set<String> ret = new HashSet<>();
	final Set<String> resourcePaths = servletContext.getResourcePaths("/skins");

	for (final String path : resourcePaths) {
		final String dirName = path.substring("/skins".length() + 1, path.length() - 1);

		if (dirName.startsWith(".")) {
			continue;
		}

		ret.add(dirName);
	}

	return ret;
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:34,代码来源:Skins.java

示例3: doGet

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("text/plain");

    ServletContext context = getServletContext();

    // Check resources individually
    URL url = context.getResource("/WEB-INF/lib/taglibs-standard-spec-1.2.5.jar");
    if (url != null) {
        resp.getWriter().write("00-PASS\n");
    }

    url = context.getResource("/WEB-INF/lib/taglibs-standard-impl-1.2.5.jar");
    if (url != null) {
        resp.getWriter().write("01-PASS\n");
    }

    // Check a directory listing
    Set<String> libs = context.getResourcePaths("/WEB-INF/lib");
    if (libs == null) {
        return;
    }

    if (!libs.contains("/WEB-INF/lib/taglibs-standard-spec-1.2.5.jar")) {
        return;
    }
    if (!libs.contains("/WEB-INF/lib/taglibs-standard-impl-1.2.5.jar")) {
        return;
    }

    resp.getWriter().write("02-PASS\n");
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:35,代码来源:TestStandardContextAliases.java

示例4: tldScanResourcePaths

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private void tldScanResourcePaths(String startPath) {

        if (log.isTraceEnabled()) {
            log.trace(sm.getString("tldConfig.webinfScan", startPath));
        }

        ServletContext ctxt = context.getServletContext();

        Set<String> dirList = ctxt.getResourcePaths(startPath);
        if (dirList != null) {
            Iterator<String> it = dirList.iterator();
            while (it.hasNext()) {
                String path = it.next();
                if (!path.endsWith(TLD_EXT)
                        && (path.startsWith(WEB_INF_LIB)
                                || path.startsWith("/WEB-INF/classes/"))) {
                    continue;
                }
                if (path.endsWith(TLD_EXT)) {
                    if (path.startsWith("/WEB-INF/tags/") &&
                            !path.endsWith("implicit.tld")) {
                        continue;
                    }
                    InputStream stream = ctxt.getResourceAsStream(path);
                    try {
                        XmlErrorHandler handler = tldScanStream(stream);
                        handler.logFindings(log, path);
                    } catch (IOException ioe) {
                        log.warn(sm.getString("tldConfig.webinfFail", path),
                                ioe);
                    } finally {
                        if (stream != null) {
                            try {
                                stream.close();
                            } catch (Throwable t) {
                                ExceptionUtils.handleThrowable(t);
                            }
                        }
                    }
                } else {
                    tldScanResourcePaths(path);
                }
            }
        }
    }
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:46,代码来源:TldConfig.java

示例5: doRetrieveMatchingServletContextResources

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Recursively retrieve ServletContextResources that match the given pattern,
 * adding them to the given result set.
 * @param servletContext the ServletContext to work on
 * @param fullPattern the pattern to match against,
 * with preprended root directory path
 * @param dir the current directory
 * @param result the Set of matching Resources to add to
 * @throws IOException if directory contents could not be retrieved
 * @see ServletContextResource
 * @see javax.servlet.ServletContext#getResourcePaths
 */
protected void doRetrieveMatchingServletContextResources(
		ServletContext servletContext, String fullPattern, String dir, Set<Resource> result)
		throws IOException {

	Set<String> candidates = servletContext.getResourcePaths(dir);
	if (candidates != null) {
		boolean dirDepthNotFixed = fullPattern.contains("**");
		int jarFileSep = fullPattern.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
		String jarFilePath = null;
		String pathInJarFile = null;
		if (jarFileSep > 0 && jarFileSep + ResourceUtils.JAR_URL_SEPARATOR.length() < fullPattern.length()) {
			jarFilePath = fullPattern.substring(0, jarFileSep);
			pathInJarFile = fullPattern.substring(jarFileSep + ResourceUtils.JAR_URL_SEPARATOR.length());
		}
		for (String currPath : candidates) {
			if (!currPath.startsWith(dir)) {
				// Returned resource path does not start with relative directory:
				// assuming absolute path returned -> strip absolute path.
				int dirIndex = currPath.indexOf(dir);
				if (dirIndex != -1) {
					currPath = currPath.substring(dirIndex);
				}
			}
			if (currPath.endsWith("/") && (dirDepthNotFixed || StringUtils.countOccurrencesOf(currPath, "/") <=
					StringUtils.countOccurrencesOf(fullPattern, "/"))) {
				// Search subdirectories recursively: ServletContext.getResourcePaths
				// only returns entries for one directory level.
				doRetrieveMatchingServletContextResources(servletContext, fullPattern, currPath, result);
			}
			if (jarFilePath != null && getPathMatcher().match(jarFilePath, currPath)) {
				// Base pattern matches a jar file - search for matching entries within.
				String absoluteJarPath = servletContext.getRealPath(currPath);
				if (absoluteJarPath != null) {
					doRetrieveMatchingJarEntries(absoluteJarPath, pathInJarFile, result);
				}
			}
			if (getPathMatcher().match(fullPattern, currPath)) {
				result.add(new ServletContextResource(servletContext, currPath));
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:55,代码来源:ServletContextResourcePatternResolver.java

示例6: tldScanResourcePaths

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private void tldScanResourcePaths(String startPath) {

		if (log.isTraceEnabled()) {
			log.trace(sm.getString("tldConfig.webinfScan", startPath));
		}

		ServletContext ctxt = context.getServletContext();

		Set<String> dirList = ctxt.getResourcePaths(startPath);
		if (dirList != null) {
			Iterator<String> it = dirList.iterator();
			while (it.hasNext()) {
				String path = it.next();
				if (!path.endsWith(TLD_EXT) && (path.startsWith(WEB_INF_LIB) || path.startsWith("/WEB-INF/classes/"))) {
					continue;
				}
				if (path.endsWith(TLD_EXT)) {
					if (path.startsWith("/WEB-INF/tags/") && !path.endsWith("implicit.tld")) {
						continue;
					}
					InputStream stream = ctxt.getResourceAsStream(path);
					try {
						XmlErrorHandler handler = tldScanStream(stream);
						handler.logFindings(log, path);
					} catch (IOException ioe) {
						log.warn(sm.getString("tldConfig.webinfFail", path), ioe);
					} finally {
						if (stream != null) {
							try {
								stream.close();
							} catch (Throwable t) {
								ExceptionUtils.handleThrowable(t);
							}
						}
					}
				} else {
					tldScanResourcePaths(path);
				}
			}
		}
	}
 
开发者ID:how2j,项目名称:lazycat,代码行数:42,代码来源:TldConfig.java

示例7: getFilesContext

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private static Set<URL> getFilesContext(ServletContext context,String path,Set<URL> set){

        Set<String> libs = context.getResourcePaths(path);

        if(libs==null)
            return set;

        for(String filePath : libs) {

            try {

                //Directory
                if(filePath.substring(filePath.length()-1,filePath.length()).equals("/")){

                    getFilesContext(context,filePath,set);
                    continue;

                }


                URL resource = context.getResource(filePath);
                if(resource!=null)
                    set.add(resource);

            }catch (Exception ex){

                log.error(String.format("Error getting files in path %s",path),ex);

            }
        }

        return set;


    }
 
开发者ID:Emerjoin,项目名称:Hi-Framework,代码行数:36,代码来源:BootstrapUtils.java


注:本文中的javax.servlet.ServletContext.getResourcePaths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。