/** * Emit the supplied object to the specified writer, escaping characters if needed. * * @param src the object to write * @param escapeXml if true, escape unsafe characters before writing * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(Object src, boolean escapeXml, JspWriter out) throws IOException { if (src instanceof Reader) { emit((Reader) src, escapeXml, out); } else { emit(String.valueOf(src), escapeXml, out); } }
/** * Escapes characters that could be interpreted as XML markup as defined by the <code><c:out> action. * * @param input the string to escape * @return escaped string */ public static String escapeXml(String input) { return EscapeXML.escape(input); }
/** * Emit the supplied object to the specified writer, escaping characters if needed. * * @param src the object to write * @param escapeXml if true, escape unsafe characters before writing * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(Object src, boolean escapeXml, JspWriter out) throws IOException { if (src instanceof Reader) { emit((Reader) src, escapeXml, out); } else { emit(String.valueOf(src), escapeXml, out); } }
/** * Emit escaped content into the specified JSPWriter. * * @param src the string to escape; must not be null * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(String src, JspWriter out) throws IOException { int end = src.length(); int from = 0; for (int to = from; to < end; to++) { String escape = getEscape(src.charAt(to)); if (escape != null) { if (to != from) { out.write(src, from, to - from); } out.write(escape); from = to + 1; } } if (from != end) { out.write(src, from, end - from); } }
/** * Escapes characters that could be interpreted as XML markup as defined by the <code><c:out> action. * * @param input the string to escape * @return escaped string */ public static String escapeXml(String input) { return EscapeXML.escape(input); }
/** * Emit the supplied String to the specified writer, escaping characters if needed. * * @param src the String to write * @param escapeXml if true, escape unsafe characters before writing * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(String src, boolean escapeXml, JspWriter out) throws IOException { if (escapeXml) { emit(src, out); } else { out.write(src); } }
/** * Emit escaped content into the specified JSPWriter. * * @param src the string to escape; must not be null * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(String src, JspWriter out) throws IOException { int end = src.length(); int from = 0; for (int to = from; to < end; to++) { String escape = getEscape(src.charAt(to)); if (escape != null) { if (to != from) { out.write(src, from, to - from); } out.write(escape); from = to + 1; } } if (from != end) { out.write(src, from, end - from); } }
/** * Emit the supplied String to the specified writer, escaping characters if needed. * * @param src the String to write * @param escapeXml if true, escape unsafe characters before writing * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(String src, boolean escapeXml, JspWriter out) throws IOException { if (escapeXml) { emit(src, out); } else { out.write(src); } }
/** * Emit escaped content into the specified JSPWriter. * * @param buffer characters to escape * @param from start position in the buffer * @param count number of characters to emit * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(char[] buffer, int from, int count, JspWriter out) throws IOException { int end = from + count; for (int to = from; to < end; to++) { String escape = getEscape(buffer[to]); if (escape != null) { if (to != from) { out.write(buffer, from, to - from); } out.write(escape); from = to + 1; } } if (from != end) { out.write(buffer, from, end - from); } } }
@Override public int doEndTag() throws JspException { try { boolean escapeXml = evalEscapeXml(); EscapeXML.emit(output, escapeXml, pageContext.getOut()); } catch (IOException e) { throw new JspTagException(e); } finally { output = null; } return EVAL_PAGE; } }
/** * Emit escaped content into the specified JSPWriter. * * @param buffer characters to escape * @param from start position in the buffer * @param count number of characters to emit * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(char[] buffer, int from, int count, JspWriter out) throws IOException { int end = from + count; for (int to = from; to < end; to++) { String escape = getEscape(buffer[to]); if (escape != null) { if (to != from) { out.write(buffer, from, to - from); } out.write(escape); from = to + 1; } } if (from != end) { out.write(buffer, from, end - from); } } }
@Override public int doEndTag() throws JspException { try { boolean escapeXml = evalEscapeXml(); EscapeXML.emit(output, escapeXml, pageContext.getOut()); } catch (IOException e) { throw new JspTagException(e); } finally { output = null; } return EVAL_PAGE; } }
/** * Copy the content of a Reader into the specified JSPWriter escaping characters if needed. * * @param src the Reader to read from * @param escapeXml if true, escape characters * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(Reader src, boolean escapeXml, JspWriter out) throws IOException { int bufferSize = out.getBufferSize(); if (bufferSize == 0) { bufferSize = 4096; } char[] buffer = new char[bufferSize]; int count; while ((count = src.read(buffer)) > 0) { if (escapeXml) { emit(buffer, 0, count, out); } else { out.write(buffer, 0, count); } } }
/** * Copy the content of a Reader into the specified JSPWriter escaping characters if needed. * * @param src the Reader to read from * @param escapeXml if true, escape characters * @param out the JspWriter to emit to * @throws IOException if there was a problem emitting the content */ public static void emit(Reader src, boolean escapeXml, JspWriter out) throws IOException { int bufferSize = out.getBufferSize(); if (bufferSize == 0) { bufferSize = 4096; } char[] buffer = new char[bufferSize]; int count; while ((count = src.read(buffer)) > 0) { if (escapeXml) { emit(buffer, 0, count, out); } else { out.write(buffer, 0, count); } } }
@Override public int doStartTag() throws JspException { try { XPathContext context = XalanUtil.getContext(this, pageContext); String result = select.execute(context, context.getCurrentNode(), null).str(); EscapeXML.emit(result, escapeXml, pageContext.getOut()); return SKIP_BODY; } catch (IOException ex) { throw new JspTagException(ex.toString(), ex); } catch (TransformerException e) { throw new JspTagException(e); } }
@Override public int doStartTag() throws JspException { try { XPathContext context = XalanUtil.getContext(this, pageContext); String result = select.execute(context, context.getCurrentNode(), null).str(); EscapeXML.emit(result, escapeXml, pageContext.getOut()); return SKIP_BODY; } catch (IOException ex) { throw new JspTagException(ex.toString(), ex); } catch (TransformerException e) { throw new JspTagException(e); } }