summaryrefslogtreecommitdiff
path: root/subversion/bindings/javahl/native/Path.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'subversion/bindings/javahl/native/Path.cpp')
-rw-r--r--subversion/bindings/javahl/native/Path.cpp81
1 files changed, 56 insertions, 25 deletions
diff --git a/subversion/bindings/javahl/native/Path.cpp b/subversion/bindings/javahl/native/Path.cpp
index b9c69ea..c1a1fec 100644
--- a/subversion/bindings/javahl/native/Path.cpp
+++ b/subversion/bindings/javahl/native/Path.cpp
@@ -27,18 +27,24 @@
#include <jni.h>
#include "Path.h"
#include "svn_path.h"
+#include "svn_dirent_uri.h"
#include "JNIUtil.h"
+#include "JNIStringHolder.h"
#include "Pool.h"
+#include "svn_private_config.h"
/**
* Constructor
*
- * @see Path::Path(const std::string &)
+ * @see PathBase::PathBase(const std::string &)
* @param path Path string
*/
-Path::Path(const char *pi_path, SVN::Pool &in_pool)
+PathBase::PathBase(const char *pi_path,
+ svn_error_t* initfunc(const char*&, SVN::Pool&),
+ SVN::Pool &in_pool)
+ : m_error_occurred(NULL)
{
- init(pi_path, in_pool);
+ init(pi_path, initfunc, in_pool);
}
/**
@@ -48,19 +54,26 @@ Path::Path(const char *pi_path, SVN::Pool &in_pool)
*
* @param path Path string
*/
-Path::Path(const std::string &pi_path, SVN::Pool &in_pool)
+PathBase::PathBase(const std::string &pi_path,
+ svn_error_t* initfunc(const char*&, SVN::Pool&),
+ SVN::Pool &in_pool)
+ : m_error_occurred(NULL)
{
- init(pi_path.c_str(), in_pool);
+ init(pi_path.c_str(), initfunc, in_pool);
}
/**
- * Copy constructor
- *
- * @param path Path to be copied
+ * Constructor from a Java string.
*/
-Path::Path(const Path &pi_path, SVN::Pool &in_pool)
+PathBase::PathBase(jstring jpath,
+ svn_error_t* initfunc(const char*&, SVN::Pool&),
+ SVN::Pool &in_pool)
+ : m_error_occurred(NULL)
{
- init(pi_path.c_str(), in_pool);
+ JNIStringHolder path(jpath);
+ if (JNIUtil::isJavaExceptionThrown())
+ return;
+ init(path, initfunc, in_pool);
}
/**
@@ -69,17 +82,13 @@ Path::Path(const Path &pi_path, SVN::Pool &in_pool)
* @param path Path string
*/
void
-Path::init(const char *pi_path, SVN::Pool &in_pool)
+PathBase::init(const char *pi_path,
+ svn_error_t* initfunc(const char*&, SVN::Pool&),
+ SVN::Pool &in_pool)
{
- if (*pi_path == 0)
- {
- m_error_occurred = NULL;
- m_path = "";
- }
- else
+ if (pi_path && *pi_path)
{
- m_error_occurred = JNIUtil::preprocessPath(pi_path, in_pool.getPool());
-
+ m_error_occurred = initfunc(pi_path, in_pool);
m_path = pi_path;
}
}
@@ -88,7 +97,7 @@ Path::init(const char *pi_path, SVN::Pool &in_pool)
* @return Path string
*/
const std::string &
-Path::path() const
+PathBase::path() const
{
return m_path;
}
@@ -97,7 +106,7 @@ Path::path() const
* @return Path string as a C string
*/
const char *
-Path::c_str() const
+PathBase::c_str() const
{
return m_path.c_str();
}
@@ -105,8 +114,8 @@ Path::c_str() const
/**
* Assignment operator
*/
-Path&
-Path::operator=(const Path &pi_path)
+PathBase&
+PathBase::operator=(const PathBase &pi_path)
{
m_error_occurred = NULL;
m_path = pi_path.m_path;
@@ -114,12 +123,12 @@ Path::operator=(const Path &pi_path)
return *this;
}
- svn_error_t *Path::error_occurred() const
+svn_error_t *PathBase::error_occurred() const
{
return m_error_occurred;
}
-jboolean Path::isValid(const char *p)
+jboolean PathBase::isValid(const char *p)
{
if (p == NULL)
return JNI_FALSE;
@@ -136,3 +145,25 @@ jboolean Path::isValid(const char *p)
return JNI_FALSE;
}
}
+
+svn_error_t*
+Path::initfunc(const char*& path, SVN::Pool& pool)
+{
+ return JNIUtil::preprocessPath(path, pool.getPool());
+}
+
+svn_error_t*
+URL::initfunc(const char*& path, SVN::Pool& pool)
+{
+ if (svn_path_is_url(path))
+ return JNIUtil::preprocessPath(path, pool.getPool());
+ return svn_error_createf(SVN_ERR_BAD_URL, NULL,
+ _("Not an URL: %s"), path);
+}
+
+svn_error_t*
+Relpath::initfunc(const char*& path, SVN::Pool& pool)
+{
+ path = svn_relpath__internal_style(path, pool.getPool());
+ return SVN_NO_ERROR;
+}