de.tuberlin.cs.flp.jspwiki.plugin.wikiarchive
Class ArchiveHandlerAbstract

java.lang.Object
  extended byde.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandlerAbstract
All Implemented Interfaces:
ArchiveHandler
Direct Known Subclasses:
ArchiveHandlerExternalFormatAbstract, ArchiveHandlerWiki

public abstract class ArchiveHandlerAbstract
extends java.lang.Object
implements ArchiveHandler

Generic base implementation for concrete ArchiveIO-classes. This makes implementing an ArchiveIOHandler easier.


Field Summary
protected  java.util.Map config
           
protected  WikiEngine engine
           
 
Fields inherited from interface de.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandler
EXPORT, IMPORT
 
Constructor Summary
ArchiveHandlerAbstract()
           
 
Method Summary
abstract  java.lang.Object createData()
          Creates an empty data source to be filled for export.
protected abstract  void createEntry(java.lang.Object data, ArchiveEntry entry)
          Creates a new archive entry in the data source handled by this ArchiveIOHandler.
 java.lang.String dataToString(java.lang.Object data)
          Converts the handled data source to string for export.
protected  boolean equalEntries(ArchiveEntry a, ArchiveEntry b)
          Tests whether all data carried by two entries is the same.
abstract  java.lang.String getContentSuffix()
          Content type for export via HTTP.
abstract  java.lang.String getContentType()
          Content type for export via HTTP.
 WikiEngine getEngine()
           
 void init(WikiEngine engine, java.util.Map config)
          Initialize this ArchiveHandler.
protected abstract  java.lang.String msgDone(ArchiveEntry entry, ArchiveEntry outEntry, int mode)
          Outputs a message informing about the action that has been taken for an entry.
protected abstract  java.lang.String msgNotDone(ArchiveEntry entry, ArchiveEntry outEntry, int mode)
          Outputs a message informing that an action has not been taken for an entry.
protected abstract  java.lang.String msgToDo(ArchiveEntry inEntry, ArchiveEntry outEntry, int mode)
          Outputs a message informing about the possible action to be taken for an input entry, e.g.
protected abstract  java.util.Map parseAll(java.lang.Object data)
          Retrieves all archive entries from the data source.
 java.lang.String performIO(boolean io, Archive archive, java.lang.Object data, int mode, java.util.Collection exceptions)
          Perform either input from the Archive model interface into the data source handled by this ArchiveIOHandler.
protected abstract  void replaceEntry(java.lang.Object data, ArchiveEntry newEntry, ArchiveEntry oldEntry)
          Replaces an archive entry in the data source handled by this ArchiveIOHandler.
 void setEngine(WikiEngine wikiEngine)
           
 void stringToData(java.lang.String s, java.lang.Object data)
          Converts a string to a handled data source for import.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

engine

protected WikiEngine engine

config

protected java.util.Map config
Constructor Detail

ArchiveHandlerAbstract

public ArchiveHandlerAbstract()
Method Detail

init

public void init(WikiEngine engine,
                 java.util.Map config)
Initialize this ArchiveHandler.

Specified by:
init in interface ArchiveHandler
Parameters:
engine -
config -

performIO

public java.lang.String performIO(boolean io,
                                  Archive archive,
                                  java.lang.Object data,
                                  int mode,
                                  java.util.Collection exceptions)
                           throws java.io.IOException
Perform either input from the Archive model interface into the data source handled by this ArchiveIOHandler.

Specified by:
performIO in interface ArchiveHandler
Parameters:
io - Switch between input or output mode, true for input into data source, false for output into Archive model interface.
archive - The Archive model interface.
data - The data source handled by this ArchiveIOHandler.
mode - The processing mode. This is a bit mask with:
bit #0 set: update exisiting entries with new values, if new data is different
bit #1 set: insert new entries
bit #2 set: ask individually for each entry (generate HTML checkbox-form first)
exceptions - Collection of entry names that should be treated as exceptions to the behaviour specified by mode. (Not used.)
Returns:
Throws:
java.io.IOException - if an i/o error occurs

createData

