org.mmbase.applications.community.builders
Class Message

java.lang.Object
  extended byorg.mmbase.module.core.MMTable
      extended byorg.mmbase.module.core.MMObjectBuilder
          extended byorg.mmbase.applications.community.builders.Message

public class Message
extends MMObjectBuilder

This builder implements additional functionality and methods to handle community objects. Added functionality involve posting and removing a message, managing temporary messages, and retrieving message lists for a specific 'thread'.

Version:
$Id: Message.java,v 1.23 2004/01/08 07:34:22 pierre Exp $
Author:
Dirk-Jan Hoekstra, Pierre van Rooden

Field Summary
static java.lang.String F_BODY
          Field : body
static java.lang.String F_GET_INFO_VALUE
          Formatting Function : getinfovalue
static java.lang.String F_HAS_REPLIES
          Virtual Field : hasreplies
static java.lang.String F_INFO
          Field : info
static java.lang.String F_PARENT
          Virtual Field : parent
static java.lang.String F_RE_SUBJECT
          Virtual Field : resubject
static java.lang.String F_REPLY_COUNT
          Virtual Field : replycount
static java.lang.String F_SEQUENCE
          Field : sequence
static java.lang.String F_SUBJECT
          Field : subject
static java.lang.String F_THREAD
          Field : thread
static java.lang.String F_TIMESTAMP
          Field : timestamp
static java.lang.String F_TIMESTAMPSEC
          Field : timestamp in seconds
static java.lang.String LIST_HEAD_TAG
          Default tag for the listhead message field
static java.lang.String LIST_TAIL_TAG
          Default tag for the listtail message field
protected  int maxBodySize
          Maximum message body size in bytes.
static int POST_ERROR_BODY_EXCEEDS_SIZE
           
static int POST_ERROR_NEED_LOGIN
           
static int POST_ERROR_NO_BODY_TEXT
           
static int POST_ERROR_NO_SUBJECT
           
static int POST_ERROR_NO_USER
           
static int POST_ERROR_RELATION_CHANNEL
           
static int POST_ERROR_RELATION_USER
           
static int POST_ERROR_UNKNOWN
           
static int POST_OK
           
 TemporaryNodeManager tmpNodeManager
           
 
Fields inherited from class org.mmbase.module.core.MMObjectBuilder
AGE_PARAMETERS, broadcastChanges, database, DEFAULT_ALINEA, DEFAULT_EOL, description, descriptions, fields, GUI_PARAMETERS, listCache, nodeCache, OBJ2TYPE_MAX_SIZE, oType, REPLACE_CACHE, searchAge, sortedDBLayout, TEMPNODE_DEFAULT_SIZE, TemporaryNodes, virtual
 
Fields inherited from class org.mmbase.module.core.MMTable
mmb, tableName
 
Constructor Summary
Message()
          Constructor
 
Method Summary
 boolean activate()
          Activates the message builder for the community application by associating it with other community builders
