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:
$JOMC: SectionEditor.java 3934 2011-11-12 00:42:08Z 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.
 boolean isSectionPresent(String sectionName)
          Gets a flag indicating that the input of the editor contained a named section.
 
Methods inherited from class org.jomc.util.LineEditor
edit, getLineNumber, 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)
                      throws IOException
Parses the given line to mark the start of a new section.

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

isSectionFinished

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

Parameters:
line - The line to parse or null.
Returns:
true, if line marks the end of a section; false, if line does not mark the end of a section.
Throws:
IOException - if parsing fails.

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.

isSectionPresent

public boolean isSectionPresent(String sectionName)
Gets a flag indicating that the input of the editor contained a named section.

Parameters:
sectionName - The name of the section to test or null.
Returns:
true, if the input of the editor contained a section with name sectionName; false, if the input of the editor did not contain a section with name sectionName.


Copyright © 2005-2012 The JOMC Project. All Rights Reserved.Get JOMC at SourceForge.net. Fast, secure and Free Open Source software downloads
Please note that this documentation is maintained by non-native english speaking authors. As such, you may encounter phrases or wordings which seem imprecise or may even have a totally different meaning to native english speaking readers than what the individual author was trying to express. If you are a native english speaking reader and find any such phrases or wordings we kindly ask you to send an email to the corresponding author and help us improve this documentation in order to avoid misunderstandings. You will find the authors' email addresses at the top of each class. Please accept our apologies for any inconvenience caused.