const std::string Translate(const std::string& key, const std::string& originalText) {
	if ( LoadScriptTranslation() ) {
		std::vector<std::string> tokens;
		IuStringUtils::Split(key, ".", tokens, -1);
		Json::Value root = *translationRoot;
		int count = tokens.size();
		for ( int i = 0; i < count; i++ ) {
			std::string token = tokens[i];
			if ( !root.isMember(token) ) {
				break;
			}
			root = root[token];
			if ( root.type() != Json::objectValue && i+1 != count ) {
				break;
			}
			if ( i+1 == count && root.type() == Json::stringValue  ) {
				return root.asString();
			}
		}
	}

#ifndef IU_CLI
	return IuCoreUtils::WstringToUtf8((LPCTSTR)Lang.GetString(IuCoreUtils::Utf8ToWstring(originalText).c_str()));
#endif
	return originalText;
}
    Json::Value JsonHelper::GetValue( const Json::Value& fromValue, const std::string& path, const Json::Value& defValue )
    {              
        Json::Value node = fromValue;
        int foundPosFirst = 0;
        int foundPosSecond = path.find( "/" );
        bool slashFound = ( foundPosSecond != std::string::npos );
        
        while( slashFound )
        {
            if ( node.type() != Json::objectValue )
            {
                return defValue;
            }
            const std::string& nodeName = path.substr( foundPosFirst, foundPosSecond - foundPosFirst );
            node = node.get( nodeName.c_str(), Json::nullValue );
            foundPosFirst = foundPosSecond + 1;
            foundPosSecond = path.find( "/", foundPosFirst );
            slashFound = ( foundPosSecond != std::string::npos );
        }

        if ( node.type() != Json::objectValue )
        {
            return defValue;
        }
        const std::string& nodeName2 = path.substr( foundPosFirst, path.length() - foundPosFirst );
        node = node.get( nodeName2.c_str(), Json::nullValue );
        if ( node.isNull() )
        {
            return defValue;
        }
        else
        {
            return node;
        }
    };
