/** * Returns a new instance of {@link BrowserSniffer} from the {@link BrowserSnifferFactory} found by the {@link * FactoryExtensionFinder}. The returned instance is designed to be used during execution of a request thread, so it * is not guaranteed to be {@link java.io.Serializable}. * * @param externalContext The external context associated with the current faces context. It is needed in order * for the {@link FactoryExtensionFinder} to be able to find the factory. * * @since 3.1 * @since 2.1 * @since 1.1 */ public static BrowserSniffer getBrowserSnifferInstance(ExternalContext externalContext) { BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( externalContext, BrowserSnifferFactory.class); return browserSnifferFactory.getBrowserSniffer(externalContext); }
@Override public PartialResponseWriter getPartialResponseWriter() { if (partialResponseWriter == null) { BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); FacesContext facesContext = FacesContext.getCurrentInstance(); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); partialResponseWriter = new PartialResponseWriterAlloyImpl(super.getPartialResponseWriter(), browserSniffer); } return partialResponseWriter; }
@Override public PartialResponseWriter getPartialResponseWriter() { if (partialResponseWriter == null) { BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); FacesContext facesContext = FacesContext.getCurrentInstance(); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); partialResponseWriter = new PartialResponseWriterAlloyImpl(super.getPartialResponseWriter(), browserSniffer); } return partialResponseWriter; }
@Override public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) { String alloyClassName = super.getAlloyClassName(facesContext, uiComponent); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); InputTime inputTime = (InputTime) uiComponent; if (isNative(browserSniffer, inputTime)) { alloyClassName = alloyClassName.concat("Native"); } return alloyClassName; }
@Override public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) { String alloyClassName = super.getAlloyClassName(facesContext, uiComponent); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); InputDate inputDate = (InputDate) uiComponent; if (isNative(browserSniffer, inputDate)) { alloyClassName = alloyClassName.concat("Native"); } return alloyClassName; }
@Override public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) { String alloyClassName = super.getAlloyClassName(facesContext, uiComponent); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); InputDate inputDate = (InputDate) uiComponent; if (isNative(browserSniffer, inputDate)) { alloyClassName = alloyClassName.concat("Native"); } return alloyClassName; }
@Override public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) { String alloyClassName = super.getAlloyClassName(facesContext, uiComponent); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); InputTime inputTime = (InputTime) uiComponent; if (isNative(browserSniffer, inputTime)) { alloyClassName = alloyClassName.concat("Native"); } return alloyClassName; }
@Override public String getPattern() { String timePattern; FacesContext facesContext = FacesContext.getCurrentInstance(); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); if (browserSniffer.isMobile() && isNativeWhenMobile()) { timePattern = DEFAULT_HTML5_TIME_PATTERN; } else { timePattern = super.getPattern(); } return timePattern; } }
@Override protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, InputDate inputDate, boolean first) throws IOException { BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); if (!isNative(browserSniffer, inputDate)) { encodeCalendar(facesContext, responseWriter, inputDate, first); first = false; encodeHiddenAttributesInputDateTime(facesContext, responseWriter, inputDate, first); first = false; } }
@Override public String getPattern() { String timePattern; FacesContext facesContext = FacesContext.getCurrentInstance(); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); if (browserSniffer.isMobile() && isNativeWhenMobile()) { timePattern = DEFAULT_HTML5_TIME_PATTERN; } else { timePattern = super.getPattern(); } return timePattern; } }
@Override protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, InputTime inputTime, boolean first) throws IOException { BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); if (!isNative(browserSniffer, inputTime)) { encodeAutocomplete(facesContext, responseWriter, inputTime, first); first = false; encodeHiddenAttributesInputDateTime(facesContext, responseWriter, inputTime, first); first = false; } }
@Override protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, InputTime inputTime, boolean first) throws IOException { BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); if (!isNative(browserSniffer, inputTime)) { encodeAutocomplete(facesContext, responseWriter, inputTime, first); first = false; encodeHiddenAttributesInputDateTime(facesContext, responseWriter, inputTime, first); first = false; } }
@Override protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, InputDate inputDate, boolean first) throws IOException { BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); if (!isNative(browserSniffer, inputDate)) { encodeCalendar(facesContext, responseWriter, inputDate, first); first = false; encodeHiddenAttributesInputDateTime(facesContext, responseWriter, inputDate, first); first = false; } }
@Override public BrowserSniffer getBrowserSniffer(ExternalContext externalContext) { PortletRequest portletRequest = (PortletRequest) externalContext.getRequest(); HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest); // Calling ExternalContext.setRequest(httpServletRequest) adds extra overhead because all of the // underlying maps have to get re-created. Instead, create a simple ExternalContextWrapper. ExternalContext externalContextBrowserSnifferImpl = new ExternalContextBrowserSnifferImpl(externalContext, httpServletRequest); BrowserSnifferFactory firstNonBridgeBrowserSnifferFactory = getFirstNonBridgeBrowserSnifferFactory(); return firstNonBridgeBrowserSnifferFactory.getBrowserSniffer(externalContextBrowserSnifferImpl); }
@Override public String getPattern() { String datePattern; FacesContext facesContext = FacesContext.getCurrentInstance(); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); if (browserSniffer.isMobile() && isNativeWhenMobile()) { datePattern = DEFAULT_HTML5_DATE_PATTERN; } else { datePattern = super.getPattern(); if (datePattern == null) { // Provide a default datePattern based on the locale. Object locale = getLocale(); datePattern = getDefaultDatePattern(locale); } } return datePattern; } }
@Override public BrowserSniffer getBrowserSniffer(ExternalContext externalContext) { if (LIFERAY_PORTAL_DETECTED) { PortletRequest portletRequest = (PortletRequest) externalContext.getRequest(); HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest); // Calling ExternalContext.setRequest(httpServletRequest) adds extra overhead because all of the // underlying maps have to get re-created. Instead, create a simple ExternalContextWrapper. externalContext = new ExternalContextBrowserSnifferImpl(externalContext, httpServletRequest); } // Otherwise we cannot obtain the HttpServletRequest, so we cannot obtain information about the browser, so // return a BrowserSniffer implementation which returns false for all booleans, 0 for all numbers, and "" for // all Strings. else { return new BrowserSnifferPortalImpl(); } return wrappedBrowserSnifferFactory.getBrowserSniffer(externalContext); }
@Override public BrowserSniffer getBrowserSniffer(ExternalContext externalContext) { if (LIFERAY_PORTAL_DETECTED) { PortletRequest portletRequest = (PortletRequest) externalContext.getRequest(); HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest); // Calling ExternalContext.setRequest(httpServletRequest) adds extra overhead because all of the // underlying maps have to get re-created. Instead, create a simple ExternalContextWrapper. externalContext = new ExternalContextBrowserSnifferImpl(externalContext, httpServletRequest); } // Otherwise we cannot obtain the HttpServletRequest, so we cannot obtain information about the browser, so // return a BrowserSniffer implementation which returns false for all booleans, 0 for all numbers, and "" for // all Strings. else { return new BrowserSnifferPortalImpl(); } return wrappedBrowserSnifferFactory.getBrowserSniffer(externalContext); }
@Override public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException { if (LIFERAY_FACES_BRIDGE_DETECTED) { super.encodeEnd(facesContext, uiComponent); } else { ResponseWriter responseWriter = facesContext.getResponseWriter(); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); ExternalContext externalContext = facesContext.getExternalContext(); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(externalContext); PartialViewContext partialViewContext = facesContext.getPartialViewContext(); boolean ajaxRequest = partialViewContext.isAjaxRequest(); BodyResponseWriter delegationResponseWriter = new BodyResponseWriter(responseWriter, browserSniffer, ajaxRequest); super.encodeEnd(facesContext, uiComponent, delegationResponseWriter); } }
@Override public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException { if (LIFERAY_FACES_BRIDGE_DETECTED) { super.encodeEnd(facesContext, uiComponent); } else { ResponseWriter responseWriter = facesContext.getResponseWriter(); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); ExternalContext externalContext = facesContext.getExternalContext(); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(externalContext); PartialViewContext partialViewContext = facesContext.getPartialViewContext(); boolean ajaxRequest = partialViewContext.isAjaxRequest(); BodyResponseWriter delegationResponseWriter = new BodyResponseWriter(responseWriter, browserSniffer, ajaxRequest); super.encodeEnd(facesContext, uiComponent, delegationResponseWriter); } }
@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); BrowserSnifferFactory browserSnifferFactory = (BrowserSnifferFactory) FactoryExtensionFinder.getFactory( BrowserSnifferFactory.class); BrowserSniffer browserSniffer = browserSnifferFactory.getBrowserSniffer(facesContext.getExternalContext()); InputDateTime inputDateTime = (InputDateTime) uiComponent; InputDateTimeResponseWriter inputDateTimeResponseWriter = getInputDateTimeResponseWriter(responseWriter, inputClientId, isNative(browserSniffer, inputDateTime)); super.encodeMarkupBegin(facesContext, uiComponent, inputDateTimeResponseWriter); }