use of com.liferay.faces.alloy.component.media.Media in project liferay-faces-alloy by liferay.
the class MediaRenderer method encodeBegin.
@Override
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.startElement("div", uiComponent);
String clientId = uiComponent.getClientId(facesContext);
responseWriter.writeAttribute("id", clientId, "id");
responseWriter.writeAttribute("name", clientId, null);
Media media = (Media) uiComponent;
RendererUtil.encodeStyleable(responseWriter, media);
responseWriter.startElement(getMediaType(), media);
boolean autoplay = media.isAutoplay();
if (autoplay) {
responseWriter.writeAttribute(AUTOPLAY, "true", AUTOPLAY);
}
boolean controls = media.isControls();
if (controls) {
responseWriter.writeAttribute(CONTROLS, "true", CONTROLS);
}
boolean loop = media.isLoop();
if (loop) {
responseWriter.writeAttribute(LOOP, "true", LOOP);
}
boolean muted = media.isMuted();
if (muted) {
responseWriter.writeAttribute(MUTED, "true", MUTED);
}
String preload = media.getPreload();
if (preload != null) {
responseWriter.writeAttribute(PRELOAD, preload, PRELOAD);
}
encodeMediaSize(responseWriter, media);
// Encode JSF 2.1 passthrough attributes
encodePassThroughAttributes(responseWriter, uiComponent, KEYBOARD_DOM_EVENTS);
encodePassThroughAttributes(responseWriter, uiComponent, MOUSE_DOM_EVENTS);
encodePassThroughAttributes(responseWriter, uiComponent, MEDIA_DOM_EVENTS);
// Encode JSF 2.2 passthrough attributes (attributes prefixed with the http://xmlns.jcp.org/jsf/passthrough
// namespace)
encodeJSF22PassthroughAttributes(facesContext, media, responseWriter);
encodeCustomMediaAttributes(facesContext, responseWriter, media);
}
use of com.liferay.faces.alloy.component.media.Media 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);
}
}
Aggregations