bool GetValueFromDapiResponse(Json::Value& value, const DAPIResponse& response)
{
	bool bSuccess = true;
	
	// Conditionals to avoid unecessary assert
	if(value.type() == Json::nullValue ||
	   value.type() == Json::arrayValue ||
	   value.type() == Json::objectValue) {
		value.clear();
	}
	
	string valueString;
	DapiMgr::GetStringFromDapiResponse(valueString, response);
	uint64_t length = valueString.length();
	const char* c = valueString.c_str();
	
	if (length != 0)
	{
		Json::Reader reader;
		bool parsingSuccessful = reader.parse(c, c + length, value);
		if (!parsingSuccessful)
		{
			std::cout << "Failed to parse configuration\n" << reader.getFormattedErrorMessages();
			bSuccess = false;
		}
	}
	return bSuccess;
}
Exemple #4
0
int GetJsonInt(const Json::Value& _jsValue)
{
	if ( _jsValue.type() == Json::intValue)
		return _jsValue.asInt();
	else if (_jsValue.type() == Json::stringValue)
		return atoi(_jsValue.asCString());
	else if (_jsValue.isBool())
		return (int)_jsValue.asBool();
	return 0;
}
Exemple #5
0
Json::Value make_rpc_req(Json::Value query, bool logit,unsigned char host,int timeout)
{
	HTTPClient cl;
	cl.rh["Authorization"] = hosts[host].aut;
	cl.rh["Connection"] = "close";
	Json::FastWriter writer;
	cl.pr["_full_post"] = writer.write(query);
	if (logit) {
		FILE *fd = fopen(".rpc.log", "w"); // log only 1 transaction
		if (fd) {
			fprintf(fd, "COMPLETE RPC REQUEST:\n%s\nEND OF REQUEST\n", cl.pr["_full_post"].c_str());
			fclose(fd);
		}
	}
        if(timeout){
                signal(SIGALRM,connect_alarm);
                alarm(timeout);
                cl.request(hosts[host].url,true);
                alarm(0);}
        else{
                cl.request(hosts[host].url,true);}
	if (!cl.isOK()) {
		return Json::Value();
	}
	std::string ans;
	while (cl.peek() != EOF) {
		unsigned to_r = cl.rdbuf()->in_avail();
		if (to_r == 0) break;
		if (to_r > 4000) to_r = 4000;
		char tbuf[to_r+2];
		cl.read(tbuf,to_r);
		ans += std::string(tbuf, to_r);
	}
	if (logit) {
		FILE *fd = fopen(".rpc.log", "a");
		if (fd) {
			fprintf(fd, "COMPLETE RPC ANSWER:\n%s\nEND OF ANSWER\n", ans.c_str());
			fclose(fd);
		}
	}
	cl.disconnect();
	Json::Reader reader;
	Json::Value answ;
	if (!reader.parse(ans, answ)) return false;
	if (answ.type() != Json::objectValue) return false;
	answ = answ["result"];
	if (answ.type() != Json::objectValue) return false;
	return answ;
}
static bool handleNumberOptions(const Json::Value& options, ENumberType& type, std::string& error)
{
    if (options.isNull())
        return true;

    if (!options.isObject()) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: invalid options type: %d",
                options.type());
        error = "Invalid options type!";
        return false;
    }

    Json::Value tv = options["type"];
    if (tv.isNull()) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: No type found!");
        error = "No type found!";
        return false;
    }

    if (!tv.isString()) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: Invalid type type: %d",
                tv.type());
        error = "Invalid type type!";
        return false;
    }

    std::string tstr = tv.asString();
    if (tstr.empty()) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: Empty type!");
        error = "Empty type!";
        return false;
    }

    if (tstr == "currency") {
        type = kNumberCurrency;
    } else if (tstr == "percent") {
        type = kNumberPercent;
    } else if (tstr == "decimal") {
        type = kNumberDecimal;
    } else {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::handleNumberOptions: unsupported type: %s",
                tstr.c_str());
        error = "Unsupported type!";
        return false;
    }

    return true;
}
Exemple #7
0
Matrix4 FileParser::parseTransformation(const Json::Value& transformNode) const {
  Matrix4 matrix = identity();
  if (transformNode.type() != Json::arrayValue) {
    throw RenderException("transform node must be array");
  }
  for (unsigned int i = 0; i < transformNode.size(); i++) {
    if (transformNode[i]["scale"] != Json::nullValue) {
      Json::Value node = transformNode[i]["scale"];
      matrix = scale(node[(Json::Value::UInt)0].asDouble(),
        node[1].asDouble(), node[2].asDouble()) * matrix;
    } else if (transformNode[i]["rotateX"] != Json::nullValue) {
      matrix = rotate(X, deg2rad(parseDouble(transformNode[i]["rotateX"], "rotateX"))) * matrix;
    } else if (transformNode[i]["rotateY"] != Json::nullValue) {
      matrix = rotate(Y, deg2rad(parseDouble(transformNode[i]["rotateY"], "rotateY"))) * matrix;
    } else if (transformNode[i]["rotateZ"] != Json::nullValue) {
      matrix = rotate(Z, deg2rad(parseDouble(transformNode[i]["rotateZ"], "rotateZ"))) * matrix;
    } else if (transformNode[i]["translate"] != Json::nullValue) {
      Json::Value node = transformNode[i]["translate"];
      matrix = translate(node[(Json::Value::UInt)0].asDouble(), node[1].asDouble(), node[2].asDouble()) * matrix;
    } else {
      throw RenderException("unrecognized scene transformation");
    }
  }
  return matrix;
}
Exemple #8
0
/**
 * \brief Fetch the list of upcoming recordings
 */
int GetUpcomingRecordings(Json::Value& response)
{
    int retval = -1;

    XBMC->Log(LOG_DEBUG, "GetUpcomingRecordings");

    // http://madcat:49943/ArgusTV/Control/UpcomingRecordings/7?includeCancelled=true
    retval = ArgusTVJSONRPC("ArgusTV/Control/UpcomingRecordings/7?includeActive=true", "", response);

    if(retval >= 0)
    {
        if( response.type() == Json::arrayValue)
        {
            int size = response.size();
            return size;
        }
        else
        {
            XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
            return -1;
        }
    }
    else
    {
        XBMC->Log(LOG_DEBUG, "GetUpcomingRecordings failed. Return value: %i\n", retval);
    }

    return retval;
}
Exemple #9
0
/**
 * \brief Get the upcoming recordings for a given schedule
 */
