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


Java Resource类代码示例

本文整理汇总了Java中org.apache.velocity.runtime.resource.Resource的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Resource类属于org.apache.velocity.runtime.resource包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResourceStream

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
@Override
public InputStream getResourceStream(String source) throws ResourceNotFoundException {
	if (logger.isDebugEnabled()) {
		logger.debug("Looking for Velocity resource with name [" + source + "]");
	}
	for (String resourceLoaderPath : this.resourceLoaderPaths) {
		org.springframework.core.io.Resource resource =
				this.resourceLoader.getResource(resourceLoaderPath + source);
		try {
			return resource.getInputStream();
		}
		catch (IOException ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Could not find Velocity resource: " + resource);
			}
		}
	}
	throw new ResourceNotFoundException(
			"Could not find resource [" + source + "] in Spring resource loader path");
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:SpringResourceLoader.java

示例2: getLastModified

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
/**
 * Checks to see when a resource was last modified
 *
 * @param resource Resource the resource to check
 * @return long The time when the resource was last modified or 0 if the file can't be read
 */
@Override
public long getLastModified(Resource resource)
{
    String rootPath = servletContext.getRealPath("/");
    if (rootPath == null) {
        // rootPath is null if the servlet container cannot translate the
        // virtual path to a real path for any reason (such as when the
        // content is being made available from a .war archive)
        return 0;
    }

    File cachedFile = getCachedFile(rootPath, resource.getName());
    if (cachedFile.canRead())
    {
        return cachedFile.lastModified();
    }
    else
    {
        return 0;
    }
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:28,代码来源:WebappResourceLoader.java

示例3: getResourceStream

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
@Override
public InputStream getResourceStream(String name) throws ResourceNotFoundException {
    try {
        Registry registry =
                CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
        if (registry == null) {
            throw new IllegalStateException("No valid registry instance is attached to the current carbon context");
        }
        if (!registry.resourceExists(EMAIL_CONFIG_BASE_LOCATION + "/" + name)) {
            throw new ResourceNotFoundException("Resource '" + name + "' does not exist");
        }
        org.wso2.carbon.registry.api.Resource resource =
                registry.get(EMAIL_CONFIG_BASE_LOCATION + "/" + name);
        resource.setMediaType("text/plain");
        return resource.getContentStream();
    } catch (RegistryException e) {
        throw new ResourceNotFoundException("Error occurred while retrieving resource", e);
    }
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:20,代码来源:RegistryBasedResourceLoader.java

示例4: isSourceModified

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
/**
 * Checks to see if a resource has been deleted, moved or modified.
 *
 * @param resource Resource The resource to check for modification
 * @return boolean True if the resource has been modified
 */
@Override
public boolean isSourceModified(Resource resource) {

    // first, try getting the previously found file
    String fileName = resource.getName();
    Date fileLastLoaded = getCachedFileLastLoaded(fileName);
    if (fileLastLoaded == null) {
        return true;
    }

    if (new Date().getTime() - fileLastLoaded.getTime() > CACHE_EXPIRATION_IN_MILLIS) {
        return true;
    }

    return false;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:23,代码来源:LibraryWebappLoader.java

示例5: local

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
private Resource local(final HttpServletRequest req) {
  final String name = req.getPathInfo();
  if (name.length() < 2 || !name.startsWith("/") || isUnreasonableName(name)) {
    // Too short to be a valid file name, or doesn't start with
    // the path info separator like we expected.
    //
    return null;
  }

  String resourceName = name.substring(1);
  try {
    return velocity.getContent(resourceName);
  } catch (Exception e) {
    log.error("Cannot resolve resource " + resourceName, e);
    return null;
  }
}
 
开发者ID:GerritCodeReview,项目名称:plugins_github,代码行数:18,代码来源:VelocityStaticServlet.java

示例6: getLastModified

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
/**
 * Checks to see when a resource was last modified
 *
 * @param resource Resource the resource to check
 * @return long The time when the resource was last modified or 0 if the file can't be read
 */
public long getLastModified(Resource resource)
{
    String rootPath = servletContext.getRealPath("/");
    if (rootPath == null) {
        // rootPath is null if the servlet container cannot translate the
        // virtual path to a real path for any reason (such as when the
        // content is being made available from a .war archive)
        return 0;
    }

    File cachedFile = getCachedFile(rootPath, resource.getName());
    if (cachedFile.canRead())
    {
        return cachedFile.lastModified();
    }
    else
    {
        return 0;
    }
}
 
开发者ID:sabob,项目名称:ratel,代码行数:27,代码来源:WebappResourceLoader.java

示例7: getLastModified

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
@Override
public long getLastModified(Resource resource) {
  File f = getFile(resource.getName());
  if (f != null) {
    return f.lastModified();
  }
  return 0;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:9,代码来源:VelocityTemplateLoader.java

示例8: isSourceModified

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
@Override
public boolean isSourceModified(Resource resource) {
  if (resource == null)
    return true;

  File f = getFile(resource.getName());

  return f == null || f.lastModified() != resource.getLastModified();
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:10,代码来源:VelocityTemplateLoader.java

示例9: getLastModified

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
/**
 * Checks to see when a resource was last modified
 *
 * @param resource Resource the resource to check
 * @return long The time when the resource was last modified or 0 if the
 *         file can't be read
 */
@Override
public long getLastModified(Resource resource) {
    String fileName = resource.getName();
    Date fileLastLoaded = getCachedFileLastLoaded(fileName);
    if (fileLastLoaded == null) {
        return 0;
    }
    return fileLastLoaded.getTime();

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:18,代码来源:LibraryWebappLoader.java

示例10: getLastModified

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
/**
 * Return get the last modified time for the resource.
 *
 * @param resource The Resource
 * @return The last modified time
 */

public long getLastModified(Resource resource) {
    if (VM_GLOBAL_LIBRARY.equals(resource.getName())) {
        return -1;
    }

    try {
        return siteContext.getLastModified(resource.getName());
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}
 
开发者ID:florinpatrascu,项目名称:jpublish,代码行数:20,代码来源:JPublishResourceLoader.java

示例11: readResource

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
private static byte[] readResource(final Resource p) throws IOException {
  try (InputStream in = p.getResourceLoader().getResourceStream(p.getName());
      ByteArrayOutputStream byteOut = new ByteArrayOutputStream()) {
    IOUtils.copy(in, byteOut);
    return byteOut.toByteArray();
  }
}
 
开发者ID:GerritCodeReview,项目名称:plugins_github,代码行数:8,代码来源:VelocityStaticServlet.java

示例12: doGet

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse rsp)
    throws IOException {
  final Resource p = local(req);
  if (p == null) {
    CacheHeaders.setNotCacheable(rsp);
    rsp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    return;
  }

  final String type = contentType(p.getName());
  final byte[] tosend;
  if (!type.equals("application/x-javascript") && RPCServletUtils.acceptsGzipEncoding(req)) {
    rsp.setHeader("Content-Encoding", "gzip");
    tosend = compress(readResource(p));
  } else {
    tosend = readResource(p);
  }

  CacheHeaders.setCacheable(req, rsp, 12, TimeUnit.HOURS);
  rsp.setDateHeader("Last-Modified", p.getLastModified());
  rsp.setContentType(type);
  rsp.setContentLength(tosend.length);
  try (OutputStream out = rsp.getOutputStream()) {
    out.write(tosend);
  }
}
 
开发者ID:GerritCodeReview,项目名称:plugins_github,代码行数:28,代码来源:VelocityStaticServlet.java

示例13: getResource

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
/**
 * Returns a resource according with given data.
 * 
 * @param resourceName the resource name.
 * @param resourceType the resource kind.
 * @return The resource described by name and type.
 */
public static Resource getResource(final String resourceName, final int resourceType) {
    switch (resourceType) {
        case ResourceManager.RESOURCE_TEMPLATE:
            return new AliadaTemplate();
        case ResourceManager.RESOURCE_CONTENT:
            return new ContentResource();
        default:
        	throw new IllegalArgumentException("WARNIGN: Unknown resource type: " + resourceType);
    }
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:18,代码来源:AliadaResourceFactory.java

示例14: refreshResource

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
@Override
protected Resource refreshResource(final Resource resource, final String encoding) {
    resource.touch();

    final ResourceLoader loader = resource.getResourceLoader();
    if (resourceLoaders.size() > 0 && resourceLoaders.indexOf(loader) > 0) {
        final String name = resource.getName();
        if (loader != getLoaderForResource(name)) {
            return loadResource(name, resource.getType(), encoding);
        }
    }

    if (resource.isSourceModified()) {
        if (!StringUtils.equals(resource.getEncoding(), encoding)) {
            resource.setEncoding(encoding);
        }
        
        final String resourceName = resource.getName();
        final Resource newResource = AliadaResourceFactory.getResource(resourceName, resource.getType());

        newResource.setRuntimeServices(rsvc);
        newResource.setName(resourceName);
        newResource.setEncoding(resource.getEncoding());
        newResource.setResourceLoader(loader);
        newResource.setModificationCheckInterval(loader.getModificationCheckInterval());

        newResource.process();
        newResource.setLastModified(loader.getLastModified(resource));

        globalCache.put(
        		new StringBuilder(resource.getType())
        			.append(resource.getName())
        			.toString(), 
        		newResource);
        return newResource;
    }
    return resource;
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:39,代码来源:AliadaResourceManager.java

示例15: readLastModified

import org.apache.velocity.runtime.resource.Resource; //导入依赖的package包/类
private long readLastModified(final Resource resource, final String operation) {
    String templateName = resource.getName();
    Integer templateId = readTemplateId(templateName);
    logger.info("{} from mail message template {} ", operation, templateId);
    MailMessageTemplate template = templateRepository.findOne(templateId);
    return template.getLastModifiedDate().toEpochSecond(ZoneOffset.UTC);
}
 
开发者ID:antoniomaria,项目名称:gazpachoquest,代码行数:8,代码来源:LocalizedTemplateResourceLoaderImpl.java


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