Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
minhdv committed Nov 24, 2015
2 parents afb6917 + 9bf05bb commit 66d9bf0
Show file tree
Hide file tree
Showing 127 changed files with 1,599 additions and 558 deletions.
Expand Up @@ -41,7 +41,7 @@ protected MessageInfo makeMessage(NotificationContext ctx) {
AbstractNotificationPlugin abstractPlugin = (AbstractNotificationPlugin) basePlugin;
return abstractPlugin.buildMessage(ctx);
}
return null;
return new MessageInfo().body(ctx.getNotificationInfo().getTitle());
}

@Override
Expand Down
Expand Up @@ -451,6 +451,7 @@ public NotificationInfo clone(boolean isNew) {
NotificationInfo message = instance();
message.setFrom(from)
.key(key)
.setTitle(title)
.setOrder(order)
.setOwnerParameter(new HashMap<String, String>(ownerParameter))
.setSendToDaily(arrayCopy(sendToDaily))
Expand Down
Expand Up @@ -113,12 +113,12 @@ public static String getFrom(String from) {
}

public static String getEmailFrom() {
SettingValue<?> mail = getSettingService().get(Context.GLOBAL, Scope.GLOBAL, NOTIFICATION_SENDER_EMAIL);
SettingValue<?> mail = getSettingService().get(Context.GLOBAL, Scope.GLOBAL.id(null), NOTIFICATION_SENDER_EMAIL);
return mail != null ? (String) mail.getValue() : System.getProperty("gatein.email.smtp.from", "noreply@exoplatform.com");
}

public static String getSenderName() {
SettingValue<?> name = getSettingService().get(Context.GLOBAL, Scope.GLOBAL, NOTIFICATION_SENDER_NAME);
SettingValue<?> name = getSettingService().get(Context.GLOBAL, Scope.GLOBAL.id(null), NOTIFICATION_SENDER_NAME);
return name != null ? (String) name.getValue() : System.getProperty("exo.notifications.portalname", "eXo");
}

Expand All @@ -127,7 +127,7 @@ public static String getSenderName() {
* @return
*/
public static String getBrandingPortalName() {
SettingValue<?> name = getSettingService().get(Context.GLOBAL, Scope.GLOBAL, BRANDING_PORTAL_NAME);
SettingValue<?> name = getSettingService().get(Context.GLOBAL, Scope.GLOBAL.id(null), BRANDING_PORTAL_NAME);
return name != null ? (String) name.getValue() : "eXo";
}

Expand Down
@@ -0,0 +1,10 @@
package org.exoplatform.commons.api.persistence;

/**
* Interface for data initialization
*/
public interface DataInitializer {
public void initData();

public void initData(String datasourceName);
}
@@ -1,20 +1,22 @@
package org.exoplatform.commons.api.search;

import java.util.Collection;

import org.apache.commons.lang.StringUtils;
import org.exoplatform.commons.api.search.data.SearchContext;
import org.exoplatform.commons.api.search.data.SearchResult;
import org.exoplatform.container.component.BaseComponentPlugin;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;

import java.util.Collection;

/**
* Is extended by all SearchService connectors, and allows to build configuration needed by a list of connectors that is used for the Unified Search.
*
*/
public abstract class SearchServiceConnector extends BaseComponentPlugin {
private String searchType; //search type name
private String displayName; //for use when rendering
private boolean enable = true;

/**
* Gets a search type.
Expand Down Expand Up @@ -51,6 +53,21 @@ public String getDisplayName() {
public void setDisplayName(String displayName) {
this.displayName = displayName;
}

/**
* is enable by default
*/
public boolean isEnable() {
return enable;
}

/**
* set enable by default
*/
public void setEnable(boolean enable) {
this.enable = enable;
}

/**
* Initializes a search service connector. The constructor is default that connectors must implement.
* @param initParams The parameters which are used for initializing the search service connector from configuration.
Expand All @@ -60,6 +77,7 @@ public SearchServiceConnector(InitParams initParams) {
PropertiesParam param = initParams.getPropertiesParam("constructor.params");
this.searchType = param.getProperty("searchType");
this.displayName = param.getProperty("displayName");
if (StringUtils.isNotBlank(param.getProperty("enable"))) this.setEnable(Boolean.parseBoolean(param.getProperty("enable")));
}

/**
Expand Down
11 changes: 10 additions & 1 deletion commons-component-common/pom.xml
Expand Up @@ -84,6 +84,10 @@
<groupId>org.gatein.portal</groupId>
<artifactId>exo.portal.component.common</artifactId>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>exo.portal.webui.portal</artifactId>
</dependency>
<dependency>
<groupId>org.owasp.antisamy</groupId>
<artifactId>antisamy</artifactId>
Expand Down Expand Up @@ -143,6 +147,11 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -174,13 +183,13 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.12.Final</version>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
</exclusion>
</exclusions>
<version>4.1.12.Final</version>
</dependency>
</dependencies>
<build>
Expand Down
Expand Up @@ -18,12 +18,14 @@

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Pattern;

import javax.ws.rs.core.UriBuilder;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;
import org.exoplatform.services.log.Log;
Expand Down Expand Up @@ -60,6 +62,22 @@ public void setUrl(String url) {
this.url = url;
}

/** Correct URI String
*
* @param URI URI string to correct
* @param scheme scheme to set
* @param force if force is false, only set again scheme when scheme is missing. Otherwise, always set it
* @return
*/

public String correctURIString(String uriString, String scheme, boolean force) {
URI uri = UriBuilder.fromUri(uriString).build();
if (uri.getScheme() == null || force) {
uri = UriBuilder.fromUri(uri.toString()).scheme(scheme).build();
}
return uri.toString();
}

protected JSONObject getJSONObject(URL url) {

BufferedReader bufferedReader;
Expand Down
Expand Up @@ -19,6 +19,8 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.webui.util.Util;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -55,6 +57,8 @@ public class OembedEmbedder extends AbstractEmbedder {

private static final String EMBED_THUMBNAIL = "thumbnail";

private static final Pattern SECURE_SHORTEN_DAILY_MOTION_PATTERN = Pattern.compile("https://dai\\.ly/.*");

/**
* constructor
*
Expand Down Expand Up @@ -92,7 +96,20 @@ private URL getOembedUrl(String url) {
Matcher matcher = pattern.matcher(url);
if (matcher.find()) {
String endpoint = schemeEndpointMap.get(pattern);
return new URL(String.format(endpoint, url));
String scheme = "http";
try {
PortalRequestContext portalRequestContext = Util.getPortalRequestContext();
scheme = portalRequestContext.getRequest().getScheme();
} catch (Exception e) {
LOG.info("Cannot get scheme from Portal Request Context");
}
// COMMONS-400: Workaround for share secure daily motion pattern by using oEmbed
// https://www.dailymotion.com/services/oembed?format=json&url=https://dai.ly/xxxxx does not work
Matcher shortenMatcher = SECURE_SHORTEN_DAILY_MOTION_PATTERN.matcher(url);
if (shortenMatcher.find()) {
url = correctURIString(url, "http", true);
}
return new URL(correctURIString(String.format(endpoint, url),scheme, false));
}
}
} catch (MalformedURLException e) {
Expand Down
Expand Up @@ -24,7 +24,8 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.json.JSONArray;
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.webui.util.Util;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -38,7 +39,7 @@ public class YoutubeEmbedder extends AbstractEmbedder {

private static final Pattern YOUTUBE_ID_PATTERN = Pattern
.compile("(youtu\\.be\\/|youtube\\.com\\/(watch\\?(.*&)?v=|(embed|v)\\/))([^\\?&\"'>]+)");
private static final String YOUTUBE_SRC = "http://www.youtube.com/embed/%s?enablejsapi=1";
private static final String YOUTUBE_SRC = "//www.youtube.com/embed/%s?enablejsapi=1";
private static final String YOUTUBE_V3_API_KEY_PROPERTY = "youtube.v3.api.key";

/**
Expand All @@ -60,10 +61,17 @@ public Pattern getYouTubeURLPattern() {
*/
public ExoMedia getExoMedia() {
String feedsURL = null;
String scheme = "http";
for(Pattern pattern : schemeEndpointMap.keySet()) {
Matcher matcher = pattern.matcher(url);
if(matcher.find()) {
feedsURL = schemeEndpointMap.get(pattern);
try {
PortalRequestContext portalRequestContext = Util.getPortalRequestContext();
scheme = portalRequestContext.getRequest().getScheme();
} catch (Exception e) {
LOG.info("Cannot get scheme from Portal Request Context");
}
} else {
return null;
}
Expand All @@ -79,9 +87,8 @@ public ExoMedia getExoMedia() {
while (matcher.find()) {
youtubeId = matcher.group(5);
}

//
String html = buildIFramePlayer(youtubeId);

String html = buildIFramePlayer(youtubeId,scheme);

if (html == null) {
return null;
Expand All @@ -97,7 +104,7 @@ public ExoMedia getExoMedia() {
}

String youTubeFeedURL = String.format(feedsURL, youtubeV3APIKey, youtubeId);
URL reqURL = new URL(youTubeFeedURL);
URL reqURL = new URL(correctURIString(youTubeFeedURL, scheme, false));
JSONObject jsonObject = getJSONObject(reqURL);
JSONObject snippetObject = jsonObject.getJSONArray("items").getJSONObject(0).getJSONObject("snippet");

Expand Down Expand Up @@ -136,15 +143,16 @@ public ExoMedia getExoMedia() {
}
}

private String buildIFramePlayer(String youtubeId) throws JSONException {
private String buildIFramePlayer(String youtubeId, String scheme) throws JSONException {

if (youtubeId == null) {
LOG.info("Returned content url not match the pattern to get content source.");
return null;
}
String youTubeSRC = String.format(YOUTUBE_SRC, youtubeId);
StringBuilder contentURL = new StringBuilder();
contentURL.append("<iframe id=\"player\" type=\"text/html\" width=\"330\" height=\"200\" frameborder=\"0\" allowfullscreen=\"true\"")
.append(" src=\"").append(youTubeSRC).append("\">").append("&nbsp;</iframe>");
.append(" src=\"").append(correctURIString(youTubeSRC,scheme,false)).append("\">").append("&nbsp;</iframe>");
return contentURL.toString();
}

Expand Down
Expand Up @@ -32,6 +32,11 @@
import org.apache.commons.lang.StringUtils;
import org.exoplatform.commons.api.notification.plugin.config.PluginConfig;
import org.exoplatform.commons.api.notification.template.Element;
import org.exoplatform.commons.api.settings.SettingService;
import org.exoplatform.commons.api.settings.SettingValue;
import org.exoplatform.commons.api.settings.data.Context;
import org.exoplatform.commons.api.settings.data.Scope;
import org.exoplatform.commons.notification.impl.AbstractService;
import org.exoplatform.commons.notification.template.DigestTemplate;
import org.exoplatform.commons.notification.template.SimpleElement;
import org.exoplatform.commons.notification.template.TemplateUtils;
Expand All @@ -56,7 +61,7 @@ public class NotificationUtils {

private static final Pattern LINK_PATTERN = Pattern.compile("<a ([^>]+)>([^<]+)</a>");

private static final Pattern EMAIL_PATTERN = Pattern.compile("^[_a-zA-Z0-9-+]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,5})$");
private static final Pattern EMAIL_PATTERN = Pattern.compile("^[_a-zA-Z0-9-+]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,})$");

private static final String styleCSS = " style=\"color: #2f5e92; text-decoration: none;\"";

Expand Down Expand Up @@ -245,6 +250,16 @@ public static boolean isDeletedMember(String userName) {
}
}

public static boolean isActiveSetting(String userId) {
try {
SettingService settingService = CommonsUtils.getService(SettingService.class);
SettingValue<Boolean> value = (SettingValue<Boolean>) settingService.get(Context.USER.id(userId), Scope.GLOBAL, AbstractService.EXO_IS_ACTIVE);
return (value.getValue() == null) ? true : value.getValue();
} catch (Exception e) {
return false;
}
}

/**
* Add the style css for a link in the activity title to display a link without underline
*
Expand Down

0 comments on commit 66d9bf0

Please sign in to comment.