int GetUpcomingRecordingsForSchedule(const std::string& scheduleid, Json::Value& response)
{
    int retval = -1;

    XBMC->Log(LOG_DEBUG, "GetUpcomingRecordingsForSchedule");

    char command[256];
    snprintf(command, 256, "ArgusTV/Control/UpcomingRecordingsForSchedule/%s?includeCancelled=true" , scheduleid.c_str());

    retval = ArgusTVJSONRPC(command, "", response);

    if (retval < 0)
    {
        XBMC->Log(LOG_DEBUG, "GetUpcomingRecordingsForSchedule failed. Return value: %i\n", retval);
    }
    else
    {
        if( response.type() == Json::arrayValue)
        {
            int size = response.size();
            return size;
        }
        else
        {
            XBMC->Log(LOG_DEBUG, "Unknown response format %d. Expected Json::arrayValue\n", response.type());
            return -1;
        }
    }

    return retval;
}
Exemple #10
0
void Object::set (std::string const& k, Json::Value const& v)
{
    auto t = v.type();
    switch (t)
    {
    case Json::nullValue:
        return set (k, nullptr);
    case Json::intValue:
        return set (k, v.asInt());
    case Json::uintValue:
        return set (k, v.asUInt());
    case Json::realValue:
        return set (k, v.asDouble());
    case Json::stringValue:
        return set (k, v.asString());
    case Json::booleanValue:
        return set (k, v.asBool());

    case Json::objectValue:
    {
        auto object = setObject (k);
        copyFrom (object, v);
        return;
    }

    case Json::arrayValue:
    {
        auto array = setArray (k);
        for (auto& item: v)
            array.append (item);
        return;
    }
    }
    assert (false);  // Can't get here.
}
Exemple #11
0
/** Set the ordered list of properties by a json value collection
 *
 *  @param jsonValue :: The jsonValue of property values
 *  @param ignoreProperties :: A set of names of any properties NOT to set
 *      from the propertiesArray
 *  @param targetPropertyManager :: the propertymanager to make the changes to,
 *      most of the time this will be *this
 */
void PropertyManager::setProperties(
    const ::Json::Value &jsonValue, IPropertyManager *targetPropertyManager,
    const std::set<std::string> &ignoreProperties) {
  if (jsonValue.type() == ::Json::ValueType::objectValue) {

    // Some algorithms require Filename to be set first do that here
    const std::string propFilename = "Filename";
    ::Json::Value filenameValue = jsonValue[propFilename];
    if (!filenameValue.isNull()) {
      const std::string value = jsonValue[propFilename].asString();
      // Set it
      targetPropertyManager->setPropertyValue(propFilename, value);
    }

    for (::Json::ArrayIndex i = 0; i < jsonValue.size(); i++) {
      const std::string propName = jsonValue.getMemberNames()[i];
      if ((propFilename != propName) &&
          (ignoreProperties.find(propName) == ignoreProperties.end())) {
        ::Json::Value propValue = jsonValue[propName];
        const std::string value = propValue.asString();
        // Set it
        targetPropertyManager->setPropertyValue(propName, value);
      }
    }
  }
}
Exemple #12
0
  /*
   * \brief Retrieve the TV channels that are in the guide
   */
  int RequestGuideChannelList()
  {
    Json::Value root;
    int retval = E_FAILED;

    retval = ForTheRecordJSONRPC("ForTheRecord/Guide/Channels/Television", "", root);

    if(retval >= 0)
    {
      if( root.type() == Json::arrayValue)
      {
        int size = root.size();

        // parse channel list
        for ( int index =0; index < size; ++index )
        {
          std::string name = root[index]["Name"].asString();
          XBMC->Log(LOG_DEBUG, "Found channel %i: %s\n", index, name.c_str());
        }
        return size;
      }
      else
      {
        XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
        return -1;
      }
    }
    else
    {
      XBMC->Log(LOG_DEBUG, "RequestChannelList failed. Return value: %i\n", retval);
    }

    return retval;
  }
