Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.myfaces.trinidadinternal.skin;
import java.beans.Beans;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.context.RenderingContext;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.resource.SkinResourceLoader;
import org.apache.myfaces.trinidad.share.io.NameResolver;
import org.apache.myfaces.trinidad.skin.CustomMetadata;
import org.apache.myfaces.trinidad.skin.Icon;
import org.apache.myfaces.trinidad.skin.Skin;
import org.apache.myfaces.trinidad.skin.SkinAddition;
import org.apache.myfaces.trinidad.skin.SkinFeatures;
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.trinidad.util.ClassLoaderUtils;
import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderingContext;
import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TrinidadRenderingConstants;
import org.apache.myfaces.trinidadinternal.share.xml.ClassParserFactory;
import org.apache.myfaces.trinidadinternal.share.xml.ParseContextImpl;
import org.apache.myfaces.trinidadinternal.share.xml.ParserFactory;
import org.apache.myfaces.trinidadinternal.share.xml.ParserManager;
import org.apache.myfaces.trinidadinternal.share.xml.TreeBuilder;
import org.apache.myfaces.trinidadinternal.share.xml.XMLProvider;
import org.apache.myfaces.trinidadinternal.share.xml.XMLUtils;
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.style.StyleContext;
import org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetDocument;
import org.apache.myfaces.trinidadinternal.util.JsonUtils;
import org.xml.sax.InputSource;
/**
* Utility functions for creating Skin objects and SkinExtension objects
* from the trinidad-skins.xml file and
* adding them to the SkinFactory. It also adds SkinAdditions to the Skin objects.
* @version $Name: $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/skin/SkinUtils.java#0 $) $Date: 10-nov-2005.18:59:00 $
*/
public class SkinUtils
{
/**
* An enumeration which determined how much information to return in the skin
* debug info.
*/
public static enum DebugInfoLevel
{
TERSE,
NORMAL,
VERBOSE;
@SuppressWarnings("compatibility:-5980442644319693066")
private static final long serialVersionUID = 1L;
}
/**
* 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
*/
public static FacesContext getNonNullFacesContext(FacesContext context)
{
if (context != null)
return context;
// 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("FacesContext is null. Cannot retrieve default FacesContext");
return 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.
*/
public static Skin getDefaultSkinForRenderKitId(
SkinProvider provider,
ExternalContext context,
String renderKitId)
{
if (provider == null || context == null)
throw new NullPointerException("SkinProvider or FacesContext is passed as null.");
String defaultSkinId;
if (TrinidadRenderingConstants.APACHE_TRINIDAD_PORTLET.equals(renderKitId))
defaultSkinId = TrinidadRenderingConstants.SIMPLE_PORTLET_ID;
else if (TrinidadRenderingConstants.APACHE_TRINIDAD_PDA.equals(renderKitId))
defaultSkinId = TrinidadRenderingConstants.SIMPLE_PDA_ID;
else
defaultSkinId = TrinidadRenderingConstants.SIMPLE_DESKTOP_ID;
Skin defaultSkin = provider.getSkin(context,
new SkinMetadata.Builder().id(defaultSkinId).build());
assert (defaultSkin != null);
return defaultSkin;
}
/**
* Builds the SkinMetadata hierarchy from trinidad-skins.xml
*
* @return
*/
static public List buildSkinsNodes(ExternalContext extCtxt)
{
List metaInfSkinsNode = _getMetaInfSkinsNodeList();
SkinsNode webInfSkinsNode = _getWebInfSkinsNode(extCtxt);
List resourceLoaderSkinsNodes =
_getSkinsNodesFromSkinResourceLoaderServices(extCtxt);
List skinsNodes = new ArrayList(20);
if (metaInfSkinsNode != null)
skinsNodes.addAll(metaInfSkinsNode);
if (webInfSkinsNode != null)
skinsNodes.add(webInfSkinsNode);
if (resourceLoaderSkinsNodes != null)
skinsNodes.addAll(resourceLoaderSkinsNodes);
return skinsNodes;
}
/**
* Returns the actual Icon referenced by 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.
*/
static public Icon resolveReferenceIcon(
Skin skin,
ReferenceIcon refIcon)
{
return _resolveReferenceIcon(skin, refIcon, null);
}
/**
* Returns skin debug information of DebugInfoLevel.NORMAL.
*
* @param skin
* @return
*/
public static String getSkinDebugInfo(Skin skin)
{
return getSkinDebugInfo(skin, DebugInfoLevel.NORMAL);
}
/**
* Returns a JSON object containing debug information for a skin depending on
* the DebugInfoLevel. This will return a information on the supplied skin and
* any skin it extends so that information on the skin heirarcy can be
* obtained. If DebugInfoLevel.VERBOSE is specified, this will return a class
* containing the following information:
*
* id: the skin id
* family: the skin family
* version: the skin version
* renderkit: the skin render kit
* documentId: the current document checksum
* document: the full path to the css document
* features: a map of name/value pairs for the skinning features
* additions: a list of skinning additions (see below) for this skin
* parent: the json object for the stylesheet this skin extends (if any)
*
* Skinning additions consist of the following properties:
*
* document: the full path to the css document
* documentId: the skin addition checksum
*
* The 'parent' property is only provided if the skin is a skin extension
* and the documentId in both the skin additions as well as the main skin object
* is provided only if we have a valid RenderingContext.
*
* If DebugInfoLevel is NORMAL, all of the 'document' properties will contain a
* location WITHIN the current classpath as opposed to the full resource path.
*
* If DebugInfoLevel is TERSE, then information on the document, features, and
* additions will not be provided for any object.
*
* This information is in JSON format so that it can be quickly parsed and compared
* to other skin information.
*
* @param skin
* @param level
* @return
*/
public static String getSkinDebugInfo(Skin skin, DebugInfoLevel level)
{
assert (null != skin);
StringBuilder sb = new StringBuilder();
try
{
JsonUtils.writeObject(sb, _getDebugInfoMap(skin, level), false);
}
catch (IOException e)
{
//We should never hit this because we control the object and the socket, but
//if we do, we should wrap it in a runtime exception.
throw new RuntimeException(e);
}
return sb.toString();
}
static private Map _getDebugInfoMap(Skin skin, DebugInfoLevel level)
{
assert (null != skin);
RenderingContext rc = RenderingContext.getCurrentInstance();
StringBuilder sb = new StringBuilder();
//The Map which will be converted into JSON
Map m = new LinkedHashMap();
m.put("id", skin.getId());
m.put("family", skin.getFamily());
m.put("version", skin.getVersion().getName());
m.put("renderkit", skin.getRenderKitId());
if(null != rc)
{
m.put("documentId", skin.getStyleSheetDocumentId(rc));
}
//Skip all of this information for terse logging
if(!DebugInfoLevel.TERSE.equals(level))
{
m.put("document", _getStyleSheetLocation(skin.getStyleSheetName(), level));
m.put("features", skin.getSkinFeatures());
StyleContext sctx =(null != rc && rc instanceof CoreRenderingContext)?((CoreRenderingContext)rc).getStyleContext():null;
List additions = skin.getSkinAdditions();
List