protected  java.lang.Object executeFunction(MMObjectNode node, java.lang.String function, java.lang.String field)
          Executes a function on the field of a node, and returns the result.
 java.util.Vector getListMessages(MMObjectNode thread, java.util.Vector fields, java.util.Comparator ci, int maxCount, int depth, int maxDepth, int startAfterNode, java.lang.String nodeselectfield)
          Retrieves a list of messages related to a thread.
 java.util.Vector getListMessages(StringTagger params)
          Retrieves a list of messages related to a thread.
 java.lang.String getMessageError(int error)
          Obtains the description of an error that occurred during a user-induced action on a message (such as a post).
 java.lang.String getNewTemporaryKey()
          Generates a new temporary key for a temporary message.
 org.mmbase.applications.community.builders.ThreadStats getNrMsgAndHighSeq(MMObjectNode node)
           
 java.util.Vector getRelatedMessages(MMObjectNode node, java.util.Comparator ci)
          Retrieves a list of messages related to a thread.
 java.util.Enumeration getReplies(MMObjectNode node)
          Get all relations for a node with other messages.
 java.util.Vector getTemporaryRelated(MMObjectNode node, java.lang.String wtype)
          Get temporary MMObjectNodes related to a specified MMObjectNode
 java.util.Vector getTemporaryRelated(MMObjectNode node, java.lang.String wtype, int offset, int max)
          Get temporary MMObjectNodes related to a specified MMObjectNode
 TimeStamp getTimeStamp(MMObjectNode node)
          Get the nodes timestampl and timestamph and return them as a TimeStamp.
 java.lang.Object getValue(MMObjectNode node, java.lang.String field)
          Provides additional functionality when obtaining field values.
 boolean hasReplies(MMObjectNode node)
          Returns whether a node has replies or not.
 boolean init()
          Initializes this builder The property 'mmb' needs to be set for the builder before this method can be called.
 int insert(java.lang.String owner, MMObjectNode node)
          Inserts a message node to the database.
 MMObjectNode isPostedInChannel(MMObjectNode node)
          Returns the channel in which the given message node is posted.
 int post(java.lang.String body, int channel, int chatter)
          Posts a message as a temporary message node.
 int post(java.lang.String body, int channel, int chatter, java.lang.String chatterName)
          Posts a message as a temporary message node.
 int post(java.lang.String subject, java.lang.String body, int channel, int thread, int chatter, java.lang.String chatterName)
          Post a new message in the channel.
 void removeNode(MMObjectNode node)
          Remove a node if it's not a parent message to another message.
 void removeNode(MMObjectNode node, boolean recursive)
          Remove a node and, optionally, it's child nodes.
 java.lang.String replace(scanpage sp, java.util.StringTokenizer tok)
          Handles the $MOD-MMBASE-BUILDER-message- commands.
 int update(java.lang.String chatterName, int chatter, java.lang.String subject, java.lang.String body, int number)
          Changes the subject and body fields, and the name of the poster when stored in the info-field of an already existing message.
 int update(java.lang.String chatterName, java.lang.String subject, java.lang.String body, int number)
          Changes the subject and body fields, and the name of the poster when stored in the info-field of an already existing message.
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addField, addLocalObserver, addRemoteObserver, buildSet, checkAddTmpField, commit, convertMMNode2SQL, count, count, create, createAlias, delete, deleteNodeCache, drop, equals, equals, executeFunction, fieldLocalChanged, getAge, getAliasedNode, getAncestors, getCacheNumbers, getCacheSize, getCacheSize, getClassName, getConfigFile, getDBByte, getDBKey, getDBState, getDBText, getDBType, getDefaultTeaser, getDefaultUrl, getDescendants, getDescription, getDescription, getDescriptions, getEditFields, getField, getFieldNames, getFields, getFields, getFunctionParameters, getGUIIndicator, getGUIIndicator, getHardNode, getHardNode, getHTML, getInitParameter, getInitParameters, getList, getLocaleGUIIndicator, getLocaleGUIIndicator, getMachineName, getMaintainer, getMMBase, getNewNode, getNewTmpNode, getNextField, getNextField, getNode, getNode, getNode, getNode, getNodes, getNodes, getNodeType, getNumberFromName, getObjectType, getObjectValue, getParameterDefinition, getParentBuilder, getPluralName, getPluralName, getPluralNames, getQuery, getQuery, getQuery, getRawNodes, getRelations_main, getSearchAge, getShort, getShortedByte, getShortedText, getSingularName, getSingularName, getSingularNames, getSmartPath, getSortedFields, getSortedListFields, getTmpNode, getURLEncode, getVersion, getWAP, getXMLPath, hashCode, hostname_function, insert, insertDone, isExtensionOf, isNodeCached, isVirtual, nodeLocalChanged, nodeRemoteChanged, preCommit, preEdit, process, processSearchResults, putTmpNode, readSearchResults, removeField, removeRelations, removeSyncNodes, removeTmpNode, safeCache, safeCommit, safeInsert, search, search, search, searchIn, searchIn, searchIn, searchList, searchList, searchNumbers, searchVector, searchVector, searchVector, searchVector, searchVectorIn, searchVectorIn, searchVectorIn, searchVectorIn, searchWithWhere, sendFieldChangeSignal, setDBLayout_xml, setDefaults, setDescription, setDescriptions, setInitParameter, setMaintainer, setMMBase, setParentBuilder, setPluralNames, setSearchAge, setSingularNames, setTableName, setUniqueValue, setUniqueValue, setValue, setValue, setVersion, setXMLPath, setXMLValues, signalNewObject, testValidData, toString, toString, toXML, updateFields, waitUntilNodeChanged, wrap
 
