Skip to content

Fix bug 5119: the JCR migration doesn't take into account of an external location of the JCR repository #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
*/
package org.silverpeas.migration.jcr.service;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -56,10 +55,8 @@ public class RepositoryManager {

public RepositoryManager() {
try {
String conf = ConfigurationHolder.getHome() + File.separatorChar + "setup"
+ File.separatorChar + "jackrabbit" + File.separatorChar + "repository.xml";
String repositoryHome = ConfigurationHolder.getDataHome() + File.separatorChar
+ "jackrabbit";
String conf = ConfigurationHolder.getJCRRepositoryConfiguration();
String repositoryHome = ConfigurationHolder.getJCRRepositoryHome();
initRepository(repositoryHome, conf);
} catch (RepositoryException ex) {
logger.error("Error during JCR repository initalisation", ex);
@@ -77,6 +74,8 @@ public RepositoryManager(String repositoryHome, String repositoryXml) {
}

private void initRepository(String repositoryHome, String conf) throws RepositoryException {
logger.info("Initialize repository [JCR Home: '" + repositoryHome + "', JCR Configuration: '"
+ conf + "']");
Map<String, String> parameters = new HashMap<String, String>(2);
parameters.put(RepositoryFactoryImpl.REPOSITORY_HOME, repositoryHome);
parameters.put(RepositoryFactoryImpl.REPOSITORY_CONF, conf);
50 changes: 50 additions & 0 deletions src/main/java/org/silverpeas/util/ConfigurationHolder.java
Original file line number Diff line number Diff line change
@@ -22,10 +22,13 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.silverpeas.util.file.FileUtil;

/**
* This class holds all of the settings and parameters for the different applications used in the
@@ -37,7 +40,9 @@ public class ConfigurationHolder {

private static final String SILVERPEAS_HOME_PROP_KEY = "silverpeas.home";
private static final String SILVERPEAS_HOME_ENV_KEY = "SILVERPEAS_HOME";
private static final String JCR_PROPERTIES = "org/silverpeas/util/jcr.properties";
private static final String THREADS_KEY = "threads";
private static final String JCR_HOME_KEY = "jcr.home.dir.url";
private static String silverpeasHome = null;
private static GestionVariables configuration = null;
private static boolean abortOnError = true;
@@ -116,6 +121,51 @@ public static String getDataHome() throws IOException {
return configuration.resolveAndEvalString("${SILVERPEAS_DATA_HOME}");
}

/**
* Gets the home directory of the JCR repository in Silverpeas.
*
* @return the absolute path of the JCR repository home directory.
* @throws IOException if an errors occurs while getting the parameter.
*/
public static String getJCRRepositoryHome() throws IOException {
String repositoryHome = ConfigurationHolder.getDataHome() + File.separatorChar
+ "jackrabbit";
Properties props = FileUtil.loadResource(JCR_PROPERTIES);
repositoryHome = props.getProperty(JCR_HOME_KEY, repositoryHome);
File repositoryHomeDir;
if (repositoryHome.toLowerCase().startsWith("file:")) {
repositoryHomeDir = new File(URI.create(repositoryHome));
} else {
repositoryHomeDir = new File(repositoryHome);
}
if (!repositoryHomeDir.isDirectory()) {
throw new FileNotFoundException("The JCR home directory '" + repositoryHome + "' isn't found");
}
return repositoryHomeDir.getAbsolutePath();
}

/**
* Gets the location of the JCR repository configuration file. Usually this configuration is done
* in an XML file repository.xml.
*
* @return the absolute path of the configuration file of the JCR repository.
* @throws java.io.IOException if an error occurs while getting the configuration file.
*/
public static String getJCRRepositoryConfiguration() throws IOException {
String conf = ConfigurationHolder.getHome() + File.separatorChar + "setup"
+ File.separatorChar + "jackrabbit" + File.separatorChar + "repository.xml";
File confFile;
if (conf.toLowerCase().startsWith("file:")) {
confFile = new File(URI.create(conf));
} else {
confFile = new File(conf);
}
if (!confFile.exists()) {
throw new FileNotFoundException("The JCR Configuration file '" + conf + "' isn't found");
}
return confFile.getAbsolutePath();
}

/**
* Gets the maximum number of threads the executors of parallelized configuration tasks are
* permitted to allocate with their threads pool.
20 changes: 19 additions & 1 deletion src/main/java/org/silverpeas/util/StringUtil.java
Original file line number Diff line number Diff line change
@@ -20,13 +20,31 @@
*/
package org.silverpeas.util;

import java.net.URI;

public class StringUtil {

public static final int RECURSION_THRESHOLD = 10;

/**
* Converts the specified path to an URI.
*
* @param anURI the string representation of an URI to convert.
* @return either the URI form of the specified string or null if the string isn't an URI.
*/
public static URI toURI(String anURI) {
try {
URI uri = URI.create(anURI);
return uri;
} catch (IllegalArgumentException ex) {
return null;
}
}

/**
* Search a string for all instances of a substring and replace it with another string. Amazing
* that this is not a method of java.lang.String since I use it all the time.
*
* @param search Substring to search for
* @param replace String to replace it with
* @param source String to search through
@@ -64,6 +82,7 @@ public static String sReplace(String search, String replace, String source) {
/**
* Match a file glob style expression without ranges. '*' matches zero or more chars. '?' matches
* any single char.
*
* @param pattern A glob-style pattern to match
* @param input The string to match
* @return whether or not the string matches the pattern.
@@ -135,7 +154,6 @@ public static String lookupKeysInString(String str, int recurselvl,

// this is where all those years of c/c++ pay off in java
// boolean foundkey = false;

char[] sb = str.toCharArray();
int len = sb.length;