Author: tolusha
Date: 2010-06-15 06:53:03 -0400 (Tue, 15 Jun 2010)
New Revision: 2600
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/statistics/JCRStatisticsManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceDataContainer.java
Log:
EXOJCR-756: small refactoring
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-06-15
10:21:46 UTC (rev 2599)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2010-06-15
10:53:03 UTC (rev 2600)
@@ -40,6 +40,7 @@
import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
@@ -99,7 +100,7 @@
else
restorePath = fullBackupPath;
- this.tempDir = new File(System.getProperty("java.io.tmpdir"));
+ this.tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
@Override
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-06-15
10:21:46 UTC (rev 2599)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java 2010-06-15
10:53:03 UTC (rev 2600)
@@ -44,6 +44,7 @@
import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.log.ExoLogger;
@@ -416,7 +417,7 @@
+ ") RestoreIntializer should have mandatory parameter "
+ SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER);
- this.tempDir = new File(System.getProperty("java.io.tmpdir"));
+ this.tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
/**
@@ -462,7 +463,7 @@
WorkspaceDataContainer.DEF_MAXBUFFERSIZE);
this.restorePath = restorePath;
- this.tempDir = new File(System.getProperty("java.io.tmpdir"));
+ this.tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
}
/**
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2010-06-15
10:21:46 UTC (rev 2599)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2010-06-15
10:53:03 UTC (rev 2600)
@@ -35,6 +35,7 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.update.StorageUpdateManager;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerException;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
@@ -70,7 +71,7 @@
* Indicates if the statistics has to be enabled.
*/
public static final boolean STATISTICS_ENABLED =
-
Boolean.valueOf(System.getProperty("JDBCWorkspaceDataContainer.statistics.enabled"));
+
Boolean.valueOf(PrivilegedSystemHelper.getProperty("JDBCWorkspaceDataContainer.statistics.enabled"));
static
{
if (STATISTICS_ENABLED)
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-15
10:21:46 UTC (rev 2599)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-15
10:53:03 UTC (rev 2600)
@@ -39,6 +39,13 @@
public class PrivilegedFileHelper
{
+ /**
+ * Create FileOutputStream in privileged mode.
+ *
+ * @param file
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileOutputStream fileOutputStream(final File file) throws
FileNotFoundException
{
PrivilegedExceptionAction<FileOutputStream> action = new
PrivilegedExceptionAction<FileOutputStream>()
@@ -70,6 +77,13 @@
}
}
+ /**
+ * Create FileOutputStream in privileged mode.
+ *
+ * @param name
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileOutputStream fileOutputStream(final String name) throws
FileNotFoundException
{
PrivilegedExceptionAction<FileOutputStream> action = new
PrivilegedExceptionAction<FileOutputStream>()
@@ -101,6 +115,14 @@
}
}
+ /**
+ * Create FileOutputStream in privileged mode.
+ *
+ * @param file
+ * @param append
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileOutputStream fileOutputStream(final File file, final boolean append)
throws FileNotFoundException
{
PrivilegedExceptionAction<FileOutputStream> action = new
PrivilegedExceptionAction<FileOutputStream>()
@@ -132,6 +154,13 @@
}
}
+ /**
+ * Create FileInputStream in privileged mode.
+ *
+ * @param file
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileInputStream fileInputStream(final File file) throws
FileNotFoundException
{
PrivilegedExceptionAction<FileInputStream> action = new
PrivilegedExceptionAction<FileInputStream>()
@@ -163,6 +192,13 @@
}
}
+ /**
+ * Create FileInputStream in privileged mode.
+ *
+ * @param name
+ * @return
+ * @throws FileNotFoundException
+ */
public static FileInputStream fileInputStream(final String name) throws
FileNotFoundException
{
PrivilegedExceptionAction<FileInputStream> action = new
PrivilegedExceptionAction<FileInputStream>()
@@ -194,6 +230,16 @@
}
}
+ /**
+ * Create temporary file in privileged mode.
+ *
+ * @param prefix
+ * @param suffix
+ * @param directory
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IOException
+ */
public static File createTempFile(final String prefix, final String suffix, final File
directory)
throws IllegalArgumentException, IOException
{
@@ -230,6 +276,16 @@
}
}
+ /**
+ * Create teamporary file in privileged mode.
+ *
+ *
+ * @param prefix
+ * @param suffix
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IOException
+ */
public static File createTempFile(final String prefix, final String suffix) throws
IllegalArgumentException,
IOException
{
@@ -266,6 +322,15 @@
}
}
+ /**
+ * Create RandomAccessFile in privileged mode.
+ *
+ * @param file
+ * @param mode
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IOException
+ */
public static RandomAccessFile randomAccessFile(final File file, final String mode)
throws IllegalArgumentException,
IOException
{
@@ -302,6 +367,12 @@
}
}
+ /**
+ * Get file length in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static long length(final File file)
{
PrivilegedAction<Long> action = new PrivilegedAction<Long>()
@@ -314,6 +385,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Requests in privileged mode that the file or directory denoted by this abstract
+ * pathname be deleted when the virtual machine terminates.
+ *
+ * @param file
+ */
public static void deleteOnExit(final File file)
{
PrivilegedAction<Object> action = new PrivilegedAction<Object>()
@@ -327,6 +404,12 @@
AccessController.doPrivileged(action);
}
+ /**
+ * Get file absolute path in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static String getAbsolutePath(final File file)
{
PrivilegedAction<String> action = new PrivilegedAction<String>()
@@ -339,6 +422,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Delete file in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static boolean delete(final File file)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -351,6 +440,13 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Tests in privileged mode whether the file denoted by this abstract pathname is a
+ * directory.
+ *
+ * @param file
+ * @return
+ */
public static boolean isDirectory(final File file)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -363,6 +459,13 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Tests in privileged mode whether the file or directory denoted by this abstract
pathname
+ * exists.
+ *
+ * @param file
+ * @return
+ */
public static boolean exists(final File file)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -375,6 +478,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Creates the directory in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static boolean mkdirs(final File file)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -387,6 +496,13 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Rename File in privileged mode.
+ *
+ * @param srcFile
+ * @param dstfile
+ * @return
+ */
public static boolean renameTo(final File srcFile, final File dstfile)
{
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
@@ -399,6 +515,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Get file's list in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static String[] list(final File file)
{
PrivilegedAction<String[]> action = new PrivilegedAction<String[]>()
@@ -411,6 +533,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Get file's list in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static String[] list(final File file, final FilenameFilter filter)
{
PrivilegedAction<String[]> action = new PrivilegedAction<String[]>()
@@ -423,6 +551,12 @@
return AccessController.doPrivileged(action);
}
+ /**
+ * Get file's list in privileged mode.
+ *
+ * @param file
+ * @return
+ */
public static File[] listFiles(final File file)
{
PrivilegedAction<File[]> action = new PrivilegedAction<File[]>()
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java 2010-06-15
10:21:46 UTC (rev 2599)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedSystemHelper.java 2010-06-15
10:53:03 UTC (rev 2600)
@@ -29,25 +29,38 @@
public class PrivilegedSystemHelper
{
- public static String getProperty(final String name)
+ /**
+ * Gets system property in privileged mode.
+ *
+ * @param key
+ * @return
+ */
+ public static String getProperty(final String key)
{
PrivilegedAction<String> action = new PrivilegedAction<String>()
{
public String run()
{
- return System.getProperty(name);
+ return System.getProperty(key);
}
};
return AccessController.doPrivileged(action);
}
- public static String getProperty(final String name, final String def)
+ /**
+ * Gets system property in privileged mode.
+ *
+ * @param key
+ * @param def
+ * @return
+ */
+ public static String getProperty(final String key, final String def)
{
PrivilegedAction<String> action = new PrivilegedAction<String>()
{
public String run()
{
- return System.getProperty(name, def);
+ return System.getProperty(key, def);
}
};
return AccessController.doPrivileged(action);
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/statistics/JCRStatisticsManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/statistics/JCRStatisticsManager.java 2010-06-15
10:21:46 UTC (rev 2599)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/statistics/JCRStatisticsManager.java 2010-06-15
10:53:03 UTC (rev 2600)
@@ -26,6 +26,7 @@
import org.exoplatform.management.jmx.annotations.Property;
import org.exoplatform.management.rest.annotations.RESTEndpoint;
import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -80,13 +81,13 @@
* Indicates if the persistence of the statistics has to be enabled.
*/
public static final boolean PERSISTENCE_ENABLED =
-
Boolean.valueOf(System.getProperty("JCRStatisticsManager.persistence.enabled",
"true"));
+
Boolean.valueOf(PrivilegedSystemHelper.getProperty("JCRStatisticsManager.persistence.enabled",
"true"));
/**
* The length of time in milliseconds after which the snapshot of the statistics is
persisted.
*/
public static final long PERSISTENCE_TIMEOUT =
-
Long.valueOf(System.getProperty("JCRStatisticsManager.persistence.timeout",
"5000"));
+
Long.valueOf(PrivilegedSystemHelper.getProperty("JCRStatisticsManager.persistence.timeout",
"5000"));
/**
* Default constructor.
@@ -148,8 +149,8 @@
try
{
file =
- new File(System.getProperty("user.dir"), "Statistics" +
category + "-" + System.currentTimeMillis()
- + ".csv");
+ new File(PrivilegedSystemHelper.getProperty("user.dir"),
"Statistics" + category + "-"
+ + System.currentTimeMillis() + ".csv");
file.createNewFile();
pw = new PrintWriter(file);
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceDataContainer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceDataContainer.java 2010-06-15
10:21:46 UTC (rev 2599)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceDataContainer.java 2010-06-15
10:53:03 UTC (rev 2600)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.storage;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedSystemHelper;
+
import java.util.Calendar;
import javax.jcr.RepositoryException;
@@ -45,7 +47,7 @@
public final static int DEF_MAXBUFFERSIZE = 1024 * 200; // 200k
- public final static String DEF_SWAPDIR =
System.getProperty("java.io.tmpdir");
+ public final static String DEF_SWAPDIR =
PrivilegedSystemHelper.getProperty("java.io.tmpdir");
public final static String CHECK_SNS_NEW_CONNECTION =
"check-sns-new-connection";