當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。