@Override
  public void endElement(String name) throws IOException {

    if (StringPool.BODY.equals(name)) {
      super.startElement(StringPool.SCRIPT, uiComponent);
      super.writeAttribute(StringPool.TYPE, ContentTypes.TEXT_JAVASCRIPT, null);

      FacesContext facesContext = FacesContext.getCurrentInstance();
      ExternalContext externalContext = facesContext.getExternalContext();
      ClientScriptFactory clientScriptFactory =
          (ClientScriptFactory) FactoryExtensionFinder.getFactory(ClientScriptFactory.class);
      ClientScript clientScript = clientScriptFactory.getClientScript(externalContext);
      super.write(clientScript.toString());
      super.endElement(StringPool.SCRIPT);
    }

    super.endElement(name);
  }
  public static void renderScript(
      FacesContext facesContext, UIComponent uiComponent, String script, String use) {

    // Render the script at the bottom of the page by setting the WebKeys.AUI_SCRIPT_DATA request
    // attribute.
    ExternalContext externalContext = facesContext.getExternalContext();
    ClientScriptFactory clientScriptFactory =
        (ClientScriptFactory) FactoryExtensionFinder.getFactory(ClientScriptFactory.class);
    ClientScript clientScript = clientScriptFactory.getClientScript(externalContext);

    String portletId = StringPool.BLANK;
    Object portlet = externalContext.getRequestMap().get(WebKeys.RENDER_PORTLET);

    if (portlet != null) {
      portletId = LiferayPortletUtil.getPortletId(portlet);
    }

    clientScript.append(portletId, script, use);
  }