org.jomc.util
Class SectionEditor

Package class diagram package SectionEditor
java.lang.Object
  extended by org.jomc.util.LineEditor
      extended by org.jomc.util.SectionEditor

public class SectionEditor
extends LineEditor

Interface to section based editing.

Section based editing is a two phase process of parsing the editor's input into a corresponding hierarchy of Section instances, followed by rendering the parsed sections to produce the output of the editor. Method editLine returns null during parsing and the output of the editor on end of input, rendered by calling method getOutput. Parsing is backed by methods getSection and isSectionFinished.

Version:
$Id: SectionEditor.java 891 2009-11-02 03:40:00Z schulte2005 $
Author:
Christian Schulte
See Also:
LineEditor.edit(java.lang.String)

Constructor Summary
SectionEditor()
          Creates a new SectionEditor instance.
SectionEditor(LineEditor editor)
          Creates a new SectionEditor instance taking an editor to chain.
SectionEditor(LineEditor editor, String lineSeparator)
          Creates a new SectionEditor instance taking an editor to chain and a string to use for separating lines.
SectionEditor(String lineSeparator)
          Creates a new SectionEditor instance taking a string to use for separating lines.
 
Method Summary
protected  String editLine(String line)
          Edits a line.
protected  void editSection(Section section)
          Edits a section.
protected  String getOutput(Section section)
          Gets the output of the editor.
protected  Section getSection(String line)
          Parses the given line to mark the start of a new section.
protected  boolean isSectionFinished(String line)
          Parses the given line to mark the end of a section.
 
Methods inherited from class org.jomc.util.LineEditor
edit, getLineSeparator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SectionEditor

public SectionEditor()
Creates a new SectionEditor instance.


SectionEditor

public SectionEditor(String lineSeparator)
Creates a new SectionEditor instance taking a string to use for separating lines.

Parameters:
lineSeparator - String to use for separating lines.

SectionEditor

public SectionEditor(LineEditor editor)
Creates a new SectionEditor instance taking an editor to chain.

Parameters:
editor - The editor to chain.

SectionEditor

public SectionEditor(LineEditor editor,
                     String lineSeparator)
Creates a new SectionEditor instance taking an editor to chain and a string to use for separating lines.

Parameters:
editor - The editor to chain.
lineSeparator - String to use for separating lines.
Method Detail

editLine

protected final String editLine(String line)
                         throws IOException
Description copied from class: LineEditor
Edits a line.

Overrides:
editLine in class LineEditor
Parameters:
line - The line to edit or null indicating the end of input.
Returns:
The string to replace line with, or null to replace line with nothing.
Throws:
IOException - if editing fails.

getSection

protected Section getSection(String line)
Parses the given line to mark the start of a new section.

Parameters:
line - The line to parse.
Returns:
The section starting at line or null if line does not mark the start of a section.

isSectionFinished

protected boolean isSectionFinished(String line)
Parses the given line to mark the end of a section.

Parameters:
line - The line to parse.
Returns:
true if line marks the end of a section; false if line does not mark the end of a section.

editSection

protected void editSection(Section section)
                    throws IOException
Edits a section.

This method does not change any content by default. Overriding classes may use this method for editing sections prior to rendering.

Parameters:
section - The section to edit.
Throws:
NullPointerException - if section is null.
IOException - if editing fails.

getOutput

protected String getOutput(Section section)
                    throws IOException
Gets the output of the editor.

This method calls method editSection() for each section of the editor prior to rendering the sections to produce the output of the editor.

Parameters:
section - The section to start rendering the editor's output with.
Returns:
The output of the editor.
Throws:
NullPointerException - if section is null.
IOException - if editing or rendering fails.


Copyright © 2005-2009 The JOMC Project. All Rights Reserved.