Methods inherited from class org.mmbase.module.core.MMTable
created, getFullTableName, getTableName, size
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

POST_OK

public static final int POST_OK
See Also:
Constant Field Values

POST_ERROR_UNKNOWN

public static final int POST_ERROR_UNKNOWN
See Also:
Constant Field Values

POST_ERROR_BODY_EXCEEDS_SIZE

public static final int POST_ERROR_BODY_EXCEEDS_SIZE
See Also:
Constant Field Values

POST_ERROR_NO_USER

public static final int POST_ERROR_NO_USER
See Also:
Constant Field Values

POST_ERROR_NEED_LOGIN

public static final int POST_ERROR_NEED_LOGIN
See Also:
Constant Field Values

POST_ERROR_RELATION_CHANNEL

public static final int POST_ERROR_RELATION_CHANNEL
See Also:
Constant Field Values

POST_ERROR_RELATION_USER

public static final int POST_ERROR_RELATION_USER
See Also:
Constant Field Values

POST_ERROR_NO_BODY_TEXT

public static final int POST_ERROR_NO_BODY_TEXT
See Also:
Constant Field Values

POST_ERROR_NO_SUBJECT

public static final int POST_ERROR_NO_SUBJECT
See Also:
Constant Field Values

LIST_HEAD_TAG

public static final java.lang.String LIST_HEAD_TAG
Default tag for the listhead message field

See Also:
Constant Field Values

LIST_TAIL_TAG

public static final java.lang.String LIST_TAIL_TAG
Default tag for the listtail message field

See Also:
Constant Field Values

F_THREAD

public static final java.lang.String F_THREAD
Field : thread

See Also:
Constant Field Values

F_BODY

public static final java.lang.String F_BODY
Field : body

See Also:
Constant Field Values

F_SUBJECT

public static final java.lang.String F_SUBJECT
Field : subject

See Also:
Constant Field Values

F_SEQUENCE

public static final java.lang.String F_SEQUENCE
Field : sequence

See Also:
Constant Field Values

F_INFO

public static final java.lang.String F_INFO
Field : info

See Also:
Constant Field Values

F_TIMESTAMP

public static final java.lang.String F_TIMESTAMP
Field : timestamp

See Also:
Constant Field Values

F_TIMESTAMPSEC

public static final java.lang.String F_TIMESTAMPSEC
Field : timestamp in seconds

See Also:
Constant Field Values

F_RE_SUBJECT

public static final java.lang.String F_RE_SUBJECT
Virtual Field : resubject

See Also:
Constant Field Values

F_REPLY_COUNT

public static final java.lang.String F_REPLY_COUNT
Virtual Field : replycount

See Also:
Constant Field Values

F_HAS_REPLIES

public static final java.lang.String F_HAS_REPLIES
Virtual Field : hasreplies

See Also:
Constant Field Values

F_PARENT

public static final java.lang.String F_PARENT
Virtual Field : parent

See Also:
Constant Field Values

F_GET_INFO_VALUE

public static final java.lang.String F_GET_INFO_VALUE
Formatting Function : getinfovalue

See Also:
Constant Field Values

maxBodySize

protected int maxBodySize
Maximum message body size in bytes.


tmpNodeManager

public TemporaryNodeManager tmpNodeManager
Constructor Detail

Message

public Message()
Constructor

Method Detail

init

public boolean init()
Description copied from class: MMObjectBuilder
Initializes this builder The property 'mmb' needs to be set for the builder before this method can be called. The method retrieves data from the TypeDef builder, or adds data to that builder if the current builder is not yet registered.

Overrides:
init in class MMObjectBuilder
Returns:
true if init was completed, false if uncompleted.
See Also:
MMObjectBuilder.create()

activate

public boolean activate()
Activates the message builder for the community application by associating it with other community builders

Returns:
true if activation worked

