Author: areshetnyak
Date: 2011-01-06 05:24:17 -0500 (Thu, 06 Jan 2011)
New Revision: 3779
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
Log:
EXOJCR-1077 : The problem with portability repository backup created on OS Windows to OS
Linux was fixed.
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2011-01-06
08:37:35 UTC (rev 3778)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2011-01-06
10:24:17 UTC (rev 3779)
@@ -45,7 +45,6 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
-import java.net.URL;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@@ -79,6 +78,8 @@
XMLStreamWriter writer;
+ private RepositoryChainLogPathHelper helper = new RepositoryChainLogPathHelper();
+
public LogWriter(File file) throws FileNotFoundException, XMLStreamException,
FactoryConfigurationError
{
this.logFile = file;
@@ -150,11 +151,8 @@
for (String path : wsLogFilePathList)
{
writer.writeStartElement("url");
- URL urlPath = new URL(resolveFileURL("file:" + path));
- URL urlBackupDir =
- new URL(resolveFileURL("file:" +
PrivilegedFileHelper.getCanonicalPath(config.getBackupDir())));
-
- writer.writeCharacters(urlPath.toString().replace(urlBackupDir.getPath() +
"/", ""));
+ writer.writeCharacters(helper.getRelativePath(path,
PrivilegedFileHelper.getCanonicalPath(config
+ .getBackupDir())));
writer.writeEndElement();
}
@@ -287,6 +285,8 @@
private XMLStreamReader reader;
+ private RepositoryChainLogPathHelper helper = new RepositoryChainLogPathHelper();
+
private String version;
public LogReader(File logFile) throws FileNotFoundException, XMLStreamException,
FactoryConfigurationError
@@ -426,11 +426,8 @@
if (version != null && version.equals(VERSION_LOG_1_1))
{
String path = readContent();
- path = path.replace("file:", "file:" +
PrivilegedFileHelper.getCanonicalPath(config.getBackupDir()) + "/");
-
- URL urlPath = new URL(resolveFileURL(path));
-
- wsBackupInfo.add(urlPath.getFile());
+ wsBackupInfo.add(helper.getPath(path,
PrivilegedFileHelper.getCanonicalPath(config
+ .getBackupDir())));
}
else
{
@@ -542,36 +539,6 @@
}
}
- private 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;
- }
-
protected static Log logger =
ExoLogger.getLogger("exo.jcr.component.ext.BackupChainLog");
/**
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java 2011-01-06
10:24:17 UTC (rev 3779)
@@ -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$
+ */
+public class RepositoryChainLogPathHelper
+{
+
+ public 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 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 String getPath(String relativePath, String backupDirCanonicalPath) throws
MalformedURLException
+ {
+ String path = "file:" + backupDirCanonicalPath + "/" +
relativePath;
+
+ URL urlPath = new URL(resolveFileURL(path));
+
+ return urlPath.getFile();
+ }
+
+ private 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;
+ }
+
+}
Property changes on:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryChainLogPathHelper.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java 2011-01-06
10:24:17 UTC (rev 3779)
@@ -0,0 +1,81 @@
+/*
+ * 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$
+ */
+public class TestRepositoryChainLogPathHelper
+ extends TestCase
+{
+
+ public void testGetRelativePathOSLinux() throws Exception
+ {
+ RepositoryChainLogPathHelper helper = new RepositoryChainLogPathHelper();
+
+ String path =
"/path/to/repository-backup-dir/workspace-backup-dir/workspace-backup-log.xml";
+ String backupDirCanonicalPath = "/path/to/repository-backup-dir";
+
+ String relativePath = helper.getRelativePath(path, backupDirCanonicalPath);
+
+ assertEquals("workspace-backup-dir/workspace-backup-log.xml",
relativePath);
+ }
+
+ public void testGetRelativePathOSWindows() throws Exception
+ {
+ RepositoryChainLogPathHelper helper = new RepositoryChainLogPathHelper();
+
+ 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 = helper.getRelativePath(path, backupDirCanonicalPath);
+
+ assertEquals("workspace-backup-dir/workspace-backup-log.xml",
relativePath);
+ }
+
+ public void testGetPathOSLinux() throws Exception
+ {
+ RepositoryChainLogPathHelper helper = new RepositoryChainLogPathHelper();
+
+ String relativePath = "workspace-backup-dir/workspace-backup-log.xml";
+ String backupDirCanonicalPath = "/path/to/repository-backup-dir";
+
+ String path = helper.getPath(relativePath, backupDirCanonicalPath);
+
+
assertEquals("/path/to/repository-backup-dir/workspace-backup-dir/workspace-backup-log.xml",
path);
+ }
+
+ public void testGetPathOSWindiws() throws Exception
+ {
+ RepositoryChainLogPathHelper helper = new RepositoryChainLogPathHelper();
+
+ String relativePath = "workspace-backup-dir/workspace-backup-log.xml";
+ String backupDirCanonicalPath = "c:\\\\path\\to\\repository-backup-dir";
+
+ String path = helper.getPath(relativePath, backupDirCanonicalPath);
+
+
assertEquals("/c://path/to/repository-backup-dir/workspace-backup-dir/workspace-backup-log.xml",
path);
+ }
+
+}
Property changes on:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRepositoryChainLogPathHelper.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native