01: /*
02: *
03: * Copyright 2005 Joe Walker
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package uk.ltd.getahead.dwrdemo.chat;
20:
21: import java.net.MalformedURLException;
22: import java.net.URL;
23:
24: import org.directwebremoting.Security;
25:
26: /**
27: * A POJO that represents a typed message
28: * @author Joe Walker [joe at getahead dot ltd dot uk]
29: */
30: public class Message {
31: /**
32: * @param newtext the new message text
33: */
34: public Message(String newtext) {
35: text = newtext;
36:
37: if (text.length() > 256) {
38: text = text.substring(0, 256);
39: }
40: text = Security.replaceXmlCharacters(text);
41:
42: try {
43: if (text.startsWith("http://")) {
44: URL url = new URL(text);
45: text = "<a href='#' onclick='window.open(\""
46: + url.toExternalForm()
47: + "\", \"\", \"resizable=yes,scrollbars=yes,status=yes\");'>"
48: + url.toExternalForm() + "</a>";
49: }
50: } catch (MalformedURLException ex) {
51: // Ignore - it's not a URL
52: }
53: }
54:
55: /**
56: * @return the message id
57: */
58: public long getId() {
59: return id;
60: }
61:
62: /**
63: * @return the message itself
64: */
65: public String getText() {
66: return text;
67: }
68:
69: /**
70: * When the message was created
71: */
72: private long id = System.currentTimeMillis();
73:
74: /**
75: * The text of the message
76: */
77: private String text;
78: }
|