Esempio n. 1
0
//============================================================================
//		NFileUtilities::SetFileText : Set a file to text.
//----------------------------------------------------------------------------
NStatus NFileUtilities::SetFileText(const NFile &theFile, const NString &theText, NStringEncoding theEncoding, NStringRendering renderAs)
{


	// Set the file text
	return(SetFileData(theFile, theText.GetData(theEncoding, renderAs)));
}
Esempio n. 2
0
//============================================================================
//		NDataEncoder::B64_Decode : Decode from Base64.
//----------------------------------------------------------------------------
NData NDataEncoder::B64_Decode(const NString &theValue)
{	NData					theData, valueData;
	base64_decodestate		theState;
	char					*dataPtr;
	NIndex					dataSize;



	// Get the state we need
	base64_init_decodestate(&theState);

	valueData = theValue.GetData(kNStringEncodingUTF8);
	
	if (!theData.SetSize(valueData.GetSize()))
		return(theData);



	// Decode the value
	dataPtr  = (char *) theData.GetData();
	dataSize = base64_decode_block((const char *) valueData.GetData(), valueData.GetSize(), dataPtr, &theState);

	theData.SetSize(dataSize);

	return(theData);
}
Esempio n. 3
0
const NString& NStringBundleImpl::GetString(const NString& name)
{
    if(name.GetLength() < 1 || name[0] != _T('@'))
        return NString::EmptyString;

    // Find BundleName and stringId
    int pos = name.IndexOf(_T(':'));
    if(pos <= 1 || pos >= name.GetLength() - 1)
        return NString::EmptyString;

    NString bundleName = name.SubString(1, pos - 1);
    NString stringId = name.SubString(pos + 1);

    // Find if existed
    BundleMap::const_iterator iteBundle = bundleMap_.find(bundleName);
    if(iteBundle != bundleMap_.end())
    {
        // existed
        const StringBundle& stringBundle = iteBundle->second;
        StringBundle::const_iterator iteString = stringBundle.find(stringId);
        if(iteString == stringBundle.end())
            return NString::EmptyString;
        return iteString->second;
    }

    // Load Bundle Data
    NString bundlePath = nui::Util::File::CombinePath(basePath_, bundleName);
    bundlePath += _T(".xml");
    NAutoPtr<NDataReader> reader = CreateDataReader(ReaderXml);
    if(!reader->ParseFile(bundlePath.GetData()))
        return NString::EmptyString;

    StringBundle tmpBundle;
    std::pair<BundleMap::iterator, bool> result = bundleMap_.insert(std::make_pair(bundleName, tmpBundle));
    if(!result.second)
        return NString::EmptyString;

    StringBundle& bundleData = result.first->second;

    NString id;
    NString value;
    bool hasId = false;
    NAutoPtr<NDataReader> node;
    for(int i=0; reader->ReadNode(i, node); ++ i)
    {
        if(node->ReadValue(_T("id"), id)
            && node->ReadValue(_T("value"), value))
        {
            if(id == stringId)
                hasId = true;
            bundleData.insert(std::make_pair(id, value));
        }
    }

    if(hasId)
        return bundleData[stringId];
    return NString::EmptyString;
}
Esempio n. 4
0
//============================================================================
//		TSocketClient::ExecuteWeb : Execute a web client test.
//----------------------------------------------------------------------------
void TSocketClient::ExecuteWeb(bool *isDone, NData *theData)
{	NSocket		*theSocket;
	NString		theText;
	NStatus		theErr;



	// Open the socket
	theSocket = new NSocket(this);
	theSocket->Open("www.google.com", 80);
	
	while (theSocket->GetStatus() != kNSocketOpened)
		NThread::Sleep();



	// Write some data
	theText = "GET / HTTP/1.0\r\n\r\n";
	theErr  = theSocket->WriteData(theText.GetData());
	NN_ASSERT_NOERR(theErr);



	// Read some data
	theErr = theSocket->ReadData(400, *theData);
	NN_ASSERT_NOERR(theErr);



	// Clean up
	theSocket->Close();

	while (theSocket->GetStatus() != kNSocketClosed)
		NThread::Sleep();
	
	delete theSocket;



	// Finish off
	*isDone = true;
}
Esempio n. 5
0
bool NParserImpl::GetStyleParam(LPCTSTR packFilePath, NString& filePath, NString& styleName)
{
    // Normalize path
    LPCTSTR separator = _tcschr(packFilePath, _T(':'));
    if(separator == NULL)
        return false;

    styleName = separator + 1;

    if(packFilePath[0] == _T('@'))
    {
        NString tmpPath;
        tmpPath.Assign(packFilePath, separator - packFilePath);
        filePath.Format(_T("@style:%s.xml"), tmpPath.GetData() + 1);
    }
    else
    {
        filePath.Assign(packFilePath, separator - packFilePath);
    }

    return true;
}
Esempio n. 6
0
NAutoPtr<NBaseObj> NParserImpl::Parse(Ui::NFrame* parentFrame, LPCTSTR packFilePath)
{
    NString filePath;
    NString styleName;

    if(!GetStyleParam(packFilePath, filePath, styleName))
        return NULL;

    // Find Resource
    NInstPtr<NBuffer> buffer(MemToolParam);
    NInstPtr<NFileSystem> fs(MemToolParam);
    if(!fs->LoadFile(filePath.GetData(), buffer))
        return NULL;

    // Load Xml
    NAutoPtr<NDataReader> reader = CreateDataReader(ReaderXml);
    if(!reader->ParseUtf8(static_cast<const char*>(buffer->GetBuffer()), buffer->GetSize()))
        return NULL;

    NAutoPtr<NDataReader> styleNode = FindStyleNode(reader, styleName);

    return ParserUtil::LoadObj(parentFrame, styleNode);
}