gpt4 book ai didi

org.apache.catalina.WebResource类的使用及代码示例

转载 作者:知者 更新时间:2024-03-26 14:39:05 25 4
gpt4 key购买 nike

本文整理了Java中org.apache.catalina.WebResource类的一些代码示例,展示了WebResource类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebResource类的具体详情如下:
包路径:org.apache.catalina.WebResource
类名称:WebResource

WebResource介绍

[英]Represents a file or directory within a web application. It borrows heavily from java.io.File.
[中]表示web应用程序中的文件或目录。它大量借鉴了java。伊奥。文件

代码示例

代码示例来源:origin: psi-probe/psi-probe

@Override
public Long[] getResourceAttributes(String name, Context context) {
 Long[] result = new Long[2];
 WebResource resource = context.getResources().getResource(name);
 result[0] = resource.getContentLength();
 result[1] = resource.getLastModified();
 return result;
}

代码示例来源:origin: psi-probe/psi-probe

@Override
public InputStream getResourceStream(String name, Context context) throws IOException {
 WebResource resource = context.getResources().getResource(name);
 return resource.getInputStream();
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

@Override
public String getCanonicalPath() {
  return webResource.getCanonicalPath();
}

代码示例来源:origin: stackoverflow.com

for (WebResource jar : jars) {
  if (jar.getName().endsWith(".jar") && jar.isFile() && jar.canRead()) {
    addURL(jar.getURL());

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

if (!resource.exists()) {
if (!resource.canRead()) {
if (resource.isFile()) {
String contentType = resource.getMimeType();
if (contentType == null) {
  contentType = getServletContext().getMimeType(resource.getName());
  resource.setMimeType(contentType);
if (resource.isFile() && !isError) {
  eTag = resource.getETag();
  lastModifiedHttp = resource.getLastModifiedHttp();
if (compressionFormats.length > 0 && !included && resource.isFile() &&
    !pathEndsWithCompressedExtension(path)) {
  List<PrecompressedResource> precompressedResources =
if (resource.isDirectory()) {
  if (!path.endsWith("/")) {
    doDirectoryRedirect(request, response);
  contentLength = resource.getContentLength();
if (resource.isDirectory() ||
    isError ||
    ( (ranges == null || ranges.isEmpty())

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

if (!resource.exists()) {
else
  href += path;
if (resource.isDirectory() && (!href.endsWith("/")))
  href += "/";
    resource.isFile(), false, resource.getCreation(), resource.getLastModified(),
    resource.getContentLength(), getServletContext().getMimeType(resource.getName()),
    resource.getETag());

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

/**
 * Start the class loader.
 *
 * @exception LifecycleException if a lifecycle error occurs
 */
@Override
public void start() throws LifecycleException {
  state = LifecycleState.STARTING_PREP;
  WebResource classes = resources.getResource("/WEB-INF/classes");
  if (classes.isDirectory() && classes.canRead()) {
    localRepositories.add(classes.getURL());
  }
  WebResource[] jars = resources.listResources("/WEB-INF/lib");
  for (WebResource jar : jars) {
    if (jar.getName().endsWith(".jar") && jar.isFile() && jar.canRead()) {
      localRepositories.add(jar.getURL());
      jarModificationTimes.put(
          jar.getName(), Long.valueOf(jar.getLastModified()));
    }
  }
  state = LifecycleState.STARTED;
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

protected void processAnnotationsWebResource(WebResource webResource,
    WebXml fragment, boolean handlesTypesOnly,
    Map<String,JavaClassCacheEntry> javaClassCache) {
  if (webResource.isDirectory()) {
    WebResource[] webResources =
        webResource.getWebResourceRoot().listResources(
            webResource.getWebappPath());
    if (webResources.length > 0) {
      if (log.isDebugEnabled()) {
        log.debug(sm.getString(
            "contextConfig.processAnnotationsWebDir.debug",
            webResource.getURL()));
      }
      for (WebResource r : webResources) {
        processAnnotationsWebResource(r, fragment, handlesTypesOnly, javaClassCache);
      }
    }
  } else if (webResource.isFile() &&
      webResource.getName().endsWith(".class")) {
    try (InputStream is = webResource.getInputStream()) {
      processAnnotationsStream(is, fragment, handlesTypesOnly, javaClassCache);
    } catch (IOException e) {
      log.error(sm.getString("contextConfig.inputStreamWebResource",
          webResource.getWebappPath()),e);
    } catch (ClassFormatException e) {
      log.error(sm.getString("contextConfig.inputStreamWebResource",
          webResource.getWebappPath()),e);
    }
  }
}

代码示例来源:origin: codefollower/Tomcat-Research

long cachedLastModified = entry.getValue().lastModified;
long lastModified = resources.getClassLoaderResource(
    entry.getKey()).getLastModified();
if (lastModified != cachedLastModified) {
  if( log.isDebugEnabled() )
if (jar.getName().endsWith(".jar") && jar.isFile() && jar.canRead()) {
  Long recordedLastModified = jarModificationTimes.get(jar.getName());
  if (recordedLastModified == null) {
    return true;
  if (recordedLastModified.longValue() != jar.getLastModified()) {
      jar.getName(), Long.valueOf(jar.getLastModified()));

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

@Override
public boolean resolveResource(int type, String name) {
  WebResourceRoot resources = request.getContext().getResources();
  WebResource resource = resources.getResource(name);
  if (!resource.exists()) {
    return false;
  } else {
    switch (type) {
    case 0:
      return resource.isDirectory();
    case 1:
      return resource.isFile();
    case 2:
      return resource.isFile() && resource.getContentLength() > 0;
    default:
      return false;
    }
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

WebResource webResourceInternal = root.getResourceInternal(
    webAppPath, useClassLoaderResources);
if (!webResource.exists() && webResourceInternal.exists()) {
  return false;
if (webResource.getLastModified() != getLastModified() ||
    webResource.getContentLength() != getContentLength()) {
  return false;
if (webResource.getLastModified() != webResourceInternal.getLastModified() ||
    webResource.getContentLength() != webResourceInternal.getContentLength()) {
  return false;

代码示例来源:origin: codefollower/Tomcat-Research

private void processWebInfLib() {
  WebResource[] possibleJars = listResources("/WEB-INF/lib", false);
  for (WebResource possibleJar : possibleJars) {
    if (possibleJar.isFile() && possibleJar.getName().endsWith(".jar")) {
      createWebResourceSet(ResourceSetType.CLASSES_JAR,
          "/WEB-INF/classes", possibleJar.getURL(), "/");
    }
  }
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

private WebXml getTomcatWebXmlFragment(WebXmlParser webXmlParser) {
  WebXml webXmlTomcatFragment = createWebXml();
  webXmlTomcatFragment.setOverridable(true);
  // Set to distributable else every app will be prevented from being
  // distributable when the Tomcat fragment is merged with the main
  // web.xml
  webXmlTomcatFragment.setDistributable(true);
  // When merging, the default welcome files are only used if the app has
  // not defined any welcomes files.
  webXmlTomcatFragment.setAlwaysAddWelcomeFiles(false);
  WebResource resource = context.getResources().getResource(Constants.TomcatWebXml);
  if (resource.isFile()) {
    try {
      InputSource source = new InputSource(resource.getURL().toURI().toString());
      source.setByteStream(resource.getInputStream());
      if (!webXmlParser.parseWebXml(source, webXmlTomcatFragment, false)) {
        ok = false;
      }
    } catch (URISyntaxException e) {
      log.error(sm.getString("contextConfig.tomcatWebXmlError"), e);
    }
  }
  return webXmlTomcatFragment;
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

if (!resource.exists()) {
  resp.sendError(WebdavStatus.SC_NOT_FOUND);
  return false;
if (!resource.isDirectory()) {
  if (!resource.delete()) {
    resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
    return false;
  if (!resource.delete()) {
    errorList.put(path, Integer.valueOf
      (WebdavStatus.SC_INTERNAL_SERVER_ERROR));

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

try {
  WebResource resource = resources.getResource(path);
  String canonicalPath = resource.getCanonicalPath();
  if (canonicalPath == null) {
    return null;
  } else if ((resource.isDirectory() && !canonicalPath.endsWith(File.separator) ||
      !resource.exists()) && path.endsWith("/")) {
    return canonicalPath + File.separatorChar;
  } else {

代码示例来源:origin: codefollower/Tomcat-Research

/**
 * Get the readme file as a string.
 */
protected String getReadme(WebResource directory) {
  if (readmeFile != null) {
    WebResource resource = resources.getResource(
        directory.getWebappPath() + readmeFile);
    if (resource.isFile()) {
      StringWriter buffer = new StringWriter();
      InputStream is = resource.getInputStream();
      copyRange(new InputStreamReader(is),
          new PrintWriter(buffer));
      return buffer.toString();
    } else {
      if (debug > 10)
        log("readme '" + readmeFile + "' not found");
      return null;
    }
  }
  return null;
}

代码示例来源:origin: codefollower/Tomcat-Research

/**
 * Check if sendfile can be used.
 */
protected boolean checkSendfile(HttpServletRequest request,
               HttpServletResponse response,
               WebResource resource,
               long length, Range range) {
  if (sendfileSize > 0
    && resource.isFile()
    && length > sendfileSize
    && (resource.getCanonicalPath() != null)
    && (Boolean.TRUE == request.getAttribute(Globals.SENDFILE_SUPPORTED_ATTR))
    && (request.getClass().getName().equals("org.apache.catalina.connector.RequestFacade"))
    && (response.getClass().getName().equals("org.apache.catalina.connector.ResponseFacade"))) {
    request.setAttribute(Globals.SENDFILE_FILENAME_ATTR, resource.getCanonicalPath());
    if (range == null) {
      request.setAttribute(Globals.SENDFILE_FILE_START_ATTR, Long.valueOf(0L));
      request.setAttribute(Globals.SENDFILE_FILE_END_ATTR, Long.valueOf(length));
    } else {
      request.setAttribute(Globals.SENDFILE_FILE_START_ATTR, Long.valueOf(range.start));
      request.setAttribute(Globals.SENDFILE_FILE_END_ATTR, Long.valueOf(range.end + 1));
    }
    return true;
  }
  return false;
}

代码示例来源:origin: stackoverflow.com

final Context currentContext = ctx;
 ContextConfig ctxCfg = new ContextConfig() {
   @Override
   public void lifecycleEvent(LifecycleEvent event) {
     if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
       WebResourceRoot webResourcesRoot = currentContext.getResources();
       String baseDir = Platform.getBaseDir(); // Server Base Directory
       File libDir = new File(baseDir + File.separator + "lib");
       DirResourceSet dirResourceSet = null;
       try {
         dirResourceSet = new DirResourceSet(webResourcesRoot, "/WEB-INF/lib", libDir.getCanonicalPath(), "/");
       } catch (IOException e) {
         throw new RuntimeException(e);
       }
       webResourcesRoot.addPostResources(dirResourceSet);
       String[] possibleJars = dirResourceSet.list("/WEB-INF/lib");
       for(String libfile : possibleJars) {
         WebResource possibleJar = dirResourceSet.getResource("/WEB-INF/lib/"+libfile);
         System.err.println(String.format("Loading possible jar %s",possibleJar.getCanonicalPath())); // Just checking...
         if (possibleJar.isFile() && possibleJar.getName().endsWith(".jar")) {
           WebResourceSet resourceSet = new JarResourceSet(webResourcesRoot, "/WEB-INF/classes", possibleJar.getCanonicalPath(),"/");
           webResourcesRoot.addPostResources(resourceSet);
         }
       }
     }
     super.lifecycleEvent(event);
   }
 };
 ctx.addLifecycleListener(ctxCfg);

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

@Override
public long getLastModified() {
  Long cachedLastModified = this.cachedLastModified;
  if (cachedLastModified == null) {
    cachedLastModified =
        Long.valueOf(webResource.getLastModified());
    this.cachedLastModified = cachedLastModified;
  }
  return cachedLastModified.longValue();
}

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

private List<PrecompressedResource> getAvailablePrecompressedResources(String path) {
  List<PrecompressedResource> ret = new ArrayList<>(compressionFormats.length);
  for (CompressionFormat format : compressionFormats) {
    WebResource precompressedResource = resources.getResource(path + format.extension);
    if (precompressedResource.exists() && precompressedResource.isFile()) {
      ret.add(new PrecompressedResource(precompressedResource, format));
    }
  }
  return ret;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com