Author: areshetnyak
Date: 2011-01-10 07:14:19 -0500 (Mon, 10 Jan 2011)
New Revision: 3784
Added:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
Log:
JCR-1564 : The problem with portability repository backup created on OS Windows to OS
Linux was fixed.
Modified:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2011-01-10
08:30:21 UTC (rev 3783)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2011-01-10
12:14:19 UTC (rev 3784)
@@ -114,8 +114,7 @@
for (String path : wsLogFilePathList)
{
writer.writeStartElement("url");
- writer.writeCharacters(path.replace(config.getBackupDir().getCanonicalPath()
- + File.separator, ""));
+ writer.writeCharacters(RepositoryChainLogPathHelper.getRelativePath(path,
config.getBackupDir().getCanonicalPath()));
writer.writeEndElement();
}
@@ -361,9 +360,8 @@
{
if (version != null && version.equals(VERSION_LOG_1_1))
{
- String path = config.getBackupDir().getCanonicalPath() +
File.separator
- + readContent();
- wsBackupInfo.add(path);
+ String path = readContent();
+ wsBackupInfo.add(RepositoryChainLogPathHelper.getPath(path,
config.getBackupDir().getCanonicalPath()));
}
else
{
Added:
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java
(rev 0)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java 2011-01-10
12:14:19 UTC (rev 3784)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2003-2011 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2011
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id: RepositoryChainLogPathHelper.java 111 2011-11-11 11:11:11Z rainf0x $
+ */
+public class RepositoryChainLogPathHelper
+{
+
+ private RepositoryChainLogPathHelper()
+ {
+ }
+
+ /**
+ * Will be returned relative path <name>/<name>.xml for all OS.
+ *
+ * @param path
+ * String, path to
+ * @param backupDirCanonicalPath
+ * String, path to backup dir
+ * @return String
+ * Will be returned relative path <name>/<name>.xml for all OS
+ * @throws MalformedURLException
+ *
+ */
+ public static String getRelativePath(String path, String backupDirCanonicalPath)
throws MalformedURLException
+ {
+ URL urlPath = new URL(resolveFileURL("file:" + path));
+ URL urlBackupDir = new URL(resolveFileURL("file:" +
backupDirCanonicalPath));
+
+ return urlPath.toString().replace(urlBackupDir.toString() + "/",
"");
+ }
+
+ /**
+ * Will be returned absolute path.
+ *
+ * @param relativePath
+ * String, relative path.
+ * @param backupDirCanonicalPath
+ * String, path to backup dir
+ * @return String
+ * Will be returned absolute path.
+ * @throws MalformedURLException
+ */
+ public static String getPath(String relativePath, String backupDirCanonicalPath)
throws MalformedURLException
+ {
+ String path = "file:" + backupDirCanonicalPath + "/" +
relativePath;
+
+ URL urlPath = new URL(resolveFileURL(path));
+
+ return urlPath.getFile();
+ }
+
+ private static String resolveFileURL(String url)
+ {
+ // we ensure that we don't have windows path separator in the url
+ url = url.replace('\\', '/');
+ if (!url.startsWith("file:///"))
+ {
+ // The url is invalid, so we will fix it
+ // it happens when we use a path of type file://${path}, under
+ // linux or mac os the path will start with a '/' so the url
+ // will be correct but under windows we will have something
+ // like C:\ so the first '/' is missing
+ if (url.startsWith("file://"))
+ {
+ // The url is of type file://, so one '/' is missing
+ url = "file:///" + url.substring(7);
+ }
+ else if (url.startsWith("file:/"))
+ {
+ // The url is of type file:/, so two '/' are missing
+ url = "file:///" + url.substring(6);
+ }
+ else
+ {
+ // The url is of type file:, so three '/' are missing
+ url = "file:///" + url.substring(5);
+ }
+ }
+ return url;
+ }
+
+}
Added:
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java
(rev 0)
+++
jcr/branches/1.12.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java 2011-01-10
12:14:19 UTC (rev 3784)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2003-2011 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup;
+
+import junit.framework.TestCase;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2011
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id: TestRepositoryChainLogPathHelper.java 111 2011-11-11 11:11:11Z rainf0x
$
+ */
+public class TestRepositoryChainLogPathHelper
+ extends TestCase
+{
+
+ public void testGetRelativePathOSLinux() throws Exception
+ {
+ String path =
"/path/to/repository-backup-dir/workspace-backup-dir/workspace-backup-log.xml";
+ String backupDirCanonicalPath = "/path/to/repository-backup-dir";
+
+ String relativePath = RepositoryChainLogPathHelper.getRelativePath(path,
backupDirCanonicalPath);
+
+ assertEquals("workspace-backup-dir/workspace-backup-log.xml",
relativePath);
+ }
+
+ public void testGetRelativePathOSWindows() throws Exception
+ {
+ String path =
"c:\\\\path\\to\\repository-backup-dir\\workspace-backup-dir\\workspace-backup-log.xml";
+ String backupDirCanonicalPath = "c:\\\\path\\to\\repository-backup-dir";
+
+ String relativePath = RepositoryChainLogPathHelper.getRelativePath(path,
backupDirCanonicalPath);
+
+ assertEquals("workspace-backup-dir/workspace-backup-log.xml",
relativePath);
+ }
+
+ public void testGetPathOSLinux() throws Exception
+ {
+ String relativePath = "workspace-backup-dir/workspace-backup-log.xml";
+ String backupDirCanonicalPath = "/path/to/repository-backup-dir";
+
+ String path = RepositoryChainLogPathHelper.getPath(relativePath,
backupDirCanonicalPath);
+
+
assertEquals("/path/to/repository-backup-dir/workspace-backup-dir/workspace-backup-log.xml",
path);
+ }
+
+ public void testGetPathOSWindiws() throws Exception
+ {
+ String relativePath = "workspace-backup-dir/workspace-backup-log.xml";
+ String backupDirCanonicalPath = "c:\\\\path\\to\\repository-backup-dir";
+
+ String path = RepositoryChainLogPathHelper.getPath(relativePath,
backupDirCanonicalPath);
+
+
assertEquals("/c://path/to/repository-backup-dir/workspace-backup-dir/workspace-backup-log.xml",
path);
+ }
+
+}