1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-13 17:56:20 +00:00

Closes #29: Upgrade to Jersey 2

This commit is contained in:
jendib
2015-09-07 21:51:13 +02:00
parent 97694d5d59
commit 0fe51d355c
44 changed files with 1643 additions and 2292 deletions

View File

@@ -26,6 +26,11 @@
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<!-- Other external dependencies -->
<dependency>
<groupId>joda-time</groupId>

View File

@@ -1,38 +0,0 @@
package com.sismics.docs.core.dao.file.theme;
import com.google.common.collect.Lists;
import com.sismics.docs.core.util.DirectoryUtil;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
/**
* Theme DAO.
*
* @author jtremeaux
*/
public class ThemeDao {
private final static FilenameFilter CSS_FILTER = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".css") || name.endsWith(".less");
}
};
/**
* Return the list of all themes.
*
* @return List of themes
*/
public List<String> findAll() {
final File themeDirectory = DirectoryUtil.getThemeDirectory();
if (themeDirectory != null) {
return Lists.newArrayList(themeDirectory.list(CSS_FILTER));
} else {
return new ArrayList<String>();
}
}
}

View File

@@ -1,9 +1,10 @@
package com.sismics.docs.core.util;
import com.sismics.util.EnvironmentUtil;
import java.io.File;
import org.apache.commons.lang.StringUtils;
import java.io.File;
import com.sismics.util.EnvironmentUtil;
/**
* Utilities to gain access to the storage directories used by the application.
@@ -18,27 +19,27 @@ public class DirectoryUtil {
*/
public static File getBaseDataDirectory() {
File baseDataDir = null;
if (EnvironmentUtil.getWebappRoot() != null) {
// We are in a webapp environment
if (StringUtils.isNotBlank(EnvironmentUtil.getDocsHome())) {
// If the docs.home property is set then use it
baseDataDir = new File(EnvironmentUtil.getDocsHome());
if (!baseDataDir.isDirectory()) {
baseDataDir.mkdirs();
}
} else {
// Use the base of the Webapp directory
baseDataDir = new File(EnvironmentUtil.getWebappRoot() + File.separator + "sismicsdocs");
if (!baseDataDir.isDirectory()) {
baseDataDir.mkdirs();
}
if (StringUtils.isNotBlank(EnvironmentUtil.getDocsHome())) {
// If the docs.home property is set then use it
baseDataDir = new File(EnvironmentUtil.getDocsHome());
} else if (EnvironmentUtil.isUnitTest()) {
// For unit testing, use a temporary directory
baseDataDir = new File(System.getProperty("java.io.tmpdir"));
} else {
// We are in a webapp environment and nothing is specified, use the default directory for this OS
if (EnvironmentUtil.isUnix()) {
baseDataDir = new File("/var/docs");
} if (EnvironmentUtil.isWindows()) {
baseDataDir = new File(EnvironmentUtil.getWindowsAppData() + "\\Sismics\\Docs");
} else if (EnvironmentUtil.isMacOs()) {
baseDataDir = new File(EnvironmentUtil.getMacOsUserHome() + "/Library/Sismics/Docs");
}
}
if (baseDataDir == null) {
// Or else (for unit testing), use a temporary directory
baseDataDir = new File(System.getProperty("java.io.tmpdir"));
if (baseDataDir != null && !baseDataDir.isDirectory()) {
baseDataDir.mkdirs();
}
return baseDataDir;
}
@@ -78,25 +79,6 @@ public class DirectoryUtil {
return getDataSubDirectory("log");
}
/**
* Returns the themes directory.
*
* @return Theme directory.
*/
public static File getThemeDirectory() {
String webappRoot = EnvironmentUtil.getWebappRoot();
File themeDir = null;
if (webappRoot != null) {
themeDir = new File(webappRoot + File.separator + "style" + File.separator + "theme");
} else {
themeDir = new File(DirectoryUtil.class.getResource("/style/theme").getFile());
}
if (themeDir != null && themeDir.isDirectory()) {
return themeDir;
}
return null;
}
/**
* Returns a subdirectory of the base data directory
*

View File

@@ -9,7 +9,7 @@ public class EnvironmentUtil {
private static String OS = System.getProperty("os.name").toLowerCase();
private static String TEST_ENV = System.getProperty("test");
private static String APPLICATION_MODE = System.getProperty("application.mode");
private static String WINDOWS_APPDATA = System.getenv("APPDATA");
@@ -18,9 +18,9 @@ public class EnvironmentUtil {
private static String DOCS_HOME = System.getProperty("docs.home");
/**
* Web application root.
* In a web application context.
*/
private static String webappRoot;
private static boolean webappContext;
/**
* Returns true if running under Microsoft Windows.
@@ -55,10 +55,18 @@ public class EnvironmentUtil {
* @return Unit testing environment
*/
public static boolean isUnitTest() {
return webappRoot == null ||
TEST_ENV != null && "true".equals(TEST_ENV);
return !webappContext || isDevMode();
}
/**
* Return true if we are in dev mode.
*
* @return Dev mode
*/
public static boolean isDevMode() {
return "dev".equalsIgnoreCase(APPLICATION_MODE);
}
/**
* Returns the MS Windows AppData directory of this user.
*
@@ -87,20 +95,20 @@ public class EnvironmentUtil {
}
/**
* Getter of webappRoot.
* Getter of webappContext.
*
* @return webappRoot
* @return webappContext
*/
public static String getWebappRoot() {
return webappRoot;
public static boolean isWebappContext() {
return webappContext;
}
/**
* Setter of webappRoot.
* Setter of webappContext.
*
* @param webappRoot webappRoot
* @param webappContext webappContext
*/
public static void setWebappRoot(String webappRoot) {
EnvironmentUtil.webappRoot = webappRoot;
public static void setWebappContext(boolean webappContext) {
EnvironmentUtil.webappContext = webappContext;
}
}