3
* ====================================================================
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
20
* ====================================================================
23
* @file PropertyTable.cpp
24
* @brief Implementation of the class PropertyTable
27
#include "PropertyTable.h"
29
#include "JNIStringHolder.h"
30
#include "JNIByteArray.h"
32
#include <apr_tables.h>
33
#include <apr_strings.h>
36
#include "svn_props.h"
39
PropertyTable::~PropertyTable()
41
if (m_revpropTable != NULL)
42
JNIUtil::getEnv()->DeleteLocalRef(m_revpropTable);
45
apr_hash_t *PropertyTable::hash(const SVN::Pool &pool)
47
if (!m_revpropTable && !m_empty_if_null)
50
apr_hash_t *revprop_table = apr_hash_make(pool.getPool());
52
std::map<std::string, std::string>::const_iterator it;
53
for (it = m_revprops.begin(); it != m_revprops.end(); ++it)
55
const char *propname = apr_pstrdup(pool.getPool(), it->first.c_str());
56
if (!svn_prop_name_is_valid(propname))
58
const char *msg = apr_psprintf(pool.getPool(),
59
"Invalid property name: '%s'",
61
JNIUtil::throwNativeException(JAVAHL_CLASS("/ClientException"), msg,
62
NULL, SVN_ERR_CLIENT_PROPERTY_NAME);
66
svn_string_t *propval = svn_string_ncreate(it->second.c_str(),
70
apr_hash_set(revprop_table, propname, APR_HASH_KEY_STRING, propval);
76
PropertyTable::PropertyTable(jobject jrevpropTable, bool bytearray_values,
78
: m_revpropTable(jrevpropTable),
79
m_empty_if_null(empty_if_null)
81
m_revpropTable = jrevpropTable;
83
if (jrevpropTable != NULL)
85
static jmethodID keySet = 0, get = 0;
86
JNIEnv *env = JNIUtil::getEnv();
88
jclass mapClazz = env->FindClass("java/util/Map");
92
keySet = env->GetMethodID(mapClazz, "keySet",
94
if (JNIUtil::isExceptionThrown())
98
jobject jkeySet = env->CallObjectMethod(jrevpropTable, keySet);
99
if (JNIUtil::isExceptionThrown())
104
get = env->GetMethodID(mapClazz, "get",
105
"(Ljava/lang/Object;)Ljava/lang/Object;");
106
if (JNIUtil::isExceptionThrown())
110
Array keyArray(jkeySet);
111
std::vector<jobject> keys = keyArray.vector();
113
for (std::vector<jobject>::const_iterator it = keys.begin();
114
it < keys.end(); ++it)
116
JNIStringHolder propname((jstring)*it);
117
if (JNIUtil::isExceptionThrown())
120
jobject jpropval = env->CallObjectMethod(jrevpropTable, get, *it);
121
if (JNIUtil::isExceptionThrown())
125
if (bytearray_values)
127
JNIByteArray propval((jbyteArray)jpropval);
128
if (JNIUtil::isExceptionThrown())
130
if (!propval.isNull())
132
reinterpret_cast<const char*>(propval.getBytes()),
133
propval.getLength());
137
JNIStringHolder propval((jstring)jpropval);
138
if (JNIUtil::isExceptionThrown())
140
if (NULL != static_cast<const char *>(propval))
141
pv = static_cast<const char *>(propval);
144
m_revprops[std::string(static_cast<const char *>(propname))] = pv;
146
JNIUtil::getEnv()->DeleteLocalRef(jpropval);
149
JNIUtil::getEnv()->DeleteLocalRef(jkeySet);