@Override public TextInJavaScriptEncoder append(char c, Appendable out) throws IOException { encodeTextInJavaScript(c, out); return this; }
public static void encodeTextInJavaScript(char ch, Appendable out) throws IOException { String escaped = getEscapedCharacter(ch); if(escaped!=null) out.append(escaped); else out.append(ch); }
) { textInJavaScriptEncoder.writePrefixTo(javaScriptInXhtmlAttributeWriter); Coercion.write(value, textInJavaScriptEncoder, javaScriptInXhtmlAttributeWriter); textInJavaScriptEncoder.writeSuffixTo(javaScriptInXhtmlAttributeWriter); } else { String str = Coercion.toString(value); textInJavaScriptEncoder.writePrefixTo(javaScriptInXhtmlAttributeWriter); textInJavaScriptEncoder.write(str, javaScriptInXhtmlAttributeWriter); textInJavaScriptEncoder.writeSuffixTo(javaScriptInXhtmlAttributeWriter); if(lookupMarkup!=null) lookupMarkup.appendSuffixTo(MarkupType.JAVASCRIPT, javaScriptInXhtmlAttributeWriter);
) { textInJavaScriptEncoder.writePrefixTo(javaScriptInXhtmlWriter); Coercion.write(value, textInJavaScriptEncoder, javaScriptInXhtmlWriter); textInJavaScriptEncoder.writeSuffixTo(javaScriptInXhtmlWriter); } else { String str = Coercion.toString(value); textInJavaScriptEncoder.writePrefixTo(javaScriptInXhtmlWriter); textInJavaScriptEncoder.write(str, javaScriptInXhtmlWriter); textInJavaScriptEncoder.writeSuffixTo(javaScriptInXhtmlWriter); if(lookupMarkup!=null) lookupMarkup.appendSuffixTo(MarkupType.JAVASCRIPT, javaScriptInXhtmlWriter);
@Override public TextInJavaScriptEncoder append(CharSequence csq, Appendable out) throws IOException { encodeTextInJavaScript(csq==null ? "null" : csq, out); return this; }
public static void encodeTextInJavaScript(char[] cbuf, int start, int len, Writer out) throws IOException { int end = start+len; int toPrint = 0; for (int c = start; c < end; c++) { String escaped = getEscapedCharacter(cbuf[c]); if(escaped!=null) { if(toPrint>0) { out.write(cbuf, c-toPrint, toPrint); toPrint=0; } out.write(escaped); } else { toPrint++; } } if(toPrint>0) out.write(cbuf, end-toPrint, toPrint); }
@Override public TextInJavaScriptEncoder append(CharSequence csq, int start, int end, Appendable out) throws IOException { encodeTextInJavaScript(csq==null ? "null" : csq, start, end, out); return this; }
public static void encodeTextInJavaScript(CharSequence S, int start, int end, Appendable out) throws IOException { if(S!=null) { int toPrint = 0; for (int c = start; c < end; c++) { String escaped = getEscapedCharacter(S.charAt(c)); if(escaped!=null) { if(toPrint>0) { out.append(S, c-toPrint, c); toPrint=0; } out.append(escaped); } else { toPrint++; } } if(toPrint>0) out.append(S, end-toPrint, end); } } // </editor-fold>
public static void encodeTextInJavaScript(char[] cbuf, Writer out) throws IOException { encodeTextInJavaScript(cbuf, 0, cbuf.length, out); }
@Override public void write(int c, Writer out) throws IOException { encodeTextInJavaScript((char)c, out); }
@Override public void write(char cbuf[], Writer out) throws IOException { encodeTextInJavaScript(cbuf, out); }
@Override public void write(char[] cbuf, int off, int len, Writer out) throws IOException { encodeTextInJavaScript(cbuf, off, len, out); }
public static void encodeTextInJavaScript(CharSequence S, Appendable out) throws IOException { if(S!=null) { encodeTextInJavaScript(S, 0, S.length(), out); } }
@Override public void write(String str, Writer out) throws IOException { if(str==null) throw new IllegalArgumentException("str is null"); encodeTextInJavaScript(str, out); }
@Override public void write(String str, int off, int len, Writer out) throws IOException { if(str==null) throw new IllegalArgumentException("str is null"); encodeTextInJavaScript(str, off, off+len, out); }
/** * @see TextInJavaScriptEncoder#encodeTextInJavaScript(java.lang.String, Appendable) * * @deprecated */ @Deprecated public ChainWriter encodeJavaScriptString(String S) throws IOException { encodeTextInJavaScript(S, out); return this; }
public static void encodeTextInJavaScriptInXhtml(String text, Appendable out) throws IOException { StringBuilder javascript = new StringBuilder(text.length()); encodeTextInJavaScript(text, javascript); encodeJavaScriptInXhtml(javascript, out); }
public static void encodeTextInJavaScriptInXhtmlAttribute(String text, Appendable out) throws IOException { StringBuilder javascript = new StringBuilder(text.length()); encodeTextInJavaScript(text, javascript); encodeJavaScriptInXhtmlAttribute(javascript, out); }
@Override protected void writeSuffix(StringBuilder buffer, Appendable out) throws IOException { TextInJavaScriptEncoder.encodeTextInJavaScript( context.encodeURL(buffer.toString()), out ); out.append('"'); } }
@Override public void doComponent( ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, Writer out, View view, Page page, ComponentPosition position ) throws ServletException, IOException { if(position == ComponentPosition.HEAD_END) { out.write("<script type=\"text/javascript\">\n" + "// <![CDATA[\n" + "(function(i,s,o,g,r,a,m){i[\"GoogleAnalyticsObject\"]=r;i[r]=i[r]||function(){\n" + "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n" + "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n" + "})(window,document,\"script\",\"https://www.google-analytics.com/analytics.js\",\"ga\");\n" + "ga(\"create\",\""); TextInJavaScriptEncoder.encodeTextInJavaScript(trackingId, out); out.write("\",\"auto\");\n" + "ga(\"send\",\"pageview\");\n" + "// ]]>\n" + "</script>"); } } }