You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2013/12/03 19:31:34 UTC
svn commit: r1547514 [2/2] - in /myfaces/trinidad/trunk:
trinidad-api/src/main/java/org/apache/myfaces/trinidad/skin/
trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/
trinidad-impl/src/main/java/org/apache/myfaces/trinida...
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java?rev=1547514&r1=1547513&r2=1547514&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java Tue Dec 3 18:31:33 2013
@@ -64,8 +64,6 @@ import org.apache.myfaces.trinidadintern
import org.apache.myfaces.trinidadinternal.skin.icon.ReferenceIcon;
import org.apache.myfaces.trinidadinternal.skin.parse.SkinsNode;
import org.apache.myfaces.trinidadinternal.skin.parse.XMLConstants;
-import org.apache.myfaces.trinidadinternal.skin.provider.ExternalSkinProvider;
-import org.apache.myfaces.trinidadinternal.skin.provider.TrinidadSkinProvider;
import org.apache.myfaces.trinidadinternal.style.StyleContext;
import org.xml.sax.InputSource;
@@ -80,56 +78,31 @@ import org.xml.sax.InputSource;
public class SkinUtils
{
/**
- * Utility method to get the SkinProvider instance
- * @param context Tries to obtain the default FacesContext if null is passed
- * @return
+ * Tries to retrieve the default FacesContext
+ * @param context FacesContext object or null
+ * @return the same context object if not null, or the default FacesContext
+ * @throws java.lang.NullPointerException if unable to retrieve default FacesContext
*/
- static public SkinProvider getSkinProvider(FacesContext context)
+ public static FacesContext getNonNullFacesContext(FacesContext context)
{
- if (context == null)
- context = FacesContext.getCurrentInstance();
+ if (context != null)
+ return context;
- if (context == null)
- throw new NullPointerException("Cannot retrieve FacesContext. FacesContext is null.");
-
- return SkinProvider.getCurrentInstance(context.getExternalContext());
- }
-
- /**
- * Utility method to get the ExternalSkinProvider instance
- * @param context Tries to obtain the default FacesContext if null is passed
- * @return
- */
- static public SkinProvider getExternalSkinProvider(FacesContext context)
- {
- if (context == null)
- context = FacesContext.getCurrentInstance();
+ // get the current
+ context = FacesContext.getCurrentInstance();
+ // this cannot happen as we have a FacesContext always. If there is some case where we don't,
+ // then it is a fail
if (context == null)
- throw new NullPointerException("Cannot retrieve FacesContext. FacesContext is null.");
+ throw new NullPointerException("FacesContext is null. Cannot retrieve default FacesContext");
- return ExternalSkinProvider.getCurrentInstance(context.getExternalContext());
+ return context;
}
/**
- * Utility method to get the TrinidadSkinProvider instance
- * @param context Tries to obtain the default FacesContext if null is passed
- * @return
- */
- static public TrinidadSkinProvider getTrinidadSkinProvider(FacesContext context)
- {
- if (context == null)
- context = FacesContext.getCurrentInstance();
-
- if (context == null)
- throw new NullPointerException("Cannot retrieve FacesContext. FacesContext is null.");
-
- return TrinidadSkinProvider.getCurrentInstance(context.getExternalContext());
- }
-
- /**
- * Adds skinAddition passed into the skin object passed, if the skin object does not have
- * the same skin addition already.
+ * Adds skinAddition passed into the skin object passed, if the skin object does not have the same
+ * skin addition already.
+ *
* @param skin
* @param skinAddition
* @return true if the SkinAddition was added into Skin and false if it was not.
@@ -153,13 +126,16 @@ public class SkinUtils
}
/**
- * @param provider skin provider
- * @param context faces context
+ * @param provider skin provider
+ * @param context faces context
* @param renderKitId renderKit Id for default skin
- * @return the default skin for the renderKit passed. Assumes renderKit as DESKTOP if null.
- * does not return null, returns the DESKTOP simple skin in worst case.
+ * @return the default skin for the renderKit passed. Assumes renderKit as DESKTOP if null. does
+ * not return null, returns the DESKTOP simple skin in worst case.
*/
- public static Skin getDefaultSkinForRenderKitId(SkinProvider provider, FacesContext context, String renderKitId)
+ public static Skin getDefaultSkinForRenderKitId(
+ SkinProvider provider,
+ ExternalContext context,
+ String renderKitId)
{
if (provider == null || context == null)
@@ -174,7 +150,8 @@ public class SkinUtils
else
defaultSkinId = TrinidadRenderingConstants.SIMPLE_DESKTOP_ID;
- Skin defaultSkin = provider.getSkin(context, new SkinMetadata.Builder().id(defaultSkinId).build());
+ Skin defaultSkin = provider.getSkin(context,
+ new SkinMetadata.Builder().id(defaultSkinId).build());
assert (defaultSkin != null);
@@ -183,13 +160,15 @@ public class SkinUtils
/**
* Builds the SkinMetadata hierarchy from trinidad-skins.xml
+ *
* @return
*/
static public List<SkinsNode> buildSkinsNodes(ExternalContext extCtxt)
{
List<SkinsNode> metaInfSkinsNode = _getMetaInfSkinsNodeList();
SkinsNode webInfSkinsNode = _getWebInfSkinsNode(extCtxt);
- List<SkinsNode> resourceLoaderSkinsNodes = _getSkinsNodesFromSkinResourceLoaderServices(extCtxt);
+ List<SkinsNode> resourceLoaderSkinsNodes =
+ _getSkinsNodesFromSkinResourceLoaderServices(extCtxt);
List<SkinsNode> skinsNodes = new ArrayList<SkinsNode>(20);
@@ -208,7 +187,8 @@ public class SkinUtils
/**
* Returns the actual Icon referenced by the ReferenceIcon.
- * @param skin the Skin to use when resolving the ReferenceIcon
+ *
+ * @param skin the Skin to use when resolving the ReferenceIcon
* @param refIcon a ReferenceIcon instance
* @return icon which is resolved. i.e., it is not a ReferenceIcon.
*/
@@ -216,7 +196,7 @@ public class SkinUtils
Skin skin,
ReferenceIcon refIcon)
{
- return _resolveReferenceIcon(skin, refIcon, null);
+ return _resolveReferenceIcon(skin, refIcon, null);
}
public static String getSkinDebugInfo(Skin skin)
@@ -224,7 +204,7 @@ public class SkinUtils
assert (null != skin);
RenderingContext rc = RenderingContext.getCurrentInstance();
StringBuilder sb = new StringBuilder();
-
+
sb.append("[Id: ")
.append(skin.getId())
.append(" Family: ")
@@ -234,13 +214,13 @@ public class SkinUtils
.append(" Renderkit: ")
.append(skin.getRenderKitId())
.append(" StylesheetId: ")
- .append( skin.getStyleSheetDocumentId(rc))
+ .append(skin.getStyleSheetDocumentId(rc))
.append(" Features: { ");
-
+
boolean first = false;
- for(Map.Entry<String,String>entry:skin.getSkinFeatures().entrySet())
+ for (Map.Entry<String, String> entry : skin.getSkinFeatures().entrySet())
{
- if(!first)
+ if (!first)
{
sb.append(", ");
}
@@ -248,26 +228,26 @@ public class SkinUtils
{
first = false;
}
-
+
sb.append("k:")
.append(entry.getKey())
.append(" v:")
.append(entry.getValue());
}
-
+
sb.append(" } ");
-
- if(rc instanceof CoreRenderingContext)
+
+ if (rc instanceof CoreRenderingContext)
{
sb.append(" Additions: {");
-
- StyleContext sctx = ((CoreRenderingContext)rc).getStyleContext();
- List<SkinAddition>additions = skin.getSkinAdditions();
-
+
+ StyleContext sctx = ((CoreRenderingContext) rc).getStyleContext();
+ List<SkinAddition> additions = skin.getSkinAdditions();
+
first = true;
- for(SkinAddition addition:additions)
+ for (SkinAddition addition : additions)
{
- if(!first)
+ if (!first)
{
sb.append(", ");
}
@@ -275,27 +255,28 @@ public class SkinUtils
{
first = false;
}
-
+
String styleSheetName = addition.getStyleSheetName();
sb.append("\"")
.append(styleSheetName)
.append("\"(");
StyleSheetEntry entry = StyleSheetEntry.createEntry(sctx, styleSheetName);
sb.append(entry.getDocument().getDocumentId(sctx))
- .append(")");
+ .append(")");
}
sb.append("}");
}
-
+
return sb.append("]").toString();
}
/**
- * Get all the META-INF/trinidad-skins.xml files, parse them, and from each file we get
- * a SkinsNode object -- the information inside the <skins> element -- each skin
- * and each skin-addition.
- * @return Each SkinsNode object we get from each META-INF/trinidad-skins.xml file,
- * in a List<SkinsNode>.
+ * Get all the META-INF/trinidad-skins.xml files, parse them, and from each file we get a
+ * SkinsNode object -- the information inside the <skins> element -- each skin and each
+ * skin-addition.
+ *
+ * @return Each SkinsNode object we get from each META-INF/trinidad-skins.xml file, in a
+ * List<SkinsNode>.
*/
private static List<SkinsNode> _getMetaInfSkinsNodeList()
{
@@ -341,15 +322,12 @@ public class SkinUtils
* is null.
*/
/**
- *
- * @param provider an XMLProvider implementation.
- * @param resolver A NameResolver that can be used to locate
- * resources, such as source images for colorized
- * icons.
- * @param inputStream the inputStream. Must be non-null
- * @param parserManager the ParserManager to use for parsing
- * Must be non-null.
- * @param configFile The name of the config file we are parsing.
+ * @param provider an XMLProvider implementation.
+ * @param resolver A NameResolver that can be used to locate resources, such as source images
+ * for colorized icons.
+ * @param inputStream the inputStream. Must be non-null
+ * @param parserManager the ParserManager to use for parsing Must be non-null.
+ * @param configFile The name of the config file we are parsing.
* @return A SkinsNode object (contains a List of SkinMetadata and a List of SkinAddition)
*/
static private SkinsNode _getSkinsNodeFromInputStream(
@@ -363,11 +341,9 @@ public class SkinUtils
{
if (inputStream == null)
- throw new NullPointerException(_LOG.getMessage(
- "NO_INPUTSTREAM"));
+ throw new NullPointerException(_LOG.getMessage("NO_INPUTSTREAM"));
if (parserManager == null)
- throw new NullPointerException(_LOG.getMessage(
- "NULL_PARSEMANAGER"));
+ throw new NullPointerException(_LOG.getMessage("NULL_PARSEMANAGER"));
SkinsNode skinsNode = null;
try
{
@@ -389,7 +365,7 @@ public class SkinUtils
// Create the TreeBuilder
TreeBuilder builder = new TreeBuilder(parserManager,
SkinsNode.class);
- skinsNode = ((SkinsNode)builder.parse(provider, input, context));
+ skinsNode = ((SkinsNode) builder.parse(provider, input, context));
if (isMetaInf)
context.setProperty(XMLConstants.SKIN_NAMESPACE, XMLConstants.META_INF, null);
@@ -415,15 +391,15 @@ public class SkinUtils
}
/**
- * Creates a ParserManager pre-registered witih all
- * the default ParserFactories needed to create SkinExtensions.
+ * Creates a ParserManager pre-registered witih all the default ParserFactories needed to create
+ * SkinExtensions.
*/
static public ParserManager createDefaultManager()
{
ParserManager manager = new ParserManager();
// Register top-level factory
- _registerFactory(manager, SkinsNode.class, "SkinsNode");
+ _registerFactory(manager, SkinsNode.class, "SkinsNode");
// Register skin node factory and skin addition node factory
_registerFactory(manager, SkinMetadata.class, "SkinMetadata");
@@ -462,6 +438,7 @@ public class SkinUtils
/**
* Get the WEB-INF/trinidad-skins.xml file, parse it, and return a List of SkinsNode objects.
+ *
* @param context ServletContext used to getResourceAsStream
* @return List of SkinNodes (skin elements) found in trinidad-skins.xml
*/
@@ -480,10 +457,10 @@ public class SkinUtils
_LOG.fine("Skin {0} with stylesheet {1}",
new Object[]{node.getId(), node.getStyleSheetName()});
}
- for (SkinAddition node: webInfSkinsNode.getSkinAdditionNodes())
+ for (SkinAddition node : webInfSkinsNode.getSkinAdditionNodes())
{
_LOG.fine("SkinAddition {0} with stylesheet {1}",
- new Object[]{node.getSkinId(), node.getStyleSheetName()});
+ new Object[]{node.getSkinId(), node.getStyleSheetName()});
}
}
@@ -496,17 +473,17 @@ public class SkinUtils
}
/**
- * Looks for SPIs registered in META-INF/services folder with file
- * name "org.apache.myfaces.trinidad.resource.SkinResourceLoader".
- * Loads the trinidad-skins.xml exposed by these resource loades by calling findResource().
- * Creates SkinsNodes and returns
+ * Looks for SPIs registered in META-INF/services folder with file name
+ * "org.apache.myfaces.trinidad.resource.SkinResourceLoader". Loads the trinidad-skins.xml exposed
+ * by these resource loades by calling findResource(). Creates SkinsNodes and returns
*
* @param context
* @return list of SkinsNode representing trinidad-skins.xml loaded using SkinResourceLoader SPI
*/
- private static List<SkinsNode> _getSkinsNodesFromSkinResourceLoaderServices(ExternalContext context)
+ private static List<SkinsNode> _getSkinsNodesFromSkinResourceLoaderServices(
+ ExternalContext context)
{
- if (_LOG.isFine()) _LOG.fine("Parse SkinResourceLoader trinidad-skins.xml");
+ if (_LOG.isFine()) _LOG.fine("Parse SkinResourceLoader trinidad-skins.xml");
// register skins found in DT using the META-INF/services
List<SkinResourceLoader> urlProviders = ClassLoaderUtils.getServices(
"org.apache.myfaces.trinidad.resource.SkinResourceLoader");
@@ -519,8 +496,9 @@ public class SkinUtils
}
/**
- * Given the list of SkinResourceLoaders, load the trindiad-skins
- * This is used by DT to load trinidad-skins.xml not in META-INF or WEB-INF
+ * Given the list of SkinResourceLoaders, load the trindiad-skins This is used by DT to load
+ * trinidad-skins.xml not in META-INF or WEB-INF
+ *
* @param context
* @param providers
* @return
@@ -533,7 +511,7 @@ public class SkinUtils
List<SkinsNode> allSkinsNodes = new ArrayList<SkinsNode>();
- for (SkinResourceLoader urlProvider : providers )
+ for (SkinResourceLoader urlProvider : providers)
{
Iterator<URL> urlIterator = urlProvider.findResources(context, _TRINIDAD_SKINS_XML);
@@ -575,7 +553,7 @@ public class SkinUtils
{
_LOG.fine("Skipping skin URL:{0} because it was already processed. " +
"It was on the classpath more than once.",
- url);
+ url);
}
// continue to the next url
}
@@ -611,16 +589,16 @@ public class SkinUtils
for (SkinMetadata node : metaInfSkinsNode.getSkinNodes())
_LOG.fine("Skin {0} with stylesheet {1}",
new Object[]{node.getId(), node.getStyleSheetName()});
- for (SkinAddition node: metaInfSkinsNode.getSkinAdditionNodes())
+ for (SkinAddition node : metaInfSkinsNode.getSkinAdditionNodes())
_LOG.fine("SkinAddition {0} with stylesheet {1}",
- new Object[]{node.getSkinId(), node.getStyleSheetName()});
+ new Object[]{node.getSkinId(), node.getStyleSheetName()});
}
allSkinsNodes.add(metaInfSkinsNode);
}
else
{
- if(_LOG.isFine()) _LOG.fine("No skins found in the URL.");
+ if (_LOG.isFine()) _LOG.fine("No skins found in the URL.");
}
}
}
@@ -637,13 +615,13 @@ public class SkinUtils
}
/**
- * Helper for resolveReferenceIcon which uses a Stack of icon names
- * to detect circular dependencies.
+ * Helper for resolveReferenceIcon which uses a Stack of icon names to detect circular
+ * dependencies.
*
- * @param skin the Skin to use when resolving the ReferenceIcon
- * @param refIcon a ReferenceIcon instance
- * @param referencedIconStack The stack of reference icon names which have
- * already been visited. Used to detect circular dependencies.
+ * @param skin the Skin to use when resolving the ReferenceIcon
+ * @param refIcon a ReferenceIcon instance
+ * @param referencedIconStack The stack of reference icon names which have already been visited.
+ * Used to detect circular dependencies.
* @return icon which is resolved. i.e., it is not a ReferenceIcon.
*/
static private Icon _resolveReferenceIcon(
@@ -674,8 +652,8 @@ public class SkinUtils
{
return _resolveReferenceIcon(skin,
- (ReferenceIcon)icon,
- referencedIconStack);
+ (ReferenceIcon) icon,
+ referencedIconStack);
}
@@ -683,7 +661,9 @@ public class SkinUtils
}
- private SkinUtils() {}
+ private SkinUtils()
+ {
+ }
// The default ParserManager
static private ParserManager _sManager;
@@ -691,12 +671,11 @@ public class SkinUtils
// Constants
// Prefix of LAf parsing package
- static private final String _LAF_PARSE_PACKAGE =
+ static private final String _LAF_PARSE_PACKAGE =
"org.apache.myfaces.trinidadinternal.skin.parse.";
-
-
- static private final String _CONFIG_FILE = "/WEB-INF/trinidad-skins.xml";
- static private final String _META_INF_CONFIG_FILE = "META-INF/trinidad-skins.xml";
- static private final String _TRINIDAD_SKINS_XML = "trinidad-skins.xml";
- static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(SkinUtils.class);
+ static private final String _CONFIG_FILE = "/WEB-INF/trinidad-skins.xml";
+ static private final String _META_INF_CONFIG_FILE = "META-INF/trinidad-skins.xml";
+ static private final String _TRINIDAD_SKINS_XML = "trinidad-skins.xml";
+ static private final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(SkinUtils.class);
}
\ No newline at end of file
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/pregen/SkinPregenerationService.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/pregen/SkinPregenerationService.java?rev=1547514&r1=1547513&r2=1547514&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/pregen/SkinPregenerationService.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/pregen/SkinPregenerationService.java Tue Dec 3 18:31:33 2013
@@ -141,8 +141,9 @@ public class SkinPregenerationService ex
private static Skin _getSkin(FacesContext context, String skinId)
{
- SkinProvider provider = SkinProvider.getCurrentInstance(context.getExternalContext());
- return provider.getSkin(context, new SkinMetadata.Builder().id(skinId).build());
+ ExternalContext ec = context.getExternalContext();
+ SkinProvider provider = SkinProvider.getCurrentInstance(ec);
+ return provider.getSkin(ec, new SkinMetadata.Builder().id(skinId).build());
}
private static void _pregenFailed(FacesContext context, Exception e)
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/BaseSkinProvider.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/BaseSkinProvider.java?rev=1547514&r1=1547513&r2=1547514&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/BaseSkinProvider.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/BaseSkinProvider.java Tue Dec 3 18:31:33 2013
@@ -25,19 +25,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.faces.context.FacesContext;
+import javax.faces.context.ExternalContext;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.skin.Skin;
import org.apache.myfaces.trinidad.skin.SkinMetadata;
import org.apache.myfaces.trinidad.skin.SkinProvider;
import org.apache.myfaces.trinidad.skin.SkinVersion;
-import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.XhtmlConstants;
/**
- * This is the common base class for Trinidad SkinProviders. This class abstracts out some common code that is useful
- * across Trinidad internal SkinProviders. One such example worth mentioning is the code to finding a Skin match
- * for a given SkinMetadata search criteria.
+ * This is the common base class for Trinidad SkinProviders. This class abstracts out some common
+ * code that is useful across Trinidad internal SkinProviders. One such example worth mentioning is
+ * the code to finding a Skin match for a given SkinMetadata search criteria.
+ *
* @See TrinidadBaseSkinProvider
* @See TrinidadSkinProvider
* @See ExternalSkinProvider
@@ -53,7 +53,7 @@ public abstract class BaseSkinProvider e
* {@inheritDoc}
*/
@Override
- public Skin getSkin(FacesContext context, SkinMetadata skinMetadata)
+ public Skin getSkin(ExternalContext context, SkinMetadata skinMetadata)
{
synchronized (this)
{
@@ -65,7 +65,7 @@ public abstract class BaseSkinProvider e
* {@inheritDoc}
*/
@Override
- public Collection<SkinMetadata> getSkinMetadata(FacesContext context)
+ public Collection<SkinMetadata> getSkinMetadata(ExternalContext context)
{
synchronized (this)
{
@@ -75,6 +75,7 @@ public abstract class BaseSkinProvider e
/**
* add method used to register a skin with the provider.
+ *
* @param metadata
* @param skin
* @return Any previously registered skins existing with the same metadata
@@ -97,16 +98,18 @@ public abstract class BaseSkinProvider e
}
/**
- * template method to be implemented by subclasses with logic to load a skin
- * that base class knows as available with the current skin provider being asked
- * to load the skin
+ * template method to be implemented by subclasses with logic to load a skin that base class knows
+ * as available with the current skin provider being asked to load the skin
+ *
* @param context
* @param skinMetadata
*/
- protected abstract Skin loadAvailableSkin(FacesContext context, SkinMetadata skinMetadata);
+ protected abstract Skin loadAvailableSkin(ExternalContext context, SkinMetadata skinMetadata);
/**
- * getter for the skins, only used by ExternalSkinProvider.reload to cache and restore the skins if reload fails
+ * getter for the skins, only used by ExternalSkinProvider.reload to cache and restore the skins
+ * if reload fails
+ *
* @return
*/
protected Map<SkinMetadata, Skin> getSkins()
@@ -118,7 +121,9 @@ public abstract class BaseSkinProvider e
}
/**
- * setter for the skins, only used by ExternalSkinProvider.reload to cache and restore the skins if reload fails
+ * setter for the skins, only used by ExternalSkinProvider.reload to cache and restore the skins
+ * if reload fails
+ *
* @param skins
*/
protected void setSkins(Map<SkinMetadata, Skin> skins)
@@ -134,8 +139,7 @@ public abstract class BaseSkinProvider e
}
/**
- * initialize a new HashMap for the skins,
- * used by constructor and ExternalSkinProvider.reload
+ * initialize a new HashMap for the skins, used by constructor and ExternalSkinProvider.reload
*/
protected void initSkins()
{
@@ -146,21 +150,23 @@ public abstract class BaseSkinProvider e
}
/**
- * Hook to do any kind of initialization before loading a skin or skin metadata
- * sub classes can choose to implement
+ * Hook to do any kind of initialization before loading a skin or skin metadata sub classes can
+ * choose to implement
+ *
* @param context
*/
- protected void initialize(FacesContext context)
+ protected void initialize(ExternalContext context)
{
}
/**
* one point method for searching skins
+ *
* @param context
* @param searchMetadata to search for
* @return matching skin
*/
- private final Skin _getMatchingSkin(FacesContext context, SkinMetadata searchMetadata)
+ private final Skin _getMatchingSkin(ExternalContext context, SkinMetadata searchMetadata)
{
if (searchMetadata == null)
throw new NullPointerException("SkinMetadata passed for search is null");
@@ -183,7 +189,7 @@ public abstract class BaseSkinProvider e
initialize(context);
if (_LOG.isFine())
- _LOG.fine("SP_FINDING_SKIN_FOR", new Object[]{searchMetadata.toString()} );
+ _LOG.fine("SP_FINDING_SKIN_FOR", new Object[]{searchMetadata.toString()});
// first check if a skin matching the requirement is present in this provider
SkinMetadata availableMetadata = _findSkinMetadata(context, searchMetadata);
@@ -217,10 +223,11 @@ public abstract class BaseSkinProvider e
/**
* find if there is a skin with the search condition supported by the current SkinProvider
+ *
* @param search
* @return
*/
- private SkinMetadata _findSkinMetadata(FacesContext context, SkinMetadata search)
+ private SkinMetadata _findSkinMetadata(ExternalContext context, SkinMetadata search)
{
SkinMetadata matchingSkinMetadata = null;
String skinId = search.getId();
@@ -268,7 +275,8 @@ public abstract class BaseSkinProvider e
// search using family and renderkit id
for (SkinMetadata m : skinMetadata)
- if (family.equalsIgnoreCase(m.getFamily()) && renderKit.equalsIgnoreCase(m.getRenderKitId()))
+ if (family.equalsIgnoreCase(m.getFamily()) &&
+ renderKit.equalsIgnoreCase(m.getRenderKitId()))
familyRenderKitMatches.add(m);
if (familyRenderKitMatches.isEmpty())
@@ -287,7 +295,7 @@ public abstract class BaseSkinProvider e
// at this point we know we have something in the familyRenderKitMatches
// which is a list of matching family and renderKitId skins. Now match the version
// to find the best matched skin.
- String versionName = version.getName();
+ String versionName = version.getName();
boolean versionIsDefault = version.isDefault();
boolean foundMatchingSkin = false;
@@ -297,9 +305,11 @@ public abstract class BaseSkinProvider e
matchingSkinMetadata = _findSkinMetadataForVersionName(familyRenderKitMatches, version);
}
- // matchingSkinMetadata will be null if an exact version match (family+renderKitId+version) was not found;
+ // matchingSkinMetadata will be null if an exact version match (family+renderKitId+version)
+ // was not found;
// or if user was asking for a default version
- // we can have an exact version match if the user asks for null version, and we find a skin with no
+ // we can have an exact version match if the user asks for null version,
+ // and we find a skin with no
// version set.
if (matchingSkinMetadata == null || versionIsDefault)
{
@@ -336,17 +346,17 @@ public abstract class BaseSkinProvider e
}
else if (matchingSkinMetadata != null)
{
- if(_LOG.isFine())
+ if (_LOG.isFine())
{
if ("".equals(versionName))
{
_LOG.fine("GET_SKIN_CANNOT_FIND_NO_VERSION",
- new Object[]{family, matchingSkinMetadata.getId()});
+ new Object[]{family, matchingSkinMetadata.getId()});
}
else
{
_LOG.fine("GET_SKIN_CANNOT_FIND_SKIN_VERSION",
- new Object[]{family, version, matchingSkinMetadata.getId()});
+ new Object[]{family, version, matchingSkinMetadata.getId()});
}
}
}
@@ -358,7 +368,6 @@ public abstract class BaseSkinProvider e
}
-
if (matchingSkinMetadata != null)
if (_LOG.isFine())
_LOG.fine(this + " found matching metadata: " + matchingSkinMetadata);
@@ -368,11 +377,13 @@ public abstract class BaseSkinProvider e
/**
* find a skin with version passed
+ *
* @param skins
* @param version
* @return
*/
- private SkinMetadata _findSkinMetadataForVersionName(Collection<SkinMetadata> skins, SkinVersion version)
+ private SkinMetadata _findSkinMetadataForVersionName(Collection<SkinMetadata> skins,
+ SkinVersion version)
{
if (version == null)
throw new IllegalArgumentException("skin version cannot be null");
@@ -396,10 +407,10 @@ public abstract class BaseSkinProvider e
}
/**
- * Latest skin is the one which is last in the family hierarchy
- * eg: fusion-v1 -> fusion-v2 -> fusion-v3
- * Among this fusion-v3 is the latest. So we look for a skin that is
- * not extended by any other skin in the family.
+ * Latest skin is the one which is last in the family hierarchy eg: fusion-v1 -> fusion-v2 ->
+ * fusion-v3 Among this fusion-v3 is the latest. So we look for a skin that is not extended by any
+ * other skin in the family.
+ *
* @param skins
* @return
*/
@@ -440,10 +451,12 @@ public abstract class BaseSkinProvider e
/**
* find a skin that has its SkinVersion set to 'default', if it exists.
+ *
* @param matchingSkinList A list of Skins that we will look through to find the 'default'.
* @return Skin with SkinVersion isDefault true, otherwise, null.
*/
- private SkinMetadata _findSkinMetadataWithDefaultVersion(Collection<SkinMetadata> matchingSkinList)
+ private SkinMetadata _findSkinMetadataWithDefaultVersion(
+ Collection<SkinMetadata> matchingSkinList)
{
for (SkinMetadata metadata : matchingSkinList)
{
@@ -462,5 +475,6 @@ public abstract class BaseSkinProvider e
}
private Map<SkinMetadata, Skin> _skins;
- private final static TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(BaseSkinProvider.class);
+ private final static TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(BaseSkinProvider.class);
}
\ No newline at end of file
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/ExternalSkinProvider.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/ExternalSkinProvider.java?rev=1547514&r1=1547513&r2=1547514&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/ExternalSkinProvider.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/ExternalSkinProvider.java Tue Dec 3 18:31:33 2013
@@ -28,16 +28,15 @@ import org.apache.myfaces.trinidad.skin.
import org.apache.myfaces.trinidad.skin.SkinFactory;
import org.apache.myfaces.trinidad.skin.SkinMetadata;
import org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl;
-import org.apache.myfaces.trinidadinternal.skin.SkinUtils;
/**
* ExternalSkinProvider serves to maintain backward compatibility with legacy SkinFactory users.
- * Before we introduced SkinProvider SPI, users can register skins in the lifecycle of
- * the Configurator using reloadSkins API.
- * With SkinProvider SPI, this method of registering skins is deprecated. This provider is used to
- * support the existing users who use SkinFactory to register / reload skins. This provider manages
- * the skins added to the SkinFactory and provides methods to perform the SkinFactory operations.
- *
+ * Before we introduced SkinProvider SPI, users can register skins in the lifecycle of the
+ * Configurator using reloadSkins API. With SkinProvider SPI, this method of registering skins is
+ * deprecated. This provider is used to support the existing users who use SkinFactory to register /
+ * reload skins. This provider manages the skins added to the SkinFactory and provides methods to
+ * perform the SkinFactory operations.
+ * <p/>
* Essentially SkinFactory methods will call this provider for methods like addSkin, getSkinIds etc
* which interact with the skins added to the factory.
*/
@@ -47,14 +46,15 @@ public class ExternalSkinProvider extend
* {@inheritDoc}
*/
@Override
- public Skin getSkin(FacesContext context, SkinMetadata skinMetadata)
+ public Skin getSkin(ExternalContext context, SkinMetadata skinMetadata)
{
synchronized (this)
{
Skin skin = super.getSkin(context, skinMetadata);
// ensure that the skin's and its parent's skin additions are added before we return.
- // see _ensureSkinAdditions method documentation for more information on why we need to do this.
+ // see _ensureSkinAdditions method documentation for more information on why we need to do
+ // this.
if (skin != null)
_ensureSkinAdditions(context, skin);
@@ -66,7 +66,7 @@ public class ExternalSkinProvider extend
* {@inheritDoc}
*/
@Override
- protected Skin loadAvailableSkin(FacesContext context, SkinMetadata skinMetadata)
+ protected Skin loadAvailableSkin(ExternalContext context, SkinMetadata skinMetadata)
{
// this case will never rise with this provider.
// any skin supported by this provider is added using
@@ -76,8 +76,8 @@ public class ExternalSkinProvider extend
}
/**
- * called from SkinFactory to reload the skins that are registered with SkinFactory
- * With this provider, the skins registered with SkinFactory are managed in this provider
+ * called from SkinFactory to reload the skins that are registered with SkinFactory With this
+ * provider, the skins registered with SkinFactory are managed in this provider
*/
public final void reload()
{
@@ -96,7 +96,8 @@ public class ExternalSkinProvider extend
try
{
- // give chance for configurator services to attach any skins that was not defined trinidad-skins.xml
+ // give chance for configurator services to attach any skins that was not defined
+ // trinidad-skins.xml
GlobalConfiguratorImpl.getInstance().reloadSkins(fc.getExternalContext(), factory);
}
catch (Exception e)
@@ -113,9 +114,9 @@ public class ExternalSkinProvider extend
}
/**
- * static factory method to get hold of a ExternalSkinProvider object
- * This can be used for easy creation of Skin object without having to
- * implement the abstract class
+ * static factory method to get hold of a ExternalSkinProvider object This can be used for easy
+ * creation of Skin object without having to implement the abstract class
+ *
* @param ec
* @return
*/
@@ -124,32 +125,35 @@ public class ExternalSkinProvider extend
if (ec == null)
throw new NullPointerException("ExternalContext is passed as null");
- ExternalSkinProvider esp = (ExternalSkinProvider) ec.getApplicationMap().get(EXTERNAL_SKIN_PROVIDER_KEY);
+ ExternalSkinProvider esp =
+ (ExternalSkinProvider) ec.getApplicationMap().get(EXTERNAL_SKIN_PROVIDER_KEY);
return esp;
}
/**
- * {@link org.apache.myfaces.trinidad.config.Configurator} allows access to SkinFactory in its init() and
- * reloadSkin() API. These are now deprecated. But for existing use cases where user registers Skins during init() of
- * Configurator, they obtains their base skin by doing something like SkinFactory.getSkin(null, "simple.desktop");
- * Then custom skin is created using the simple skin as base and put it into SkinFactory using SkinFactory.addSkin method.
- * All skins registered using SkinFactory.addSkin method lands up here in ExternalSkinProvider.
- * Such skins will not have the skin additions registered in trinidad-skins.xml because
- * TrinidadSkinProvider was not able to kick in and provide this information. So we need to ensure that
- * skins returned from ExternalSkinProvider the skin additions for that skin and its base skins are added, before we
+ * {@link org.apache.myfaces.trinidad.config.Configurator} allows access to SkinFactory in its
+ * init() and reloadSkin() API. These are now deprecated. But for existing use cases where user
+ * registers Skins during init() of Configurator, they obtains their base skin by doing something
+ * like SkinFactory.getSkin(null, "simple.desktop"); Then custom skin is created using the simple
+ * skin as base and put it into SkinFactory using SkinFactory.addSkin method. All skins registered
+ * using SkinFactory.addSkin method lands up here in ExternalSkinProvider. Such skins will not
+ * have the skin additions registered in trinidad-skins.xml because TrinidadSkinProvider was not
+ * able to kick in and provide this information. So we need to ensure that skins returned from
+ * ExternalSkinProvider the skin additions for that skin and its base skins are added, before we
* return them to the caller.
+ *
* @param context
* @param skin
* @return
*/
- private Skin _ensureSkinAdditions(FacesContext context, Skin skin)
+ private Skin _ensureSkinAdditions(ExternalContext context, Skin skin)
{
// It is possible to optimize here by keeping track of skins which already went through
// this process. Such optimization will avoid repeating this operation for skins which already
// went through this. However, this is a corner case as there are not many skins are registered
// like this. Moreover we are deprecating SkinFactory.addSkin and it may be removed
// in a later release, so there is no point in adding premature optimization.
- TrinidadSkinProvider trinidadSkinProvider = SkinUtils.getTrinidadSkinProvider(context);
+ TrinidadSkinProvider trinidadSkinProvider = TrinidadSkinProvider.getCurrentInstance(context);
trinidadSkinProvider.ensureSkinAdditions(skin);
return skin;
}
@@ -157,8 +161,8 @@ public class ExternalSkinProvider extend
/**
* Key for the ExternalSkinProvider stored in ExternalContext
*/
- public static final String EXTERNAL_SKIN_PROVIDER_KEY =
+ public static final String EXTERNAL_SKIN_PROVIDER_KEY =
"org.apache.myfaces.trinidad.skin.EXTERNAL_SKIN_PROVIDER_INSTANCE";
-
- private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(ExternalSkinProvider.class);
+ private static final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(ExternalSkinProvider.class);
}
\ No newline at end of file
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/SkinProviderRegistry.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/SkinProviderRegistry.java?rev=1547514&r1=1547513&r2=1547514&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/SkinProviderRegistry.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/SkinProviderRegistry.java Tue Dec 3 18:31:33 2013
@@ -22,7 +22,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
@@ -31,17 +33,16 @@ import org.apache.myfaces.trinidad.skin.
import org.apache.myfaces.trinidad.skin.SkinProvider;
import org.apache.myfaces.trinidad.skin.SkinVersion;
import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
-import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants;
import org.apache.myfaces.trinidadinternal.skin.SkinUtils;
/**
* Internal implementation of SkinProvider which is exposed using SkinProvider.getCurrentInstance()
- * This class collates all SkinProvider SPIs, Trinidad SkinProviders
- * and SkinFactory to return the best match for a Skin requested
- * This class reads all registered SPIs using org.apache.myfaces.trinidad.skin.SkinProvider
- *<p/>
- * Instance of this class is created and put into the ExternalContext during
- * bootstrap in GlobalConfiguratorImpl and retrieved in the static factory inside SkinProvider
+ * This class collates all SkinProvider SPIs, Trinidad SkinProviders and SkinFactory to return the
+ * best match for a Skin requested This class reads all registered SPIs using
+ * org.apache.myfaces.trinidad.skin.SkinProvider
+ * <p/>
+ * Instance of this class is created and put into the ExternalContext during bootstrap in
+ * GlobalConfiguratorImpl and retrieved in the static factory inside SkinProvider
* <p/>
*/
public class SkinProviderRegistry extends SkinProvider
@@ -49,6 +50,7 @@ public class SkinProviderRegistry extend
public SkinProviderRegistry()
{
+ ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
List<SkinProvider> services = ClassLoaderUtils.getServices(SkinProvider.class.getName());
if (_LOG.isFine())
@@ -62,7 +64,7 @@ public class SkinProviderRegistry extend
if (_LOG.isFine())
_LOG.fine("Adding TrinidadSkinProvider... ");
- providers.add(SkinUtils.getTrinidadSkinProvider(null));
+ providers.add(TrinidadSkinProvider.getCurrentInstance(context));
if (_LOG.isFine())
_LOG.fine("Adding TrinidadBaseSkinProvider... ");
@@ -72,13 +74,13 @@ public class SkinProviderRegistry extend
if (_LOG.isFine())
_LOG.fine("Adding ExternalSkinProvider... ");
- providers.add(SkinUtils.getExternalSkinProvider(null));
+ providers.add(ExternalSkinProvider.getCurrentInstance(context));
_providers = Collections.unmodifiableList(providers);
}
@Override
- public Collection<SkinMetadata> getSkinMetadata(FacesContext context)
+ public Collection<SkinMetadata> getSkinMetadata(ExternalContext context)
{
Collection<SkinMetadata> metadata = new ArrayList<SkinMetadata>();
@@ -90,19 +92,18 @@ public class SkinProviderRegistry extend
/**
* @param context
- * @param skinMetadata search criteria object containing the information of skin to be queried
- * id, family, renderKit, version are the information used from skin metadata
- * to perform search for the skin requested.
- * Other fields do not participate in the search.
- * @return matching skin for the search criteria passed,
- * if none found, return the simple skin for the renderKit in search criteria
- * if renderKit not specified in search criteria, skinMetadata automatically assumes it as
- * SkinMetadata.RenderKitId.DESKTOP
+ * @param skinMetadata search criteria object containing the information of skin to be queried id,
+ * family, renderKit, version are the information used from skin metadata to
+ * perform search for the skin requested. Other fields do not participate in
+ * the search.
+ * @return matching skin for the search criteria passed, if none found, return the simple skin for
+ * the renderKit in search criteria if renderKit not specified in search criteria, skinMetadata
+ * automatically assumes it as SkinMetadata.RenderKitId.DESKTOP
*/
@Override
- public Skin getSkin(FacesContext context, SkinMetadata skinMetadata)
+ public Skin getSkin(ExternalContext context, SkinMetadata skinMetadata)
{
- _handleCircularDependency(context, skinMetadata);
+ _handleCircularDependency(skinMetadata);
List<Skin> matchingSkins = new ArrayList<Skin>();
Skin matchingSkin = null;
@@ -141,11 +142,13 @@ public class SkinProviderRegistry extend
if (_LOG.isFine())
_LOG.fine("NO MATCH. Will return a simple skin or null for skin metadata: " + skinMetadata);
- assert (skinMetadata.getRenderKitId() != null);
+ assert (skinMetadata.getRenderKitId() != null);
// if renderKit is available return the simple skin for that renderKit
// skinMetadata.getRenderKitId() can never be null, default renderKit will always be DESKTOP
- return _returnSkin(context, skinMetadata,
- SkinUtils.getDefaultSkinForRenderKitId(this, context, skinMetadata.getRenderKitId()));
+ return _returnSkin(skinMetadata,
+ SkinUtils.getDefaultSkinForRenderKitId(this,
+ context,
+ skinMetadata.getRenderKitId()));
}
@@ -157,7 +160,7 @@ public class SkinProviderRegistry extend
if (_LOG.isFine())
_LOG.fine("returning ONLY match for skin metadata: " + skinMetadata);
- return _returnSkin(context, skinMetadata, matchingSkins.get(0));
+ return _returnSkin(skinMetadata, matchingSkins.get(0));
}
// at this point we have more than one matches for the search criteria passed
@@ -166,7 +169,9 @@ public class SkinProviderRegistry extend
}
/**
- * ensure sanity in the list of matches received by filtering the skins based on id, family and renderKit
+ * ensure sanity in the list of matches received by filtering the skins based on id, family and
+ * renderKit
+ *
* @param skins
* @param metadata
* @return
@@ -195,7 +200,8 @@ public class SkinProviderRegistry extend
return filterList;
}
- // if family based filtering resulted in multiple matches, or if family and id are not specified,
+ // if family based filtering resulted in multiple matches, or if family and id are not
+ // specified,
// proceed with renderKit based filtering.
filterList = _renderKitFilter(filterList, metadata.getRenderKitId());
@@ -204,6 +210,7 @@ public class SkinProviderRegistry extend
/**
* filter based on skin id, if mentioned. Otherwise return the list as is
+ *
* @param skins
* @param id
* @return
@@ -224,6 +231,7 @@ public class SkinProviderRegistry extend
/**
* filter based on skin family, if mentioned. Otherwise return the list as is
+ *
* @param skins
* @param family
* @return
@@ -244,6 +252,7 @@ public class SkinProviderRegistry extend
/**
* filter based on skin renderkit id, if mentioned. Otherwise return the list as is
+ *
* @param skins
* @param renderKitId
* @return
@@ -263,17 +272,18 @@ public class SkinProviderRegistry extend
}
/**
- * filter based on version
- * if version is mentioned try to return exact match
- * else if version is not mentioned or version is default try to return default skin
- * else try to return leaf skin
+ * filter based on version if version is mentioned try to return exact match else if version is
+ * not mentioned or version is default try to return default skin else try to return leaf skin
* else return first match
+ *
* @param context
* @param searchCriteria
* @param matchingSkins
* @return
*/
- private Skin _versionFilter(FacesContext context, SkinMetadata searchCriteria, List<Skin> matchingSkins)
+ private Skin _versionFilter(ExternalContext context,
+ SkinMetadata searchCriteria,
+ List<Skin> matchingSkins)
{
SkinVersion version = searchCriteria.getVersion();
Skin matchingSkin;
@@ -288,7 +298,7 @@ public class SkinProviderRegistry extend
if (_LOG.isFine())
_LOG.fine("returning exact version match.");
- return _returnSkin(context, searchCriteria, matchingSkin);
+ return _returnSkin(searchCriteria, matchingSkin);
}
// either user is looking for default version or did not find the version requested
@@ -300,7 +310,7 @@ public class SkinProviderRegistry extend
{
if (_LOG.isFine())
_LOG.fine("returning DEFAULT version match.");
- return _returnSkin(context, searchCriteria, matchingSkin);
+ return _returnSkin(searchCriteria, matchingSkin);
}
// the version that user asked for is not available
@@ -313,40 +323,35 @@ public class SkinProviderRegistry extend
if (_LOG.isFine())
_LOG.fine("return LEAF skin or one of the matches.");
- return _returnSkin(context, searchCriteria, matchingSkin);
+ return _returnSkin(searchCriteria, matchingSkin);
}
// we failed to find any better result for the given version, so return first match
if (_LOG.isFine())
_LOG.fine("nothing worked so return first match.");
- return _returnSkin(context, searchCriteria, matchingSkins.get(0));
+ return _returnSkin(searchCriteria, matchingSkins.get(0));
}
- private Skin _returnSkin(FacesContext context, SkinMetadata skinMetadata, Skin skin)
+ private Skin _returnSkin(SkinMetadata skinMetadata, Skin skin)
{
- // nothing to do if context is not available
- if (context == null)
- return skin;
+ FacesContext context = FacesContext.getCurrentInstance();
- Object o = context.getAttributes().get(_SKIN_PROVIDER_CONTEXT);
- List<SkinMetadata> requesters = null;
+ Map attrMap = context.getAttributes();
+ Object o = attrMap.get(_SKIN_PROVIDER_CONTEXT);
+ List<SkinMetadata> requesters;
- if (o == null)
+ if (o != null)
{
- requesters = new ArrayList<SkinMetadata>();
- context.getAttributes().put(_SKIN_PROVIDER_CONTEXT, requesters);
- }
- else
requesters = (List) o;
+ // remove the skinMetadata
+ requesters.remove(skinMetadata);
- // remove the skinMetadata
- requesters.remove(skinMetadata);
-
- if (_LOG.isFiner())
- {
- _LOG.finer("Removing " + skinMetadata + " from context");
- _LOG.finer("Context now is " + requesters);
+ if (_LOG.isFiner())
+ {
+ _LOG.finer("Removing " + skinMetadata + " from context");
+ _LOG.finer("Context now is " + requesters);
+ }
}
return skin;
@@ -354,6 +359,7 @@ public class SkinProviderRegistry extend
/**
* find a skin with version passed
+ *
* @param skins
* @param version
* @return
@@ -382,10 +388,10 @@ public class SkinProviderRegistry extend
}
/**
- * Latest skin is the one which is last in the family hierarchy
- * eg: fusion-v1 -> fusion-v2 -> fusion-v3
- * Among this fusion-v3 is the latest. So we look for a skin that is
- * not extended by any other skin in the family.
+ * Latest skin is the one which is last in the family hierarchy eg: fusion-v1 -> fusion-v2 ->
+ * fusion-v3 Among this fusion-v3 is the latest. So we look for a skin that is not extended by any
+ * other skin in the family.
+ *
* @param skins
* @return
*/
@@ -430,6 +436,7 @@ public class SkinProviderRegistry extend
/**
* find a skin that has its SkinVersion set to 'default', if it exists.
+ *
* @param matchingSkinList A list of Skins that we will look through to find the 'default'.
* @return Skin with SkinVersion isDefault true, otherwise, null.
*/
@@ -451,19 +458,17 @@ public class SkinProviderRegistry extend
return null;
}
- private void _handleCircularDependency(FacesContext context, SkinMetadata skinMetadata)
+ private void _handleCircularDependency(SkinMetadata skinMetadata)
{
- // nothing to do if context is not available
- if (context == null)
- return;
-
- Object o = context.getAttributes().get(_SKIN_PROVIDER_CONTEXT);
+ FacesContext context = FacesContext.getCurrentInstance();
+ Map attrMap = context.getAttributes();
+ Object o = attrMap.get(_SKIN_PROVIDER_CONTEXT);
List<SkinMetadata> requesters = null;
if (o == null)
{
requesters = new ArrayList<SkinMetadata>();
- context.getAttributes().put(_SKIN_PROVIDER_CONTEXT, requesters);
+ attrMap.put(_SKIN_PROVIDER_CONTEXT, requesters);
}
else
requesters = (List) o;
@@ -471,7 +476,7 @@ public class SkinProviderRegistry extend
if (requesters.contains(skinMetadata))
{
String message = "Circlular dependency detected whille loading skin: " + skinMetadata
- + ". Requesters are: " + requesters;
+ + ". Requesters are: " + requesters;
if (_LOG.isSevere())
_LOG.severe(message);
@@ -490,7 +495,8 @@ public class SkinProviderRegistry extend
private final List<SkinProvider> _providers;
- private static final String _SKIN_PROVIDER_CONTEXT =
+ private static final String _SKIN_PROVIDER_CONTEXT =
"org.apache.myfaces.trinidadinternal.skin.provider.SkinProviderRegistry.Context";
- private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(SkinProviderRegistry.class);
+ private static final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(SkinProviderRegistry.class);
}
\ No newline at end of file
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/TrinidadBaseSkinProvider.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/TrinidadBaseSkinProvider.java?rev=1547514&r1=1547513&r2=1547514&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/TrinidadBaseSkinProvider.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/TrinidadBaseSkinProvider.java Tue Dec 3 18:31:33 2013
@@ -22,7 +22,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import javax.faces.context.FacesContext;
+import javax.faces.context.ExternalContext;
import org.apache.myfaces.trinidad.skin.Skin;
import org.apache.myfaces.trinidad.skin.SkinMetadata;
@@ -35,25 +35,45 @@ import org.apache.myfaces.trinidadintern
import org.apache.myfaces.trinidadinternal.renderkit.core.skin.SimpleDesktopSkin;
import org.apache.myfaces.trinidadinternal.renderkit.core.skin.SimplePdaSkin;
import org.apache.myfaces.trinidadinternal.renderkit.core.skin.SimplePortletSkin;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.CASABLANCA_DESKTOP_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.CASABLANCA_PDA_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.CASABLANCA_PORTLET_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.CASABLANCA_SKIN_FAMILY;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.CASABLANCA_STYLE_SHEET_NAME;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.MINIMAL_DESKTOP_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.MINIMAL_DESKTOP_STYLE_SHEET_NAME;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.MINIMAL_PDA_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.MINIMAL_PDA_STYLE_SHEET_NAME;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.MINIMAL_PORTLET_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.MINIMAL_PORTLET_STYLE_SHEET_NAME;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.MINIMAL_SKIN_FAMILY;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.SIMPLE_DESKTOP_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.SIMPLE_DESKTOP_LOCATION;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.SIMPLE_PDA_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.SIMPLE_PDA_LOCATION;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.SIMPLE_PORTLET_ID;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.SIMPLE_PORTLET_LOCATION;
-import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants.SIMPLE_SKIN_FAMILY;
+
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .CASABLANCA_DESKTOP_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .CASABLANCA_PDA_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .CASABLANCA_PORTLET_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .CASABLANCA_SKIN_FAMILY;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .CASABLANCA_STYLE_SHEET_NAME;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .MINIMAL_DESKTOP_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .MINIMAL_DESKTOP_STYLE_SHEET_NAME;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .MINIMAL_PDA_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .MINIMAL_PDA_STYLE_SHEET_NAME;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .MINIMAL_PORTLET_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .MINIMAL_PORTLET_STYLE_SHEET_NAME;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .MINIMAL_SKIN_FAMILY;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .SIMPLE_DESKTOP_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .SIMPLE_DESKTOP_LOCATION;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .SIMPLE_PDA_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .SIMPLE_PDA_LOCATION;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .SIMPLE_PORTLET_ID;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .SIMPLE_PORTLET_LOCATION;
+import static org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants
+ .SIMPLE_SKIN_FAMILY;
/**
* This SkinProvider creates the very base skins such as simple, minimal and casablanca
@@ -64,7 +84,7 @@ public class TrinidadBaseSkinProvider ex
* {@inheritDoc}
*/
@Override
- public Collection<SkinMetadata> getSkinMetadata(FacesContext context)
+ public Collection<SkinMetadata> getSkinMetadata(ExternalContext context)
{
return Collections.unmodifiableCollection(_METADATA);
}
@@ -73,7 +93,7 @@ public class TrinidadBaseSkinProvider ex
* {@inheritDoc}
*/
@Override
- protected Skin loadAvailableSkin(FacesContext context, SkinMetadata search)
+ protected Skin loadAvailableSkin(ExternalContext context, SkinMetadata search)
{
// avoid round trips to SkinProviderRegistry for trinidad base skins
// any base skin used in this provider is also a static skin and can be loaded locally
@@ -92,7 +112,7 @@ public class TrinidadBaseSkinProvider ex
if (search == _CASABLANCA_DESKTOP_METADATA)
{
parentSkin = _loadBaseSkinAndRegisterIfRequired(context, _SIMPLE_DESKTOP_METADATA);
- loadedSkin = new CasablancaDesktopSkin(parentSkin);
+ loadedSkin = new CasablancaDesktopSkin(parentSkin);
}
else if (search == _CASABLANCA_PDA_METADATA)
{
@@ -107,7 +127,7 @@ public class TrinidadBaseSkinProvider ex
else if (search == _MINIMAL_DESKTOP_METADATA)
{
parentSkin = _loadBaseSkinAndRegisterIfRequired(context, _SIMPLE_DESKTOP_METADATA);
- loadedSkin = new MinimalDesktopSkinExtension(parentSkin);
+ loadedSkin = new MinimalDesktopSkinExtension(parentSkin);
}
else if (search == _MINIMAL_PDA_METADATA)
{
@@ -135,7 +155,7 @@ public class TrinidadBaseSkinProvider ex
return loadedSkin;
}
- private Skin _loadBaseSkinAndRegisterIfRequired(FacesContext context, SkinMetadata metadata)
+ private Skin _loadBaseSkinAndRegisterIfRequired(ExternalContext context, SkinMetadata metadata)
{
Skin skin = getSkins().get(metadata);
@@ -150,40 +170,70 @@ public class TrinidadBaseSkinProvider ex
private final static Collection<SkinMetadata> _METADATA;
- private final static SkinMetadata _SIMPLE_DESKTOP_METADATA;
- private final static SkinMetadata _SIMPLE_PDA_METADATA;
- private final static SkinMetadata _SIMPLE_PORTLET_METADATA;
- private final static SkinMetadata _MINIMAL_DESKTOP_METADATA;
- private final static SkinMetadata _MINIMAL_PORTLET_METADATA;
- private final static SkinMetadata _MINIMAL_PDA_METADATA;
- private final static SkinMetadata _CASABLANCA_DESKTOP_METADATA;
- private final static SkinMetadata _CASABLANCA_PDA_METADATA;
- private final static SkinMetadata _CASABLANCA_PORTLET_METADATA;
-
- static {
- _SIMPLE_DESKTOP_METADATA = new SkinMetadata.Builder().id(SIMPLE_DESKTOP_ID).family(SIMPLE_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.DESKTOP).styleSheetName(SIMPLE_DESKTOP_LOCATION).build();
- _SIMPLE_PDA_METADATA = new SkinMetadata.Builder().id(SIMPLE_PDA_ID).family(SIMPLE_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.PDA).styleSheetName(SIMPLE_PDA_LOCATION).build();
- _SIMPLE_PORTLET_METADATA = new SkinMetadata.Builder().id(SIMPLE_PORTLET_ID).family(SIMPLE_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.PORTLET).styleSheetName(SIMPLE_PORTLET_LOCATION).build();
- _MINIMAL_DESKTOP_METADATA= new SkinMetadata.Builder().id(MINIMAL_DESKTOP_ID).family(MINIMAL_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.DESKTOP).baseSkinId(SIMPLE_DESKTOP_ID)
- .styleSheetName(MINIMAL_DESKTOP_STYLE_SHEET_NAME).build();
- _MINIMAL_PDA_METADATA = new SkinMetadata.Builder().id(MINIMAL_PDA_ID).family(MINIMAL_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.PDA).baseSkinId(SIMPLE_PDA_ID)
- .styleSheetName(MINIMAL_PDA_STYLE_SHEET_NAME).build();
- _MINIMAL_PORTLET_METADATA = new SkinMetadata.Builder().id(MINIMAL_PORTLET_ID).family(MINIMAL_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.PORTLET).baseSkinId(SIMPLE_PORTLET_ID)
- .styleSheetName(MINIMAL_PORTLET_STYLE_SHEET_NAME).build();
- _CASABLANCA_DESKTOP_METADATA = new SkinMetadata.Builder().id(CASABLANCA_DESKTOP_ID).family(CASABLANCA_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.DESKTOP).baseSkinId(SIMPLE_DESKTOP_ID)
- .styleSheetName(CASABLANCA_STYLE_SHEET_NAME).build();
- _CASABLANCA_PDA_METADATA = new SkinMetadata.Builder().id(CASABLANCA_PDA_ID).family(CASABLANCA_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.PDA).baseSkinId(SIMPLE_PDA_ID)
- .styleSheetName(CASABLANCA_STYLE_SHEET_NAME).build();
- _CASABLANCA_PORTLET_METADATA = new SkinMetadata.Builder().id(CASABLANCA_PORTLET_ID).family(CASABLANCA_SKIN_FAMILY)
- .renderKitId(SkinMetadata.RenderKitId.PORTLET).baseSkinId(SIMPLE_PORTLET_ID).build();
+ private final static SkinMetadata _SIMPLE_DESKTOP_METADATA;
+ private final static SkinMetadata _SIMPLE_PDA_METADATA;
+ private final static SkinMetadata _SIMPLE_PORTLET_METADATA;
+ private final static SkinMetadata _MINIMAL_DESKTOP_METADATA;
+ private final static SkinMetadata _MINIMAL_PORTLET_METADATA;
+ private final static SkinMetadata _MINIMAL_PDA_METADATA;
+ private final static SkinMetadata _CASABLANCA_DESKTOP_METADATA;
+ private final static SkinMetadata _CASABLANCA_PDA_METADATA;
+ private final static SkinMetadata _CASABLANCA_PORTLET_METADATA;
+
+ static
+ {
+ _SIMPLE_DESKTOP_METADATA =
+ new SkinMetadata.Builder().id(SIMPLE_DESKTOP_ID)
+ .family(SIMPLE_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.DESKTOP)
+ .styleSheetName(SIMPLE_DESKTOP_LOCATION)
+ .build();
+ _SIMPLE_PDA_METADATA = new SkinMetadata.Builder().id(SIMPLE_PDA_ID)
+ .family(SIMPLE_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.PDA)
+ .styleSheetName(SIMPLE_PDA_LOCATION)
+ .build();
+ _SIMPLE_PORTLET_METADATA =
+ new SkinMetadata.Builder().id(SIMPLE_PORTLET_ID)
+ .family(SIMPLE_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.PORTLET)
+ .styleSheetName(SIMPLE_PORTLET_LOCATION)
+ .build();
+ _MINIMAL_DESKTOP_METADATA =
+ new SkinMetadata.Builder().id(MINIMAL_DESKTOP_ID)
+ .family(MINIMAL_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.DESKTOP)
+ .baseSkinId(SIMPLE_DESKTOP_ID)
+ .styleSheetName(MINIMAL_DESKTOP_STYLE_SHEET_NAME)
+ .build();
+ _MINIMAL_PDA_METADATA =
+ new SkinMetadata.Builder().id(MINIMAL_PDA_ID).family(MINIMAL_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.PDA).baseSkinId(SIMPLE_PDA_ID)
+ .styleSheetName(MINIMAL_PDA_STYLE_SHEET_NAME).build();
+ _MINIMAL_PORTLET_METADATA =
+ new SkinMetadata.Builder().id(MINIMAL_PORTLET_ID)
+ .family(MINIMAL_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.PORTLET)
+ .baseSkinId(SIMPLE_PORTLET_ID)
+ .styleSheetName(MINIMAL_PORTLET_STYLE_SHEET_NAME)
+ .build();
+ _CASABLANCA_DESKTOP_METADATA =
+ new SkinMetadata.Builder().id(CASABLANCA_DESKTOP_ID)
+ .family(CASABLANCA_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.DESKTOP)
+ .baseSkinId(SIMPLE_DESKTOP_ID)
+ .styleSheetName(CASABLANCA_STYLE_SHEET_NAME)
+ .build();
+ _CASABLANCA_PDA_METADATA =
+ new SkinMetadata.Builder().id(CASABLANCA_PDA_ID).family(CASABLANCA_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.PDA).baseSkinId(SIMPLE_PDA_ID)
+ .styleSheetName(CASABLANCA_STYLE_SHEET_NAME).build();
+ _CASABLANCA_PORTLET_METADATA =
+ new SkinMetadata.Builder().id(CASABLANCA_PORTLET_ID)
+ .family(CASABLANCA_SKIN_FAMILY)
+ .renderKitId(SkinMetadata.RenderKitId.PORTLET)
+ .baseSkinId(SIMPLE_PORTLET_ID)
+ .build();
_METADATA = new ArrayList<SkinMetadata>(9);
_METADATA.add(_SIMPLE_DESKTOP_METADATA);
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/TrinidadSkinProvider.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/TrinidadSkinProvider.java?rev=1547514&r1=1547513&r2=1547514&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/TrinidadSkinProvider.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/provider/TrinidadSkinProvider.java Tue Dec 3 18:31:33 2013
@@ -24,22 +24,21 @@ import java.util.Collections;
import java.util.List;
import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.skin.Skin;
import org.apache.myfaces.trinidad.skin.SkinAddition;
import org.apache.myfaces.trinidad.skin.SkinMetadata;
import org.apache.myfaces.trinidad.skin.SkinProvider;
-import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants;
import org.apache.myfaces.trinidadinternal.skin.SkinExtension;
import org.apache.myfaces.trinidadinternal.skin.SkinUtils;
import org.apache.myfaces.trinidadinternal.skin.parse.SkinsNode;
/**
- * This is the Trinidad's SkinProvider for loading skins from trinidad-skins.xml. This provider reads and caches
- * trinidad-skins.xml from various sources like META-INF, WEB-INF and SkinResourceLoader API during its initialization.
- * Subsequently the Skin objects are created lazily using the cached metadata, only when it is first requested for.
+ * This is the Trinidad's SkinProvider for loading skins from trinidad-skins.xml. This provider
+ * reads and caches trinidad-skins.xml from various sources like META-INF, WEB-INF and
+ * SkinResourceLoader API during its initialization. Subsequently the Skin objects are created
+ * lazily using the cached metadata, only when it is first requested for.
*/
public final class TrinidadSkinProvider extends BaseSkinProvider
{
@@ -50,9 +49,9 @@ public final class TrinidadSkinProvider
"org.apache.myfaces.trinidad.skin.TRINDIAD_SKIN_PROVIDER_INSTANCE";
/**
- * static factory method to get hold of a TrinidadSkinProvider object
- * This can be used for easy creation of Skin object without having to
- * implement the abstract class
+ * static factory method to get hold of a TrinidadSkinProvider object This can be used for easy
+ * creation of Skin object without having to implement the abstract class
+ *
* @param ec
* @return
*/
@@ -61,12 +60,15 @@ public final class TrinidadSkinProvider
if (ec == null)
throw new NullPointerException("ExternalContext is passed as null");
- TrinidadSkinProvider trinidadSkinProvider = (TrinidadSkinProvider) ec.getApplicationMap().get(TRINDIAD_SKIN_PROVIDER_KEY);
+ TrinidadSkinProvider trinidadSkinProvider =
+ (TrinidadSkinProvider) ec.getApplicationMap().get(TRINDIAD_SKIN_PROVIDER_KEY);
return trinidadSkinProvider;
}
/**
- * used by ExternalSkinProvider to ensure that the skin and its base skin additions are added correctly
+ * used by ExternalSkinProvider to ensure that the skin and its base skin additions are added
+ * correctly
+ *
* @param skin
*/
public void ensureSkinAdditions(Skin skin)
@@ -85,7 +87,7 @@ public final class TrinidadSkinProvider
* {@inheritDoc}
*/
@Override
- public Collection<SkinMetadata> getSkinMetadata(FacesContext context)
+ public Collection<SkinMetadata> getSkinMetadata(ExternalContext context)
{
// already initialized to unmodifiableCollection
return _skinMetadata;
@@ -95,7 +97,7 @@ public final class TrinidadSkinProvider
* {@inheritDoc}
*/
@Override
- protected Skin loadAvailableSkin(FacesContext context, SkinMetadata skinMetadata)
+ protected Skin loadAvailableSkin(ExternalContext context, SkinMetadata skinMetadata)
{
SkinMetadata matchingNode = null;
@@ -110,19 +112,21 @@ public final class TrinidadSkinProvider
if (matchingNode == null)
{
- // This cannot happen because base class checks for availability before it calls for the skin to be loaded
+ // This cannot happen because base class checks for availability before it calls for the
+ // skin to be loaded
if (_LOG.isSevere())
- _LOG.severe("SP_LOADING_UNKNOWN_SKIN", new Object[] {skinMetadata.getId()});
+ _LOG.severe("SP_LOADING_UNKNOWN_SKIN", new Object[]{skinMetadata.getId()});
- throw new NullPointerException(_LOG.getMessage("SP_LOADING_UNKNOWN_SKIN", new Object[] {skinMetadata.getId()}));
+ throw new NullPointerException(_LOG.getMessage("SP_LOADING_UNKNOWN_SKIN",
+ new Object[]{skinMetadata.getId()}));
}
- String id = matchingNode.getId();
- String family = matchingNode.getFamily();
- String renderKitId = matchingNode.getRenderKitId();
+ String id = matchingNode.getId();
+ String family = matchingNode.getFamily();
+ String renderKitId = matchingNode.getRenderKitId();
Skin baseSkin = null;
String baseSkinId = matchingNode.getBaseSkinId();
- SkinProvider provider = SkinUtils.getSkinProvider(context);
+ SkinProvider provider = SkinProvider.getCurrentInstance(context);
if (provider != null && baseSkinId != null)
baseSkin = provider.getSkin(context, new SkinMetadata.Builder().id(baseSkinId).build());
@@ -172,11 +176,11 @@ public final class TrinidadSkinProvider
* {@inheritDoc}
*/
@Override
- protected void initialize(FacesContext context)
+ protected void initialize(ExternalContext extCtxt)
{
- if (context == null || context.getExternalContext() == null)
+ if (extCtxt == null)
{
- return;
+ throw new NullPointerException("ExternalContext is passed as null");
}
if (_skinMetadata == null)
@@ -185,14 +189,13 @@ public final class TrinidadSkinProvider
_LOG.fine("init provider.");
// only now do initialization
- ExternalContext extCtxt = context.getExternalContext();
List<SkinsNode> skinsNodes = SkinUtils.buildSkinsNodes(extCtxt);
List<SkinMetadata> skinNodes = new ArrayList<SkinMetadata>();
List<SkinAddition> skinAdditionNodes = new ArrayList<SkinAddition>();
for (SkinsNode node : skinsNodes)
{
- if (node != null)
+ if (node != null)
{
skinNodes.addAll(node.getSkinNodes());
skinAdditionNodes.addAll(node.getSkinAdditionNodes());
@@ -239,5 +242,6 @@ public final class TrinidadSkinProvider
private List<SkinMetadata> _skinMetadata;
private List<SkinAddition> _skinAdditionNodes;
- private final static TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(TrinidadSkinProvider.class);
+ private final static TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(TrinidadSkinProvider.class);
}
\ No newline at end of file
Modified: myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java?rev=1547514&r1=1547513&r2=1547514&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java Tue Dec 3 18:31:33 2013
@@ -28,6 +28,7 @@ import java.io.Writer;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import java.util.logging.Handler;
import java.util.logging.Level;
@@ -161,7 +162,7 @@ abstract public class RenderKitTestCase
}
@Override
- protected void setUp() throws IOException
+ protected void setUp() throws IOException
{
_facesContext = createMockFacesContext(MApplication.sharedInstance(), true);
_requestContext = createRequestContext();
@@ -181,17 +182,20 @@ abstract public class RenderKitTestCase
if (service != null)
service.encodeBegin(_facesContext);
-
}
-
+
protected MFacesContext createMockFacesContext(
Application mockApplication,
boolean testMode)
{
MFacesContext ctx = new MFacesContext(mockApplication, testMode);
- ctx.getExternalContext().getApplicationMap().put(TrinidadSkinProvider.TRINDIAD_SKIN_PROVIDER_KEY, new TrinidadSkinProvider());
- ctx.getExternalContext().getApplicationMap().put(ExternalSkinProvider.EXTERNAL_SKIN_PROVIDER_KEY, new ExternalSkinProvider());
- ctx.getExternalContext().getApplicationMap().put(SkinProvider.SKIN_PROVIDER_INSTANCE_KEY, new SkinProviderRegistry());
+ Map<String, Object> applicatationMap = ctx.getExternalContext().getApplicationMap();
+ applicatationMap.put(TrinidadSkinProvider.TRINDIAD_SKIN_PROVIDER_KEY,
+ new TrinidadSkinProvider());
+ applicatationMap.put(ExternalSkinProvider.EXTERNAL_SKIN_PROVIDER_KEY,
+ new ExternalSkinProvider());
+ applicatationMap.put(SkinProvider.SKIN_PROVIDER_INSTANCE_KEY,
+ new SkinProviderRegistry());
return ctx;
}
@@ -201,7 +205,7 @@ abstract public class RenderKitTestCase
}
@Override
- protected void tearDown() throws IOException
+ protected void tearDown() throws IOException
{
ExtendedRenderKitService service =
_getExtendedRenderKitService(_facesContext);
@@ -241,7 +245,7 @@ abstract public class RenderKitTestCase
{
RenderUtils.encodeRecursive(_facesContext, root);
}
-
+
protected void initializeContext(Writer out) throws IOException
{
_facesContext.getExternalContext().getRequestMap().clear();
@@ -272,24 +276,27 @@ abstract public class RenderKitTestCase
}
@Override
- public void flush() { }
+ public void flush()
+ {
+ }
@Override
- public void close() { }
+ public void close()
+ {
+ }
}
- private TestResult _result;
- private MFacesContext _facesContext;
- private MRequestContext _requestContext;
- private String _skin;
- private String _outputMode;
- private Agent _agent;
- private RequestContext.Accessibility _accMode;
- private boolean _rightToLeft;
+ private TestResult _result;
+ private MFacesContext _facesContext;
+ private MRequestContext _requestContext;
+ private String _skin;
+ private String _outputMode;
+ private Agent _agent;
+ private RequestContext.Accessibility _accMode;
+ private boolean _rightToLeft;
}
-
public class RendererTest extends BaseTest
{
public RendererTest(String name,
@@ -300,9 +307,8 @@ abstract public class RenderKitTestCase
_scriptName = name + ".xml";
File scriptFile = new File(_scriptDir, _scriptName);
- _script =
- TestScriptParser.getTestScript(scriptFile, _facesConfigInfo);
- _lenient = lenient;
+ _script = TestScriptParser.getTestScript(scriptFile, _facesConfigInfo);
+ _lenient = lenient;
// We run golden-file checks on each subtest - though all differences
@@ -324,7 +330,7 @@ abstract public class RenderKitTestCase
}
@Override
- protected void tearDown() throws IOException
+ protected void tearDown() throws IOException
{
super.tearDown();
_script = null;
@@ -343,17 +349,17 @@ abstract public class RenderKitTestCase
StringWriter first = new StringWriter();
docRoot.getChildren().add(new GatherContent(first,
- _createComponent(),
- getResult(),
- this,
- _lenient));
+ _createComponent(),
+ getResult(),
+ this,
+ _lenient));
StringWriter base = new StringWriter();
docRoot.getChildren().add(new GatherContent(base,
- _createComponent(),
- getResult(),
- this,
- _lenient));
+ _createComponent(),
+ getResult(),
+ this,
+ _lenient));
Iterator<TestScript.Test> tests = _script.getTests().iterator();
while (tests.hasNext())
@@ -364,13 +370,12 @@ abstract public class RenderKitTestCase
test.apply(getFacesContext(), testComponent);
docRoot.getChildren().add(new GatherContent(test.getOutput(),
- testComponent,
- getResult(),
- this,
- _lenient));
+ testComponent,
+ getResult(),
+ this,
+ _lenient));
}
-
renderRoot(root);
@@ -423,7 +428,7 @@ abstract public class RenderKitTestCase
getResult().addError(this, failure);
}
else if (test.shouldMatchBase() &&
- !baseResults.equals(testResults))
+ !baseResults.equals(testResults))
{
AssertionFailedError failure = new AssertionFailedError(
"Result of " + test.toString() + " were not identical to " +
@@ -477,13 +482,13 @@ abstract public class RenderKitTestCase
private UIComponent _createComponent()
{
- return _script.getDefinition().createComponent(getFacesContext());
+ return _script.getDefinition().createComponent(getFacesContext());
}
- private int _testCaseCount;
- private String _scriptName;
- private TestScript _script;
- private boolean _lenient;
+ private int _testCaseCount;
+ private String _scriptName;
+ private TestScript _script;
+ private boolean _lenient;
}
@@ -551,10 +556,10 @@ abstract public class RenderKitTestCase
}
}
}
-
+
protected void addRendererTest(
- String name,
- SuiteDefinition definition,
+ String name,
+ SuiteDefinition definition,
boolean lenient) throws IOException, SAXException
{
RendererTest test = new RendererTest(name, definition, lenient);
@@ -562,13 +567,14 @@ abstract public class RenderKitTestCase
{
addTest(test);
}
- }
+ }
protected abstract UIComponent populateDefaultComponentTree(
UIViewRoot root,
TestScript script);
protected abstract Iterable<SuiteDefinition> getSuiteDefinitions();
+
protected abstract String getRenderKitId();
static public class SuiteDefinition
@@ -582,7 +588,7 @@ abstract public class RenderKitTestCase
{
this(category, skin, accessibilityMode, agent, rightToLeft, null);
}
-
+
public SuiteDefinition(
String category,
String skin,
@@ -590,11 +596,11 @@ abstract public class RenderKitTestCase
Agent agent,
boolean rightToLeft,
String outputMode)
- {
+ {
_category = category;
- _skin = skin;
- _accessibilityMode = accessibilityMode;
- _agent = agent;
+ _skin = skin;
+ _accessibilityMode = accessibilityMode;
+ _agent = agent;
_rightToLeft = rightToLeft;
_outputMode = outputMode;
}
@@ -612,7 +618,7 @@ abstract public class RenderKitTestCase
public String getOutputMode()
{
return _outputMode;
- }
+ }
public RequestContext.Accessibility getAccessibilityMode()
{
@@ -630,12 +636,12 @@ abstract public class RenderKitTestCase
return _rightToLeft;
}
- private String _category;
- private String _skin;
- private String _outputMode;
+ private String _category;
+ private String _skin;
+ private String _outputMode;
private RequestContext.Accessibility _accessibilityMode;
- private Agent _agent;
- private boolean _rightToLeft;
+ private Agent _agent;
+ private boolean _rightToLeft;
}
static private ExtendedRenderKitService _getExtendedRenderKitService(
@@ -647,7 +653,7 @@ abstract public class RenderKitTestCase
static private FacesConfigInfo _facesConfigInfo;
- static private File _scriptDir;
- static private File _goldenDir;
- static private File _failureDir;
+ static private File _scriptDir;
+ static private File _goldenDir;
+ static private File _failureDir;
}