diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java
index c9a74f01..24389c51 100644
--- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java
+++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/TagDao.java
@@ -1,17 +1,5 @@
package com.sismics.docs.core.dao.jpa;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-
import com.google.common.base.Joiner;
import com.sismics.docs.core.constant.AuditLogType;
import com.sismics.docs.core.dao.jpa.criteria.TagCriteria;
@@ -24,6 +12,11 @@ import com.sismics.docs.core.util.jpa.QueryUtil;
import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.util.context.ThreadLocalContext;
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import java.util.*;
+
/**
* Tag DAO.
*
@@ -204,7 +197,7 @@ public class TagDao {
}
if (criteria.getNameLike() != null) {
criteriaList.add("t.TAG_NAME_C like :nameLike");
- parameterMap.put("nameLike", "%" + criteria.getNameLike() + "%");
+ parameterMap.put("nameLike", criteria.getNameLike() + "%");
}
criteriaList.add("t.TAG_DELETEDATE_D is null");
diff --git a/docs-core/src/main/java/com/sismics/util/EnvironmentUtil.java b/docs-core/src/main/java/com/sismics/util/EnvironmentUtil.java
index 791956da..71daf9ec 100644
--- a/docs-core/src/main/java/com/sismics/util/EnvironmentUtil.java
+++ b/docs-core/src/main/java/com/sismics/util/EnvironmentUtil.java
@@ -28,7 +28,7 @@ public class EnvironmentUtil {
* @return Running under Microsoft Windows
*/
public static boolean isWindows() {
- return OS.indexOf("win") >= 0;
+ return OS.contains("win");
}
/**
@@ -37,7 +37,7 @@ public class EnvironmentUtil {
* @return Running under Mac OS
*/
public static boolean isMacOs() {
- return OS.indexOf("mac") >= 0;
+ return OS.contains("mac");
}
/**
@@ -46,7 +46,7 @@ public class EnvironmentUtil {
* @return Running under UNIX
*/
public static boolean isUnix() {
- return OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0;
+ return OS.contains("nix") || OS.contains("nux") || OS.contains("aix");
}
/**
diff --git a/docs-web-common/src/main/java/com/sismics/util/filter/CorsFilter.java b/docs-web-common/src/main/java/com/sismics/util/filter/CorsFilter.java
new file mode 100644
index 00000000..83c0c8d6
--- /dev/null
+++ b/docs-web-common/src/main/java/com/sismics/util/filter/CorsFilter.java
@@ -0,0 +1,47 @@
+package com.sismics.util.filter;
+
+import com.sismics.util.EnvironmentUtil;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Filter used to handle CORS requests.
+ *
+ * @author bgamard
+ */
+public class CorsFilter implements Filter {
+ @Override
+ public void init(FilterConfig filterConfig) {
+ // NOP
+ }
+
+ @Override
+ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
+ HttpServletRequest request = (HttpServletRequest) req;
+ HttpServletResponse response = (HttpServletResponse) res;
+
+ if (EnvironmentUtil.isDevMode() && request.getHeader("origin") != null) {
+ // Add CORS in dev mode
+ response.addHeader("Access-Control-Allow-Origin", request.getHeader("origin"));
+ response.addHeader("Access-Control-Allow-Credentials", "true");
+ response.addHeader("Access-Control-Max-Age", "3600");
+ response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
+ response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
+ }
+
+ if ("OPTIONS".equals(request.getMethod())) {
+ // Handle preflight request
+ response.getWriter().print("{ \"status\": \"ok\" }");
+ } else {
+ filterChain.doFilter(req, res);
+ }
+ }
+
+ @Override
+ public void destroy() {
+ // NOP
+ }
+}
diff --git a/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java b/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java
index 04587f31..d5367f71 100644
--- a/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java
+++ b/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java
@@ -32,7 +32,7 @@ public class RequestContextFilter implements Filter {
private static final Logger log = LoggerFactory.getLogger(RequestContextFilter.class);
@Override
- public void init(FilterConfig filterConfig) throws ServletException {
+ public void init(FilterConfig filterConfig) {
// Initialize the app directory
if (!filterConfig.getServletContext().getServerInfo().startsWith("Grizzly")) {
EnvironmentUtil.setWebappContext(true);
diff --git a/docs-web/src/main/webapp/WEB-INF/web.xml b/docs-web/src/main/webapp/WEB-INF/web.xml
index 3f82eb30..f87da573 100644
--- a/docs-web/src/main/webapp/WEB-INF/web.xml
+++ b/docs-web/src/main/webapp/WEB-INF/web.xml
@@ -12,7 +12,19 @@
ImageIO service provider loader/unloader
com.twelvemonkeys.servlet.image.IIOProviderContextListener
-
+
+
+
+ corsFilter
+ com.sismics.util.filter.CorsFilter
+ true
+
+
+
+ corsFilter
+ /api/*
+
+
requestContextFilter
@@ -23,7 +35,6 @@
requestContextFilter
/api/*
- *.jsp