public ScriptsEncoderFactoryAlloyImpl(ScriptsEncoderFactory scriptEncoderFactory) { if (LIFERAY_PORTAL_DETECTED && LIFERAY_FACES_BRIDGE_DETECTED) { this.scriptsEncoder = scriptEncoderFactory.getScriptsEncoder(); } else { this.scriptsEncoder = new ScriptsEncoderAlloyImpl(); } this.wrappedScriptsEncoderFactory = scriptEncoderFactory; }
/** * @deprecated Call {@link #getScriptsEncoderInstance(ExternalContext)} instead. * * <p>Returns a stateless, thread-safe singleton instance of {@link ScriptsEncoder} from the {@link * ScriptsEncoderFactory} found by the {@link FactoryExtensionFinder}. ScriptsEncoder is a stateless, * thread-safe (and potentially singleton) because it is designed to be used by a {@link * javax.faces.render.Renderer}, which is stateless and thread-safe singleton.</p> */ @Deprecated public static ScriptsEncoder getScriptsEncoderInstance() { return getScriptsEncoderInstance(FacesContext.getCurrentInstance().getExternalContext()); }
/** * Returns a stateless, thread-safe singleton instance of {@link ScriptsEncoder} from the {@link * ScriptsEncoderFactory} found by the {@link FactoryExtensionFinder}. ScriptsEncoder is a stateless, thread-safe * (and potentially singleton) because it is designed to be used by a {@link javax.faces.render.Renderer}, which is * stateless and thread-safe singleton. * * @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 ScriptsEncoder getScriptsEncoderInstance(ExternalContext externalContext) { ScriptsEncoderFactory scriptsEncoderFactory = (ScriptsEncoderFactory) FactoryExtensionFinder.getFactory( externalContext, ScriptsEncoderFactory.class); return scriptsEncoderFactory.getScriptsEncoder(); }
private void encodeScripts(FacesContext facesContext, List<Script> scripts) throws IOException { ExternalContext externalContext = facesContext.getExternalContext(); ScriptsEncoder ScriptsEncoder = ScriptsEncoderFactory.getScriptsEncoderInstance(externalContext); ScriptsEncoder.encodeEvalScripts(facesContext, scripts); } }
@Override public void endElement(String name) throws IOException { if (bufferedScript.isBuffering() && "script".equals(name)) { // If the script is an external resource, then write it to the response. if (bufferedScript.isResource()) { bufferedScript.write(wrappedResponseWriter); } // Otherwise ensure that the script is written before the closing <body> tag. else { String scriptSource = bufferedScript.toString(); facesRequestContext.addScript(scriptSource); } bufferedScript.clear(); } else { if ("body".equals(name)) { List<Script> scripts = facesRequestContext.getScripts(); if (!scripts.isEmpty()) { ExternalContext externalContext = facesContext.getExternalContext(); ScriptsEncoder scriptsEncoder = ScriptsEncoderFactory.getScriptsEncoderInstance(externalContext); facesContext.setResponseWriter(wrappedResponseWriter); scriptsEncoder.encodeBodyScripts(facesContext, scripts); facesContext.setResponseWriter(this); } } super.endElement(name); } }