Exemple #1
0
  /**
   * Write properly escaped text from a character array. If there is an open element that has been
   * created by a call to <code>startElement()</code>, that element will be closed first.
   *
   * <p>
   *
   * <p>All angle bracket occurrences in the argument must be escaped using the &amp;gt; &amp;lt;
   * syntax.
   *
   * @param text Text to be written
   * @param off Starting offset (zero-relative)
   * @param len Number of characters to be written
   * @throws IndexOutOfBoundsException if the calculated starting or ending position is outside the
   *     bounds of the character array
   * @throws IOException if an input/output error occurs
   * @throws NullPointerException if <code>text</code> is <code>null</code>
   */
  public void writeText(char text[], int off, int len) throws IOException {

    if (text == null) {
      throw new NullPointerException(
          MessageUtils.getExceptionMessageString(
              MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "text"));
    }
    if (off < 0 || off > text.length || len < 0 || len > text.length) {
      throw new IndexOutOfBoundsException();
    }
    closeStartIfNecessary();
    if (writingCdata) {

      // RELEASE_PENDING
      // Might take a page from the HtmlUtils book and if the content being written
      // is more than 16 chars, then use an existing buffer and copy the contents
      // to said buffer.  If 16 or less, then just iterate over the string using charAt()

      char[] cbuf = new char[off + len];
      System.arraycopy(text, off, cbuf, 0, len);

      writer.write(escapeArray(cbuf));
    } else if (dontEscape) {
      writer.write(text, off, len);
    } else {
      HtmlUtils.writeText(writer, escapeUnicode, escapeIso, buffer, text, off, len);
    }
  }
Exemple #2
0
  /**
   * Write a properly escaped single character, If there is an open element that has been created by
   * a call to <code>startElement()</code>, that element will be closed first.
   *
   * <p>
   *
   * <p>All angle bracket occurrences in the argument must be escaped using the &amp;gt; &amp;lt;
   * syntax.
   *
   * @param text Text to be written
   * @throws IOException if an input/output error occurs
   */
  public void writeText(char text) throws IOException {

    closeStartIfNecessary();
    if (dontEscape) {
      writer.write(text);
    } else {
      charHolder[0] = text;
      HtmlUtils.writeText(writer, escapeUnicode, escapeIso, buffer, charHolder);
    }
  }
Exemple #3
0
  /**
   * Write properly escaped text from a character array. The output from this command is identical
   * to the invocation: <code>writeText(c, 0, c.length)</code>. If there is an open element that has
   * been created by a call to <code>startElement()</code>, that element will be closed first.
   *
   * <p>
   *
   * <p>All angle bracket occurrences in the argument must be escaped using the &amp;gt; &amp;lt;
   * syntax.
   *
   * @param text Text to be written
   * @throws IOException if an input/output error occurs
   * @throws NullPointerException if <code>text</code> is <code>null</code>
   */
  public void writeText(char text[]) throws IOException {

    if (text == null) {
      throw new NullPointerException(
          MessageUtils.getExceptionMessageString(
              MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "text"));
    }
    closeStartIfNecessary();
    if (dontEscape) {
      writer.write(text);
    } else {
      HtmlUtils.writeText(writer, escapeUnicode, escapeIso, buffer, text);
    }
  }
Exemple #4
0
  /**
   * Write a properly escaped object. The object will be converted to a String if necessary. If
   * there is an open element that has been created by a call to <code>startElement()</code>, that
   * element will be closed first.
   *
   * @param text Text to be written
   * @param componentPropertyName The name of the component property to which this text argument
   *     applies. This argument may be <code>null</code>.
   * @throws IOException if an input/output error occurs
   * @throws NullPointerException if <code>text</code> is <code>null</code>
   */
  public void writeText(Object text, String componentPropertyName) throws IOException {

    if (text == null) {
      throw new NullPointerException(
          MessageUtils.getExceptionMessageString(
              MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "text"));
    }
    closeStartIfNecessary();
    if (writingCdata) {
      writer.write(escapeArray(text.toString().toCharArray()));
    } else if (dontEscape) {
      writer.write(text.toString());
    } else {
      String val = text.toString();
      ensureTextBufferCapacity(val);
      HtmlUtils.writeText(writer, escapeUnicode, escapeIso, buffer, val, textBuffer);
    }
  }