if (renderKitId == null)
renderKitId = XhtmlConstants.APACHE_TRINIDAD_DESKTOP;
// loop through each skin in the SkinFactory
// and see if the family and the renderKitId match
Skin matchingSkin = null;
List<Skin> matchingSkinList = new ArrayList<Skin>();
for(Skin skin : _skins.values())
{
if (family.equalsIgnoreCase(skin.getFamily()) &&
renderKitId.equalsIgnoreCase(skin.getRenderKitId()))
{
// exact family+renderKitId match!
matchingSkinList.add(skin);
}
}
if (matchingSkinList.isEmpty())
{
// if we get here, that means we couldn't find an exact
// family/renderKitId match, so return the simple skin
// that matches the renderkitid.
if (_LOG.isWarning())
{
_LOG.warning("CANNOT_FIND_MATCHING_SKIN", new Object[]{family, renderKitId});
}
if (renderKitId.equals(XhtmlConstants.APACHE_TRINIDAD_PORTLET))
matchingSkin = getSkin(context, _SIMPLE_PORTLET);
else if (renderKitId.equals(XhtmlConstants.APACHE_TRINIDAD_PDA))
matchingSkin = getSkin(context, _SIMPLE_PDA);
else
matchingSkin = getSkin(context, _SIMPLE_DESKTOP);
}
else
{
// at this point we know we have something in the matchingSkinList
// which is a list of matching family and renderKitId skins. Now match the version
// to find the best matched skin.
boolean foundMatchingSkin = false;
boolean versionIsDefault = (_DEFAULT.compareToIgnoreCase(version) == 0);
// if the user didn't ask for the 'default' version, then look for the exact match
if (!versionIsDefault)
{
for (Skin skin : matchingSkinList)
{
SkinVersion skinVersion = skin.getVersion();
if (skinVersion != null)
{
String name = skinVersion.getName();
if (version.equals(name))
{
matchingSkin = skin;
break;
}
}
}
}
// matchingSkin will be null if an exact version match (family+renderKitId+exact version) was not found;
// we can have an exact version match if the user asks for null version, and we find a skin with no
// version set.
if (matchingSkin == null || versionIsDefault)
{
// find skin with version= default
matchingSkin = _getDefaultVersionSkin(matchingSkinList);
if (matchingSkin == null)
{
// get the last skin in the matchingSkinList if there is no skin marked default.
matchingSkin = matchingSkinList.get(matchingSkinList.size() -1);
}
else if ((matchingSkin != null) && versionIsDefault)
{
// found the default skin the user wanted
foundMatchingSkin = true;
}
} // end matchingSkin == null || versionIsDefault
else
{
foundMatchingSkin = true;
}
// log messages
if (foundMatchingSkin)
{
if (_LOG.isFine())
_LOG.fine("GET_SKIN_FOUND_SKIN_VERSION",
new Object[]{family, version, matchingSkin.getId()});
}
else
{
if(_LOG.isWarning())
{
if ("".equals(version))
{
_LOG.warning("GET_SKIN_CANNOT_FIND_NO_VERSION",
new Object[]{family, matchingSkin.getId()});
}
else
{
_LOG.warning("GET_SKIN_CANNOT_FIND_SKIN_VERSION",
new Object[]{family, version, matchingSkin.getId()});
}
}
}
}