getMessageError

public java.lang.String getMessageError(int error)
Obtains the description of an error that occurred during a user-induced action on a message (such as a post).

Returns:
the error description

post

public int post(java.lang.String subject,
                java.lang.String body,
                int channel,
                int thread,
                int chatter,
                java.lang.String chatterName)
Post a new message in the channel.

Parameters:
subject - The subject of the message.
body - The body of the message.
channel - The channel in which the message has to get posted.
thread - The number of the thread (a Message or Channel) in which the Message has to get listed.
chatter - The usernumber of the user that has written the message.
chatterName - The name of the person that has written the message when he hasn't a usernumber.
Returns:
The number of the newly created message node or a negative number if for some reason no message was created. The number can be used with getPostError() to get the errormessage.

post

public int post(java.lang.String body,
                int channel,
                int chatter)
Posts a message as a temporary message node.

Parameters:
body - The body of the message.
channel - The channel in which the message has to get posted.
chatter - The usernumber of the user that has written the message.
Returns:
POST_OK on success, otherwise an error number. The number can be used with getPostError() to get the errormessage.

post

public int post(java.lang.String body,
                int channel,
                int chatter,
                java.lang.String chatterName)
Posts a message as a temporary message node.

Parameters:
body - The body of the message.
channel - The channel in which the message has to get posted.
chatter - The usernumber of the user that has written the message.
Returns:
POST_OK on success, otherwise an error number. The number can be used with getPostError() to get the errormessage.

insert

public int insert(java.lang.String owner,
                  MMObjectNode node)
Inserts a message node to the database.

Overrides:
insert in class MMObjectBuilder
Parameters:
owner - The owner of the node.
node - The node to insert.
Returns:
An int value which is the new object's unique number, -1 if the insert failed.

update

public int update(java.lang.String chatterName,
                  java.lang.String subject,
                  java.lang.String body,
                  int number)
Changes the subject and body fields, and the name of the poster when stored in the info-field of an already existing message. This function is usefull for editing or moderating the context of a message.

Parameters:
chatterName - The name of the person who has written the message.
subject - The subject of the message.
body - The body of the message.
number - The message node's number.
Returns:
POST_OK on success, otherwise an error number. The number can be used with getPostError() to get the errormessage.

update

public int update(java.lang.String chatterName,
                  int chatter,
                  java.lang.String subject,
                  java.lang.String body,
                  int number)
Changes the subject and body fields, and the name of the poster when stored in the info-field of an already existing message. This function is usefull for editing or moderating the context of a message.

Parameters:
chatterName - The name of the person who has written the message.
chatter - the number of the chatter object
subject - The subject of the message.
body - The body of the message.
number - The message node's number.
Returns:
POST_OK on success, otherwise an error number. The number can be used with getPostError() to get the errormessage.

getListMessages

public java.util.Vector getListMessages(StringTagger params)
Retrieves a list of messages related to a thread. The tagger parameter specified what fields to treturn, the order of the messages, and any filters and options to use for the list.
Attributes that can be set for th list are:

Parameters:
params - the attributes of the LIST tag.
Returns:
A Vector containing the requested fields.

getListMessages

public java.util.Vector getListMessages(MMObjectNode thread,
                                        java.util.Vector fields,
                                        java.util.Comparator ci,
                                        int maxCount,
                                        int depth,
                                        int maxDepth,
                                        int startAfterNode,
                                        java.lang.String nodeselectfield)
Retrieves a list of messages related to a thread.

Parameters:
thread - the number of the message or channel that is the parent of the messages requested
fields - a Vector with fieldnames to return. This may change as some fields are mandatory in certain situations
ci - A Comparator to use for sorting the messages
maxCount - : Maximum number of messages to return
depth - the current depth at which emssages are searched
maxDepth - the maximum depth at which to search for (replies to) messages
startAfterNode - starts messages after the message identified with the specified value
nodeselectfield - field to which to compare the value of startAfterNode (i.e. 'number' or 'sequence').
Returns:
A Vector containing the requested fields.

getRelatedMessages

public java.util.Vector getRelatedMessages(MMObjectNode node,
                                           java.util.Comparator ci)