Exemple #13
0
  /*
   * \brief Get the list with channels for the given channel group from 4TR
   * \param channelGroupId GUID of the channel group
   */
  int RequestChannelGroupMembers(const std::string& channelGroupId, Json::Value& response)
  {
    int retval = -1;

    std::string command = "ForTheRecord/Scheduler/ChannelsInGroup/" + channelGroupId;
    retval = ForTheRecordJSONRPC(command, "", response);

    if(retval >= 0)
    {
      if( response.type() == Json::arrayValue)
      {
        int size = response.size();
        return size;
      }
      else
      {
        XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
        return -1;
      }
    }
    else
    {
      XBMC->Log(LOG_ERROR, "RequestChannelGroupMembers failed. Return value: %i\n", retval);
    }
        
    return retval;
  }
Exemple #14
0
  int GetRecordingsForTitleUsingURL(const std::string& title, Json::Value& response)
  {
    int retval = E_FAILED;
    XBMC->Log(LOG_DEBUG, "GetRecordingsForTitleUsingURL");
    CURL *curl;

    curl = curl_easy_init();

    if(curl)
    {
      std::string command = "ForTheRecord/Control/RecordingsForProgramTitle/Television/";
      char* pch = curl_easy_escape(curl, title.c_str(), 0);
      command += pch;
      curl_free(pch);

      retval = ForTheRecord::ForTheRecordJSONRPC(command, "?includeNonExisting=false", response);
      if(retval >= 0)
      {           
        if (response.type() != Json::arrayValue)
        {
          retval = E_FAILED;
          XBMC->Log(LOG_NOTICE, "GetRecordingsForTitleUsingURL did not return a Json::arrayValue [%d].", response.type());
        }
      }
      else
      {
        XBMC->Log(LOG_NOTICE, "GetRecordingsForTitleUsingURL remote call failed.");
      }

      curl_easy_cleanup(curl);
    }
    return retval;
  }
Exemple #15
0
  /**
   * \brief Get the upcoming programs for a given schedule
   */
  int GetUpcomingProgramsForSchedule(const Json::Value& schedule, Json::Value& response)
  {
    int retval = -1;

    XBMC->Log(LOG_DEBUG, "GetUpcomingProgramsForSchedule");

    char arguments[1024];
    Json::FastWriter writer;
    snprintf( arguments, sizeof(arguments), "{\"IncludeCancelled\":true,\"Schedule\":%s}", writer.write(schedule).c_str());

    retval = ForTheRecordJSONRPC("ForTheRecord/Scheduler/UpcomingProgramsForSchedule", arguments, response);

    if(retval >= 0)
    {
      if( response.type() == Json::arrayValue)
      {
        int size = response.size();
        return size;
      }
      else
      {
        XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
        return -1;
      }
    }
    else
    {
      XBMC->Log(LOG_DEBUG, "GetUpcomingProgramsForSchedule failed. Return value: %i\n", retval);
    }

    return retval;
  }
Exemple #16
0
  /**
   * \brief Fetch the list of schedules for tv or radio
   * \param channeltype  The type of channel to fetch the list for
   */
  int GetScheduleList(enum ChannelType channelType, Json::Value& response)
  {
    int retval = -1;

    XBMC->Log(LOG_DEBUG, "GetScheduleList");

    // http://madcat:49943/ForTheRecord/Scheduler/Schedules/0/82
    char command[256];
    
    //Format: ForTheRecord/Guide/Programs/{guideChannelId}/{lowerTime}/{upperTime}
    snprintf(command, 256, "ForTheRecord/Scheduler/Schedules/%i/%i" ,
      channelType, Recording );
    retval = ForTheRecordJSONRPC(command, "", response);

    if(retval >= 0)
    {
      if( response.type() == Json::arrayValue)
      {
        int size = response.size();
        return size;
      }
      else
      {
        XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
        return -1;
      }
    }
    else
    {
      XBMC->Log(LOG_DEBUG, "GetScheduleList failed. Return value: %i\n", retval);
    }

    return retval;
  }
