public class WikiBoard
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
WikiBoard.Entry
Contains information of wiki page.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ANONYMOUS |
private static java.util.Map<java.lang.String,java.lang.String> |
AUTHORS |
private MapHeap |
bkpbase |
private MapHeap |
datbase |
private static java.lang.String |
DATE_FORMAT |
static int |
keyLength |
protected static java.text.SimpleDateFormat |
SimpleFormatter |
Constructor and Description |
---|
WikiBoard(java.io.File actpath,
java.io.File bkppath)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes database files.
|
(package private) static java.lang.String |
dateString()
Gets current date.
|
static java.lang.String |
dateString(java.util.Date date)
Gets String representation of a Date.
|
static java.lang.String |
guessAuthor(java.lang.String ip)
Tries to guess the name of the author by a given IP address.
|
java.util.Iterator<byte[]> |
keys(boolean up)
Gets Iterator of keys in database.
|
java.util.Iterator<byte[]> |
keysBkp(boolean up)
Gets Iterator of keys in backup database.
|
WikiBoard.Entry |
newEntry(java.lang.String subject,
java.lang.String author,
java.lang.String ip,
java.lang.String reason,
byte[] page)
Creates new Entry.
|
private static java.lang.String |
normalize(java.lang.String key)
Gets normalized version of a key.
|
WikiBoard.Entry |
read(java.lang.String key)
Reads content of Entry from database.
|
(package private) WikiBoard.Entry |
read(java.lang.String key,
MapHeap base)
Reads content of Entry from database.
|
WikiBoard.Entry |
readBkp(java.lang.String key)
Reads old Entry from backup database.
|
static void |
setAuthor(java.lang.String ip,
java.lang.String author)
Adds an author name and a corresponding IP to internal Map.
|
int |
size()
Gets number of entries of wiki DB.
|
int |
sizeOfTwo()
Gets total number of entries of wiki DB and DB which contains backup entries.
|
static java.lang.String |
webalize(java.lang.String key)
Normalizes key and replaces spaces by escape code.
|
java.lang.String |
write(WikiBoard.Entry entry)
Writes content of Entry to database and returns key.
|
public static final int keyLength
private static final java.lang.String DATE_FORMAT
private static final java.lang.String ANONYMOUS
protected static final java.text.SimpleDateFormat SimpleFormatter
private MapHeap datbase
private MapHeap bkpbase
private static final java.util.Map<java.lang.String,java.lang.String> AUTHORS
public WikiBoard(java.io.File actpath, java.io.File bkppath) throws java.io.IOException
actpath
- path of database which contains current wiki data.bkppath
- path of backup database.java.io.IOException
- if error occurs during HDD access.public int sizeOfTwo()
public int size()
public void close()
static java.lang.String dateString()
public static java.lang.String dateString(java.util.Date date)
date
- the Date.private static java.lang.String normalize(java.lang.String key)
key
- the key.public static java.lang.String webalize(java.lang.String key)
key
- the key.public static java.lang.String guessAuthor(java.lang.String ip)
ip
- the IP address.public static void setAuthor(java.lang.String ip, java.lang.String author)
ip
- IP address of the author.author
- name of author.public WikiBoard.Entry newEntry(java.lang.String subject, java.lang.String author, java.lang.String ip, java.lang.String reason, byte[] page) throws java.io.IOException
subject
- subject of entry.author
- author of entry.ip
- IP address of author.reason
- reason for new Entry (for example "edit").page
- content of Entry.java.io.IOException
public java.lang.String write(WikiBoard.Entry entry)
entry
- Entry to be written.public WikiBoard.Entry read(java.lang.String key)
key
- key of Entry.WikiBoard.Entry read(java.lang.String key, MapHeap base)
key
- key of Entry.base
- database containing data.public WikiBoard.Entry readBkp(java.lang.String key)
key
- key of Entry.public java.util.Iterator<byte[]> keys(boolean up) throws java.io.IOException
up
- java.io.IOException
public java.util.Iterator<byte[]> keysBkp(boolean up) throws java.io.IOException
up
- java.io.IOException