Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #38 from tomamic/master

chat code complete clean-up
  • Loading branch information...
commit 2e0f6973a8498b9cfbb1c0ff928b4e93ddd92f1a 2 parents d5376b6 + 234068e
@rik0 authored
Showing with 711 additions and 1,785 deletions.
  1. +1 −0  .gitignore
  2. +1 −1  blogracy-vuze/pom.xml
  3. +2 −0  blogracy-vuze/src/main/java/com/aelitis/azureus/plugins/chat/ChatPlugin.java
  4. +20 −0 blogracy-vuze/src/main/java/net/blogracy/Blogracy.java
  5. +66 −47 blogracy-vuze/src/main/java/net/blogracy/services/ChatService.java
  6. +1 −1  blogracy-web/pom.xml
  7. BIN  blogracy-web/src/main/config/blogracy.jks
  8. +1 −1  blogracy-web/src/main/config/blogracyPaths.properties
  9. +7 −4 blogracy-web/src/main/java/net/blogracy/WebServer.java
  10. +15 −42 blogracy-web/src/main/java/net/blogracy/controller/ChatController.java
  11. +3 −8 blogracy-web/src/main/java/net/blogracy/controller/DistributedHashTable.java
  12. +0 −218 blogracy-web/src/main/webapp/chat files/chat2.js
  13. +0 −83 blogracy-web/src/main/webapp/chat files/chat3.css
  14. +0 −220 blogracy-web/src/main/webapp/chat files/chat3.js
  15. +0 −220 blogracy-web/src/main/webapp/chat files/chat4.js
  16. +0 −44 blogracy-web/src/main/webapp/chat files/prettify.css
  17. +0 −70 blogracy-web/src/main/webapp/chat files/sorttable.css
  18. +13 −37 blogracy-web/src/main/webapp/{chat files → }/chat.css
  19. +45 −0 blogracy-web/src/main/webapp/chat.jsp
  20. +0 −122 blogracy-web/src/main/webapp/chatform.jsp
  21. +0 −114 blogracy-web/src/main/webapp/chatform2.jsp
  22. +0 −121 blogracy-web/src/main/webapp/chatform3.jsp
  23. +0 −121 blogracy-web/src/main/webapp/chatform4.jsp
  24. +414 −0 blogracy-web/src/main/webapp/gallery.jsp
  25. 0  blogracy-web/src/main/webapp/{chat files → js}/amq.js
  26. 0  blogracy-web/src/main/webapp/{chat files → js}/amq_jquery_adapter.js
  27. +70 −72 blogracy-web/src/main/webapp/{chat files → js}/chat.js
  28. 0  blogracy-web/src/main/webapp/{chat files/jquery-1.js → js/jquery-1.4.2.min.js}
  29. +52 −239 blogracy-web/src/main/webapp/user.jsp
