本文整理汇总了Java中org.eclipse.jetty.util.resource.Resource.getFile方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.getFile方法的具体用法?Java Resource.getFile怎么用?Java Resource.getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.util.resource.Resource
的用法示例。
在下文中一共展示了Resource.getFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResource
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
public Resource getResource(String path) {
try {
Resource resource = super.getResource(path);
if (resource == null) return null;
if (!(resource instanceof PathResource) || !resource.exists()) return resource;
File f = resource.getFile();
if (f.isDirectory() && !path.equals("/")) return resource;
CacheResource cache = resourceCache.get(f);
if (cache != null) return cache;
if (f.length() < CACHE_LIMIT || f.getName().endsWith(".html") || path.equals("/")) {
cache = new CacheResource((PathResource) resource);
resourceCache.put(f, cache);
return cache;
}
return resource;
} catch (IOException e) {
Data.logger.warn("", e);
}
return null;
}
示例2: getClassPath
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
* Generate the classpath (as a string) of all classloaders
* above the given classloader.
*
* This is primarily used for jasper.
* @return the system class path
*/
public static String getClassPath(ClassLoader loader) throws Exception
{
StringBuilder classpath=new StringBuilder();
while (loader != null && (loader instanceof URLClassLoader))
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
{
for (int i=0;i<urls.length;i++)
{
Resource resource = Resource.newResource(urls[i]);
File file=resource.getFile();
if (file!=null && file.exists())
{
if (classpath.length()>0)
classpath.append(File.pathSeparatorChar);
classpath.append(file.getAbsolutePath());
}
}
}
loader = loader.getParent();
}
return classpath.toString();
}
示例3: addClassPath
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
* @param classPath Comma or semicolon separated path of filenames or URLs
* pointing to directories or jar files. Directories should end
* with '/'.
*/
public void addClassPath(String classPath)
throws IOException {
if (classPath == null) {
return;
}
StringTokenizer tokenizer = new StringTokenizer(classPath, ",;");
while (tokenizer.hasMoreTokens()) {
Resource resource = Resource.newResource(tokenizer.nextToken().trim());
// Add the resource
if (resource.isDirectory() && resource instanceof ResourceCollection) {
addClassPath(resource);
}
else {
// Resolve file path if possible
File file = resource.getFile();
if (file != null) {
URL url = resource.getURL();
addURL(url);
} else if (resource.isDirectory()) {
addURL(resource.getURL());
} else {
LOG.error("Check file exists and is not nested jar: " + resource);
throw new IllegalArgumentException("File not resolvable or incompatible with URLClassloader: " + resource);
}
}
}
}
示例4: addClassPath
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
* @param classPath Comma or semicolon separated path of filenames or URLs
* pointing to directories or jar files. Directories should end
* with '/'.
*/
public void addClassPath(String classPath)
throws IOException {
if (classPath == null) {
return;
}
StringTokenizer tokenizer = new StringTokenizer(classPath, ",;");
while (tokenizer.hasMoreTokens()) {
Resource resource = Resource.newResource(tokenizer.nextToken().trim());
// Add the resource
if (resource.isDirectory() && resource instanceof ResourceCollection)
addClassPath(resource);
else {
// Resolve file path if possible
File file = resource.getFile();
if (file != null) {
URL url = resource.getURL();
addURL(url);
} else if (resource.isDirectory()) {
addURL(resource.getURL());
} else {
LOG.error("Check file exists and is not nested jar: " + resource);
throw new IllegalArgumentException("File not resolvable or incompatible with URLClassloader: " + resource);
}
}
}
}
示例5: doStart
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
Resource resource = Resource.newResource(webapp);
File file = resource.getFile();
if (!resource.exists())
throw new IllegalStateException("WebApp resouce does not exist "+resource);
String lcName=file.getName().toLowerCase(Locale.ENGLISH);
if (lcName.endsWith(".xml")) {
XmlConfiguration xmlc = new XmlConfiguration(resource.getURI().toURL());
xmlc.getIdMap().put("Server", contexts.getServer());
xmlc.getProperties().put("jetty.home",System.getProperty("jetty.home","."));
xmlc.getProperties().put("jetty.base",System.getProperty("jetty.base","."));
xmlc.getProperties().put("jetty.webapp",file.getCanonicalPath());
xmlc.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath());
xmlc.getProperties().putAll(properties);
handler = (ContextHandler)xmlc.configure();
} else {
WebAppContext wac=new WebAppContext();
wac.setWar(webapp);
wac.setContextPath("/");
}
contexts.addHandler(handler);
if (contexts.isRunning())
handler.start();
}