Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.richfaces.resource;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.faces.application.ProjectStage;
import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
import javax.faces.context.FacesContext;
import org.richfaces.application.DependencyInjector;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.resource.external.MappedResourceFactory;
import org.richfaces.resource.external.ResourceTracker;
import org.richfaces.resource.mapping.ResourcePath;
import org.richfaces.webapp.ResourceServlet;
import org.richfaces.application.ServiceTracker;
import com.google.common.base.Function;
import com.google.common.base.Strings;
/**
* @author Nick Belaevski
*
*/
public class ResourceFactoryImpl implements ResourceFactory {
private static final Logger LOGGER = RichfacesLogger.RESOURCE.getLogger();
private static final String MAPPED_RESOURCES_RESOLUTION_STACK = MappedResourceFactory.class.getName()
+ ".MAPPED_RESOURCES_RESOLUTION_STACK";
private static final Function, MappedResourceData> DYNAMIC_MAPPINGS_DATA_PRODUCER = new Function, MappedResourceData>() {
public MappedResourceData apply(Entry from) {
String resourceLocation = from.getValue();
Map params = ResourceUtils.parseResourceParameters(resourceLocation);
String resourceQualifier = extractParametersFromResourceName(resourceLocation);
return new MappedResourceData(ResourceKey.create(resourceQualifier), params);
}
};
private ResourceHandler defaultHandler;
// private Map externalStaticResourceFactories;
private Map mappedResourceDataMap;
private MappedResourceFactory mappedResourceFactory;
private ResourceTracker resourceTracker;
public ResourceFactoryImpl(ResourceHandler defaultHandler) {
super();
this.defaultHandler = defaultHandler;
this.mappedResourceDataMap = ResourceUtils.readMappings(DYNAMIC_MAPPINGS_DATA_PRODUCER,
ResourceFactory.DYNAMIC_RESOURCE_MAPPINGS);
this.mappedResourceFactory = ServiceTracker.getProxy(MappedResourceFactory.class);
this.resourceTracker = ServiceTracker.getProxy(ResourceTracker.class);
}
private static String extractParametersFromResourceName(String resourceName) {
if (!(resourceName.lastIndexOf("{") != -1)) {
return resourceName;
}
return resourceName.substring(0, resourceName.lastIndexOf("{"));
}
private void logResourceProblem(FacesContext context, Throwable throwable, String messagePattern, Object... arguments) {
boolean isProductionStage = context.isProjectStage(ProjectStage.Production);
if (LOGGER.isWarnEnabled() || (!isProductionStage && LOGGER.isInfoEnabled())) {
String formattedMessage = MessageFormat.format(messagePattern, arguments);
if (throwable != null) {
LOGGER.warn(formattedMessage, throwable);
} else {
if (isProductionStage) {
LOGGER.info(formattedMessage);
} else {
LOGGER.warn(formattedMessage);
}
}
}
}
private void logMissingResource(FacesContext context, String resourceData) {
logResourceProblem(context, null, "Resource {0} was not found", resourceData);
}
private Resource createCompiledCSSResource(ResourceKey resourceKey) {
Resource sourceResource = defaultHandler.createResource(resourceKey.getResourceName(), resourceKey.getLibraryName(),
"text/plain");
if (sourceResource != null) {
return new CompiledCSSResource(sourceResource);
}
return null;
}
protected void injectProperties(Object resource, Map parameters) {
FacesContext facesContext = FacesContext.getCurrentInstance();
Map