Author: nbelaevski
Date: 2010-07-26 09:07:40 -0400 (Mon, 26 Jul 2010)
New Revision: 18237
Added:
root/core/trunk/impl/src/main/java/org/richfaces/skin/AbstractSkinFactory.java
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/Base2WayGradient.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
Log:
Resources bug fixes & updates
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java 2010-07-26
12:48:16 UTC (rev 18236)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java 2010-07-26
13:07:40 UTC (rev 18237)
@@ -39,7 +39,7 @@
return storage.get(key);
}
- public Object put(String key,Object value) {
+ public Object put(String key,Object value) {
return storage.put(key, value);
}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/Base2WayGradient.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/Base2WayGradient.java 2010-07-26
12:48:16 UTC (rev 18236)
+++
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/Base2WayGradient.java 2010-07-26
13:07:40 UTC (rev 18237)
@@ -3,17 +3,19 @@
*/
package org.richfaces.renderkit.html;
+import java.awt.Dimension;
+import java.awt.GradientPaint;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+
import org.richfaces.renderkit.html.images.GradientType;
import org.richfaces.renderkit.html.images.GradientType.BiColor;
-import java.awt.*;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-
/**
* @author asmirnov
*/
-public class Base2WayGradient extends BaseGradient {
+public abstract class Base2WayGradient extends BaseGradient {
/**
* @param horizontal
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-07-26
12:48:16 UTC (rev 18236)
+++
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-07-26
13:07:40 UTC (rev 18237)
@@ -71,8 +71,6 @@
this.baseColor = baseColor != null ? baseColor : Skin.HEADER_BACKGROUND_COLOR;
this.gradientColor = gradientColor != null ? gradientColor :
Skin.HEADER_GRADIENT_COLOR;
this.horizontal = horizontal;
-
- initialize();
}
public BaseGradient(int width, int height, int gradientHeight) {
@@ -243,6 +241,8 @@
}
public void writeState(FacesContext context, DataOutput dataOutput) throws
IOException {
+ initialize();
+
dataOutput.writeInt(this.headerBackgroundColor);
dataOutput.writeInt(this.headerGradientColor);
dataOutput.writeByte((byte) this.gradientType.ordinal());
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-07-26
12:48:16 UTC (rev 18236)
+++
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2010-07-26
13:07:40 UTC (rev 18237)
@@ -64,11 +64,6 @@
public CustomizeableGradient() {
super(ImageType.PNG);
-
- String gradientTypeString =
safeTrim(getValueParameter(FacesContext.getCurrentInstance(), Skin.GRADIENT_TYPE));
- if (gradientTypeString != null && gradientTypeString.length() != 0) {
- gradientType = GradientType.getByParameter(gradientTypeString);
- }
}
// @Override
@@ -189,6 +184,12 @@
dataOutput.writeInt(this.gradientColor);
dataOutput.writeInt(this.gradientHeight);
dataOutput.writeByte((byte) this.gradientAlignment.ordinal());
+
+ String gradientTypeString =
safeTrim(getValueParameter(FacesContext.getCurrentInstance(), Skin.GRADIENT_TYPE));
+ if (gradientTypeString != null && gradientTypeString.length() != 0) {
+ gradientType = GradientType.getByParameter(gradientTypeString);
+ }
+
dataOutput.writeByte((byte) this.gradientType.ordinal());
}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java 2010-07-26
12:48:16 UTC (rev 18236)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/CompiledCSSResource.java 2010-07-26
13:07:40 UTC (rev 18237)
@@ -31,7 +31,6 @@
import javax.faces.application.ProjectStage;
import javax.faces.application.Resource;
-import javax.faces.application.ResourceHandler;
import javax.faces.context.FacesContext;
import org.richfaces.log.RichfacesLogger;
@@ -56,21 +55,27 @@
private static final String NULL_STYLESHEET = "Parsed stylesheet for
''{0}'':''{1}'' resource is null.";
- private ResourceHandler defaultHandler;
+ //TODO handle sourceResources headers, etc.
+ private Resource sourceResource;
- public CompiledCSSResource(String resourceName, String libraryName, ResourceHandler
defaultHandler) {
- setResourceName(resourceName);
- setLibraryName(libraryName);
- this.defaultHandler = defaultHandler;
+ public CompiledCSSResource(Resource sourceResource) {
+ assert sourceResource != null;
+
+ this.sourceResource = sourceResource;
}
+ @Override
+ public String getLibraryName() {
+ return sourceResource.getLibraryName();
+ }
+
+ @Override
+ public String getResourceName() {
+ return sourceResource.getResourceName();
+ }
+
public InputStream getResourceInputStream() throws IOException {
- Resource resource = defaultHandler.createResource(getResourceName(),
getLibraryName(), "text/plain");
- if (resource == null) {
- return null;
- }
-
- return resource.getInputStream();
+ return sourceResource.getInputStream();
}
@Override
@@ -92,7 +97,7 @@
// parse and create a stylesheet composition
styleSheet = parser.parseStyleSheet(source, null, null);
} catch (Exception e) {
- System.out.println(e);
+ LOGGER.error(e.getMessage(), e);
} finally {
if (stream != null) {
try {
@@ -105,7 +110,7 @@
if (styleSheet != null) {
// TODO nick - handle encoding
- String encoding =
FacesContext.getCurrentInstance().getExternalContext().getResponseCharacterEncoding();
+ String encoding = ctx.getExternalContext().getResponseCharacterEncoding();
CSSVisitorImpl cssVisitor = new CSSVisitorImpl();
cssVisitor.setEncoding(encoding != null ? encoding : "UTF-8");
cssVisitor.visitStyleSheet(styleSheet);
@@ -127,7 +132,7 @@
}
private static int getSkinHashCode(FacesContext context) {
- Skin skin = SkinFactory.getInstance().getSkin(context);
+ Skin skin = SkinFactory.getInstance(context).getSkin(context);
return skin.hashCode(context);
}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-07-26
12:48:16 UTC (rev 18236)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-07-26
13:07:40 UTC (rev 18237)
@@ -175,6 +175,15 @@
context.getExternalContext().setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
}
+ private Resource createCompiledCSSResource(String resourceName, String libraryName)
{
+ Resource sourceResource = defaultHandler.createResource(resourceName,
libraryName, "text/plain");
+ if (sourceResource != null) {
+ return new CompiledCSSResource(sourceResource);
+ }
+
+ return null;
+ }
+
@Override
public void handleResourceRequest(FacesContext context) throws IOException {
if (isThisHandlerResourceRequest(context)) {
@@ -203,7 +212,7 @@
if (resourceName.lastIndexOf(".ecss") != -1) {
String libraryName = resourceCodec.decodeLibraryName(context,
resourcePath);
- resource = new CompiledCSSResource(resourceName, libraryName,
defaultHandler);
+ resource = createCompiledCSSResource(resourceName, libraryName);
}
if (resource == null) {
@@ -457,7 +466,7 @@
resourceName = extractParametersFromResourceName(resourceName);
if (resourceName.lastIndexOf(".ecss") != -1) {
//TODO nick - params?
- result = new CompiledCSSResource(resourceName, libraryName, defaultHandler);
+ result = createCompiledCSSResource(resourceName, libraryName);
} else {
//TODO nick - libraryName as package name?
if ((resourceName != null) && ((libraryName == null) ||
(libraryName.length() == 0))) {
Added: root/core/trunk/impl/src/main/java/org/richfaces/skin/AbstractSkinFactory.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/skin/AbstractSkinFactory.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/skin/AbstractSkinFactory.java 2010-07-26
13:07:40 UTC (rev 18237)
@@ -0,0 +1,232 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.skin;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.resource.util.URLToStreamHelper;
+import org.ajax4jsf.util.ELUtils;
+import org.richfaces.log.RichfacesLogger;
+import org.slf4j.Logger;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class AbstractSkinFactory extends SkinFactory {
+
+ private final class SkinBuilder implements Callable<Skin> {
+
+ private String skinName;
+
+ SkinBuilder(String skinName) {
+ super();
+ this.skinName = skinName;
+ }
+
+ public Skin call() throws Exception {
+ return buildSkin(FacesContext.getCurrentInstance(), skinName);
+ }
+
+ }
+
+ /**
+ * Resource Uri for properties file with default values of skin parameters.
+ */
+ private static final String DEFAULT_SKIN_PATH =
"META-INF/skins/%s.skin.properties";
+
+ // private static final String[] DEFAULT_SKIN_PATHS = { DEFAULT_SKIN_PATH };
+ private static final String USER_SKIN_PATH = "%s.skin.properties";
+
+ /**
+ * Path in jar to pre-defined vendor and custom user-defined skins
+ * definitions. in this realisation "META-INF/skins/" for vendor ,
"" -
+ * user-defined.
+ */
+ private static final String[] SKINS_PATHS = {DEFAULT_SKIN_PATH, USER_SKIN_PATH};
+ private static final Logger LOG = RichfacesLogger.APPLICATION.getLogger();
+
+ private ConcurrentMap<String, FutureTask<Skin>> skins = new
ConcurrentHashMap<String, FutureTask<Skin>>();
+
+ protected void processProperties(FacesContext context, Map<Object, Object>
properties) {
+ ELContext elContext = context.getELContext();
+
+ // replace all EL-expressions by prepared ValueBinding ?
+ Application app = context.getApplication();
+
+ for (Entry<Object, Object> entry : properties.entrySet()) {
+ Object propertyObject = entry.getValue();
+
+ if (propertyObject instanceof String) {
+ String property = (String) propertyObject;
+
+ if (ELUtils.isValueReference(property)) {
+ ExpressionFactory expressionFactory = app.getExpressionFactory();
+
+ entry.setValue(expressionFactory.createValueExpression(elContext,
property, Object.class));
+ } else {
+ entry.setValue(property);
+ }
+ }
+ }
+ }
+
+ /**
+ * Factory method for build skin from properties files. for given skin name,
+ * search in classpath all resources with name 'name'.skin.properties and
+ * append in content to default properties. First, get it from
+ * META-INF/skins/ , next - from root package. for any place search order
+ * determined by {@link java.lang.ClassLoader } realisation.
+ *
+ * @param name name for builded skin.
+ * @param defaultProperties
+ * @return skin instance for current name
+ * @throws SkinNotFoundException -
+ * if no skin properies found for name.
+ */
+ protected Skin buildSkin(FacesContext context, String name) throws
SkinNotFoundException {
+ Properties skinParams = loadProperties(name, SKINS_PATHS);
+ processProperties(context, skinParams);
+
+ return new SkinImpl(skinParams);
+ }
+
+ /**
+ * @param name
+ * @param paths
+ * @return
+ * @throws SkinNotFoundException
+ */
+ protected Properties loadProperties(String name, String[] paths) throws
SkinNotFoundException {
+ ClassLoader loader = getClassLoader();
+
+ // Get properties for concrete skin.
+ Properties skinProperties = new Properties();
+ int loadedPropertiesCount = 0;
+
+ for (int i = 0; i < paths.length; i++) {
+ String skinPropertiesLocation = paths[i].replaceAll("%s", name);
+
+ if (loadProperties(loader, skinProperties, skinPropertiesLocation)) {
+ loadedPropertiesCount++;
+ }
+ }
+
+ if (loadedPropertiesCount == 0) {
+ throw new
SkinNotFoundException(Messages.getMessage(Messages.SKIN_NOT_FOUND_ERROR, name));
+ }
+
+ return skinProperties;
+ }
+
+ /**
+ * @param loader
+ * @param properties
+ * @param location
+ */
+ protected boolean loadProperties(ClassLoader loader, Properties properties, String
location) {
+ boolean loaded = false;
+
+ try {
+ Enumeration<URL> resources = loader.getResources(location);
+
+ while (resources.hasMoreElements()) {
+ URL url = (URL) resources.nextElement();
+ InputStream propertyStream = null;
+
+ try {
+ propertyStream = URLToStreamHelper.urlToStream(url);
+ properties.load(propertyStream);
+ loaded = true;
+ } catch (IOException e) {
+ LOG.warn(Messages.getMessage(Messages.SKIN_PROPERTIES_IO_ERROR), e);
+
+ continue;
+ } finally {
+ if (null != propertyStream) {
+ propertyStream.close();
+ }
+ }
+ }
+ } catch (IOException e) {
+
+ // Do nothing - we can only log error, and continue to load next
+ // property.
+ if (LOG.isInfoEnabled()) {
+ LOG.info(Messages.getMessage(Messages.SKIN_PROPERTIES_IO_ERROR), e);
+ }
+ }
+
+ return loaded;
+ }
+
+ /**
+ * @return
+ */
+ protected ClassLoader getClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ @Override
+ public Skin getSkin(FacesContext context, String name) {
+ if (null == name) {
+ throw new
SkinNotFoundException(Messages.getMessage(Messages.NULL_SKIN_NAME_ERROR));
+ }
+
+ FutureTask<Skin> skinFuture = skins.get(name);
+ if (skinFuture == null) {
+ FutureTask<Skin> newSkinFuture = new FutureTask<Skin>(new
SkinBuilder(name));
+ skinFuture = skins.putIfAbsent(name, newSkinFuture);
+
+ if (skinFuture == null) {
+ skinFuture = newSkinFuture;
+ }
+ }
+
+ try {
+ skinFuture.run();
+ return skinFuture.get();
+ } catch (InterruptedException e) {
+ throw new
SkinNotFoundException(Messages.getMessage(Messages.SKIN_NOT_FOUND_ERROR), e);
+ } catch (ExecutionException e) {
+ throw new
SkinNotFoundException(Messages.getMessage(Messages.SKIN_NOT_FOUND_ERROR), e);
+ }
+ }
+
+}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2010-07-26
12:48:16 UTC (rev 18236)
+++ root/core/trunk/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2010-07-26
13:07:40 UTC (rev 18237)
@@ -21,31 +21,14 @@
package org.richfaces.skin;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.FutureTask;
-import javax.el.ELContext;
-import javax.el.ExpressionFactory;
-import javax.faces.application.Application;
import javax.faces.context.FacesContext;
import org.ajax4jsf.Messages;
import org.ajax4jsf.context.ContextInitParameters;
-import org.ajax4jsf.resource.util.URLToStreamHelper;
-import org.ajax4jsf.util.ELUtils;
-import org.richfaces.log.RichfacesLogger;
-import org.slf4j.Logger;
/**
* Implementation of {@link SkinFactory} with building skins from properties
@@ -53,7 +36,7 @@
*
* @author shura
*/
-public class SkinFactoryImpl extends SkinFactory {
+public class SkinFactoryImpl extends AbstractSkinFactory {
private static final String SKIN_KEY = SkinFactoryImpl.class.getName() +
":skin";
@@ -66,74 +49,12 @@
*/
private static final String DEFAULT_SKIN_NAME = "DEFAULT";
- /**
- * Resource Uri for properties file with default values of skin parameters.
- */
- private static final String DEFAULT_SKIN_PATH =
"META-INF/skins/%s.skin.properties";
-
private static final String[] THEME_PATHS =
{"META-INF/themes/%s.theme.properties", "%s.theme.properties"};
- // private static final String[] DEFAULT_SKIN_PATHS = { DEFAULT_SKIN_PATH };
- private static final String USER_SKIN_PATH = "%s.skin.properties";
-
- /**
- * Path in jar to pre-defined vendor and custom user-defined skins
- * definitions. in this realisation "META-INF/skins/" for vendor ,
"" -
- * user-defined.
- */
- private static final String[] SKINS_PATHS = {DEFAULT_SKIN_PATH, USER_SKIN_PATH};
- private static final Logger LOG = RichfacesLogger.APPLICATION.getLogger();
-
// private Properties defaultSkinProperties = null;
-// private static final String[] CONFIGURATIONS_PATHS = {
-// "META-INF/skins/%s.configuration.properties",
-// "%s.configuration.properties" };
- // private static final String[] DEFAULT_CONFIGURATION_PATHS = {
"META-INF/skins/DEFAULT.configuration.properties" };
- private ConcurrentMap<String, FutureTask<Skin>> skins = new
ConcurrentHashMap<String, FutureTask<Skin>>();
private Map<String, Theme> themes = new HashMap<String, Theme>();
- private final class SkinBuilder implements Callable<Skin> {
-
- private String skinName;
-
- SkinBuilder(String skinName) {
- super();
- this.skinName = skinName;
- }
-
- public Skin call() throws Exception {
- return buildSkin(FacesContext.getCurrentInstance(), skinName);
- }
-
- }
-
- @Override
- public Skin getSkin(FacesContext context, String name) {
- if (null == name) {
- throw new
SkinNotFoundException(Messages.getMessage(Messages.NULL_SKIN_NAME_ERROR));
- }
-
- FutureTask<Skin> skinFuture = skins.get(name);
- if (skinFuture == null) {
- FutureTask<Skin> newSkinFuture = new FutureTask<Skin>(new
SkinBuilder(name));
- skinFuture = skins.putIfAbsent(name, newSkinFuture);
-
- if (skinFuture == null) {
- skinFuture = newSkinFuture;
- }
- }
-
- try {
- skinFuture.run();
- return skinFuture.get();
- } catch (InterruptedException e) {
- throw new
SkinNotFoundException(Messages.getMessage(Messages.SKIN_NOT_FOUND_ERROR), e);
- } catch (ExecutionException e) {
- throw new
SkinNotFoundException(Messages.getMessage(Messages.SKIN_NOT_FOUND_ERROR), e);
- }
- }
-
public Skin getDefaultSkin(FacesContext context) {
return getSkin(context, DEFAULT_SKIN_NAME);
}
@@ -201,125 +122,6 @@
return result;
}
- private void processProperties(FacesContext context, Map<Object, Object>
properties) {
- ELContext elContext = context.getELContext();
-
- // replace all EL-expressions by prepared ValueBinding ?
- Application app = context.getApplication();
-
- for (Entry<Object, Object> entry : properties.entrySet()) {
- Object propertyObject = entry.getValue();
-
- if (propertyObject instanceof String) {
- String property = (String) propertyObject;
-
- if (ELUtils.isValueReference(property)) {
- ExpressionFactory expressionFactory = app.getExpressionFactory();
-
- entry.setValue(expressionFactory.createValueExpression(elContext,
property, Object.class));
- } else {
- entry.setValue(property);
- }
- }
- }
- }
-
- /**
- * Factory method for build skin from properties files. for given skin name,
- * search in classpath all resources with name 'name'.skin.properties and
- * append in content to default properties. First, get it from
- * META-INF/skins/ , next - from root package. for any place search order
- * determined by {@link java.lang.ClassLoader } realisation.
- *
- * @param name name for builded skin.
- * @param defaultProperties
- * @return skin instance for current name
- * @throws SkinNotFoundException -
- * if no skin properies found for name.
- */
- protected Skin buildSkin(FacesContext context, String name) throws
SkinNotFoundException {
- Properties skinParams = loadProperties(name, SKINS_PATHS);
- processProperties(context, skinParams);
-
- return new SkinImpl(skinParams);
- }
-
- /**
- * @param name
- * @param paths
- * @return
- * @throws SkinNotFoundException
- */
- protected Properties loadProperties(String name, String[] paths) throws
SkinNotFoundException {
- ClassLoader loader = getClassLoader();
-
- // Get properties for concrete skin.
- Properties skinProperties = new Properties();
- int loadedPropertiesCount = 0;
-
- for (int i = 0; i < paths.length; i++) {
- String skinPropertiesLocation = paths[i].replaceAll("%s", name);
-
- if (loadProperties(loader, skinProperties, skinPropertiesLocation)) {
- loadedPropertiesCount++;
- }
- }
-
- if (loadedPropertiesCount == 0) {
- throw new
SkinNotFoundException(Messages.getMessage(Messages.SKIN_NOT_FOUND_ERROR, name));
- }
-
- return skinProperties;
- }
-
- /**
- * @return
- */
- protected ClassLoader getClassLoader() {
- return Thread.currentThread().getContextClassLoader();
- }
-
- /**
- * @param loader
- * @param properties
- * @param location
- */
- protected boolean loadProperties(ClassLoader loader, Properties properties, String
location) {
- boolean loaded = false;
-
- try {
- Enumeration<URL> resources = loader.getResources(location);
-
- while (resources.hasMoreElements()) {
- URL url = (URL) resources.nextElement();
- InputStream propertyStream = null;
-
- try {
- propertyStream = URLToStreamHelper.urlToStream(url);
- properties.load(propertyStream);
- loaded = true;
- } catch (IOException e) {
- LOG.warn(Messages.getMessage(Messages.SKIN_PROPERTIES_IO_ERROR), e);
-
- continue;
- } finally {
- if (null != propertyStream) {
- propertyStream.close();
- }
- }
- }
- } catch (IOException e) {
-
- // Do nothing - we can only log error, and continue to load next
- // property.
- if (LOG.isInfoEnabled()) {
- LOG.info(Messages.getMessage(Messages.SKIN_PROPERTIES_IO_ERROR), e);
- }
- }
-
- return loaded;
- }
-
@Override
public Theme getTheme(FacesContext facesContext, String name) {
Theme theme = themes.get(name);