Java 类org.apache.velocity.runtime.resource.Resource 实例源码

项目:lams    文件:SpringResourceLoader.java   
@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");
}
项目:spring-velocity-adapter    文件:SpringResourceLoader.java   
@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");
}
项目:spring4-understanding    文件:SpringResourceLoader.java   
@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");
}
项目:beyondj    文件:SpringResourceLoader.java   
@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");
}
项目:ozark    文件:WebappResourceLoader.java   
/**
 * 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;
    }
}
项目:carbon-device-mgt    文件:RegistryBasedResourceLoader.java   
@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);
    }
}
项目:sakai    文件:LibraryWebappLoader.java   
/**
 * 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;
}
项目:plugins_github    文件:VelocityStaticServlet.java   
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;
  }
}
项目:class-guard    文件:SpringResourceLoader.java   
@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");
}
项目:sakai    文件:LibraryWebappLoader.java   
/**
 * 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;
}
项目:ratel    文件:WebappResourceLoader.java   
/**
 * 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;
    }
}
项目:giiwa    文件:VelocityTemplateLoader.java   
@Override
public long getLastModified(Resource resource) {
  File f = getFile(resource.getName());
  if (f != null) {
    return f.lastModified();
  }
  return 0;
}
项目:giiwa    文件:VelocityTemplateLoader.java   
@Override
public boolean isSourceModified(Resource resource) {
  if (resource == null)
    return true;

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

  return f == null || f.lastModified() != resource.getLastModified();
}
项目:sakai    文件:LibraryWebappLoader.java   
/**
 * 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();

}
项目:jpublish    文件:JPublishResourceLoader.java   
/**
 * 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;
    }
}
项目:plugins_github    文件:VelocityStaticServlet.java   
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();
  }
}
项目:plugins_github    文件:VelocityStaticServlet.java   
@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);
  }
}
项目:aliada-tool    文件:AliadaResourceFactory.java   
/**
 * 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);
    }
}
项目:aliada-tool    文件:AliadaResourceManager.java   
@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;
}
项目:sakai    文件:LibraryWebappLoader.java   
/**
 * 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();

}
项目:gazpachoquest    文件:LocalizedTemplateResourceLoaderImpl.java   
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);
}
项目:simile-butterfly    文件:ButterflyResourceLoader.java   
@Override
public long getLastModified(Resource resource) {
    long result = Long.MAX_VALUE;
    try {
        URLConnection c = getResource(resource.getName()).openConnection();
        result = c.getLastModified();
    } catch (Exception e) {
        _logger.error("Error opening connection", e);
    }
    return result;
}
项目:lams    文件:SpringResourceLoader.java   
@Override
public boolean isSourceModified(Resource resource) {
    return false;
}
项目:lams    文件:SpringResourceLoader.java   
@Override
public long getLastModified(Resource resource) {
    return 0;
}
项目:spring-velocity-adapter    文件:SpringResourceLoader.java   
@Override
public boolean isSourceModified(Resource resource) {
    return false;
}
项目:spring-velocity-adapter    文件:SpringResourceLoader.java   
@Override
public long getLastModified(Resource resource) {
    return 0;
}
项目:spring4-understanding    文件:SpringResourceLoader.java   
@Override
public boolean isSourceModified(Resource resource) {
    return false;
}
项目:spring4-understanding    文件:SpringResourceLoader.java   
@Override
public long getLastModified(Resource resource) {
    return 0;
}
项目:beyondj    文件:SpringResourceLoader.java   
@Override
public boolean isSourceModified(Resource resource) {
    return false;
}
项目:beyondj    文件:SpringResourceLoader.java   
@Override
public long getLastModified(Resource resource) {
    return 0;
}
项目:baratine    文件:ViewVelocity.java   
@Override
public boolean isSourceModified(Resource resource)
{
  return false;
}
项目:baratine    文件:ViewVelocity.java   
@Override
public long getLastModified(Resource resource)
{
  return 0;
}
项目:ozark    文件:WebappResourceLoader.java   
/**
 * 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)
{
    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 false;
    }

    // first, try getting the previously found file
    String fileName = resource.getName();
    File cachedFile = getCachedFile(rootPath, fileName);
    if (!cachedFile.exists())
    {
        /* then the source has been moved and/or deleted */
        return true;
    }

    /* check to see if the file can now be found elsewhere
     * before it is found in the previously saved path */
    File currentFile = null;
    for (String path : paths) {
        currentFile = new File(rootPath + path, fileName);
        if (currentFile.canRead())
        {
            /* stop at the first resource found
            * (just like in getResourceReader()) */
            break;
        }
    }

    /* if the current is the cached and it is readable */
    if (cachedFile.equals(currentFile) && cachedFile.canRead())
    {
        /* then (and only then) do we compare the last modified values */
        return (cachedFile.lastModified() != resource.getLastModified());
    }
    else
    {
        /* we found a new file for the resource
         * or the resource is no longer readable. */
        return true;
    }
}
项目:communote-server    文件:NoteTemplateVelocityResourceLoader.java   
@Override
public long getLastModified(Resource resource) {
    return resourceTemplatesLastModified;
}
项目:communote-server    文件:NoteTemplateVelocityResourceLoader.java   
@Override
public boolean isSourceModified(Resource resource) {
    // resource is considered modified if the last modified timestamp of the (cached) resource
    // is after timestamp of last plugin add/remove event
    return resource.getLastModified() < resourceTemplatesLastModified;
}
项目:openeet-android    文件:AndroidAssetLoader.java   
public long getLastModified(Resource resource) {
    return 0;
}
项目:openeet-android    文件:AndroidAssetLoader.java   
public boolean  isSourceModified(Resource resource) {
    return false;
}
项目:intellij-ce-playground    文件:FileTemplateUtil.java   
@Override
public boolean isSourceModified(Resource resource) {
  return true;
}
项目:intellij-ce-playground    文件:FileTemplateUtil.java   
@Override
public long getLastModified(Resource resource) {
  return 0L;
}
项目:carbon-device-mgt    文件:RegistryBasedResourceLoader.java   
@Override
public boolean isSourceModified(Resource resource) {
    return false;
}