Search in sources :

Example 26 with Resource

use of javax.faces.application.Resource in project liferay-faces-alloy by liferay.

the class MediaRenderer method encodeFlashPlayer.

protected void encodeFlashPlayer(FacesContext facesContext, ResponseWriter responseWriter, Media media, String mediaResourceURL) throws IOException {
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    boolean browserIE = browserSniffer.isIe();
    responseWriter.startElement("object", null);
    encodeMediaSize(responseWriter, media);
    Application application = facesContext.getApplication();
    ResourceHandler resourceHandler = application.getResourceHandler();
    Object flashPlayer = media.getFlashPlayer();
    String flashPlayerURL;
    // If the developer has specified a Flash player, then
    if (flashPlayer != null) {
        flashPlayerURL = getEncodedResourceURL(facesContext, resourceHandler, application, flashPlayer);
    } else // Otherwise, get the default Alloy Flash player.
    {
        Resource defaultFlashPlayerResource = resourceHandler.createResource(getDefaultFlashPlayerName(), "liferay-faces-alloy");
        String defaultFlashPlayerRequestPath = defaultFlashPlayerResource.getRequestPath();
        ExternalContext externalContext = facesContext.getExternalContext();
        flashPlayerURL = externalContext.encodeResourceURL(defaultFlashPlayerRequestPath);
    }
    if (browserIE) {
        responseWriter.writeAttribute("classid", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", null);
        String flashPlayerVersion = media.getFlashPlayerVersion();
        String codebaseURL = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=".concat(flashPlayerVersion);
        responseWriter.writeAttribute("codebase", codebaseURL, null);
        responseWriter.startElement("param", null);
        responseWriter.writeAttribute("name", "movie", null);
        responseWriter.writeAttribute("value", flashPlayerURL, null);
        responseWriter.endElement("param");
    } else {
        responseWriter.writeAttribute("data", flashPlayerURL, null);
        responseWriter.writeAttribute("type", "application/x-shockwave-flash", null);
    }
    encodeFlashPlayerChildren(facesContext, responseWriter, media, mediaResourceURL, resourceHandler, application, (flashPlayer == null));
    responseWriter.endElement("object");
}
Also used : BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) ExternalContext(javax.faces.context.ExternalContext) Resource(javax.faces.application.Resource) FacesResource(com.liferay.faces.util.application.FacesResource) ResourceHandler(javax.faces.application.ResourceHandler) Application(javax.faces.application.Application)

Example 27 with Resource

use of javax.faces.application.Resource in project liferay-faces-bridge-ext by liferay.

the class JSResourceWithDisabledAMDLoaderImpl method initFilteredResourceCache.

/**
 * This method initializes the filtered resource cache for JSResourceWithDisabledAMDLoaderImpl. The initialization
 * cannot be performed in the constructor of {@link
 * com.liferay.faces.bridge.ext.application.internal.ResourceHandlerLiferayImpl} since that class is created before
 * the {@link CacheFactory} has been created. This method is called in {@link
 * com.liferay.faces.bridge.ext.event.internal.PostConstructApplicationConfigEventListener#processEvent(javax.faces.event.SystemEvent)
 * } to ensure that the CacheFactory has been created.
 *
 * @param  initFacesContext
 */
public static void initFilteredResourceCache(FacesContext initFacesContext) {
    if (!initFacesContext.isProjectStage(ProjectStage.Development)) {
        ExternalContext externalContext = initFacesContext.getExternalContext();
        Cache<String, Resource> filteredResourceCache;
        int initialCacheCapacity = LiferayPortletConfigParam.DisabledAMDLoaderResourcesInitialCacheCapacity.getIntegerValue(externalContext);
        int maxCacheCapacity = LiferayPortletConfigParam.DisabledAMDLoaderResourcesMaxCacheCapacity.getIntegerValue(externalContext);
        if (maxCacheCapacity > -1) {
            filteredResourceCache = CacheFactory.getConcurrentLRUCacheInstance(externalContext, initialCacheCapacity, maxCacheCapacity);
        } else {
            filteredResourceCache = CacheFactory.getConcurrentCacheInstance(externalContext, initialCacheCapacity);
        }
        Map<String, Object> applicationMap = externalContext.getApplicationMap();
        applicationMap.put(JSResourceWithDisabledAMDLoaderImpl.class.getName(), filteredResourceCache);
    }
}
Also used : ExternalContext(javax.faces.context.ExternalContext) Resource(javax.faces.application.Resource)

Aggregations

Resource (javax.faces.application.Resource)27 ExternalContext (javax.faces.context.ExternalContext)10 ResourceHandler (javax.faces.application.ResourceHandler)9 FacesContext (javax.faces.context.FacesContext)7 FacesResource (com.liferay.faces.util.application.FacesResource)5 Application (javax.faces.application.Application)5 IOException (java.io.IOException)4 ResponseWriter (javax.faces.context.ResponseWriter)4 URL (java.net.URL)3 Collection (java.util.Collection)3 FacesException (javax.faces.FacesException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 LocalDateTime (java.time.LocalDateTime)2 ZoneId (java.time.ZoneId)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2