List of usage examples for com.liferay.portal.kernel.util WebKeys AUI_SCRIPT_DATA
String AUI_SCRIPT_DATA
To view the source code for com.liferay.portal.kernel.util WebKeys AUI_SCRIPT_DATA.
Click Source Link
From source file:com.liferay.faces.bridge.ext.renderkit.html_basic.internal.ScriptsEncoderLiferayImpl.java
License:Open Source License
@Override public void encodeBodyScripts(FacesContext facesContext, List<Script> scripts) throws IOException { ExternalContext externalContext = facesContext.getExternalContext(); Map<String, Object> requestMap = externalContext.getRequestMap(); ThemeDisplay themeDisplay = (ThemeDisplay) requestMap.get(WebKeys.THEME_DISPLAY); // If the portlet is being rendered on its own, then render the scripts immediately before the closing <div> // of the portlet. if (themeDisplay.isStateExclusive() || themeDisplay.isIsolated()) { String scriptsString = getScriptsAsString(facesContext, scripts); ResponseWriter responseWriter = facesContext.getResponseWriter(); responseWriter.write(scriptsString); }// w w w . j a v a 2 s.c o m // Otherwise, allow Liferay to render the scripts at the bottom of the page before the closing <body> tag. else { ScriptData scriptData = (ScriptData) requestMap.get(WebKeys.AUI_SCRIPT_DATA); if (scriptData == null) { scriptData = new ScriptData(); requestMap.put(WebKeys.AUI_SCRIPT_DATA, scriptData); } scriptDataAppendScripts(scriptData, requestMap, scripts); } }
From source file:com.liferay.faces.bridge.renderkit.html_basic.internal.BodyRendererBridgeCompatImpl.java
License:Open Source License
protected void encodeScripts(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException { FacesRequestContext facesRequestContext = FacesRequestContext.getCurrentInstance(); List<Script> scripts = facesRequestContext.getScripts(); if (LIFERAY_PORTAL_DETECTED) { ExternalContext externalContext = facesContext.getExternalContext(); Map<String, Object> requestMap = externalContext.getRequestMap(); ScriptData scriptData = (ScriptData) requestMap.get(WebKeys.AUI_SCRIPT_DATA); if (scriptData == null) { scriptData = new ScriptData(); requestMap.put(WebKeys.AUI_SCRIPT_DATA, scriptData); }//from w w w . j a v a 2s . c o m ScriptDataUtil.scriptDataAppendScripts(scriptData, requestMap, scripts); } else { responseWriter.startElement("script", uiComponent); responseWriter.writeAttribute("type", "text/javascript", null); BridgeScriptUtil.writeScripts(responseWriter, scripts); responseWriter.endElement("script"); } }
From source file:com.liferay.faces.portal.render.internal.PortalTagRenderer.java
License:Open Source License
protected PortalTagOutput getPortalTagOutput(FacesContext facesContext, UIComponent uiComponent, Tag tag) throws JspException { // Setup the Facelet -> JSP tag adapter. ExternalContext externalContext = facesContext.getExternalContext(); PortletRequest portletRequest = (PortletRequest) externalContext.getRequest(); HttpServletRequest httpServletRequest = getHttpServletRequest(portletRequest); PortletResponse portletResponse = (PortletResponse) externalContext.getResponse(); HttpServletResponse httpServletResponse = getHttpServletResponse(portletResponse); ELContext elContext = facesContext.getELContext(); JspAdapterFactory jspAdapterFactory = (JspAdapterFactory) FactoryExtensionFinder .getFactory(JspAdapterFactory.class); JspWriter stringJspWriter = jspAdapterFactory.getStringJspWriter(); PageContext stringPageContext = jspAdapterFactory.getStringPageContext(httpServletRequest, httpServletResponse, elContext, stringJspWriter); // Invoke the JSP tag lifecycle directly (rather than using the tag from a JSP). tag.setPageContext(stringPageContext); tag.doStartTag();//from w w w . j a v a 2 s .c o m tag.doEndTag(); // If executing within an Ajax request, then write all the scripts contained in the AUI_SCRIPT_DATA attribute // directly to the tag output. PartialViewContext partialViewContext = facesContext.getPartialViewContext(); if (partialViewContext.isAjaxRequest()) { //J- // TODO: Possibly need to be concerned about inline scripts written in the <head>...</head> section during Ajax. // // StringBundler data = HtmlTopTag.getData(httpServletRequest, WebKeys.PAGE_TOP); //J+ Object scriptData = httpServletRequest.getAttribute(WebKeys.AUI_SCRIPT_DATA); if (scriptData != null) { try { stringJspWriter.write(portalTagOutputParser.getScriptSectionMarker()); ScriptTagUtil.flushScriptData(stringPageContext); } catch (IOException e) { throw new JspException(e); } } } // Return the tag output. return portalTagOutputParser.parse(stringJspWriter); }
From source file:com.liferay.taglib.aui.ScriptTag.java
License:Open Source License
public static void flushScriptData(PageContext pageContext) throws Exception { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); ScriptData scriptData = (ScriptData) request.getAttribute(ScriptTag.class.getName()); if (scriptData == null) { scriptData = (ScriptData) request.getAttribute(WebKeys.AUI_SCRIPT_DATA); if (scriptData != null) { request.removeAttribute(WebKeys.AUI_SCRIPT_DATA); }//www . ja v a 2 s .c om } if (scriptData != null) { ScriptTag scriptTag = new ScriptTag(); scriptTag.setPageContext(pageContext); scriptTag.processEndTag(scriptData); } }
From source file:com.liferay.taglib.aui.ScriptTag.java
License:Open Source License
@Override public int doEndTag() throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); boolean positionInline = isPositionInLine(); try {// ww w .j a va2s. c o m StringBundler bodyContentSB = getBodyContentAsStringBundler(); String use = getUse(); if (positionInline) { ScriptData scriptData = new ScriptData(); request.setAttribute(ScriptTag.class.getName(), scriptData); scriptData.append(bodyContentSB, use); String page = getPage(); if (FileAvailabilityUtil.isAvailable(pageContext.getServletContext(), page)) { PortalIncludeUtil.include(pageContext, page); } else { processEndTag(scriptData); } } else { ScriptData scriptData = (ScriptData) request.getAttribute(WebKeys.AUI_SCRIPT_DATA); if (scriptData == null) { scriptData = new ScriptData(); request.setAttribute(WebKeys.AUI_SCRIPT_DATA, scriptData); } scriptData.append(bodyContentSB, use); } return EVAL_PAGE; } catch (Exception e) { throw new JspException(e); } finally { if (positionInline) { request.removeAttribute(ScriptTag.class.getName()); } if (!ServerDetector.isResin()) { cleanUp(); } } }
From source file:org.tvs.ui.renderkit.InputEditorInternalRenderer.java
License:Open Source License
@Override public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException { super.encodeBegin(facesContext, uiComponent); InputEditorInternal inputEditorInternal = (InputEditorInternal) uiComponent; ResponseWriter responseWriter = facesContext.getResponseWriter(); ExternalContext externalContext = facesContext.getExternalContext(); PortletRequest portletRequest = (PortletRequest) externalContext.getRequest(); PortletResponse portletResponse = (PortletResponse) externalContext.getResponse(); HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest); httpServletRequest = new NonNamespacedHttpServletRequest(httpServletRequest); HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(portletResponse); PortletRequest liferayPortletRequest = getLiferayPortletRequest(portletRequest); boolean resourcePhase = (liferayPortletRequest instanceof ResourceRequest); Map<String, Object> attributes = inputEditorInternal.getAttributes(); String onBlurMethod = (String) attributes.get("onBlurMethod"); String editorImpl = (String) attributes.get("editorImpl"); if (editorImpl == null) { editorImpl = CKEDITOR;/*from w w w . j a v a 2 s .c om*/ } // Build up a URL that can be used to invoke the liferay-ui:input-editor JSP tag. String url = "/resources/liferay-ui/jsp/input-editor.jsp"; StringBuilder queryString = new StringBuilder(); queryString.append(StringPool.QUESTION); queryString.append("editorImpl"); queryString.append(StringPool.EQUAL); queryString.append(editorImpl); queryString.append(StringPool.AMPERSAND); queryString.append("height"); queryString.append(StringPool.EQUAL); queryString.append(attributes.get("height")); queryString.append(StringPool.AMPERSAND); queryString.append("initMethod"); queryString.append(StringPool.EQUAL); queryString.append(attributes.get("initMethod")); queryString.append(StringPool.AMPERSAND); queryString.append("name"); queryString.append(StringPool.EQUAL); String editorName = (String) attributes.get("name"); queryString.append(editorName); queryString.append(StringPool.AMPERSAND); queryString.append("onChangeMethod"); queryString.append(StringPool.EQUAL); queryString.append(attributes.get("onChangeMethod")); queryString.append(StringPool.AMPERSAND); queryString.append("skipEditorLoading"); queryString.append(StringPool.EQUAL); if (resourcePhase) { // FACES-1439: Ensure that the <script src=".../ckeditor.js" /> element is not included in the response by // specifying skipEditorLoading="true" during Ajax requests. queryString.append(Boolean.TRUE.toString()); } else { queryString.append(Boolean.FALSE.toString()); } queryString.append(StringPool.AMPERSAND); queryString.append("toolbarSet"); queryString.append(StringPool.EQUAL); queryString.append(attributes.get("toolbarSet")); queryString.append(StringPool.AMPERSAND); queryString.append("width"); queryString.append(StringPool.EQUAL); queryString.append(attributes.get("width")); url = url + queryString.toString(); // Invoke the tag and capture it's output in a String, rather than having the output go directly to the // response. RequestDispatcher requestDispatcher = httpServletRequest.getRequestDispatcher(url); JspIncludeResponse jspIncludeResponse = new JspIncludeResponse(httpServletResponse); try { requestDispatcher.include(httpServletRequest, jspIncludeResponse); } catch (ServletException e) { logger.error(e.getMessage()); throw new IOException(e.getMessage()); } String bufferedResponse = jspIncludeResponse.getBufferedResponse(); if (bufferedResponse != null) { // Note: Trim the buffered response since there is typically over 100 newlines at the beginning. bufferedResponse = bufferedResponse.trim(); // If rendering an instance of the CKEditor, then String editorType = EditorUtil.getEditorValue(httpServletRequest, editorImpl); if (editorType.indexOf(CKEDITOR) >= 0) { String namespace = portletResponse.getNamespace(); // FACES-1441: The liferay-ui:input-editor JSP tag (and associated ckeditor.jsp file) do not provide a // way to hook-in to the "onblur" callback feature of the CKEditor. In order to overcome this // limitation, it is necessary to append a <script>...</script> to the response that provides this // ability. String onBlurScript = getOnBlurScript(editorName, onBlurMethod, namespace); // If running within an Ajax request, include the "onblur" callback script must be included directly // to the response. if (resourcePhase) { StringBuilder scriptMarkup = new StringBuilder(); scriptMarkup.append(StringPool.LESS_THAN); scriptMarkup.append(StringPool.SCRIPT); scriptMarkup.append(StringPool.GREATER_THAN); scriptMarkup.append(StringPool.CDATA_OPEN); scriptMarkup.append(onBlurScript); scriptMarkup.append(COMMENT_CDATA_CLOSE); scriptMarkup.append(StringPool.LESS_THAN); scriptMarkup.append(StringPool.FORWARD_SLASH); scriptMarkup.append(StringPool.SCRIPT); scriptMarkup.append(StringPool.GREATER_THAN); bufferedResponse = bufferedResponse.concat(scriptMarkup.toString()); } // Otherwise, append the script to the "LIFERAY_SHARED_AUI_SCRIPT_DATA" request attribute, which will // cause the script to be rendered at the bottom of the portal page. else { ScriptData scriptData = (ScriptData) externalContext.getRequestMap() .get(WebKeys.AUI_SCRIPT_DATA); scriptData.append(onBlurScript, null); } // FACES-1439: If the component was rendered on the page on the previous JSF lifecycle, then prevent it // from being re-initialized by removing all <script>...</script> elements. boolean scriptsRemoved = false; String clientId = inputEditorInternal.getClientId(); if (resourcePhase && inputEditorInternal.isPreviouslyRendered()) { logger.debug("Preventing re-initialization of CKEditor for clientId=[{0}]", clientId); ParsedResponse parsedResponse = new ParsedResponse(bufferedResponse); bufferedResponse = parsedResponse.getNonScripts(); scriptsRemoved = true; } // FACES-1422: Move the scripts to the <eval>...</eval> section of the partial-response so that they // will execute properly. This has the added benefit of preempt a DOM-diff with ICEfaces. if (resourcePhase && !scriptsRemoved) { logger.debug( "Moving CKEditor scripts to <eval>...</eval> section of the partial-response for clientId=[{0}]", clientId); ParsedResponse parsedResponse = new ParsedResponse(bufferedResponse); bufferedResponse = parsedResponse.getNonScripts(); String scripts = parsedResponse.getScripts(); LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance(); liferayFacesContext.getJavaScriptMap().put(clientId, scripts); logger.trace(scripts); } } // Write the captured output from the JSP tag to the Faces responseWriter. logger.trace(bufferedResponse); responseWriter.write(bufferedResponse); } }