Class Rewriter

java.lang.Object
org.apache.sis.internal.doclet.Rewriter

final class Rewriter extends Object
Rewrites some HTML files after they have been generated. The hyphenation() method scans for <code>...</code> elements (without attributes) in the HTML files and performs the following changes in any occurrences found:
  • For any Java identifier, insert soft-hyphens between lower-case letters followed by an upper-case letter.
  • Between any Java identifiers separated by a '.' or '_' character, insert a zero-width space before the dot or underscore.
The intent is to avoid large amount of white spaces in Javadoc when a line content long code.

Current version does not try to extends the standard doclet because the latter is under revision in JDK 9. We may revisit when JDK 9 become available, if their new standard doclet API is public.

Since:
0.7
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final char[]
    A temporary buffer for loading files.
    private static final String
    The closing HTML element.
    private final StringBuilder
    The full content of file.
    private static final String
    The encoding to use for reading and writing HTML files.
    private File
    The file being processed.
    private boolean
    true if the content has been modified an need to be saved.
    private static final String
    The HTML element to search.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Rewriter.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    For any Java identifier inside <code>...</code> elements, inserts soft-hyphens or zero-width spaces where this method decides that the code could be wrapped on the next line.
    private boolean
    Returns true if the characters just before i are <td…> or <th…> where are ignored characters.
    private void
    load(File file)
    Loads the given file.
    (package private) void
    Processes recursively all HTML files in the given directory.
    private void
    Saves the files after processing, provided that the content has changed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ENCODING

      private static final String ENCODING
      The encoding to use for reading and writing HTML files.
      See Also:
    • OPEN

      private static final String OPEN
      The HTML element to search. Only text inside those elements will be processed.
      See Also:
    • CLOSE

      private static final String CLOSE
      The closing HTML element.
      See Also:
    • file

      private File file
      The file being processed.
    • content

      private final StringBuilder content
      The full content of file. Hyphenation will be done directly in this string builder.
    • buffer

      private final char[] buffer
      A temporary buffer for loading files.
    • modified

      private boolean modified
      true if the content has been modified an need to be saved.
  • Constructor Details

  • Method Details

    • processDirectory

      void processDirectory(File directory) throws IOException
      Processes recursively all HTML files in the given directory.
      Throws:
      IOException
    • load

      private void load(File file) throws IOException
      Loads the given file.
      Throws:
      IOException
    • save

      private void save() throws IOException
      Saves the files after processing, provided that the content has changed. This method does nothing if the content did not changed.
      Throws:
      IOException
    • isBeginningOfCell

      private boolean isBeginningOfCell(int i)
      Returns true if the characters just before i are <td…> or <th…> where are ignored characters. If the element before is <a…>, then that element is skipped an the other element before it is verified.
    • hyphenation

      private void hyphenation()
      For any Java identifier inside <code>...</code> elements, inserts soft-hyphens or zero-width spaces where this method decides that the code could be wrapped on the next line. We make an exception to this rule if the <code> tag is just after a <td> or <th> tag.