本文整理汇总了Java中javax.faces.application.Resource.getResourceName方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.getResourceName方法的具体用法?Java Resource.getResourceName怎么用?Java Resource.getResourceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.faces.application.Resource
的用法示例。
在下文中一共展示了Resource.getResourceName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareStreamingFromCache
import javax.faces.application.Resource; //导入方法依赖的package包/类
/**
* This method collects the resources eagerly and combines them into a byte array. The byte array is cached.
* @param streamIterator The stream iterator iterates over the resources to be read.
* @param resources The resources to be read.
* @return a byte array containing the combined resources. Can't be null.
* @throws IOException
If something fails at I/O level.
*/
@SuppressWarnings("resource")
private static byte[] prepareStreamingFromCache(Iterator<InputStream> streamIterator, Set<Resource> resources)
throws IOException {
String key = "";
for (Resource resource : resources) {
key += resource.getLibraryName() + "/" + resource.getResourceName() + " ";
}
org.omnifaces.component.output.cache.Cache scopedCache = CacheFactory.getCache(FacesContext.getCurrentInstance(), DEFAULT_SCOPE);
byte[] _combinedResource;
synchronized(CombinedResourceHandler.class){
_combinedResource = (byte[]) scopedCache.getObject(key);
}
if (null != _combinedResource) {
return _combinedResource;
}
streamIterator.hasNext(); // We assume it to be always true, see also CombinedResource#getInputStream().
InputStream currentStream = streamIterator.next();
// Caching added by Stephan Rauh, www.beyondjava.net, Feb 02, 2015
if (null == _combinedResource) {
ByteArrayOutputStream collector = new ByteArrayOutputStream();
int read = -1;
while (true) {
read = currentStream.read();
if (read == -1) {
if (streamIterator.hasNext()) {
currentStream = streamIterator.next();
} else {
break;
}
} else
collector.write(read);
}
_combinedResource = collector.toByteArray();
synchronized(CombinedResourceHandler.class){
if (null==scopedCache.getObject(key))
scopedCache.putObject(key, _combinedResource, getTimeToLiveOfCacheEntries());
}
}
return _combinedResource;
}
示例2: createResource
import javax.faces.application.Resource; //导入方法依赖的package包/类
@Override
public Resource createResource(final String resourceName, final String libraryName, final String contentType) {
final Resource resource = super.createResource(resourceName, libraryName, contentType);
if (resource == null) {
return null;
}
return new ResourceWrapper() {
@Override
public String getRequestPath() {
final String path = super.getRequestPath();
if (path.indexOf(getLibrary()) >= 0) {
return path + getVersion();
} else {
return path;
}
}
@Override
// Necessary because this is missing in ResourceWrapper (will be
// fixed in JSF 2.2).
public String getResourceName() {
return resource.getResourceName();
}
@Override
// Necessary because this is missing in ResourceWrapper (will be
// fixed in JSF 2.2).
public String getLibraryName() {
return resource.getLibraryName();
}
@Override
// Necessary because this is missing in ResourceWrapper (will be
// fixed in JSF 2.2).
public String getContentType() {
return resource.getContentType();
}
@Override
public Resource getWrapped() {
return resource;
}
};
}