001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/chat/tags/sakai_2-4-1/chat-api/api/src/java/org/sakaiproject/chat2/model/ChatMessage.java $
003: * $Id: ChatMessage.java 29100 2007-04-18 21:45:18Z ajpoland@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.chat2.model;
021:
022: import java.util.Date;
023: import java.util.Stack;
024:
025: import org.sakaiproject.component.cover.ServerConfigurationService;
026: import org.sakaiproject.entity.api.Entity;
027: import org.sakaiproject.entity.api.ResourceProperties;
028: import org.w3c.dom.Document;
029: import org.w3c.dom.Element;
030:
031: /**
032: *
033: * @author andersjb
034: *
035: */
036: public class ChatMessage implements Entity {
037:
038: private String id;
039: private ChatChannel chatChannel;
040: private String owner;
041: private Date messageDate;
042: private String body;
043:
044: public ChatMessage() {
045: }
046:
047: public String getBody() {
048: return body;
049: }
050:
051: public void setBody(String body) {
052: this .body = body;
053: }
054:
055: public ChatChannel getChatChannel() {
056: return chatChannel;
057: }
058:
059: public void setChatChannel(ChatChannel chatChannel) {
060: this .chatChannel = chatChannel;
061: }
062:
063: public String getId() {
064: return id;
065: }
066:
067: public void setId(String id) {
068: this .id = id;
069: }
070:
071: public Date getMessageDate() {
072: return messageDate;
073: }
074:
075: public void setMessageDate(Date messageDate) {
076: this .messageDate = messageDate;
077: }
078:
079: public String getOwner() {
080: return owner;
081: }
082:
083: public void setOwner(String owner) {
084: this .owner = owner;
085: }
086:
087: /**
088: * Serialize the resource into XML, adding an element to the doc under the top of the stack element.
089: *
090: * @param doc
091: * The DOM doc to contain the XML (or null for a string return).
092: * @param stack
093: * The DOM elements, the top of which is the containing element of the new "resource" element.
094: * @return The newly added element.
095: */
096: public Element toXml(Document doc, Stack stack) {
097: //I don't think this will get called since chat messages don't appear to be archived. - chmaurer
098:
099: Element message = doc.createElement("message");
100:
101: if (stack.isEmpty()) {
102: doc.appendChild(message);
103: } else {
104: ((Element) stack.peek()).appendChild(message);
105: }
106:
107: stack.push(message);
108:
109: //m_header.toXml(doc, stack);
110:
111: //FormattedText.encodeFormattedTextAttribute(message, "body", getBody());
112: message.setAttribute("body", getBody());
113: message.setAttribute("owner", getOwner());
114: message.setAttribute("messageDate", Long
115: .toString(getMessageDate().getTime()));
116: message.setAttribute("channelId", getChatChannel().getId());
117:
118: /*
119: * // Note: the old way to set the body - CDATA is too sensitive to the characters within -ggolden Element body = doc.createElement("body"); message.appendChild(body); body.appendChild(doc.createCDATASection(getBody()));
120: */
121:
122: // properties
123: //m_properties.toXml(doc, stack);
124: stack.pop();
125:
126: return message;
127:
128: } // toXml
129:
130: /* (non-Javadoc)
131: * @see org.sakaiproject.entity.api.Entity#getProperties()
132: */
133: public ResourceProperties getProperties() {
134: // TODO Auto-generated method stub
135: return null;
136: }
137:
138: /* (non-Javadoc)
139: * @see org.sakaiproject.entity.api.Entity#getReference()
140: */
141: public String getReference() {
142: return ChatManager.REFERENCE_ROOT + Entity.SEPARATOR
143: + ChatManager.REF_TYPE_MESSAGE + Entity.SEPARATOR
144: + chatChannel.getContext() + Entity.SEPARATOR
145: + chatChannel.getId() + Entity.SEPARATOR + id;
146: }
147:
148: /* (non-Javadoc)
149: * @see org.sakaiproject.entity.api.Entity#getReference(java.lang.String)
150: */
151: public String getReference(String rootProperty) {
152: return getReference();
153: }
154:
155: /* (non-Javadoc)
156: * @see org.sakaiproject.entity.api.Entity#getUrl()
157: */
158: public String getUrl() {
159: return ServerConfigurationService.getAccessUrl()
160: + getReference();
161: }
162:
163: /* (non-Javadoc)
164: * @see org.sakaiproject.entity.api.Entity#getUrl(java.lang.String)
165: */
166: public String getUrl(String rootProperty) {
167: return getUrl();
168: }
169:
170: }
|