/**
 * Returns the value of a config file key.
 *
 * @param env		    Java environment
 * @param self		    class calling this function
 * @param section		the config file section
 * @param key			the config file key
 *
 * @return the key value, or null if the key doesn't exist
 */
jstring JNICALL ScriptMethodsSystemNamespace::getConfigSetting(JNIEnv * env, jobject self,
	jstring section, jstring key)
{
	UNREF(self);

	if (section == 0 || key == 0)
		return 0;

	JavaStringParam jsection(section);
	JavaStringParam jkey(key);

	std::string sectionName;
	if (!JavaLibrary::convert(jsection, sectionName))
		return 0;

	std::string keyName;
	if (!JavaLibrary::convert(jkey, keyName))
		return 0;

	const ConfigFile::Section * sec = ConfigFile::getSection(sectionName.c_str());
	if (sec == NULL)
		return 0;

	const ConfigFile::Key * ky = sec->findKey(keyName.c_str());
	if (ky == NULL)
		return NULL;

	JavaString jvalue(ky->getAsString(ky->getCount()-1, ""));
	return jvalue.getReturnValue();
}	// JavaLibrary::getConfigSetting
예제 #2
0
ZConstString Settings::string(ZConstString key, Settings::Locker_t& lk) const
{
  (void)lk;
  auto jp = jvalue(key, lk);
  bool ok = nullptr != jp && jp->isString();
  const char* b = 0, *e = 0;
  assert(ok);
  if (ok)
    {
      jp->getString(&b, &e);
    }
  return ZConstString(b, e);
}
void getMap(jobject jobj, const std::function<void(jobject, jobject)> &cb) {
  const Context::Handle ctx = Context::getContext();
  LocalRef<jclass> clazz(ctx->env()->GetObjectClass(jobj));
  const jmethodID entrySetId =
      ctx->env()->GetMethodID(clazz.get(), "entrySet", "()Ljava/util/Set;");
  LocalRef<jobject> entrySet(ctx->env()->CallObjectMethod(jobj, entrySetId));
  LocalRef<jclass> mapEntryClass(ctx->env()->FindClass("java/util/Map$Entry"));
  const jmethodID getKeyId = ctx->env()->GetMethodID(
      mapEntryClass.get(), "getKey", "()Ljava/lang/Object;");
  const jmethodID getValueId = ctx->env()->GetMethodID(
      mapEntryClass.get(), "getValue", "()Ljava/lang/Object;");
  ctx->throwIfOccured();
  getIterable(entrySet.get(), [&ctx, &cb, getKeyId, getValueId](jobject jobj) {
    LocalRef<jobject> jkey(ctx->env()->CallObjectMethod(jobj, getKeyId));
    LocalRef<jobject> jvalue(ctx->env()->CallObjectMethod(jobj, getValueId));
    cb(jkey.get(), jvalue.get());
  });
}