Exemple #17
0
  /**
   * \brief Fetch the list of upcoming programs
   */
  int GetUpcomingPrograms(Json::Value& response)
  {
    int retval = -1;

    XBMC->Log(LOG_DEBUG, "GetUpcomingPrograms");

    // http://madcat:49943/ForTheRecord/Scheduler/UpcomingPrograms/82?includeCancelled=true
    retval = ForTheRecordJSONRPC("ForTheRecord/Scheduler/UpcomingPrograms/82?includeCancelled=false", "", response);

    if(retval >= 0)
    {
      if( response.type() == Json::arrayValue)
      {
        int size = response.size();
        return size;
      }
      else
      {
        XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
        return -1;
      }
    }
    else
    {
      XBMC->Log(LOG_DEBUG, "GetUpcomingPrograms failed. Return value: %i\n", retval);
    }

    return retval;
  }
Exemple #18
0
  int GetScheduleById(const std::string& id, Json::Value& response)
  {
    int retval = E_FAILED;
    CURL *curl;

    XBMC->Log(LOG_DEBUG, "GetScheduleById");

    curl = curl_easy_init();

    if(curl)
    {
      std::string command = "ForTheRecord/Scheduler/ScheduleById/" + id;

      retval = ForTheRecord::ForTheRecordJSONRPC(command, "", response);
      if(retval >= 0)
      {           
        if (response.type() != Json::objectValue)
        {
          retval = E_FAILED;
          XBMC->Log(LOG_NOTICE, "GetScheduleById did not return a Json::objectValue [%d].", response.type());
        }
      }
      else
      {
        XBMC->Log(LOG_NOTICE, "GetScheduleById remote call failed.");
      }

      curl_easy_cleanup(curl);
    }
    return retval;
  }
Exemple #19
0
	AST(Json::Value& expr, Table *t) {
		op = VAL;
		val = Val();

		switch(expr.type()) {
			case Json::arrayValue: {
				string call = expr[0].asString();
				if (call == "get") {
					path p;
					for(u32 i=1; i<expr.size(); ++i)
						p.push_back( expr[i].asString() );

					forn = t->findColumn(p);
					if (forn.size() == 1) {
						op = GET;
						get = forn.front();
					} else if (forn.size() != 0) {
						op = FORN;
						for(auto &c: forn)
							if(c->type == Type::MFORN)
								op = MFORN;
					}
				} else {
					if (!determineFunc(call))
						throw UnknownOperationE(call);
					for(u32 i=1; i<expr.size(); ++i)
						params.push_back(AST(expr[i], t));
				}
			} break;
			case Json::objectValue:
				throw HashExpressionE();
			break; default:
				val = Val(expr);
		}
	}
Exemple #20
0
		AnyValue JsonSerializer::toAny(const Json::Value & val)
		{
			std::vector<AnyValue> arr;
			Bundle b;
			switch (val.type())
			{
			case Json::ValueType::arrayValue:
				for (auto e : val) arr.push_back(this->toAny(e));
				return arr;
			case Json::ValueType::booleanValue:
				return val.asBool();
			case Json::ValueType::intValue:
				return (int64_t)val.asInt64();
			case Json::ValueType::nullValue:
				return nullptr;
			case Json::ValueType::objectValue:
				for (Json::ValueConstIterator it = val.begin(); it != val.end(); it++)
				{
					std::string name = it.name();
					b.set(name, this->toAny(*it));
				}
				return b;
			case Json::ValueType::realValue:
				return val.asDouble();
			case Json::ValueType::stringValue:
				return val.asString();
			case Json::ValueType::uintValue:
				return (uint64_t)val.asUInt64();
			}
			return AnyValue();
		}
Exemple #21
0
	Value convert_json(const Json::Value &val)
	{
		using namespace Json;
		switch (val.type())
		{
		case nullValue:
			return Nil;
		case intValue:
			return value(val.asInt64());
		case uintValue:
			return value((int64_t)val.asUInt64());
		case realValue:
			return value(val.asDouble());
		case stringValue:
			return value(val.asString());
		case booleanValue:
			return bvalue(val.asBool());
		case arrayValue:
			return convert_json_array(val);
		case objectValue:
			return convert_json_complex(val);
		default:
			throw loader_error("Invalid value encountered while parsing json");
		}
	}