Retrieves a list of messages related to a thread.

Parameters:
ci - A Comparator to use for sorting the messages
Returns:
A Vector containing the requested message nodes.

getTemporaryRelated

public java.util.Vector getTemporaryRelated(MMObjectNode node,
                                            java.lang.String wtype)
Get temporary MMObjectNodes related to a specified MMObjectNode

Parameters:
wtype - Specifies the type of the nodes you want to have e.g. wtype="pools"

getTemporaryRelated

public java.util.Vector getTemporaryRelated(MMObjectNode node,
                                            java.lang.String wtype,
                                            int offset,
                                            int max)
Get temporary MMObjectNodes related to a specified MMObjectNode

Parameters:
wtype - Specifies the type of the nodes you want to have e.g. wtype="pools"

removeNode

public void removeNode(MMObjectNode node)
Remove a node if it's not a parent message to another message. If it is, the node is not removed.

Overrides:
removeNode in class MMObjectBuilder
Parameters:
node - the node to remove

removeNode

public void removeNode(MMObjectNode node,
                       boolean recursive)
Remove a node and, optionally, it's child nodes.

Parameters:
node - the node to remove
recursive - if true, the node will be removed along with its childnodes if it has any. Otherwise, it will only be removed if the ndoe hs no children.

getNrMsgAndHighSeq

public org.mmbase.applications.community.builders.ThreadStats getNrMsgAndHighSeq(MMObjectNode node)

hasReplies

public boolean hasReplies(MMObjectNode node)
Returns whether a node has replies or not.

Parameters:
node - the node to find the relations of
Returns:
true if the node has related messages.

getReplies

public java.util.Enumeration getReplies(MMObjectNode node)
Get all relations for a node with other messages. These are not necessarily all a reply to this message (it may be a parent message). XXX: should be fixed with a directional modifier, but then we first need a few additonal calls in InsRel or MMObjectNode.

Parameters:
node - the node to find the relations of
Returns:
an Enumeration containign the related messages.

getValue

public java.lang.Object getValue(MMObjectNode node,
                                 java.lang.String field)
Provides additional functionality when obtaining field values. This method is called whenever a Node of the builder's type fails at evaluating a getValue() request (generally when a fieldname is supplied that doesn't exist).
The following virtual fields are calculated:
timestamp - returns the timestamp of the message
resubject - returns the subject with a "RE:" prefix (if needed)
replycount - returns the number of replies
hasreplies - returns "true" if the message has replies, "false" otherwise
parent - returns the number of the parent node (same as "thread")

Overrides:
getValue in class MMObjectBuilder
Parameters:
node - the node whose fields are queried
field - the fieldname that is requested
Returns:
the result of the call, null if no valid functions or virtual fields could be determined.

executeFunction

protected java.lang.Object executeFunction(MMObjectNode node,
                                           java.lang.String function,
                                           java.lang.String field)
Executes a function on the field of a node, and returns the result. This method is called by the builder's getValue(org.mmbase.module.core.MMObjectNode, java.lang.String) method. Functions implemented are hasreplies() and getinfovalue().

Overrides:
executeFunction in class MMObjectBuilder
Parameters:
node - the node whose fields are queries
field - the fieldname that is requested
Returns:
the result of the 'function', or null if no valid functions could be determined.

replace

public java.lang.String replace(scanpage sp,
                                java.util.StringTokenizer tok)
Handles the $MOD-MMBASE-BUILDER-message- commands.

Overrides:
replace in class MMObjectBuilder
Parameters:
sp - The scanpage (containing http and user info) that calls the function
tok - a list of strings that describe the (sub)command to execute
Returns:
the result value as a String

getTimeStamp

public TimeStamp getTimeStamp(MMObjectNode node)
Get the nodes timestampl and timestamph and return them as a TimeStamp.


isPostedInChannel

public MMObjectNode isPostedInChannel(MMObjectNode node)
Returns the channel in which the given message node is posted.

Returns:
teh channel of teh message as a MMObjectNode

getNewTemporaryKey

public java.lang.String getNewTemporaryKey()
Generates a new temporary key for a temporary message.



MMBase build 1.7.4.20050922