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

java.lang.Object
  extended byde.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandlerAbstract
      extended byde.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandlerExternalFormatAbstract
          extended byde.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandlerBibTeX
All Implemented Interfaces:
ArchiveHandler

public class ArchiveHandlerBibTeX
extends ArchiveHandlerExternalFormatAbstract

I/O-handler for bidirectional data interchange from/to a BibTeX bibliography file.


Field Summary
static java.lang.String CONTENT_SUFFIX
           
static java.lang.String CONTENT_TYPE
           
protected static java.util.Properties DEFAULT_ENTRIES
          Default BibTeX-entries to labels mapping.
protected static java.util.Map DEFAULT_ENTRIES_OPTIONS
          Default entries to options-map mapping.
protected static java.util.Properties DEFAULT_FORMATS
           
protected static java.util.Properties DEFAULT_TYPES
          Default BibTeX-type to labels mapping.
protected  java.util.Properties entries
           
protected  java.util.Map entriesOptions
           
protected  java.util.Properties formats
           
protected  java.util.Properties types
           
 
Fields inherited from class de.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandlerAbstract
config, engine
 
Fields inherited from interface de.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandler
EXPORT, IMPORT
 
Constructor Summary
ArchiveHandlerBibTeX()
           
 
Method Summary
protected static void appendToken(java.io.StreamTokenizer st, java.lang.StringBuffer sb)
          Appends the current token to a StringBuffer.
protected static java.lang.String bibtexEntry(java.lang.String key, java.lang.Object val)
          Generated a field entry string inside a BibTeX entry.
protected static java.lang.String braceBlock(java.io.StreamTokenizer st)
          Parses a block enclosed in curly braces "{" and "}".
protected  ArchiveEntryBibTeX convertEntry(ArchiveEntry entry)
           
 void createEntry(java.lang.Object data, ArchiveEntry entry)
          Creates a new archive entry in the data source handled by this ArchiveIOHandler.
protected  java.lang.String entry2bibtex(ArchiveEntryBibTeX entry)
          Generate a single BibTeX entry string.
 java.lang.String getContentSuffix()
          Content type for export via HTTP.
 java.lang.String getContentType()
          Content type for export via HTTP.
 java.util.Properties getEntries()
           
 java.util.Properties getEntryOptions(java.lang.String entryName)
           
 java.util.Properties getFormats()
           
 java.util.Properties getTypes()
          Get BibTeX-type to labels mapping.
 void init(WikiEngine engine, java.util.Map config)
          Init.
 boolean isEntryOptional(java.lang.String entryName)
           
 boolean isType(java.lang.String type)
           
protected static void optional(java.io.StreamTokenizer st, char c)
          Optionally allows a token to be the current token.
protected  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 static void putDefaults(java.util.Properties p, java.lang.String[] s)
          Puts an array of strings into the Properties-object, buy using each array member both as key and value for each entry.
protected  void replaceEntry(java.lang.Object data, ArchiveEntry newEntryA, ArchiveEntry oldEntryA)
          Replaces an archive entry in the data source handled by this ArchiveIOHandler.
protected static void require(java.io.StreamTokenizer st, char tok)
          Tests if the tokenizer's current token matches a specified character.
protected static void require(java.io.StreamTokenizer st, java.lang.String tok)
          Tests if the tokenizer's current token matches a specified string.
protected static void syntax(java.io.StreamTokenizer st)
          Sets the tokenizer's syntax for parsing BibTeX.
protected  java.lang.String translateKey(java.lang.String key, boolean fromTo)
           
protected  java.util.Map translateKeys(java.util.Map m, boolean fromTo)
          Converts the key names of Map m from/to label-strings.
protected  java.lang.String translateType(java.lang.String name, boolean fromTo)
          Converts a BibTeX type name from or to its label-string.
protected static java.lang.String until(java.io.StreamTokenizer st, char tok)
          Returns all tokens until another token occurs, concatenated as one string.
 
Methods inherited from class de.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandlerExternalFormatAbstract
createData, dataToString, msgDone, msgNotDone, msgToDo, stringToData
 
Methods inherited from class de.tuberlin.cs.flp.jspwiki.plugin.wikiarchive.ArchiveHandlerAbstract
equalEntries, getEngine, setEngine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE

public static final java.lang.String CONTENT_TYPE
See Also:
Constant Field Values

CONTENT_SUFFIX

public static final java.lang.String CONTENT_SUFFIX
See Also:
Constant Field Values

DEFAULT_FORMATS

protected static java.util.Properties DEFAULT_FORMATS
See Also:
formats

DEFAULT_ENTRIES

protected static java.util.Properties DEFAULT_ENTRIES
Default BibTeX-entries to labels mapping.

See Also:
entries

DEFAULT_ENTRIES_OPTIONS

protected static java.util.Map DEFAULT_ENTRIES_OPTIONS
Default entries to options-map mapping.

See Also:
entriesOptions

DEFAULT_TYPES

protected static java.util.Properties DEFAULT_TYPES
Default BibTeX-type to labels mapping.

See Also:
types

types

protected java.util.Properties types

entries

protected java.util.Properties entries

entriesOptions

protected java.util.Map entriesOptions

formats

protected java.util.Properties formats
Constructor Detail

ArchiveHandlerBibTeX

public ArchiveHandlerBibTeX()
Method Detail

init

public void init(WikiEngine engine,
                 java.util.Map config)
Init.

Specified by:
init in interface ArchiveHandler
Overrides:
init in class ArchiveHandlerAbstract
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
Overrides:
performIO in class ArchiveHandlerAbstract
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

getContentType

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