jsontype_t          SpecificationParser::toJsonType             (Json::Value &val)
{
    jsontype_t result;
    switch(val.type())
    {
        case Json::uintValue:
        case Json::intValue:
            result =  JSON_INTEGER;
            break;
        case Json::realValue:
            result = JSON_REAL;
            break;
        case Json::stringValue:
            result = JSON_STRING;
            break;
        case Json::booleanValue:
            result = JSON_BOOLEAN;
            break;
        case Json::arrayValue:
            result = JSON_ARRAY;
            break;
        case Json::objectValue:
            result = JSON_OBJECT;
            break;
        default:
            throw JsonRpcException(Errors::ERROR_SERVER_PROCEDURE_SPECIFICATION_SYNTAX,"Unknown parameter type: "
                                   + val.toStyledString());
    }
    return result;
}
Exemple #23
0
  /*
   * \brief Get the list with channels from 4TR
   * \param channelType The channel type (Television or Radio)
   */
  int GetChannelList(enum ChannelType channelType, Json::Value& response)
  {
    int retval = -1;

    if (channelType == Television)
    {
      retval = ForTheRecordJSONRPC("ForTheRecord/Scheduler/Channels/Television", "?visibleOnly=false", response);
    }
    else if (channelType == Radio)
    {
      retval = ForTheRecordJSONRPC("ForTheRecord/Scheduler/Channels/Radio", "?visibleOnly=false", response);        
    }

    if(retval >= 0)
    {           
      if( response.type() == Json::arrayValue)
      {
        int size = response.size();
        return size;
      }
      else
      {
        XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
        return -1;
      }
    }
    else
    {
      XBMC->Log(LOG_DEBUG, "RequestChannelList failed. Return value: %i\n", retval);
    }

    return retval;
  }
Exemple #24
0
    /**
   * \brief Fetch the list of currently active recordings
   */
  int GetActiveRecordings(Json::Value& response)
  {
    int retval = -1;

    XBMC->Log(LOG_DEBUG, "GetActiveRecordings");

    retval = ForTheRecordJSONRPC("ForTheRecord/Control/ActiveRecordings", "", response);

    if(retval >= 0)
    {           
      if( response.type() == Json::arrayValue)
      {
        int size = response.size();
        return size;
      }
      else
      {
        XBMC->Log(LOG_DEBUG, "Unknown response format. Expected Json::arrayValue\n");
        return -1;
      }
    }
    else
    {
      XBMC->Log(LOG_DEBUG, "GetActiveRecordings failed. Return value: %i\n", retval);
    }

    return retval;
  }