public abstract java.lang.Object createData()
                                     throws java.io.IOException
Creates an empty data source to be filled for export.

Specified by:
createData in interface ArchiveHandler
Returns:
Throws:
java.io.IOException

dataToString

public java.lang.String dataToString(java.lang.Object data)
                              throws java.io.IOException
Converts the handled data source to string for export.

Specified by:
dataToString in interface ArchiveHandler
Parameters:
data -
Returns:
Throws:
java.io.IOException

stringToData

public void stringToData(java.lang.String s,
                         java.lang.Object data)
                  throws java.io.IOException
Converts a string to a handled data source for import.

Specified by:
stringToData in interface ArchiveHandler
Parameters:
s -
data -
Throws:
java.io.IOException

getContentSuffix

public abstract java.lang.String getContentSuffix()
Content type for export via HTTP.

Specified by:
getContentSuffix in interface ArchiveHandler
Returns:

getContentType

public abstract java.lang.String getContentType()
Content type for export via HTTP.

Specified by:
getContentType in interface ArchiveHandler
Returns:

parseAll

protected abstract java.util.Map parseAll(java.lang.Object data)
                                   throws java.io.IOException
Retrieves all archive entries from the data source.

Parameters:
data - The data source handled by this ArchiveIOHandler.
Returns:
Throws:
java.io.IOException - if an i/o error occurs

createEntry

protected abstract void createEntry(java.lang.Object data,
                                    ArchiveEntry entry)
                             throws java.io.IOException
Creates a new archive entry in the data source handled by this ArchiveIOHandler.

Parameters:
data - The data source handled by this ArchiveIOHandler.
entry - The entry.
Throws:
java.io.IOException - if an i/o error occurs

replaceEntry

protected abstract void replaceEntry(java.lang.Object data,
                                     ArchiveEntry newEntry,
                                     ArchiveEntry oldEntry)
                              throws java.io.IOException
Replaces an archive entry in the data source handled by this ArchiveIOHandler.

Parameters:
data - The data source handled by this ArchiveIOHandler.
newEntry - The new entry.
oldEntry - The old entry.
Throws:
java.io.IOException - if an i/o error occurs

equalEntries

protected boolean equalEntries(ArchiveEntry a,
                               ArchiveEntry b)
Tests whether all data carried by two entries is the same. Note that this is different from using Comparators on ArchiveEntry objects, because Comparators only look at entry-names, while this method compares all entry-data.

Parameters:
a - One archive entry.
b - Another archive entry.
Returns:
true if both entries have equals content, false otherwise.

msgToDo

protected abstract java.lang.String msgToDo(ArchiveEntry inEntry,
                                            ArchiveEntry outEntry,
                                            int mode)
Outputs a message informing about the possible action to be taken for an input entry, e.g. whether it would be added as a new entry, or an existing one would be updated.

Parameters:
inEntry - The input entry.
outEntry - The currently existing possible output entry, or null if such does not exist yet.
mode - The action mode, like the mode parameter of performIO().
Returns:
The message string. (Actually used to build a part of an HTML-form user interface.)

msgDone

protected abstract java.lang.String msgDone(ArchiveEntry entry,
                                            ArchiveEntry outEntry,
                                            int mode)
Outputs a message informing about the action that has been taken for an entry.

Parameters:
entry - The entry processed.
outEntry - The currently existing possible output entry, or null if such does not exist yet.
mode - The action mode, like the mode parameter of performIO().
Returns:
The message string. (Actually used to build a part of an HTML-form user interface.)

msgNotDone

protected abstract java.lang.String msgNotDone(ArchiveEntry entry,
                                               ArchiveEntry outEntry,
                                               int mode)
Outputs a message informing that an action has not been taken for an entry.

Parameters:
entry - The entry not processed.
outEntry - The currently existing possible output entry, or null if such does not exist yet.
mode - The action mode, like the mode parameter of performIO().
Returns:
The message string. (Actually used to build a part of an HTML-form user interface.)

getEngine

public WikiEngine getEngine()

setEngine

public void setEngine(WikiEngine wikiEngine)