Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Feb 28, 2014
1 parent c5a2fb8 commit 35d434a
Show file tree
Hide file tree
Showing 46 changed files with 986 additions and 780 deletions.
Binary file removed build/expandingtextarea-1.0.2-custom.jar
Binary file not shown.
13 changes: 11 additions & 2 deletions common/src/main/java/org/vaadin/tori/Configuration.java
Expand Up @@ -26,6 +26,15 @@ public class Configuration {
private Map<String, String> replacements;
private String googleAnalyticsTrackerId;
private String pathRoot;
private String mayNotReplyNote;

public String getMayNotReplyNote() {
return mayNotReplyNote;
}

public void setMayNotReplyNote(final String mayNotReplyNote) {
this.mayNotReplyNote = mayNotReplyNote;
}

/**
* Whether or not messages' links are replaced with what is in
Expand Down Expand Up @@ -96,15 +105,15 @@ public boolean isUpdatePageTitle() {
return updatePageTitle;
}

public void setUpdatePageTitle(boolean updatePageTitle) {
public void setUpdatePageTitle(final boolean updatePageTitle) {
this.updatePageTitle = updatePageTitle;
}

public String getPageTitlePrefix() {
return pageTitlePrefix;
}

public void setPageTitlePrefix(String pageTitlePrefix) {
public void setPageTitlePrefix(final String pageTitlePrefix) {
this.pageTitlePrefix = pageTitlePrefix;
}

Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/org/vaadin/tori/data/DataSource.java
Expand Up @@ -338,4 +338,6 @@ Post saveReply(String rawBody, Map<String, byte[]> attachments,

User getCurrentUser();

String getMayNotReplyNote();

}
2 changes: 0 additions & 2 deletions common/src/main/java/org/vaadin/tori/util/PostFormatter.java
Expand Up @@ -17,7 +17,6 @@
package org.vaadin.tori.util;

import java.util.Collection;
import java.util.Map;

import org.vaadin.tori.data.entity.Post;

Expand Down Expand Up @@ -70,5 +69,4 @@ public interface FontSize {

String getQuote(final Post postToQuote);

void setPostReplacements(Map<String, String> postReplacements);
}
Binary file removed docs/toolbar-icons.psd
Binary file not shown.
Expand Up @@ -26,6 +26,7 @@
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
Expand Down Expand Up @@ -115,7 +116,7 @@ public abstract class LiferayCommonDataSource implements DataSource,
private static final String PREFS_REPLACE_MESSAGE_BOARDS_LINKS = "toriReplaceMessageBoardsLinks";
private static final String PREFS_UPDATE_PAGE_TITLE = "toriUpdatePageTitle";
private static final String PREFS_PAGE_TITLE_PREFIX = "toriPageTitlePrefix";

private static final String PREFS_MAY_NOT_REPLY_NOTE = "mayNotReplyNote";
private static final String PREFS_PATHROOT = "pathroot";

private static final String URL_PREFIX = "/#!/";
Expand Down Expand Up @@ -290,9 +291,13 @@ private DiscussionThread wrapLiferayThread(final MBThread liferayThread,
category = getCategory(liferayThread.getCategoryId());
}

List<MBMessage> posts = getLiferayPostsForThread(liferayThread
.getThreadId());
MBMessage last = posts.get(posts.size() - 1);

final DiscussionThread thread = LiferayCommonEntityFactoryUtil
.createDiscussionThread(liferayThread, rootMessage,
threadAuthor, lastPostAuthor);
threadAuthor, lastPostAuthor, last.getMessageId());
thread.setCategory(category);
thread.setSticky(liferayThread.getPriority() >= STICKY_PRIORITY);
return thread;
Expand Down Expand Up @@ -1112,6 +1117,8 @@ public final void save(final Configuration config)
.valueOf(config.isUpdatePageTitle()).toString());
portletPreferences.setValue(PREFS_PAGE_TITLE_PREFIX,
config.getPageTitlePrefix());
portletPreferences.setValue(PREFS_MAY_NOT_REPLY_NOTE,
config.getMayNotReplyNote());

portletPreferences.store();
} catch (final Exception e) {
Expand Down Expand Up @@ -1227,6 +1234,20 @@ private Post internalGetPost(final MBMessage message,
bodyRaw = replaceMessageBoardsLinksMessages(bodyRaw);
}

if (getPostReplacements() != null) {
for (final Entry<String, String> entry : getPostReplacements()
.entrySet()) {
try {
bodyRaw = bodyRaw.replaceAll(entry.getKey(),
entry.getValue());
} catch (final PatternSyntaxException e) {
LOG.warn(
"Invalid replacement regex pattern: "
+ entry.getKey(), e);
}
}
}

return LiferayCommonEntityFactoryUtil.createPost(message, bodyRaw,
formatBBCode, author, thread, attachments);
}
Expand All @@ -1243,4 +1264,9 @@ public User getCurrentUser() {
}
}

@Override
public String getMayNotReplyNote() {
return portletPreferences.getValue(PREFS_MAY_NOT_REPLY_NOTE, null);
}

}
Expand Up @@ -48,14 +48,16 @@ public static List<Category> createCategories(

public static DiscussionThread createDiscussionThread(
final MBThread liferayThread, final MBMessage threadRootMessage,
final User threadAuthor, final User lastPostAuthor) {
final User threadAuthor, final User lastPostAuthor,
final Long lastPostId) {
final DiscussionThread entity = new DiscussionThread() {
@Override
public Post getLatestPost() {
// TODO workaround for this hack
final Post fakedLastPost = new Post();
fakedLastPost.setTime(liferayThread.getLastPostDate());
fakedLastPost.setAuthor(lastPostAuthor);
fakedLastPost.setId(lastPostId);
return fakedLastPost;
}

Expand All @@ -80,7 +82,7 @@ public static Post createPost(final MBMessage liferayMessage,
final Post entity = new Post();
entity.setId(liferayMessage.getMessageId());
entity.setTime(liferayMessage.getCreateDate());
entity.setBodyRaw(liferayMessage.getBody(false));
entity.setBodyRaw(bodyRaw);
entity.setThread(thread);
entity.setAuthor(author);
entity.setFormatBBCode(formatBBCode);
Expand Down
Expand Up @@ -69,7 +69,7 @@ public LiferayCommonToriActivityMessaging() {
}

@Override
public void sendUserTyping(long threadId, Date startedTyping) {
public void sendUserTyping(final long threadId, final Date startedTyping) {
Message message = new Message();
message.put(USER_ID, new Long(currentUserId));
message.put(THREAD_ID, new Long(threadId));
Expand All @@ -78,23 +78,23 @@ public void sendUserTyping(long threadId, Date startedTyping) {
}

@Override
public void sendUserAuthored(long postId, long threadId) {
public void sendUserAuthored(final long postId, final long threadId) {
Message message = new Message();
message.put(POST_ID, new Long(postId));
message.put(THREAD_ID, new Long(threadId));
sendMessage(message, USER_AUTHORED_DESTINATION);
}

private void sendMessage(Message message, String destinationName) {
private void sendMessage(final Message message, final String destinationName) {
message.put(SENDER_ID, getSenderId());
MessageBusUtil.sendMessage(destinationName, message);
}

private String getSenderId() {
return request.getRequestedSessionId();
return request.getPortletSession().getId();
}

private boolean isThisSender(Message message) {
private boolean isThisSender(final Message message) {
Object senderId = message.get(SENDER_ID);
return senderId != null && senderId.equals(getSenderId());
}
Expand All @@ -104,7 +104,7 @@ public void addUserTypingListener(final UserTypingListener listener) {
addListener(listener, new FilteringMessageListener(
USER_TYPING_DESTINATION) {
@Override
protected void process(Message message) {
protected void process(final Message message) {
listener.userTyping(message.getLong(USER_ID),
message.getLong(THREAD_ID),
new Date(message.getLong(STARTED_TYPING)));
Expand All @@ -117,31 +117,31 @@ public void addUserAuthoredListener(final UserAuthoredListener listener) {
addListener(listener, new FilteringMessageListener(
USER_AUTHORED_DESTINATION) {
@Override
protected void process(Message message) {
protected void process(final Message message) {
listener.userAuthored(message.getLong(POST_ID),
message.getLong(THREAD_ID));
}
});
}

@Override
public void removeUserTypingListener(UserTypingListener listener) {
public void removeUserTypingListener(final UserTypingListener listener) {
removeListener(listener, USER_TYPING_DESTINATION);
}

@Override
public void removeUserAuthoredListener(UserAuthoredListener listener) {
public void removeUserAuthoredListener(final UserAuthoredListener listener) {
removeListener(listener, USER_AUTHORED_DESTINATION);
}

private void addListener(Object key,
FilteringMessageListener messageListener) {
private void addListener(final Object key,
final FilteringMessageListener messageListener) {
MessageBusUtil.registerMessageListener(messageListener.destinationName,
messageListener);
getListeners(messageListener.destinationName).put(key, messageListener);
}

private void removeListener(Object key, String destination) {
private void removeListener(final Object key, final String destination) {
MessageListener messageListener = getListeners(destination).remove(key);
if (messageListener != null) {
MessageBusUtil.unregisterMessageListener(destination,
Expand All @@ -150,7 +150,7 @@ private void removeListener(Object key, String destination) {
}

@SuppressWarnings("unchecked")
private Map<Object, MessageListener> getListeners(String destination) {
private Map<Object, MessageListener> getListeners(final String destination) {
PortletSession session = request.getPortletSession();
String attrId = TORIACTIVITYLISTENERS + destination;
if (session.getAttribute(attrId) == null) {
Expand All @@ -160,7 +160,7 @@ private Map<Object, MessageListener> getListeners(String destination) {
}

@Override
public void setRequest(PortletRequest request) {
public void setRequest(final PortletRequest request) {
this.request = request;
if (currentUserId == 0 && request.getRemoteUser() != null) {
currentUserId = Long.valueOf(request.getRemoteUser());
Expand All @@ -171,12 +171,12 @@ private abstract class FilteringMessageListener implements MessageListener {

private final String destinationName;

public FilteringMessageListener(String destinationName) {
public FilteringMessageListener(final String destinationName) {
this.destinationName = destinationName;
}

@Override
public void receive(Message message) throws RuntimeException {
public void receive(final Message message) throws RuntimeException {
try {
getListeners(USER_TYPING_DESTINATION);
if (!isThisSender(message)) {
Expand Down
Expand Up @@ -19,32 +19,21 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.PatternSyntaxException;

import javax.portlet.PortletRequest;

import org.apache.log4j.Logger;
import org.vaadin.tori.PortletRequestAware;
import org.vaadin.tori.data.entity.Post;
import org.vaadin.tori.util.PostFormatter.FontsInfo.FontFace;
import org.vaadin.tori.util.PostFormatter.FontsInfo.FontSize;

import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portlet.messageboards.util.BBCodeUtil;

public class LiferayPostFormatter implements PostFormatter, PortletRequestAware {
public class LiferayPostFormatter implements PostFormatter {

private static final Logger LOG = Logger
.getLogger(LiferayPostFormatter.class);

private static Collection<FontFace> fontFaces;
private static Collection<FontSize> fontSizes;
private Map<String, String> postReplacements;

private ThemeDisplay themeDisplay;

static {
fontFaces = new ArrayList<FontFace>(Arrays.asList(LiferayCommonFontFace
Expand All @@ -63,20 +52,6 @@ public String format(final Post post) {
LOG.debug("Couldn't parse the given post body: " + msgBody);
}
}

if (postReplacements != null) {
for (final Entry<String, String> entry : postReplacements
.entrySet()) {
try {
msgBody = msgBody.replaceAll(entry.getKey(),
entry.getValue());
} catch (final PatternSyntaxException e) {
LOG.warn(
"Invalid replacement regex pattern: "
+ entry.getKey(), e);
}
}
}
return msgBody;
}

Expand Down Expand Up @@ -104,15 +79,4 @@ public String getQuote(final Post postToQuote) {
.getDisplayedName(), postToQuote.getBodyRaw());
}

@Override
public final void setPostReplacements(
final Map<String, String> postReplacements) {
this.postReplacements = postReplacements;
}

@Override
public void setRequest(final PortletRequest request) {
themeDisplay = (ThemeDisplay) request
.getAttribute(WebKeys.THEME_DISPLAY);
}
}
Expand Up @@ -19,9 +19,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.PatternSyntaxException;

import javax.portlet.PortletRequest;

Expand All @@ -43,8 +40,6 @@ public class LiferayPostFormatter implements PostFormatter, PortletRequestAware

private static Collection<FontFace> fontFaces;
private static Collection<FontSize> fontSizes;
private Map<String, String> postReplacements;

private ThemeDisplay themeDisplay;

static {
Expand All @@ -68,19 +63,6 @@ public String format(final Post post) {
themeDisplay.getPathThemeImages() + "/emoticons");
}

if (postReplacements != null) {
for (final Entry<String, String> entry : postReplacements
.entrySet()) {
try {
msgBody = msgBody.replaceAll(entry.getKey(),
entry.getValue());
} catch (final PatternSyntaxException e) {
LOG.warn(
"Invalid replacement regex pattern: "
+ entry.getKey(), e);
}
}
}
return msgBody;
}

Expand Down Expand Up @@ -108,12 +90,6 @@ public String getQuote(final Post postToQuote) {
.getDisplayedName(), postToQuote.getBodyRaw());
}

@Override
public final void setPostReplacements(
final Map<String, String> postReplacements) {
this.postReplacements = postReplacements;
}

@Override
public void setRequest(final PortletRequest request) {
themeDisplay = (ThemeDisplay) request
Expand Down

0 comments on commit 35d434a

Please sign in to comment.