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 509 2009-09-21 13:54:49Z schulte2005 $
Author:
Christian Schulte
See Also:
LineEditor.edit(java.lang.String)

Field Summary
private static String DEFAULT_SECTION_END
          Marker indicating the end of a section.
private static String DEFAULT_SECTION_START
          Marker indicating the start of a section.
private  Stack<Section> stack
          Stack of sections.
 
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  String getOutput(Section root)
          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.
private  StringBuilder renderSections(Section section, StringBuilder buffer)
          Appends the content of a given section to a given buffer.
 
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
 

Field Detail

DEFAULT_SECTION_START

private static final String DEFAULT_SECTION_START
Marker indicating the start of a section.

See Also:
Constant Field Values

DEFAULT_SECTION_END

private static final String DEFAULT_SECTION_END
Marker indicating the end of a section.

See Also:
Constant Field Values

stack

private Stack<Section> stack
Stack of sections.

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)
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.

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.

getOutput

protected String getOutput(Section root)
Gets the output of the editor.

This method returns the unchanged input by rendering the given sections. Overwriting classes may call this method after having updated the given sections for rendering edited content.

Parameters:
root - The root of the parsed sections to render the editor's output with.
Returns:
The output of the editor.
Throws:
NullPointerException - if root is null.
See Also:
Section.getSections()

renderSections

private StringBuilder renderSections(Section section,
                                     StringBuilder buffer)
Appends the content of a given section to a given buffer.

Parameters:
section - The section to render.
buffer - The buffer to append the content of section to.
Returns:
buffer with content of section appended.


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