use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class AlloyRendererCommon method encodeJavaScriptBegin.
/* package-private */
static void encodeJavaScriptBegin(FacesContext facesContext, UIComponent uiComponent, AlloyRenderer alloyRenderer, String[] modules, boolean sandboxed) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
if (sandboxed) {
String yuiConfig = alloyRenderer.getYUIConfig(facesContext, responseWriter, uiComponent);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
String alloyBeginScript = AlloyRendererUtil.getAlloyBeginScript(modules, yuiConfig, browserSniffer);
responseWriter.write(alloyBeginScript);
}
if (facesContext.getPartialViewContext().isAjaxRequest() && (uiComponent instanceof ClientComponent)) {
ClientComponent clientComponent = (ClientComponent) uiComponent;
String clientVarName = alloyRenderer.getClientVarName(facesContext, clientComponent);
String clientKey = clientComponent.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
responseWriter.write("if(");
responseWriter.write(clientVarName);
responseWriter.write("){");
responseWriter.write(clientVarName);
responseWriter.write(".destroy();}");
}
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputDateRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDate inputDate = (InputDate) uiComponent;
String showOn = inputDate.getShowOn();
if (isNative(browserSniffer, inputDate) || "button".equals(showOn)) {
String clientVarName = getClientVarName(facesContext, inputDate);
String clientKey = inputDate.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
JavaScriptFragment liferayComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
ResponseWriter responseWriter = facesContext.getResponseWriter();
if (isNative(browserSniffer, inputDate)) {
String clientId = uiComponent.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
Object maxDateObject = inputDate.getMaxDate();
Object minDateObject = inputDate.getMinDate();
String maxDateString = null;
String minDateString = null;
if ((maxDateObject != null) || (minDateObject != null)) {
String datePattern = inputDate.getPattern();
String timeZoneString = inputDate.getTimeZone();
TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(InputDate.DEFAULT_HTML5_DATE_PATTERN, Locale.ENGLISH);
if (maxDateObject != null) {
Date maxDate = inputDate.getObjectAsDate(maxDateObject, datePattern, timeZone);
maxDateString = simpleDateFormat.format(maxDate);
}
if (maxDateObject != null) {
Date minDate = inputDate.getObjectAsDate(minDateObject, datePattern, timeZone);
minDateString = simpleDateFormat.format(minDate);
}
}
encodeFunctionCall(responseWriter, "LFAI.initDateTimePickerMobile", liferayComponent, inputClientId, maxDateString, minDateString);
} else if ("button".equals(showOn)) {
String clientId = inputDate.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
EscapedClientId escapedInputClientId = new EscapedClientId(inputClientId);
encodeFunctionCall(responseWriter, "LFAI.initDatePickerShowOnButton", 'A', escapedInputClientId, liferayComponent);
}
}
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputDateRenderer method encodeHiddenAttributes.
@Override
protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, InputDate inputDate, boolean first) throws IOException {
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
if (!isNative(browserSniffer, inputDate)) {
encodeCalendar(facesContext, responseWriter, inputDate, first);
first = false;
encodeHiddenAttributesInputDateTime(facesContext, responseWriter, inputDate, first);
first = false;
}
}
use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.
the class InputDateTimeRenderer method encodeMarkupBegin.
@Override
public void encodeMarkupBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
// Start the encoding of the outermost <div> element.
ResponseWriter responseWriter = facesContext.getResponseWriter();
String clientId = uiComponent.getClientId(facesContext);
responseWriter.startElement("div", uiComponent);
// Encode the "id" attribute on the outermost <div> element.
responseWriter.writeAttribute("id", clientId, "id");
// Encode the "class" and "style" attributes on the outermost <div> element.
RendererUtil.encodeStyleable(responseWriter, (Styleable) uiComponent);
// Start the encoding of the text input by delegating to the renderer from the JSF runtime.
String inputClientId = clientId.concat(INPUT_SUFFIX);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputDateTime inputDateTime = (InputDateTime) uiComponent;
InputDateTimeResponseWriter inputDateTimeResponseWriter = getInputDateTimeResponseWriter(responseWriter, inputClientId, isNative(browserSniffer, inputDateTime));
super.encodeMarkupBegin(facesContext, uiComponent, inputDateTimeResponseWriter);
}
use of com.liferay.faces.util.client.BrowserSniffer 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");
}
Aggregations