Exemplo n.º 1
0
 /**
  * This directly invokes super's <code>output</code> after converting <code>string</code> to a
  * char[].
  */
 private void output(String string) throws IOException {
   int length = string.length();
   if (tempChars == null || tempChars.length < length) {
     tempChars = new char[length];
   }
   string.getChars(0, length, tempChars, 0);
   super.output(tempChars, 0, length);
 }
Exemplo n.º 2
0
 /**
  * This method is overriden to map any character entities, such as &lt; to &amp;lt;. <code>
  * super.output</code> will be invoked to write the content.
  */
 protected void output(char[] chars, int start, int length) throws IOException {
   if (!replaceEntities) {
     super.output(chars, start, length);
     return;
   }
   int last = start;
   length += start;
   for (int counter = start; counter < length; counter++) {
     // This will change, we need better support character level
     // entities.
     switch (chars[counter]) {
         // Character level entities.
       case '<':
         if (counter > last) {
           super.output(chars, last, counter - last);
         }
         last = counter + 1;
         output("&lt;");
         break;
       case '>':
         if (counter > last) {
           super.output(chars, last, counter - last);
         }
         last = counter + 1;
         output("&gt;");
         break;
       case '&':
         if (counter > last) {
           super.output(chars, last, counter - last);
         }
         last = counter + 1;
         output("&amp;");
         break;
       case '"':
         if (counter > last) {
           super.output(chars, last, counter - last);
         }
         last = counter + 1;
         output("&quot;");
         break;
         // Special characters
       case '\n':
       case '\t':
       case '\r':
         break;
       default:
         if (chars[counter] < ' ' || chars[counter] > 127) {
           if (counter > last) {
             super.output(chars, last, counter - last);
           }
           last = counter + 1;
           // If the character is outside of ascii, write the
           // numeric value.
           output("&#");
           output(String.valueOf((int) chars[counter]));
           output(";");
         }
         break;
     }
   }
   if (last < length) {
     super.output(chars, last, length - last);
   }
 }
Exemplo n.º 3
0
 /**
  * Writes the line separator. This is overriden to make sure we don't replace the newline content
  * in case it is outside normal ascii.
  */
 protected void writeLineSeparator() throws IOException {
   boolean oldReplace = replaceEntities;
   replaceEntities = false;
   super.writeLineSeparator();
   replaceEntities = oldReplace;
 }