Specified by:
getContentType in interface ArchiveHandler
Specified by:
getContentType in class ArchiveHandlerAbstract
Returns:

getContentSuffix

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

Specified by:
getContentSuffix in interface ArchiveHandler
Specified by:
getContentSuffix in class ArchiveHandlerAbstract
Returns:

createEntry

public void createEntry(java.lang.Object data,
                        ArchiveEntry entry)
Creates a new archive entry in the data source handled by this ArchiveIOHandler.

Specified by:
createEntry in class ArchiveHandlerAbstract
Parameters:
data - The data source handled by this ArchiveIOHandler.
entry - The entry.

replaceEntry

protected void replaceEntry(java.lang.Object data,
                            ArchiveEntry newEntryA,
                            ArchiveEntry oldEntryA)
Replaces an archive entry in the data source handled by this ArchiveIOHandler.

Specified by:
replaceEntry in class ArchiveHandlerAbstract
Parameters:
data - The data source handled by this ArchiveIOHandler.
newEntryA - The new entry.
oldEntryA - The old entry.

parseAll

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

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

convertEntry

protected ArchiveEntryBibTeX convertEntry(ArchiveEntry entry)
Parameters:
entry -
Returns:

getTypes

public java.util.Properties getTypes()
Get BibTeX-type to labels mapping. Keys of the properties-map are BibTeX type names (values for field 'type'), values are (language-specific) label string that are used in Wiki pages.

Returns:
Properties-map with BibTeX-type to labels mapping.
See Also:
types

getFormats

public java.util.Properties getFormats()
Returns:

getEntries

public java.util.Properties getEntries()
Returns:

getEntryOptions

public java.util.Properties getEntryOptions(java.lang.String entryName)
Parameters:
entryName -
Returns:

isEntryOptional

public boolean isEntryOptional(java.lang.String entryName)
Parameters:
entryName -
Returns:

isType

public boolean isType(java.lang.String type)
Parameters:
type - The type.
Returns:

translateKeys

protected java.util.Map translateKeys(java.util.Map m,
                                      boolean fromTo)
Converts the key names of Map m from/to label-strings. This uses label strings specified as parameters.

Parameters:
m - The map.
fromTo - If true, convert from label to key, if false, convert from key to label.
Returns:
Map with translated keys, same values.

translateKey

protected java.lang.String translateKey(java.lang.String key,
                                        boolean fromTo)
Parameters:
key -
fromTo -
Returns:

translateType

protected java.lang.String translateType(java.lang.String name,
                                         boolean fromTo)
Converts a BibTeX type name from or to its label-string. This uses label string specified as parameters.

Parameters:
name - The name or label.
fromTo - If true, convert from label to name, if false, convert from name to label.
Returns:
The translated string.
See Also:
types

entry2bibtex

protected java.lang.String entry2bibtex(ArchiveEntryBibTeX entry)
Generate a single BibTeX entry string.

Parameters:
entry - The entry to output as BibTeX.
Returns:
Single BibTeX entry.

bibtexEntry

protected static java.lang.String bibtexEntry(java.lang.String key,
                                              java.lang.Object val)
Generated a field entry string inside a BibTeX entry.

Parameters:
key - The field's name.
val - The field's value.
Returns:
field entry string

require

protected static void require(java.io.StreamTokenizer st,
                              java.lang.String tok)
                       throws java.io.IOException
Tests if the tokenizer's current token matches a specified string.

Parameters:
st - The stream tokenizer.
tok - The token to test match with.
Throws:
java.io.IOException - If the token does not match.

require

protected static void require(java.io.StreamTokenizer st,
                              char tok)
                       throws java.io.IOException
Tests if the tokenizer's current token matches a specified character.

Parameters:
st - The stream tokenizer.
tok - The token to test match with.
Throws:
java.io.IOException - If the token does not match.

optional

protected static void optional(java.io.StreamTokenizer st,
                               char c)
                        throws java.io.IOException
Optionally allows a token to be the current token. If this token is the current one, skip to next token.

Parameters:
st - The stream tokenizer.
c - The token that may optionally occur.
Throws:
java.io.IOException - if an i/o error occurs

until

protected static java.lang.String until(java.io.StreamTokenizer st,
                                        char tok)
                                 throws java.io.IOException
Returns all tokens until another token occurs, concatenated as one string.

Parameters:
st - The stream tokenizer.
tok - The token until which other tokens should be concatenated to the result string.
Returns:
The concatenated tokens that appeared until the specified end token was reached.
Throws:
java.io.IOException - if an i/o error occurs

appendToken

protected static void appendToken(java.io.StreamTokenizer st,
                                  java.lang.StringBuffer sb)
Appends the current token to a StringBuffer.

Parameters:
st - The stream tokenizer.
sb - The string buffer.

braceBlock

protected static java.lang.String braceBlock(java.io.StreamTokenizer st)
                                      throws java.io.IOException
Parses a block enclosed in curly braces "{" and "}". Returns the complete string inside the block. Nested curly braces are possible and will be returned as part of the string.

Parameters:
st - The stream tokenizer.
Returns:
The string enclosed in curly braces.
Throws:
java.io.IOException - if an i/o error occurs

syntax

protected static void syntax(java.io.StreamTokenizer st)
Sets the tokenizer's syntax for parsing BibTeX.

Parameters:
st - The stream tokenizer.

putDefaults

protected static void putDefaults(java.util.Properties p,
                                  java.lang.String[] s)
Puts an array of strings into the Properties-object, buy using each array member both as key and value for each entry. This is used for initializing dummy-properties.

Parameters:
p - The properties.
s - The string array.