Search in sources :

Example 1 with FacesResource

use of com.liferay.faces.util.application.FacesResource in project liferay-faces-alloy by liferay.

the class AudioServiceMockImpl method postConstruct.

@PostConstruct
public void postConstruct() {
    audioList = new ArrayList<FacesResource>();
    audioList.add(new FacesResource("audios", "over-the-rainbow.mp3"));
    audioList.add(new FacesResource("audios", "over-the-rainbow.m4a"));
    audioList.add(new FacesResource("audios", "over-the-rainbow.wav"));
    audioList.add(new FacesResource("audios", "over-the-rainbow.webm"));
    audioList.add(new FacesResource("audios", "over-the-rainbow.ogg"));
    audioList = Collections.unmodifiableList(audioList);
}
Also used : FacesResource(com.liferay.faces.util.application.FacesResource) PostConstruct(javax.annotation.PostConstruct)

Example 2 with FacesResource

use of com.liferay.faces.util.application.FacesResource in project liferay-faces-alloy by liferay.

the class VideoServiceMockImpl method postConstruct.

@PostConstruct
public void postConstruct() {
    videoList = new ArrayList<FacesResource>();
    videoList.add(new FacesResource("videos", "over-the-rainbow.mp4"));
    videoList.add(new FacesResource("videos", "over-the-rainbow.webm"));
    videoList.add(new FacesResource("videos", "over-the-rainbow.ogv"));
    videoList = Collections.unmodifiableList(videoList);
}
Also used : FacesResource(com.liferay.faces.util.application.FacesResource) PostConstruct(javax.annotation.PostConstruct)

Example 3 with FacesResource

use of com.liferay.faces.util.application.FacesResource in project liferay-faces-alloy by liferay.

the class MediaRenderer method encodeChildren.

@Override
@SuppressWarnings("unchecked")
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    Media media = (Media) uiComponent;
    String name = media.getName();
    Object value = media.getValue();
    Application application = facesContext.getApplication();
    ResourceHandler resourceHandler = application.getResourceHandler();
    String firstMediaResourceURL = null;
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    if (name != null) {
        String library = media.getLibrary();
        if ((name.length() > 0) && (library != null) && (library.length() > 0)) {
            Resource mediaResource = resourceHandler.createResource(name, library);
            String contentType = media.getContentType();
            if (mediaResource != null) {
                String mediaRequestPath = mediaResource.getRequestPath();
                ExternalContext externalContext = facesContext.getExternalContext();
                firstMediaResourceURL = externalContext.encodeResourceURL(mediaRequestPath);
                if (contentType == null) {
                    contentType = mediaResource.getContentType();
                }
            } else {
                firstMediaResourceURL = RES_NOT_FOUND;
                logger.error(RES_NOT_FOUND_ERROR_MSG, resourceHandler, name, library);
            }
            encodeMediaSource(responseWriter, firstMediaResourceURL, contentType);
        }
    } else if (value != null) {
        if ((value instanceof Collection) || (value instanceof FacesResource[])) {
            Collection<FacesResource> facesResources;
            if (value instanceof Collection) {
                facesResources = (Collection<FacesResource>) value;
            } else {
                FacesResource[] resourcesAsArray = (FacesResource[]) value;
                facesResources = Arrays.asList(resourcesAsArray);
            }
            for (FacesResource facesResource : facesResources) {
                String facesResourceName = facesResource.getName();
                String facesResourceLibrary = facesResource.getLibrary();
                Resource mediaResource = resourceHandler.createResource(facesResourceName, facesResourceLibrary);
                String mediaResourceURL;
                String contentType = facesResource.getContentType();
                if (mediaResource != null) {
                    String mediaRequestPath = mediaResource.getRequestPath();
                    ExternalContext externalContext = facesContext.getExternalContext();
                    mediaResourceURL = externalContext.encodeResourceURL(mediaRequestPath);
                    if (contentType == null) {
                        contentType = mediaResource.getContentType();
                    }
                } else {
                    mediaResourceURL = RES_NOT_FOUND;
                    logger.error(RES_NOT_FOUND_ERROR_MSG, resourceHandler, facesResourceName, facesResourceLibrary);
                }
                if (firstMediaResourceURL == null) {
                    firstMediaResourceURL = mediaResourceURL;
                }
                encodeMediaSource(responseWriter, mediaResourceURL, contentType);
            }
        } else {
            String contentType = media.getContentType();
            if (value instanceof FacesResource) {
                FacesResource facesResource = (FacesResource) value;
                String facesResourceName = facesResource.getName();
                String facesResourceLibrary = facesResource.getLibrary();
                Resource mediaResource = resourceHandler.createResource(facesResourceName, facesResourceLibrary);
                if (contentType == null) {
                    contentType = facesResource.getContentType();
                }
                if (mediaResource != null) {
                    String mediaRequestPath = mediaResource.getRequestPath();
                    ExternalContext externalContext = facesContext.getExternalContext();
                    firstMediaResourceURL = externalContext.encodeResourceURL(mediaRequestPath);
                    if (contentType == null) {
                        contentType = mediaResource.getContentType();
                    }
                } else {
                    firstMediaResourceURL = RES_NOT_FOUND;
                    logger.error(RES_NOT_FOUND_ERROR_MSG, resourceHandler, facesResourceName, facesResourceLibrary);
                }
            } else {
                String valueAsString = value.toString();
                firstMediaResourceURL = getEncodedResourceURL(facesContext, resourceHandler, application, valueAsString);
            }
            encodeMediaSource(responseWriter, firstMediaResourceURL, contentType);
        }
    }
    List<UIComponent> children = uiComponent.getChildren();
    for (UIComponent child : children) {
        if (child instanceof com.liferay.faces.alloy.component.resource.Resource) {
            String mediaResourceURL;
            com.liferay.faces.alloy.component.resource.Resource resource = (com.liferay.faces.alloy.component.resource.Resource) child;
            String contentType = resource.getContentType();
            String resourceName = resource.getName();
            String resourceLibrary = resource.getLibrary();
            Resource mediaResource = resourceHandler.createResource(resourceName, resourceLibrary);
            if (mediaResource != null) {
                String mediaRequestPath = mediaResource.getRequestPath();
                ExternalContext externalContext = facesContext.getExternalContext();
                mediaResourceURL = externalContext.encodeResourceURL(mediaRequestPath);
                if (contentType == null) {
                    contentType = mediaResource.getContentType();
                }
            } else {
                mediaResourceURL = RES_NOT_FOUND;
                logger.error(RES_NOT_FOUND_ERROR_MSG, resourceHandler, resourceName, resourceLibrary);
            }
            encodeMediaSource(responseWriter, mediaResourceURL, contentType);
            if (firstMediaResourceURL == null) {
                firstMediaResourceURL = mediaResourceURL;
            }
        } else {
            child.encodeAll(facesContext);
        }
    }
    // If no media has been specified, then warn the developer.
    if (firstMediaResourceURL == null) {
        logger.warn("No {0} has been specified for <alloy:{0} id=[{1}] />.", getMediaType(), media.getClientId());
    } else // first media URL.
    if (media.isDegrade()) {
        encodeFlashPlayer(facesContext, responseWriter, media, firstMediaResourceURL);
    }
}
Also used : Media(com.liferay.faces.alloy.component.media.Media) Resource(javax.faces.application.Resource) FacesResource(com.liferay.faces.util.application.FacesResource) UIComponent(javax.faces.component.UIComponent) ResourceHandler(javax.faces.application.ResourceHandler) ResponseWriter(javax.faces.context.ResponseWriter) ExternalContext(javax.faces.context.ExternalContext) FacesResource(com.liferay.faces.util.application.FacesResource) Collection(java.util.Collection) Application(javax.faces.application.Application)

