コード例 #1
0
void VJSRequireClass::_getCurrentPath (VJSParms_callStaticFunction &ioParms, void *)
{
	VJSGlobalObject	*globalObject	= ioParms.GetContext().GetGlobalObjectPrivateInstance();
	
	xbox_assert(globalObject != NULL);

	XBOX::VFilePath	*path	= (XBOX::VFilePath *) globalObject->GetSpecific(VJSContext::kURLSpecificKey);
	
	xbox_assert(path != NULL);

	XBOX::VFilePath	parent;

	if (!path->GetParent(parent)) {

		ioParms.ReturnString("/");

	} else {

		XBOX::VString	posixPath;

		parent.GetPosixPath(posixPath);

		ioParms.ReturnString(posixPath);

	}
}
コード例 #2
0
void VJSTextStream::_Read (VJSParms_callStaticFunction &ioParms, VJSTextStreamState *inStreamState)
{
	if (inStreamState == NULL)

		XBOX::vThrowError(XBOX::VE_JVSC_INVALID_STATE, L"TextStream.read()");

	else if (ioParms.CountParams() == 1 && ioParms.IsStringParam(1)) {

		XBOX::VString	delimiter;

		if (!ioParms.GetStringParam(1, delimiter) || delimiter.GetLength() > 1)

			XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
			
		else {

			XBOX::VString	result;
			bool			hasBeenFound;

			hasBeenFound = inStreamState->_ReadUntilDelimiter(delimiter, &result);
			inStreamState->fPosition += result.GetLength();
			if (hasBeenFound)

				inStreamState->fPosition++;	// Delimiter is not included.

			ioParms.ReturnString(result);
		
		}

	} else {

		// numberCharacters is the number of actual characters to read, not the number of bytes.
				
		sLONG	numberCharacters;

		numberCharacters = 0;
		if (ioParms.CountParams() >= 1 && (!ioParms.GetLongParam(1, &numberCharacters) || numberCharacters < 0))

			XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_NUMBER, "1");
			
		else {

			XBOX::VString	result;
		
			inStreamState->_ReadCharacters(numberCharacters, &result);
			inStreamState->fPosition += result.GetLength();
			ioParms.ReturnString(result);

		}

	}
}
コード例 #3
0
void VJSStream::_GetString(VJSParms_callStaticFunction& ioParms, VStream* inStream)
{
	VString s;
	VError err = s.ReadFromStream(inStream);
	if (err == VE_OK)
		ioParms.ReturnString(s);
}
コード例 #4
0
ファイル: JsUAG.cpp プロジェクト: StephaneH/core-Components
void VJSDirectory::_getLoginListener(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory)
{
	VError err;
	VString listenerRef;
	inDirectory->GetLoginListener(listenerRef);
	ioParms.ReturnString(listenerRef);
}
コード例 #5
0
void VJSGlobalClass::do_GenerateUUID(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VUUID		theUUID(true);
	VString		uuidStr;
	
	theUUID.GetString(uuidStr);
	ioParms.ReturnString(uuidStr);
}
コード例 #6
0
void VJSLanguageSyntaxTesterResults::_GetResult( VJSParms_callStaticFunction &ioParams, IJSLanguageSyntaxTesterResults *inResults )
{
	if (inResults) {
		sLONG index;
		if (ioParams.GetLongParam( 1, &index )) {
			ioParams.ReturnString( inResults->GetResult( index ) );
		}
	}
}
コード例 #7
0
void VJSGlobalClass::do_dateToIso(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString s;
	VJSValue jsval(ioParms.GetContextRef());
	if (ioParms.CountParams() > 0)
	{
		VTime dd;
		jsval = ioParms.GetParamValue(1);
		jsval.GetTime(dd);
		dd.GetJSONString(s);
	}
	ioParms.ReturnString(s);
}
コード例 #8
0
void VJSGlobalClass::do_XmlToJSON(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString xml;
	VString json, root;
	bool simpleJSON = false;

	ioParms.GetStringParam( 1, xml);
	if ( ioParms.CountParams() >= 2)
	{
		VString s;
		if (ioParms.IsStringParam(2))
		{
			ioParms.GetStringParam(2, s);
			if(s== "json-bag")
			{
				simpleJSON = true;
				root="bag";
				if(ioParms.CountParams() >= 3)
				{
					if (ioParms.IsStringParam(3))
						ioParms.GetStringParam(3, root);
					else
						vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "3");
				}
			}
		}
		else
			vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "2");
	}

	if (simpleJSON)
	{
		XBOX::VValueBag *bag = new XBOX::VValueBag;

		VError err = LoadBagFromXML( xml, root, *bag);
		if(err == VE_OK)
			bag->GetJSONString(json);
		ReleaseRefCountable( &bag); 			
	}
	else
	{
		VString errorMessage; sLONG lineNumber;
		VError err = VXMLJsonUtility::XMLToJson(xml, json, errorMessage, lineNumber);
	}

	ioParms.ReturnString(json);
}
コード例 #9
0
void VJSGlobalClass::do_JSONToXml(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	VString xml;
	VString json, root;
	bool simpleJSON = false;

	ioParms.GetStringParam( 1, json);
	if ( ioParms.CountParams() >= 2)
	{
		VString s;
		if (ioParms.IsStringParam(2))
		{
			ioParms.GetStringParam(2, s);
			if(s== "json-bag")
			{
				simpleJSON = true;
				root="bag";
				if(ioParms.CountParams() >= 3)
				{
					if (ioParms.IsStringParam(3))
						ioParms.GetStringParam(3, root);
					else
						vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "3");
				}
			}
		}
		else
			vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "2");
	}

	if (simpleJSON)
	{
		XBOX::VValueBag *bag = new XBOX::VValueBag;
		bag->FromJSONString(json);
		
		xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
		bag->DumpXML( xml, root, false);
		ReleaseRefCountable( &bag); 			
	}
	else
	{
		VError err = VXMLJsonUtility::JsonToXML(json, xml);
	}

	ioParms.ReturnString(xml);
}
コード例 #10
0
ファイル: JsUAG.cpp プロジェクト: StephaneH/core-Components
void VJSDirectory::_computeHA1(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory)
{
	VString userName, password, realm;
	ioParms.GetStringParam(1, userName);
	ioParms.GetStringParam(2, password);
	ioParms.GetStringParam(3, realm);
	if (realm.IsEmpty())
		realm = "Wakanda";

	CSecurityManager* securityManager = (CSecurityManager*)VComponentManager::RetainUniqueComponent(CSecurityManager::Component_Type);
	if (securityManager != nil)
	{
		VString ha1 = securityManager->ComputeDigestHA1(userName, password, realm);
		securityManager->Release();
		ioParms.ReturnString(ha1);
	}
}
コード例 #11
0
void VJSGlobalClass::do_LoadText(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*)
{
	bool okloaded = false;

	VFile* file = ioParms.RetainFileParam(1);

	if (file != nil)
	{
		if (file->Exists())
		{
			VFileStream inp(file);
			VError err = inp.OpenReading();
			if (err == VE_OK)
			{
				CharSet defaultCharSet = VTC_UTF_8;
				sLONG xcharset = 0;
				if (ioParms.GetLongParam(2, &xcharset) && xcharset != 0)
					defaultCharSet = (CharSet)xcharset;
				inp.GuessCharSetFromLeadingBytes(defaultCharSet );
				inp.SetCarriageReturnMode( eCRM_NATIVE );
				VString s;
				err = inp.GetText(s);
				if (err == VE_OK)
				{
					ioParms.ReturnString(s);
					okloaded = true;
				}
				inp.CloseReading();
			}
			
			
		}
		file->Release();
	}
	else
		vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1");

	if (!okloaded)
		ioParms.ReturnNullValue();

}
コード例 #12
0
void VJSStorageClass::_key (VJSParms_callStaticFunction &ioParms, VJSStorageObject *inStorageObject)
{
	xbox_assert(inStorageObject != NULL);

	sLONG	index;

	if (ioParms.CountParams() && ioParms.IsNumberParam(1) && ioParms.GetLongParam(1, &index)) {

		XBOX::VString	key;

		inStorageObject->GetKeyFromIndex(index, &key);
		if (!key.IsEmpty())

			ioParms.ReturnString(key);

		else

			ioParms.ReturnNullValue();	// Index is out of bound.

	} else

		ioParms.ReturnNullValue();
}