View
1  .gitignore
@@ -3,6 +3,7 @@
.svn
.classpath
.project
+.metadata
*.jar
.idea
$config
View
2  blogracy-vuze/pom.xml
@@ -11,7 +11,7 @@
<resources>
<resource>
<directory>src/main/plugins</directory>
- <targetPath>../plugins/</targetPath>
+ <targetPath>plugins</targetPath>
</resource>
<!--resource>
<directory>src/main/java/net/blogracy/chat/resources</directory>
View
2  blogracy-vuze/src/main/java/com/aelitis/azureus/plugins/chat/ChatPlugin.java
@@ -22,6 +22,8 @@
*/
package com.aelitis.azureus.plugins.chat;
+// Blogracy: removed all references to swt and ui
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
View
20 blogracy-vuze/src/main/java/net/blogracy/Blogracy.java
@@ -3,9 +3,12 @@
*/
package net.blogracy;
+import java.io.FileWriter;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Properties;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
@@ -23,6 +26,9 @@
import org.gudy.azureus2.plugins.Plugin;
import org.gudy.azureus2.plugins.PluginException;
import org.gudy.azureus2.plugins.PluginInterface;
+import org.gudy.azureus2.plugins.PluginManager;
+
+import com.aelitis.azureus.plugins.chat.ChatPlugin;
/**
* @author mic
@@ -80,10 +86,24 @@ public static void main(String[] args) {
} catch (Exception e) {
e.printStackTrace();
}
+
+ try {
+ (new java.io.File("plugins/chat")).mkdirs();
+ Properties chatProp = new Properties();
+ chatProp.load(Blogracy.class.getClassLoader().getResourceAsStream("plugins/chat/plugin.properties"));
+ chatProp.store(new FileWriter("plugins/chat/plugin.properties"), "Chat plugin");
+ (new java.io.File("plugins/blogracy")).mkdirs();
+ Properties blogracyProp = new Properties();
+ blogracyProp.load(Blogracy.class.getClassLoader().getResourceAsStream("plugins/blogracy/plugin.properties"));
+ blogracyProp.store(new FileWriter("plugins/blogracy/plugin.properties"), "Blogracy plugin");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
List<String> argList = new ArrayList<String>();
argList.addAll(Arrays.asList(args));
argList.add("--ui=console");
org.gudy.azureus2.ui.common.Main.main(argList.toArray(args));
+ //PluginManager.startAzureus(PluginManager.UI_NONE, new java.util.Properties());
}
}
View
113 blogracy-vuze/src/main/java/net/blogracy/services/ChatService.java
@@ -36,8 +36,7 @@
import java.util.HashMap;
-public class ChatService implements MessageListener {
-
+public class ChatService implements javax.jms.MessageListener, com.aelitis.azureus.plugins.chat.messaging.MessageListener {
private PluginInterface vuze;
private Session session;
@@ -46,9 +45,11 @@
private MessageConsumer consumer;
private String TOPIC_NAME = "CHAT.DEMO";
- private String lastMessageSend = "";
+ private String lastMessageSent = "";
private String lastMessageReceived = "";
+ private String lastMsg = "";
+
private HashMap<String, Download> channels = new HashMap<String, Download>();
public ChatService(Connection connection, PluginInterface vuze) {
@@ -61,7 +62,7 @@ public ChatService(Connection connection, PluginInterface vuze) {
consumer = session.createConsumer(topic);
consumer.setMessageListener(this);
} catch (JMSException e) {
- System.out.println("JMS error: creating the text listener");
+ Logger.error("JMS error: creating the text listener");
}
}
@@ -70,32 +71,51 @@ public void onMessage(Message message) {
if (message instanceof TextMessage) {
try {
String text = ((TextMessage) message).getText();
- if (floodControl(text)) {
- /*System.out.println("Flooding");*/
- } else {
- parseXML(text);
- lastMessageSend = text;
- //System.out.println("Outgoing Message: " + text);
- }
+ parseXML(text);
} catch (JMSException e) {
- System.out.println("JMS error: reading messages");
+ Logger.error("JMS error: reading messages");
+ }
+ }
+ else {
+ Logger.error("This is not a TextMessage");
+ }
+ }
+
+ @Override
+ public void downloadAdded(Download download) {}
+
+ @Override
+ public void downloadRemoved(Download download) {}
+
+ @Override
+ public void downloadActive(Download download) {}
+
+ @Override
+ public void downloadInactive(Download download) {}
+
+ @Override
+ public void messageReceived(Download download, byte[] sender, String nick, String text) {
+ for (String channel : channels.keySet()) {
+ if (channels.get(channel) == download) {
+ String type = "chat";
+ if (text.equals("has left the channel")) type = "leave";
+ msgFromVuze(channel, type, nick, text);
}
}
- else System.out.println("This is not a TextMessage");
}
public void msgFromVuze(String channel, String type, String nick, String text){
- String xml = createXML(channel, type, nick, text);
- //System.out.println("Incoming Message: " + XMLmessage);
- lastMessageReceived = xml;
- TextMessage message;
try {
- message = session.createTextMessage();
- message.setText(xml);
- producer.send(topic, message);
+ if (floodControl(channel, type, nick, text)) {
+ String xml = createXML(channel, type, nick, text);
+ Logger.info("Incoming Message: " + xml);
+ TextMessage message = session.createTextMessage();
+ message.setText(xml);
+ producer.send(topic, message);
+ }
} catch (JMSException e) {
- System.out.println("JMS error: sending messages");
+ Logger.error("JMS error: sending messages");
}
}
@@ -109,17 +129,23 @@ private void parseXML(String xml){
NodeList nodes = doc.getElementsByTagName("message");
Element element = (Element) nodes.item(0);
+ String channel = element.getAttribute("channel");
String type = element.getAttribute("type");
String nick = element.getAttribute("from");
- String channel = element.getAttribute("channel");
String text = element.getTextContent();
- msgToVuze(channel, type, nick, text);
+
+ if (floodControl(channel, type, nick, text)) {
+ Logger.info("Outgoing Message: " + xml);
+ msgToVuze(channel, type, nick, text);
+ }
+
} catch (Exception e) {
e.printStackTrace();
}
}
private String createXML(String channel, String type, String nick, String text){
+ String xml = "";
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
@@ -137,12 +163,11 @@ private String createXML(String channel, String type, String nick, String text){
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(source, result);
- String str = stringWriter.getBuffer().toString();//.substring(38);
- return str;
+ xml = stringWriter.getBuffer().toString().substring(38);
} catch (Exception e) {
e.printStackTrace();
- return "nothing";
}
+ return xml;
}
private void msgToVuze(String channel, String type, String nick, String text) {
@@ -151,41 +176,35 @@ private void msgToVuze(String channel, String type, String nick, String text) {
if (type.equals("chat")) {
Download download = channels.get(channel);
- plugin.sendMessage(download, text);
+ if (download != null) {
+ plugin.sendMessage(download, text);
+ }
} else if (type.equals("join")) {
Logger.info("Joining channel: " + channel);
-
+
plugin.setNick(nick);
Download download = plugin.addChannel(channel);
channels.put(channel, download);
- plugin.addMessageListener(new com.aelitis.azureus.plugins.chat.messaging.MessageListener() {
- public void downloadAdded(Download download) {}
- public void downloadRemoved(Download download) {}
- public void downloadActive(Download download) {}
- public void downloadInactive(Download download) {}
- public void messageReceived(Download download, byte[] sender, String nick, String text) {
- String channel = new String(sender);
- for (String key : channels.keySet()) {
- if (channels.get(key) == download) channel = key;
- }
- String type = "chat";
- if (text.equals("has left the channel")) type = "leave";
- msgFromVuze(channel, type, nick, text);
- }
- }, download);
+ plugin.addMessageListener(this, download);
Logger.info("chat request: " + channel);
} else if (type.equals("leave")){
Download download = channels.get(channel);
- plugin.sendMessage(download, "has left the channel");
+ if (download != null) {
+ plugin.sendMessage(download, "has left the channel");
+ }
if (nick.equals(plugin.getNick())) {
// plugin.closeBridge(channelName);
}
}
}
- private boolean floodControl(String text){
- return (text.equals(lastMessageReceived)
- ||text.equals(lastMessageSend));
+ private boolean floodControl(String channel, String type, String nick, String text) {
+ String msg = channel + ":" + type + ":" + nick + ":" + text;
+ if (! lastMsg.equals(msg)) {
+ lastMsg = msg;
+ return true;
+ }
+ return false;
}
}
View
2  blogracy-web/pom.xml
@@ -100,7 +100,7 @@
</resource>
<resource>
<directory>src/main/webapp</directory>
- <targetPath>../webapp</targetPath>
+ <targetPath>webapp</targetPath>
</resource>
</resources>
View
BIN  blogracy-web/src/main/config/blogracy.jks
Binary file not shown
View
2  blogracy-web/src/main/config/blogracyPaths.properties
@@ -21,5 +21,5 @@
#
blogracy.paths.root = webapp
-blogracy.paths.cache = webapp/cache
+blogracy.paths.cache = cache
View
11 blogracy-web/src/main/java/net/blogracy/WebServer.java
@@ -14,11 +14,13 @@
{
public static void main(String[] args) throws Exception
{
+ String webDir = WebServer.class.getClassLoader().getResource("webapp").toExternalForm();
+
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
- context.setDescriptor("webapp/WEB-INF/web.xml");
- context.setResourceBase("webapp");
+ context.setResourceBase(webDir);
+ //context.setDescriptor(webDir + "/WEB-INF/web.xml");
context.setContextPath("/");
context.setParentLoaderPriority(true);
@@ -30,14 +32,15 @@ public static void main(String[] args) throws Exception
List<User> friends = Configurations.getUserConfig().getFriends();
for (User friend : friends) {
String hash = friend.getHash().toString();
- ChatController.createChannel(hash);
+ ChatController.getSingleton().joinChannel(hash);
}
+ String id = Configurations.getUserConfig().getUser().getHash().toString();
+ ChatController.getSingleton().joinChannel(id);
int TOTAL_WAIT = 5 * 60 * 1000; // 5 minutes
while (true) {
FileSharing sharing = FileSharing.getSingleton();
- String id = Configurations.getUserConfig().getUser().getHash().toString();
sharing.addFeedEntry(id, "" + new java.util.Date(), null);
// List<User> friends = Configurations.getUserConfig().getFriends();
View
57 blogracy-web/src/main/java/net/blogracy/controller/ChatController.java
@@ -21,17 +21,18 @@
private ConnectionFactory connectionFactory;
private Connection connection;
- private static Session session;
- private static Destination topic;
- private static MessageProducer producer;
- private String TOPIC_NAME = "CHAT.DEMO";
+ private Session session;
+ private Destination topic;
+ private MessageProducer producer;
+ private static final String TOPIC_NAME = "CHAT.DEMO";
- private static String localUser, remoteUser;
+ private String localUser;
+ private String remoteUser;
- private static final ChatController THE_INSTANCE = new ChatController();
+ private static final ChatController theInstance = new ChatController();
public static ChatController getSingleton() {
- return THE_INSTANCE;
+ return theInstance;
}
public ChatController() {
@@ -39,7 +40,7 @@ public ChatController() {
connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
connection = connectionFactory.createConnection();
connection.start();
-
+
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
topic = session.createTopic(TOPIC_NAME);
producer = session.createProducer(topic);
@@ -49,18 +50,10 @@ public ChatController() {
}
}
- public static void setLocalUser(String local) {
- if (! local.equals(localUser)) {
- localUser = local;
- createChannel(localUser);
- }
- }
-
- public static void createChannel(String channel) {
+ public void joinChannel(String channel) {
System.out.println("Creating chat channel: " + channel);
- TextMessage msg;
try {
- msg = session.createTextMessage();
+ TextMessage msg = session.createTextMessage();
msg.setText("<message type=\"join\" from=\"" + localUser + "\" channel=\"" + channel + "\"/>");
producer.send(topic, msg);
} catch (JMSException e) {
@@ -68,30 +61,10 @@ public static void createChannel(String channel) {
}
}
- public static void setRemoteUser(String remote) {
- remoteUser = remote;
- System.out.println("Remote user hash: " + remoteUser);
- }
-
- public static String getRemoteUser() {
- return remoteUser;
- }
-
- public static void chatting() {
- if (! remoteUser.equals(localUser)) {
- createChannel(remoteUser);
- }
- }
-
- public static void privateChatting() {
- if (! remoteUser.equals(localUser)) {
- createChannel(localUser + remoteUser);
- }
- }
-
- public static void privateChatting2() {
- if (! remoteUser.equals(localUser)) {
- createChannel(remoteUser + localUser);
+ public static String getPrivateChannel(String localUser, String remoteUser) {
+ if (localUser.compareTo(remoteUser) <= 0) {
+ return localUser + remoteUser;
}
+ return remoteUser + localUser;
}
}
View
11 blogracy-web/src/main/java/net/blogracy/controller/DistributedHashTable.java
@@ -207,15 +207,10 @@ public void putRecord(JSONObject record) {
try {
String id = record.getString("id");
JSONObject old = records.get(id);
- if (old != null) {
- if (record.getString("version")
- .compareTo(old.getString("version")) < 0) {
- return;
- }
- String prev = old.getString("uri");
- record.put("prev", prev);
+ if (old == null || record.getString("version")
+ .compareTo(old.getString("version")) > 0) {
+ records.put(id, record);
}
- records.put(id, record);
} catch (JSONException e1) {
e1.printStackTrace();
}
View
218 blogracy-web/src/main/webapp/chat files/chat2.js
@@ -1,218 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the 'License'); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an 'AS IS' BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Modified by Andrea Vida, University of Parma (Italy).
- */
-var amq = org.activemq.Amq;
-
-org.activemq.Chat = function() {
- var last = '';
- var user = null;
-
- var chatTopic = 'topic://CHAT.DEMO';
-
- var chat, join, joined, phrase, members, username = null;
- var channel, localUser, remoteUser = null;
- var lastText = '';
-
- var chatHandler = function(message) {
- var type = message.getAttribute('type');
- var from = message.getAttribute('from');
- var channel2 = message.getAttribute('channel');
-
- if (channel2 == channel) {
- switch (type) {
- // Incoming chat message
- case 'chat' : {
- if (channel2 == localUser) {
- if (from != user) parent.resizeChat2();
- }
-
- var text = message.childNodes[0].data;
-
- if (from == last) from = '...';
- else {
- last = from;
- from += ':';
- }
-
- if (text != lastText) {
- if (from != user) chat.innerHTML += '<span class=\'from\'>' + from + '&nbsp;</span><span class=\'text\'>' + text + '</span><br/>';
- lastText = text;
- if (text == "/private") parent.privateChat2();
- }
- break;
- }
-
- case 'ping' : {
- members.innerHTML += '<span class="member">' + from + '</span><br/>';
- break;
- }
-
- // someone new joined the chatroom, clear your list and
- // broadcast your name to all users.
- case 'join' : {
- if (channel2 == localUser) {
- if (from != user) parent.resizeChat2();
- }
- members.innerHTML = '';
- if (user != null)
- amq.sendMessage(chatTopic, '<message type="ping" from="' + user + '" channel="' + channel + '"/>');
-
- chat.innerHTML += '<span class="alert"><span class="from">' + from + '&nbsp;</span><span class="text">has joined the room!</span></span><br/>';
- break;
- }
-
- // When I (and everyone else) receive a leave message, we broadcast
- // our own names in a ping in order to update everyone's list.
- case 'leave': {
- members.innerHTML = '';
- chat.innerHTML += '<span class="alert"><span class="from">' + from + '&nbsp;</span><span class="text">has left the room!</span></span><br/>';
-
- // If we are the one that is leaving...
- if (from == user) {
- // switch the input form
- join.className = '';
- joined.className = 'hidden';
- username.focus();
-
- user = null;
- amq.removeListener('chat', chatTopic);
- }
- if (user != null)
- amq.sendMessage(chatTopic, '<message type="ping" from="' + user + '" channel="' + channel + '"/>');
- break;
- }
- }
- }
-
- chat.scrollTop = chat.scrollHeight - chat.clientHeight;
- };
-
- var getKeyCode = function (ev) {
- var keyc;
- if (window.event) keyc = window.event.keyCode;
- else keyc = ev.keyCode;
- return keyc;
- };
-
- var addEvent = function(obj, type, fn) {
- if (obj.addEventListener)
- obj.addEventListener(type, fn, false);
- else if (obj.attachEvent) {
- obj["e"+type+fn] = fn;
- obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
- obj.attachEvent( "on"+type, obj[type+fn] );
- }
- };
-
- var initEventHandlers = function() {
-
- addEvent(username, 'keyup', function(ev) {
- var keyc = getKeyCode(ev);
- if (keyc == 13 || keyc == 10) {
- org.activemq.Chat.join();
- return false;
- }
- return true;
- });
-
- addEvent(document.getElementById('joinB'), 'click', function() {
- org.activemq.Chat.join();
- return true;
- });
-
-
- addEvent(phrase, 'keyup', function(ev) {
- var keyc = getKeyCode(ev);
-
- if (keyc == 13 || keyc == 10) {
- var text = phrase.value;
- phrase.value = '';
- org.activemq.Chat.chat(text);
- return false;
- }
- return true;
- });
-
- addEvent(document.getElementById('sendB'), 'click', function() {
- var text = phrase.value;
- phrase.value = '';
- org.activemq.Chat.chat(text);
- });
-
- addEvent(document.getElementById('leaveB'), 'click', function() {
- org.activemq.Chat.leave();
- return false;
- });
- };
-
- return {
- join: function() {
-
- var name = username.value;
- if (name == null || name.length == 0) {
- alert('Please enter a username!');
- } else {
- user = name;
-
- amq.addListener('chat', chatTopic, chatHandler);
- join.className = 'hidden';
- joined.className = '';
- phrase.focus();
-
- amq.sendMessage(chatTopic, '<message type="join" from="' + user + '" channel="' + channel + '"/>');
- }
- },
-
- leave: function() {
- amq.sendMessage(chatTopic, '<message type="leave" from="' + user + '" channel="' + channel + '"/>');
- },
-
- chat: function(text) {
- if (text != null && text.length > 0) {
- text = text.replace('<', '&lt;');
- text = text.replace('>', '&gt;');
-
- if (text == "/private") {
- chat.innerHTML += 'Command not allowed on this channel';
- }
- else amq.sendMessage(chatTopic, '<message type="chat" from="' + user + '" channel="' + channel + '">' + text + '</message>');
- }
- },
-
- init: function() {
- join = document.getElementById('join');
- joined = document.getElementById('joined');
- chat = document.getElementById('chat');
- members = document.getElementById('members');
- username = document.getElementById('username');
- phrase = document.getElementById('phrase');
- channel = document.getElementById('channelName').getAttribute('title');
- localUser = parent.document.getElementById('localUser').getAttribute('title');
-
- if (join.className == 'hidden' && joined.className == 'hidden') {
- join.className = '';
- joined.className = 'hidden';
- username.focus();
- }
-
- initEventHandlers();
- org.activemq.Chat.join();
- }
- }
-}();
View
83 blogracy-web/src/main/webapp/chat files/chat3.css
@@ -1,83 +0,0 @@
-body {
- padding: 0px;
- background-color: #f0f0f0;
-}
-
-div#chatroom
-{
- height: 230px;
- width: 275px;
- background-color: #f0f0f0;
- border: 0px solid black;
-}
-
-div#chat
-{
- float: left;
- height: 200px;
- width: 260px;
- overflow: auto;
- background-color: #ffffff;
- border-right: 0px solid black;
-}
-
-div#members
-{
- float: left;
- clear: right;
- height: 200px;
- width: 2px;
- background-color: #ffffff;
- border: 0px solid black;
-}
-
-div#input
-{
- clear: both;
- width: 257px;
- padding: 1px;
- border: 1px solid black;
-}
-
-input#phrase
-{
- width:75px;
- background-color: #e0f0f0;
-}
-
-input#username
-{
- width:60px;
- background-color: #e0f0f0;
-}
-
-p#title
-{
- font-family: arial,verdana,helvetica,sans-serif;
- font-size: 6px;
- font-style: normal;
- color: #000000;
-}
-
-div.body-content
-{
- font-family: sans-serif;
- font-style: normal;
- font-size: 12px;
-}
-
-div.hidden
-{
- display: none;
-}
-
-span.from
-{
- font-weight: bold;
-}
-
-span.alert
-{
- font-style: italic;
-}
-
View
220 blogracy-web/src/main/webapp/chat files/chat3.js
@@ -1,220 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the 'License'); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an 'AS IS' BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Modified by Andrea Vida, University of Parma (Italy).
- */
-var amq = org.activemq.Amq;
-
-org.activemq.Chat = function() {
- var last = '';
- var user = null;
-
- var chatTopic = 'topic://CHAT.DEMO';
-
- var chat, join, joined, phrase, members, username = null;
- var channel, localUser, remoteUser = null;
- var online = false;
-
- var chatHandler = function(message) {
- var type = message.getAttribute('type');
- var from = message.getAttribute('from');
- var channel2 = message.getAttribute('channel');
-
- if (channel2 == channel) {
- switch (type) {
- // Incoming chat message
- case 'chat' : {
- if (channel2 == localUser) {
- if (from != user) parent.resizeChat2();
- }
- var text = message.childNodes[0].data;
-
- if (from == last) from = '...';
- else {
- last = from;
- from += ':';
- }
-
- chat.innerHTML += '<span class=\'from\'>' + from + '&nbsp;</span><span class=\'text\'>' + text + '</span><br/>';
- break;
- }
-
- // Incoming ping request, add the person's name to your list.
- case 'ping' : {
- members.innerHTML += '<span class="member">' + from + '</span><br/>';
- if (channel2 != localUser) {
- if (from != user) {
- parent.setOnline();
- online = true;
- }
- }
- break;
- }
-
- // someone new joined the chatroom, clear your list and
- // broadcast your name to all users.
- case 'join' : {
- if (channel2 == localUser) {
- if (from != user) parent.resizeChat2();
- }
- members.innerHTML = '';
- if (user != null)
- amq.sendMessage(chatTopic, '<message type="ping" from="' + user + '" channel="' + channel + '"/>');
-
- chat.innerHTML += '<span class="alert"><span class="from">' + from + '&nbsp;</span><span class="text">has joined the room!</span></span><br/>';
- break;
- }
-
- // When I (and everyone else) receive a leave message, we broadcast
- // our own names in a ping in order to update everyone's list.
- case 'leave': {
- online = false;
- members.innerHTML = '';
- chat.innerHTML += '<span class="alert"><span class="from">' + from + '&nbsp;</span><span class="text">has left the room!</span></span><br/>';
-
- // If we are the one that is leaving...
- if (from == user) {
- // switch the input form
- join.className = '';
- joined.className = 'hidden';
- username.focus();
-
- user = null;
- amq.removeListener('chat', chatTopic);
- }
- if (user != null)
- amq.sendMessage(chatTopic, '<message type="ping" from="' + user + '" channel="' + channel + '"/>');
- break;
- }
- }
- }
-
- chat.scrollTop = chat.scrollHeight - chat.clientHeight;
- };
-
- var getKeyCode = function (ev) {
- var keyc;
- if (window.event) keyc = window.event.keyCode;
- else keyc = ev.keyCode;
- return keyc;
- };
-
- var addEvent = function(obj, type, fn) {
- if (obj.addEventListener)
- obj.addEventListener(type, fn, false);
- else if (obj.attachEvent) {
- obj["e"+type+fn] = fn;
- obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
- obj.attachEvent( "on"+type, obj[type+fn] );
- }
- };
-
- var initEventHandlers = function() {
-
- addEvent(username, 'keyup', function(ev) {
- var keyc = getKeyCode(ev);
- if (keyc == 13 || keyc == 10) {
- org.activemq.Chat.join();
- return false;
- }
- return true;
- });
-
- addEvent(document.getElementById('joinB'), 'click', function() {
- org.activemq.Chat.join();
- return true;
- });
-
-
- addEvent(phrase, 'keyup', function(ev) {
- var keyc = getKeyCode(ev);
-
- if (keyc == 13 || keyc == 10) {
- var text = phrase.value;
- phrase.value = '';
- org.activemq.Chat.chat(text);
- return false;
- }
- return true;
- });
-
- addEvent(document.getElementById('sendB'), 'click', function() {
- var text = phrase.value;
- phrase.value = '';
- org.activemq.Chat.chat(text);
- });
-
- addEvent(document.getElementById('leaveB'), 'click', function() {
- org.activemq.Chat.leave();
- return false;
- });
- };
-
- return {
- join: function() {
-
- var name = username.value;
- if (name == null || name.length == 0) {
- alert('Please enter a username!');
- } else {
- user = name;
-
- amq.addListener('chat', chatTopic, chatHandler);
- join.className = 'hidden';
- joined.className = '';
- phrase.focus();
-
- amq.sendMessage(chatTopic, '<message type="join" from="' + user + '" channel="' + channel + '"/>');
- }
- },
-
- leave: function() {
- amq.sendMessage(chatTopic, '<message type="leave" from="' + user + '" channel="' + channel + '"/>');
- parent.closePrivateChat();
- },
-
- chat: function(text) {
- if (text != null && text.length > 0) {
- text = text.replace('<', '&lt;');
- text = text.replace('>', '&gt;');
-
- amq.sendMessage(chatTopic, '<message type="chat" from="' + user + '" channel="' + channel + '">' + text + '</message>');
- }
- },
-
- init: function() {
- join = document.getElementById('join');
- joined = document.getElementById('joined');
- chat = document.getElementById('chat');
- members = document.getElementById('members');
- username = document.getElementById('username');
- phrase = document.getElementById('phrase');
- localUser = parent.document.getElementById('localUser').getAttribute('title');
- remoteUser = parent.document.getElementById('remoteUser').getAttribute('title');
- channel = localUser + remoteUser;
-
- if (join.className == 'hidden' && joined.className == 'hidden') {
- join.className = '';
- joined.className = 'hidden';
- username.focus();
- }
-
- initEventHandlers();
- org.activemq.Chat.join();
- }
- }
-}();
View
220 blogracy-web/src/main/webapp/chat files/chat4.js
@@ -1,220 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the 'License'); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an 'AS IS' BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Modified by Andrea Vida, University of Parma (Italy).
- */
-var amq = org.activemq.Amq;
-
-org.activemq.Chat = function() {
- var last = '';
- var user = null;
-
- var chatTopic = 'topic://CHAT.DEMO';
-
- var chat, join, joined, phrase, members, username = null;
- var channel, localUser, remoteUser = null;
- var online = false;
-
- var chatHandler = function(message) {
- var type = message.getAttribute('type');
- var from = message.getAttribute('from');
- var channel2 = message.getAttribute('channel');
-
- if (channel2 == channel) {
- switch (type) {
- // Incoming chat message
- case 'chat' : {
- if (channel2 == localUser) {
- if (from != user) parent.resizeChat2();
- }
- var text = message.childNodes[0].data;
-
- if (from == last) from = '...';
- else {
- last = from;
- from += ':';
- }
-
- chat.innerHTML += '<span class=\'from\'>' + from + '&nbsp;</span><span class=\'text\'>' + text + '</span><br/>';
- break;
- }
-
- // Incoming ping request, add the person's name to your list.
- case 'ping' : {
- members.innerHTML += '<span class="member">' + from + '</span><br/>';
- if (channel2 != localUser) {
- if (from != user) {
- parent.setOnline();
- online = true;
- }
- }
- break;
- }
-
- // someone new joined the chatroom, clear your list and
- // broadcast your name to all users.
- case 'join' : {
- if (channel2 == localUser) {
- if (from != user) parent.resizeChat2();
- }
- members.innerHTML = '';
- if (user != null)
- amq.sendMessage(chatTopic, '<message type="ping" from="' + user + '" channel="' + channel + '"/>');
-
- chat.innerHTML += '<span class="alert"><span class="from">' + from + '&nbsp;</span><span class="text">has joined the room!</span></span><br/>';
- break;
- }
-
- // When I (and everyone else) receive a leave message, we broadcast
- // our own names in a ping in order to update everyone's list.
- case 'leave': {
- online = false;
- members.innerHTML = '';
- chat.innerHTML += '<span class="alert"><span class="from">' + from + '&nbsp;</span><span class="text">has left the room!</span></span><br/>';
-
- // If we are the one that is leaving...
- if (from == user) {
- // switch the input form
- join.className = '';
- joined.className = 'hidden';
- username.focus();
-
- user = null;
- amq.removeListener('chat', chatTopic);
- }
- if (user != null)
- amq.sendMessage(chatTopic, '<message type="ping" from="' + user + '" channel="' + channel + '"/>');
- break;
- }
- }
- }
-
- chat.scrollTop = chat.scrollHeight - chat.clientHeight;
- };
-
- var getKeyCode = function (ev) {
- var keyc;
- if (window.event) keyc = window.event.keyCode;
- else keyc = ev.keyCode;
- return keyc;
- };
-
- var addEvent = function(obj, type, fn) {
- if (obj.addEventListener)
- obj.addEventListener(type, fn, false);
- else if (obj.attachEvent) {
- obj["e"+type+fn] = fn;
- obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
- obj.attachEvent( "on"+type, obj[type+fn] );
- }
- };
-
- var initEventHandlers = function() {
-
- addEvent(username, 'keyup', function(ev) {
- var keyc = getKeyCode(ev);
- if (keyc == 13 || keyc == 10) {
- org.activemq.Chat.join();
- return false;
- }
- return true;
- });
-
- addEvent(document.getElementById('joinB'), 'click', function() {
- org.activemq.Chat.join();
- return true;
- });
-
-
- addEvent(phrase, 'keyup', function(ev) {
- var keyc = getKeyCode(ev);
-
- if (keyc == 13 || keyc == 10) {
- var text = phrase.value;
- phrase.value = '';
- org.activemq.Chat.chat(text);
- return false;
- }
- return true;
- });
-
- addEvent(document.getElementById('sendB'), 'click', function() {
- var text = phrase.value;
- phrase.value = '';
- org.activemq.Chat.chat(text);
- });
-
- addEvent(document.getElementById('leaveB'), 'click', function() {
- org.activemq.Chat.leave();
- return false;
- });
- };
-
- return {
- join: function() {
-
- var name = username.value;
- if (name == null || name.length == 0) {
- alert('Please enter a username!');
- } else {
- user = name;
-
- amq.addListener('chat', chatTopic, chatHandler);
- join.className = 'hidden';
- joined.className = '';
- phrase.focus();
-
- amq.sendMessage(chatTopic, '<message type="join" from="' + user + '" channel="' + channel + '"/>');
- }
- },
-
- leave: function() {
- amq.sendMessage(chatTopic, '<message type="leave" from="' + user + '" channel="' + channel + '"/>');
- parent.closePrivateChat();
- },
-
- chat: function(text) {
- if (text != null && text.length > 0) {
- text = text.replace('<', '&lt;');
- text = text.replace('>', '&gt;');
-
- amq.sendMessage(chatTopic, '<message type="chat" from="' + user + '" channel="' + channel + '">' + text + '</message>');
- }
- },
-
- init: function() {
- join = document.getElementById('join');
- joined = document.getElementById('joined');
- chat = document.getElementById('chat');
- members = document.getElementById('members');
- username = document.getElementById('username');
- phrase = document.getElementById('phrase');
- localUser = parent.document.getElementById('localUser').getAttribute('title');
- remoteUser = parent.document.getElementById('remoteUser').getAttribute('title');
- channel = remoteUser + localUser;
-
- if (join.className == 'hidden' && joined.className == 'hidden') {
- join.className = '';
- joined.className = 'hidden';
- username.focus();
- }
-
- initEventHandlers();
- org.activemq.Chat.join();
- }
- }
-}();
View
44 blogracy-web/src/main/webapp/chat files/prettify.css
@@ -1,44 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Pretty printing styles. Used with prettify.js. */
-
-.str { color: #080; }
-.kwd { color: #008; }
-.com { color: #800; }
-.typ { color: #606; }
-.lit { color: #066; }
-.pun { color: #660; }
-.pln { color: #000; }
-.tag { color: #008; }
-.atn { color: #606; }
-.atv { color: #080; }
-.dec { color: #606; }
-pre.prettyprint { padding: 2px; }
-
-@media print {
- .str { color: #060; }
- .kwd { color: #006; font-weight: bold; }
- .com { color: #600; font-style: italic; }
- .typ { color: #404; font-weight: bold; }
- .lit { color: #044; }
- .pun { color: #440; }
- .pln { color: #000; }
- .tag { color: #006; font-weight: bold; }
- .atn { color: #404; }
- .atv { color: #060; }
-}
View
70 blogracy-web/src/main/webapp/chat files/sorttable.css
@@ -1,70 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-table.sortable {
- margin: 0px;
- padding: 0px;
- margin-bottom: 1em;
-
- margin: 1em auto;
-}
-
-th {
- padding: 2px;
- padding-left: 10px;
- text-align: left;
- background-color: #ccc;
-}
-
-tfoot {
- /* border-top: 1px solid black; */
-}
-
-td {
- padding: 0.5em;
- /* border: 1px solid black; */
- /** border-top: 1px solid black; */
-}
-
-tr {
- background-color: #ffffff;
-}
-
-tr.odd {
- background-color: #f3f3f3;
-}
-
-td.numeric,
- th.numeric {
- text-align: right;
-}
-
-/** forms using table layout */
-td.label {
- background-color: #f3f3f3;
-}
-/*
-table.layout {
- border-bottom: solid white;
- border-right: solid white;
-}
-
-td.layout {
- border-top: 1px solid black;
- border: solid white;
-}
-*/
View
50 blogracy-web/src/main/webapp/chat files/chat.css → blogracy-web/src/main/webapp/chat.css
@@ -14,75 +14,51 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-body {
- padding: 0px;
- background-color: #f0f0f0;
-}
-
div#chatroom
{
- height: 275px;
- width: 275px;
- background-color: #f0f0f0;
- border: 0px solid black;
+ width: 81em;
+ background-color: #e0e0e0;
+ border: 1px solid black;
}
div#chat
{
float: left;
- height: 240px;
- width: 260px;
+ width: 60em;
+ height: 40ex;
overflow: auto;
- background-color: #ffffff;
- border-right: 0px solid black;
+ background-color: #f0f0f0;
+ padding: 4px;
+ border-right: 1px solid black;
}
div#members
{
float: left;
clear: right;
- height: 200px;
- width: 2px;
- background-color: #ffffff;
+ width: 20em;
border: 0px solid black;
}
div#input
{
clear: both;
- width: 257px;
- padding: 1px;
- border: 1px solid black;
+ padding: 4px;
+ border-top: 1px solid black;
}
input#phrase
{
- width:75px;
+ width:28em;
background-color: #e0f0f0;
}
input#username
{
- width:60px;
+ width:14em;
background-color: #e0f0f0;
}
-p#title
-{
- font-family: arial,verdana,helvetica,sans-serif;
- font-size: 6px;
- font-style: normal;
- color: #000000;
-}
-
-div.body-content
-{
- font-family: sans-serif;
- font-style: normal;
- font-size: 12px;
-}
-
div.hidden
{
display: none;
View
45 blogracy-web/src/main/webapp/chat.jsp
@@ -0,0 +1,45 @@
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Blogracy chat</title>
+ <link rel="stylesheet" href="chat.css" type="text/css">
+
+ <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
+ <script type="text/javascript" src="js/amq_jquery_adapter.js"></script>
+ <script type="text/javascript" src="js/amq.js"></script>
+ <script type="text/javascript" src="js/chat.js"></script>
+ <script type="text/javascript">
+ channel = "${param.channel}"; // Blogracy
+ jQuery(function() {
+ org.activemq.Amq.init({ uri: 'amq', logging: true, timeout: 45, clientId:(new Date()).getTime().toString() });
+ org.activemq.Chat.init();
+ document.getElementById('joinB').click(); // Blogracy
+ });
+ </script>
+
+</head>
+
+<body>
+
+<div id="chatroom">
+ <div id="chat"></div>
+
+ <div id="members"></div>
+
+ <div id="input">
+ <div id="join" class="hidden">
+ Username:&nbsp;
+ <input id="username" type="text" value="${param.nick}"/> <!-- Blogracy -->
+ <button id="joinB">Join</button>
+ </div>
+ <div id="joined" class="hidden">
+ Chat:&nbsp;
+ <input id="phrase" type="text" />
+ <button id="sendB">Send</button>
+ <button id="leaveB">Leave</button>
+ </div>
+ </div>
+</div>
+
+</body>
+</html>
View
122 blogracy-web/src/main/webapp/chatform.jsp
@@ -1,122 +0,0 @@
-<%@ page import="net.blogracy.model.hashes.Hashes" %>
-<%@ page import="net.blogracy.model.users.Users" %>
-<%@ page import="net.blogracy.controller.FileSharing" %>
-<%@ page import="net.blogracy.controller.ChatController" %>
-<%@ page import="net.blogracy.config.Configurations" %>
-<%
-String userHash = request.getParameter("user");
-if (userHash == null || userHash.length() == 0) {
- userHash = Configurations.getUserConfig().getUser().getHash().toString();
-} else if (userHash.length() != 32) {
- userHash = Hashes.hash(userHash); // TODO: remove
-}
-
-pageContext.setAttribute("application", "Blogracy");
-pageContext.setAttribute("user", Users.newUser(Hashes.fromString(userHash)));
-pageContext.setAttribute("localUser", Configurations.getUserConfig().getUser());
-pageContext.setAttribute("remoteUser", ChatController.getRemoteUser());
-
-ChatController.chatting();
-%>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
-<!DOCTYPE html>
-<html lang="en">
-<head>
-
- <meta charset="utf-8">
- <title>${application}</title>
- <meta name="description" content="">
- <meta name="author" content="">
-
- <link rel="stylesheet" href="/chat files/chat.css" type="text/css">
- <style type="text/css" media="screen">
- @import url(/admin/styles/sorttable.css);
- @import url(/admin/styles/prettify.css);
- </style>
-
- <script type="text/javascript" src="chat files/jquery-1.js"></script>
- <script type="text/javascript" src="chat files/amq_jquery_adapter.js"></script>
- <script type="text/javascript" src="chat files/amq.js"></script>
- <script type="text/javascript" src="chat files/chat.js"></script>
-
- <script src="/scripts/jquery-1.7.js"></script>
- <script src="/scripts/jquery.form.js"></script>
- <script src="/scripts/bootstrap-alerts.js"></script>
-
- <script type="text/javascript">
- // wait for the DOM to be loaded
- jQuery(function() {
- jQuery('#message-send').ajaxForm({
- url: '/fileupload',
- clearForm: true,
- type: 'POST',
- success: function() {
- console.log(arguments);
- },
- error: function(request, status, statusMessage) {
- var serverSideException = JSON.parse(request.responseText);
- var errorMessage = '<div class="alert-message block-message error"><a class="close" href="#">x</a>' +
- '<p><strong>' + serverSideException.errorMessage + '</strong></p>' +
- '<pre>' + serverSideException.errorTrace.join("\n") + '</pre>' +
- '</div>';
- jQuery(errorPlace).html(errorMessage);
- jQuery(".alert-message").alert();
- }
-
- });
- });
-
- </script>
-
- <script type="text/javascript">
- window.onload = function() {
- org.activemq.Amq.init({ uri: 'amq', logging: true, timeout: 45, clientId:(new Date()).getTime().toString() });
- org.activemq.Chat.init();
- };
- </script>
-
- <script type="text/javascript">
- window.onunload = function() {
- org.activemq.Chat.leave();
- };
- </script>
-
-</head>
-
-<body>
-
-<div class="white_box">
- <table border="0">
- <tr>
- <td style="overflow: hidden;" valign="top" width="50%">
- <div class="body-content">
-
- <div id="chatroom">
- <div id="chat"></div>
- <div id="members" class="hidden"></div>
-
- <div id="input">
- <div id="join" class="">
- Username:&nbsp;&nbsp;
- <input id="username" type="text" value="${localUser.localNick}" readonly="readonly">
- <button id="joinB">Re-Join</button>
- </div>
- <div id="joined" class="hidden">
- Chat:&nbsp;
- <input id="phrase" type="text">
- <button id="sendB">Send</button>
- <button id="leaveB">Leave</button>
- </div>
- </div>
- </div>
-
- </div>
- </td>
- </tr>
- </table>
- <div id="channelName" title="${remoteUser}"></div>
-</div>
-
-</body>
-</html>
View
114 blogracy-web/src/main/webapp/chatform2.jsp
@@ -1,114 +0,0 @@
-<%@ page import="net.blogracy.model.hashes.Hashes" %>
-<%@ page import="net.blogracy.model.users.Users" %>
-<%@ page import="net.blogracy.controller.FileSharing" %>
-<%@ page import="net.blogracy.controller.ChatController" %>
-<%@ page import="net.blogracy.config.Configurations" %>
-<%
-String userHash = request.getParameter("user");
-if (userHash == null || userHash.length() == 0) {
- userHash = Configurations.getUserConfig().getUser().getHash().toString();
-} else if (userHash.length() != 32) {
- userHash = Hashes.hash(userHash); // TODO: remove
-}
-
-pageContext.setAttribute("application", "Blogracy");
-pageContext.setAttribute("localUser", Configurations.getUserConfig().getUser());
-pageContext.setAttribute("remoteUser", ChatController.getRemoteUser());
-pageContext.setAttribute("loc", Configurations.getUserConfig().getUser().getHash().toString());
-%>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
-<!DOCTYPE html>
-<html lang="en">
-<head>
-
- <meta charset="utf-8">
- <title>${application}</title>
- <meta name="description" content="">
- <meta name="author" content="">
-
- <link rel="stylesheet" href="/chat files/chat.css" type="text/css">
- <style type="text/css" media="screen">
- @import url(/admin/styles/sorttable.css);
- @import url(/admin/styles/prettify.css);
- </style>
-
- <script type="text/javascript" src="chat files/jquery-1.js"></script>
- <script type="text/javascript" src="chat files/amq_jquery_adapter.js"></script>
- <script type="text/javascript" src="chat files/amq.js"></script>
- <script type="text/javascript" src="chat files/chat2.js"></script>
-
- <script src="/scripts/jquery-1.7.js"></script>
- <script src="/scripts/jquery.form.js"></script>
- <script src="/scripts/bootstrap-alerts.js"></script>
-
- <script type="text/javascript">
- // wait for the DOM to be loaded
- jQuery(function() {
- jQuery('#message-send').ajaxForm({
- url: '/fileupload',
- clearForm: true,
- type: 'POST',
- success: function() {
- console.log(arguments);
- },
- error: function(request, status, statusMessage) {
- var serverSideException = JSON.parse(request.responseText);
- var errorMessage = '<div class="alert-message block-message error"><a class="close" href="#">x</a>' +
- '<p><strong>' + serverSideException.errorMessage + '</strong></p>' +
- '<pre>' + serverSideException.errorTrace.join("\n") + '</pre>' +
- '</div>';
- jQuery(errorPlace).html(errorMessage);
- jQuery(".alert-message").alert();
- }
-
- });
- });
-
- </script>
-
- <script type="text/javascript">
- window.onload = function() {
- org.activemq.Amq.init({ uri: 'amq', logging: true, timeout: 45, clientId:(new Date()).getTime().toString() });
- org.activemq.Chat.init();
- };
- </script>
-
-</head>
-
-<body>
-
-<div class="white_box">
- <table border="0">
- <tr>
- <td style="overflow: hidden;" valign="top" width="50%">
- <div class="body-content">
-
- <div id="chatroom">
- <div id="chat"></div>
- <div id="members" class="hidden"></div>
-
- <div id="input">
- <div id="join" class="">
- Username:&nbsp;&nbsp;
- <input id="username" type="text" value="${localUser.localNick}" readonly="readonly">
- <button id="joinB">Re-Join</button>
- </div>
- <div id="joined" class="hidden">
- Chat:&nbsp;
- <input id="phrase" type="text">
- <button id="sendB">Send</button>
- <button id="leaveB" disabled="disabled">Leave</button>
- </div>
- </div>
- </div>
-
- </div>
- </td>
- </tr>
- </table>
- <div id="channelName" title="${loc}"></div>
-</div>
-
-</body>
-</html>
View
121 blogracy-web/src/main/webapp/chatform3.jsp
@@ -1,121 +0,0 @@
-<%@ page import="net.blogracy.model.hashes.Hashes" %>
-<%@ page import="net.blogracy.model.users.Users" %>
-<%@ page import="net.blogracy.controller.FileSharing" %>
-<%@ page import="net.blogracy.controller.ChatController" %>
-<%@ page import="net.blogracy.config.Configurations" %>
-<%
-String userHash = request.getParameter("user");
-if (userHash == null || userHash.length() == 0) {
- userHash = Configurations.getUserConfig().getUser().getHash().toString();
-} else if (userHash.length() != 32) {
- userHash = Hashes.hash(userHash); // TODO: remove
-}
-
-pageContext.setAttribute("application", "Blogracy");
-pageContext.setAttribute("localUser", Configurations.getUserConfig().getUser());
-pageContext.setAttribute("remoteUser", ChatController.getRemoteUser());
-
-ChatController.privateChatting();
-%>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
-<!DOCTYPE html>
-<html lang="en">
-<head>
-
- <meta charset="utf-8">
- <title>${application}</title>
- <meta name="description" content="">
- <meta name="author" content="">
-
- <link rel="stylesheet" href="/chat files/chat3.css" type="text/css">
- <style type="text/css" media="screen">
- @import url(/admin/styles/sorttable.css);
- @import url(/admin/styles/prettify.css);
- </style>
-
- <script type="text/javascript" src="chat files/jquery-1.js"></script>
- <script type="text/javascript" src="chat files/amq_jquery_adapter.js"></script>
- <script type="text/javascript" src="chat files/amq.js"></script>
- <script type="text/javascript" src="chat files/chat3.js"></script>
-
- <script src="/scripts/jquery-1.7.js"></script>
- <script src="/scripts/jquery.form.js"></script>
- <script src="/scripts/bootstrap-alerts.js"></script>
-
- <script type="text/javascript">
- // wait for the DOM to be loaded
- jQuery(function() {
- jQuery('#message-send').ajaxForm({
- url: '/fileupload',
- clearForm: true,
- type: 'POST',
- success: function() {
- console.log(arguments);
- },
- error: function(request, status, statusMessage) {
- var serverSideException = JSON.parse(request.responseText);
- var errorMessage = '<div class="alert-message block-message error"><a class="close" href="#">x</a>' +
- '<p><strong>' + serverSideException.errorMessage + '</strong></p>' +
- '<pre>' + serverSideException.errorTrace.join("\n") + '</pre>' +
- '</div>';
- jQuery(errorPlace).html(errorMessage);
- jQuery(".alert-message").alert();
- }
-
- });
- });
-
- </script>
-
- <script type="text/javascript">
- window.onload = function() {
- org.activemq.Amq.init({ uri: 'amq', logging: true, timeout: 45, clientId:(new Date()).getTime().toString() });
- org.activemq.Chat.init();
- };
- </script>
-
- <script type="text/javascript">
- window.onunload = function() {
- org.activemq.Chat.leave();
- };
- </script>
-
-</head>
-
-<body>
-
-<div class="white_box">
- <h2 style="font-size: 10px;">Private chat with ${remoteUser}</h2>
- <table border="0">
- <tr>
- <td style="overflow: hidden;" valign="top" width="40%">
- <div class="body-content">
-
- <div id="chatroom">
- <div id="chat"></div>
- <div id="members" class="hidden"></div>
-
- <div id="input">
- <div id="join" class="">
- Username:&nbsp;&nbsp;
- <input id="username" type="text" value="${localUser.localNick}" readonly="readonly">
- <button id="joinB">Re-Join</button>
- </div>
- <div id="joined" class="hidden">
- Chat:&nbsp;
- <input id="phrase" type="text">
- <button id="sendB">Send</button>
- <button id="leaveB">Leave</button>
- </div>
- </div>
- </div>
-
- </div>
- </td>
- </tr>
- </table>
-</div>
-
-</body>
-</html>
View
121 blogracy-web/src/main/webapp/chatform4.jsp
@@ -1,121 +0,0 @@
-<%@ page import="net.blogracy.model.hashes.Hashes" %>
-<%@ page import="net.blogracy.model.users.Users" %>
-<%@ page import="net.blogracy.controller.FileSharing" %>
-<%@ page import="net.blogracy.controller.ChatController" %>
-<%@ page import="net.blogracy.config.Configurations" %>
-<%
-String userHash = request.getParameter("user");
-if (userHash == null || userHash.length() == 0) {
- userHash = Configurations.getUserConfig().getUser().getHash().toString();
-} else if (userHash.length() != 32) {
- userHash = Hashes.hash(userHash); // TODO: remove
-}
-
-pageContext.setAttribute("application", "Blogracy");
-pageContext.setAttribute("localUser", Configurations.getUserConfig().getUser());
-pageContext.setAttribute("remoteUser", ChatController.getRemoteUser());
-
-ChatController.privateChatting2();
-%>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
-<!DOCTYPE html>
-<html lang="en">
-<head>
-
- <meta charset="utf-8">
- <title>${application}</title>
- <meta name="description" content="">
- <meta name="author" content="">
-
- <link rel="stylesheet" href="/chat files/chat3.css" type="text/css">
- <style type="text/css" media="screen">
- @import url(/admin/styles/sorttable.css);
- @import url(/admin/styles/prettify.css);
- </style>
-
- <script type="text/javascript" src="chat files/jquery-1.js"></script>
- <script type="text/javascript" src="chat files/amq_jquery_adapter.js"></script>
- <script type="text/javascript" src="chat files/amq.js"></script>
- <script type="text/javascript" src="chat files/chat4.js"></script>
-
- <script src="/scripts/jquery-1.7.js"></script>
- <script src="/scripts/jquery.form.js"></script>
- <script src="/scripts/bootstrap-alerts.js"></script>
-
- <script type="text/javascript">
- // wait for the DOM to be loaded
- jQuery(function() {
- jQuery('#message-send').ajaxForm({
- url: '/fileupload',
- clearForm: true,
- type: 'POST',
- success: function() {
- console.log(arguments);
- },
- error: function(request, status, statusMessage) {
- var serverSideException = JSON.parse(request.responseText);
- var errorMessage = '<div class="alert-message block-message error"><a class="close" href="#">x</a>' +
- '<p><strong>' + serverSideException.errorMessage + '</strong></p>' +
- '<pre>' + serverSideException.errorTrace.join("\n") + '</pre>' +
- '</div>';
- jQuery(errorPlace).html(errorMessage);
- jQuery(".alert-message").alert();
- }
-
- });
- });
-
- </script>
-
- <script type="text/javascript">
- window.onload = function() {
- org.activemq.Amq.init({ uri: 'amq', logging: true, timeout: 45, clientId:(new Date()).getTime().toString() });
- org.activemq.Chat.init();
- };
- </script>
-
- <script type="text/javascript">
- window.onunload = function() {
- org.activemq.Chat.leave();
- };
- </script>
-
-</head>
-
-<body>
-
-<div class="white_box">
- <h2 style="font-size: 10px;">Private chat with ${remoteUser}</h2>
- <table border="0">
- <tr>
- <td style="overflow: hidden;" valign="top" width="40%">
- <div class="body-content">
-
- <div id="chatroom">
- <div id="chat"></div>
- <div id="members" class="hidden"></div>
-
- <div id="input">
- <div id="join" class="">
- Username:&nbsp;&nbsp;
- <input id="username" type="text" value="${localUser.localNick}" readonly="readonly">
- <button id="joinB">Re-Join</button>
- </div>
- <div id="joined" class="hidden">
- Chat:&nbsp;
- <input id="phrase" type="text">
- <button id="sendB">Send</button>
- <button id="leaveB">Leave</button>
- </div>
- </div>
- </div>
-
- </div>
- </td>
- </tr>
- </table>
-</div>
-
-</body>
-</html>
View
414 blogracy-web/src/main/webapp/gallery.jsp
@@ -0,0 +1,414 @@
+<%@ page import="net.blogracy.model.hashes.Hashes" %>
+<%@ page import="net.blogracy.model.users.Users" %>
+<%@ page import="net.blogracy.controller.FileSharing" %>
+<%@ page import="net.blogracy.controller.ChatController" %>
+<%@ page import="net.blogracy.config.Configurations" %>
+<%@ page import="java.util.List" %>
+<%@ page import="java.util.Map" %>
+<%@ page import="java.util.HashMap" %>
+<%@ page import="org.apache.shindig.social.opensocial.model.Album" %>
+<%@ page import="org.apache.shindig.social.opensocial.model.MediaItem" %>
+<%
+String userHash = request.getParameter("user");
+if (userHash == null || userHash.length() == 0) {
+ userHash = Configurations.getUserConfig().getUser().getHash().toString();
+} else if (userHash.length() != 32) {
+ userHash = Hashes.hash(userHash); // TODO: remove
+}
+pageContext.setAttribute("loc", Configurations.getUserConfig().getUser().getHash().toString());
+pageContext.setAttribute("rem", userHash);
+
+String loc = Configurations.getUserConfig().getUser().getHash().toString();
+ChatController.setLocalUser(loc);
+ChatController.setRemoteUser(userHash);
+if (! loc.equals(userHash)) {
+ ChatController.privateChatting();
+ String channel = ChatController.getPrivateChannel();
+ pageContext.setAttribute("channel", channel);
+}
+
+List<Album> albums= FileSharing.getSingleton().getAlbums(userHash);
+Map<String, List<MediaItem>> mediaItemMap = new HashMap<String, List<MediaItem>>();
+for (Album a : albums)
+{
+ mediaItemMap.put(a.getId(), FileSharing.getSingleton().getMediaItemsWithCachedImages(userHash, a.getId()));
+}
+
+pageContext.setAttribute("application", "Blogracy");
+pageContext.setAttribute("user", Users.newUser(Hashes.fromString(userHash)));
+pageContext.setAttribute("feed", FileSharing.getFeed(userHash));
+pageContext.setAttribute("friends", Configurations.getUserConfig().getFriends());
+pageContext.setAttribute("localUser", Configurations.getUserConfig().getUser());
+pageContext.setAttribute("userAlbums", albums);
+pageContext.setAttribute("photoMap", mediaItemMap);
+%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>${application}</title>
+ <meta name="description" content="">
+ <meta name="author" content="">
+
+ <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
+ <!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+
+ <!-- Le styles -->
+ <link href="/css/bootstrap.css" rel="stylesheet"/>
+ <link href="/css/lightbox.css" rel="stylesheet" />
+ <link type="text/css" href="/css/smoothness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
+
+ <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
+ <script type="text/javascript" src="js/amq_jquery_adapter.js"></script>
+ <script type="text/javascript" src="js/amq.js"></script>
+ <script type="text/javascript" src="js/chat.js"></script>
+ <script type="text/javascript">
+ channel = "${channel}"
+ jQuery(function() {
+ org.activemq.Amq.init({ uri: 'amq', logging: true, timeout: 45, clientId:(new Date()).getTime().toString() });
+ org.activemq.Chat.init();
+ });
+ </script>
+
+ <!--script src="/scripts/jquery-1.7.js"></script>
+ <script src="/scripts/jquery.form.js"></script>
+ <script src="/scripts/jquery-ui-1.8.20.custom.min.js"></script>
+ <script src="/scripts/bootstrap-alerts.js"></script-->
+ <script src="/scripts/lightbox.js"></script>
+
+ <script type="text/javascript">
+ // wait for the DOM to be loaded
+ jQuery(function() {
+ jQuery('#message-send').ajaxForm({
+ url: '/fileupload',
+ clearForm: true,
+ type: 'POST',
+ success: function() {
+ console.log(arguments);
+ },
+ error: function(request, status, statusMessage) {
+ var serverSideException = JSON.parse(request.responseText);
+ var errorMessage = '<div class="alert-message block-message error"><a class="close" href="#">x</a>' +
+ '<p><strong>' + serverSideException.errorMessage + '</strong></p>' +
+ '<pre>' + serverSideException.errorTrace.join("\n") + '</pre>' +
+ '</div>';
+ jQuery(errorPlace).html(errorMessage);
+ jQuery(".alert-message").alert();
+ }
+
+ });
+ });
+
+ jQuery(function() {
+ jQuery('#create-gallery').ajaxForm({
+ url: '/ImageGalleryUploader',
+ clearForm: true,
+ type: 'POST',
+ success: function() {
+ console.log(arguments);
+ location.reload();
+ },
+ error: function(request, status, statusMessage) {
+ var serverSideException = JSON.parse(request.responseText);
+ var errorMessage = '<div class="alert-message block-message error"><a class="close" href="#">x</a>' +
+ '<p><strong>' + serverSideException.errorMessage + '</strong></p>' +
+ '<pre>' + serverSideException.errorTrace.join("\n") + '</pre>' +
+ '</div>';
+ jQuery(errorPlace).html(errorMessage);
+ jQuery(".alert-message").alert();
+ }
+
+ });
+ });
+
+ function openDialogWithLink(url)
+ {
+ var $dialog = $('#pop').load(url)
+ .dialog({
+ autoOpen: false,
+ title: 'Upload Images to Gallery',
+ height: 650,
+ width: 750,
+ modal: true,
+ close: function(event,ui){location.reload(true); $(this).dialog('destroy');}
+ });
+
+ $dialog.dialog('open');
+ };
+
+ </script>
+
+ <style type="text/css">
+ /* Override some defaults */
+ html, body {
+ background-color: #eee;
+ }
+
+ body {
+ padding-top: 40px; /* 40px to make the container go all the way to the bottom of the topbar */
+ }
+
+ .container > footer p {
+ text-align: center; /* center align it with the container */
+ }
+
+ .container {
+ width: 820px; /* downsize our container to make the content feel a bit tighter and more cohesive.
+ * NOTE: this removes two full columns from the grid, meaning you only go to
+ * 14 columns and not 16.
+ */
+ }
+
+ /* The white background content wrapper */
+ .content {
+ background-color: #fff;
+ padding: 20px;
+ margin: 0 -20px; /* negative indent the amount of the padding to maintain the grid system */
+ -webkit-border-radius: 0 0 6px 6px;
+ -moz-border-radius: 0 0 6px 6px;
+ border-radius: 0 0 6px 6px;
+ -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
+ -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, .15);