Example 4 with FacesResource

use of com.liferay.faces.util.application.FacesResource in project liferay-faces-alloy by liferay.

the class MediaRenderer method getEncodedResourceURL.

protected String getEncodedResourceURL(FacesContext facesContext, ResourceHandler resourceHandler, Application application, Object value) {
    String encodedResourceURL;
    if (value instanceof FacesResource) {
        FacesResource facesResource = (FacesResource) value;
        String name = facesResource.getName();
        String library = facesResource.getLibrary();
        Resource resource = resourceHandler.createResource(name, library);
        if (resource != null) {
            String mediaRequestPath = resource.getRequestPath();
            ExternalContext externalContext = facesContext.getExternalContext();
            encodedResourceURL = externalContext.encodeResourceURL(mediaRequestPath);
        } else {
            encodedResourceURL = RES_NOT_FOUND;
            logger.error(RES_NOT_FOUND_ERROR_MSG, resourceHandler, name, library);
        }
    } else {
        String posterString = value.toString();
        encodedResourceURL = getEncodedResourceURL(facesContext, resourceHandler, application, posterString);
    }
    return encodedResourceURL;
}
Also used : FacesResource(com.liferay.faces.util.application.FacesResource) ExternalContext(javax.faces.context.ExternalContext) Resource(javax.faces.application.Resource) FacesResource(com.liferay.faces.util.application.FacesResource)

Aggregations

FacesResource (com.liferay.faces.util.application.FacesResource)4 PostConstruct (javax.annotation.PostConstruct)2 Resource (javax.faces.application.Resource)2 ExternalContext (javax.faces.context.ExternalContext)2 Media (com.liferay.faces.alloy.component.media.Media)1 Collection (java.util.Collection)1 Application (javax.faces.application.Application)1 ResourceHandler (javax.faces.application.ResourceHandler)1 UIComponent (javax.faces.component.UIComponent)1 ResponseWriter (javax.faces.context.ResponseWriter)1