Exemple #25
0
//////////////////////////////////////////////////////////////////////////
// addAllPackageCrossRefs
void CsPackageImporter::addAllPackageCrossRefs( Json::Value& Root )
{
	std::lock_guard< std::recursive_mutex > Lock( BuildingLock_ );
	BcAssert( BuildingBeginCount_ > 0 );

	// If it's a string value, attempt to match it.
	if( Root.type() == Json::stringValue )
	{
		std::cmatch Match;
		std::regex_match( Root.asCString(), Match, GRegex_ResourceReference );
		
		// Try the weak match.
		// TODO: Merge into  regex.
		if( Match.size() == 0 )
		{
			std::regex_match( Root.asCString(), Match, GRegex_WeakResourceReference );
		}

		if( Match.size() == 4 )
		{
			BcU32 RefIndex = addPackageCrossRef( Root.asCString() );

			// If we find it, replace string reference with a cross ref index.
			if( RefIndex != BcErrorCode )
			{
				PSY_LOG("Adding crossref %u: %s\n", RefIndex, Root.asCString() );
				Root = Json::Value( RefIndex );
			}
		}
	}
	else if( Root.type() == Json::arrayValue )
	{
		for( BcU32 Idx = 0; Idx < Root.size(); ++Idx )
		{
			addAllPackageCrossRefs( Root[ Idx ] );
		}
	}
	else if( Root.type() == Json::objectValue )
	{
		Json::Value::Members MemberValues = Root.getMemberNames();

		for( BcU32 Idx = 0; Idx < MemberValues.size(); ++Idx )
		{
			addAllPackageCrossRefs( Root[ MemberValues[ Idx ] ] );
		}
	}
}
Exemple #26
0
static void
printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." )
{
   switch ( value.type() )
   {
   case Json::nullValue:
      fprintf( fout, "%s=null\n", path.c_str() );
      break;
   case Json::intValue:
      fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestInt() ).c_str() );
      break;
   case Json::uintValue:
      fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestUInt() ).c_str() );
      break;
   case Json::realValue:
       fprintf( fout, "%s=%s\n", path.c_str(), normalizeFloatingPointStr(value.asDouble()).c_str() );
      break;
   case Json::stringValue:
      fprintf( fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str() );
      break;
   case Json::booleanValue:
      fprintf( fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false" );
      break;
   case Json::arrayValue:
      {
         fprintf( fout, "%s=[]\n", path.c_str() );
         int size = value.size();
         for ( int index =0; index < size; ++index )
         {
            static char buffer[16];
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
            sprintf_s( buffer, sizeof(buffer), "[%d]", index );
#else
            snprintf( buffer, sizeof(buffer), "[%d]", index );
#endif
            printValueTree( fout, value[index], path + buffer );
         }
      }
      break;
   case Json::objectValue:
      {
         fprintf( fout, "%s={}\n", path.c_str() );
         Json::Value::Members members( value.getMemberNames() );
         std::sort( members.begin(), members.end() );
         std::string suffix = *(path.end()-1) == '.' ? "" : ".";
         for ( Json::Value::Members::iterator it = members.begin(); 
               it != members.end(); 
               ++it )
         {
            const std::string &name = *it;
            printValueTree( fout, value[name], path + suffix + name );
         }
      }
      break;
   default:
      break;
   }
}
std::string GlobalizationNDK::stringToDate(const std::string& args)
{
    if (args.empty())
        return errorInJson(PARSING_ERROR, "No dateString provided!");

    Json::Reader reader;
    Json::Value root;
    bool parse = reader.parse(args, root);

    if (!parse) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: invalid json data: %s",
                args.c_str());
        return errorInJson(PARSING_ERROR, "Parameters not valid json format!");
    }

    Json::Value dateString = root["dateString"];
    if (!dateString.isString()) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: invalid dateString type: %d",
                dateString.type());
        return errorInJson(PARSING_ERROR, "dateString not a string!");
    }

    std::string dateValue = dateString.asString();
    if (dateValue.empty()) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: empty dateString.");
        return errorInJson(PARSING_ERROR, "dateString is empty!");
    }

    Json::Value options = root["options"];

    DateFormat::EStyle dstyle, tstyle;
    std::string error;
    if (!handleDateOptions(options, dstyle, tstyle, error))
        return errorInJson(PARSING_ERROR, error);

    const Locale& loc = Locale::getDefault();
    DateFormat* df = DateFormat::createDateTimeInstance(dstyle, tstyle, loc);

    if (!df) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: unable to create DateFormat instance!");
        return errorInJson(UNKNOWN_ERROR, "Unable to create DateFormat instance!");
    }
    std::auto_ptr<DateFormat> deleter(df);

    UnicodeString uDate = UnicodeString::fromUTF8(dateValue);
    UErrorCode status = U_ZERO_ERROR;
    UDate date = df->parse(uDate, status);

    // Note: not sure why U_ERROR_WARNING_START is returned when parse succeeded.
    if (status != U_ZERO_ERROR && status != U_ERROR_WARNING_START) {
        slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::stringToDate: DataFormat::parse error: %d: %s",
                status, dateValue.c_str());
        return errorInJson(PARSING_ERROR, "Failed to parse dateString!");
    }

    return resultDateInJson(date);
}
Exemple #28
0
bool JSON_Type2Type(const Json::Value &subNode, int &value)
{
	if (Json::intValue == subNode.type())
	{
		value = subNode.asInt();
		return true;
	}
	ASSERT_C(false);
	return false;
}
Exemple #29
0
unique_ptr<Surface> FileParser::buildCSGChild(const Json::Value& node,
                                              const string& name,
                                              const unordered_map<string, shared_ptr<Material>>& materials,
                                              const unordered_map<string, SurfaceStruct>& structMap) const {
  if (node.type() == Json::stringValue) {
    return buildSurface(parseString(node, "csg surface element " + name), structMap, materials);
  } else {
    return buildCSG(node, name, materials, structMap);
  }
}
Exemple #30
0
bool JSON_Type2Type(const Json::Value &subNode, std::string &value)
{
	if (Json::stringValue == subNode.type())
	{
		value = subNode.asString();
		return true;
	}
	ASSERT_C(false);
	return false;
}