51#include <wx/xml/xml.h>
52#include <wx/wfstream.h>
53#include <wx/sstream.h>
54#include <wx/mstream.h>
55#include <wx/protocol/http.h>
88 return(
Assign(MetaData) );
101 return(
Load(File, Extension) );
114 return(
Load(Stream) );
126void CSG_MetaData::_On_Construction(
void)
146 delete(m_pChildren[i]);
149 m_Children.Destroy();
156 m_Prop_Names .Clear();
157 m_Prop_Values.Clear();
198 return(
Ins_Child(MetaData, -1, bAddChildren) );
209 if( !m_Children.Inc_Array() )
223 pChildren[i] = pChildren[i - 1];
236 pChild->m_Name = Name;
237 pChild->m_Content = Content;
269 pChild->
Assign(MetaData, bAddChildren);
289 if( from_Index != to_Index )
294 if( from_Index < to_Index )
296 for(
int i=from_Index; i<to_Index; i++)
298 pChildren[i] = pChildren[i + 1];
303 for(
int i=from_Index; i>to_Index; i--)
305 pChildren[i] = pChildren[i - 1];
309 pChildren[to_Index] = pChild;
327 delete(pChildren[Index]);
331 pChildren[i] = pChildren[j];
334 m_Children.Dec_Array();
345 if( Name.
Find(
'.') > 0 )
361 if( &MetaData !=
this )
387 else if( Name && *Name )
419 m_Children.Destroy();
428 if( Name.
Find(
'.') > 0 )
442int CSG_MetaData::_Get_Child(
const CSG_String &Name)
const
463 return( bNoCase ? !m_Name.CmpNoCase(String) : !m_Name.Cmp(String) );
512 wxString s; va_list argptr;
515 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
516 va_start(argptr, _Format);
517 s.PrintfV(_Format, argptr);
519 va_start(argptr, Format);
520 s.PrintfV(Format, argptr);
531 wxString s; va_list argptr;
534 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
535 va_start(argptr, _Format);
536 s.PrintfV(_Format, argptr);
538 va_start(argptr, Format);
539 s.PrintfV(Format, argptr);
550 return( bNoCase ? !m_Content.CmpNoCase(String) : !m_Content.Cmp(String) );
561 if( !Value.
is_Empty() &&_Get_Property(Name) < 0 )
563 m_Prop_Names .Add(Name );
564 m_Prop_Values.Add(Value);
605 m_Prop_Names .Del(i);
606 m_Prop_Values.Del(i);
617 int Index = _Get_Property(Name);
621 m_Prop_Values[Index] = Value;
625 else if( bAddIfNotExists )
627 m_Prop_Names .Add(Name);
628 m_Prop_Values.Add(Value);
679int CSG_MetaData::_Get_Property(
const CSG_String &Name)
const
681 for(
int i=0; i<m_Prop_Names.
Get_Count(); i++)
683 if( Name.
CmpNoCase(m_Prop_Names[i]) == 0 )
711 wxXmlDocument XML; wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
717 wxStringOutputStream Stream;
721 s = &Stream.GetString();
759 if( &MetaData !=
this )
791 if( File.
Find(
"http://") == 0 )
815 if( XML.Load(_File.
c_str()) )
817 _Load(XML.GetRoot());
835 _Load(XML.GetRoot());
844void CSG_MetaData::_Load(wxXmlNode *pNode)
846 m_Name = pNode->GetName ().wc_str();
847 m_Content = pNode->GetNodeContent().wc_str();
850 wxXmlAttribute *pProperty = pNode->GetAttributes();
854 Add_Property(&pProperty->GetName(), &pProperty->GetValue());
856 pProperty = pProperty->GetNext();
860 wxXmlNode *pChild = pNode->GetChildren();
864 if( pChild->GetType() != wxXML_TEXT_NODE )
869 pChild = pChild->GetNext();
881 wxXmlDocument XML; wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
898 wxXmlDocument XML; wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
913void CSG_MetaData::_Save(wxXmlNode *pNode)
const
917 pNode->SetName(Name.
c_str());
923 wxXmlNode *pChild =
new wxXmlNode(pNode, wxXML_TEXT_NODE,
SG_T(
"TEXT"));
951 wxXmlDocument XML; wxMemoryInputStream Stream((
const void *)_XML,
Length);
953#if wxCHECK_VERSION(3, 3, 0)
954 if( XML.Load(Stream) )
956 if( XML.Load(Stream, Encoding) )
959 _Load(XML.GetRoot());
972 wxXmlDocument XML; wxMemoryInputStream Stream((
const void *)_XML.
c_str(),
sizeof(
SG_Char) * _XML.
Length());
974 if( XML.Load(Stream) )
976 _Load(XML.GetRoot());
987 wxXmlDocument XML; wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
993 wxMemoryOutputStream Stream;
995 if( XML.Save(Stream) )
997 CSG_Array s(
sizeof(
char), Stream.GetSize());
1022 if( Username && *Username ) { HTTP.SetUser (Username); }
1023 if( Password && *Password ) { HTTP.SetPassword(Password); }
1025 wxString s = Server.
c_str();
1027 if( s.Find(
"http://") == 0 )
1029 s = s.Right(s.Length() - wxString(
"http://").
Length());
1032 if( !HTTP.Connect(s) )
1045 wxInputStream *pStream = HTTP.GetInputStream(s);
1054 if( XML.Load(*pStream) )
1056 _Load(XML.GetRoot());
1105 for(
bool bQuota=
false; *pc; )
1109 if( c ==
'\0' || c ==
',' )
1113 else if( c ==
'{' || c ==
'[' )
1119 else if( c ==
'}' || c ==
']' )
1132 else if( c ==
'\"' )
1134 Element += c; bQuota = !bQuota;
1136 else if( bQuota || (c !=
' ' && c !=
'\n' && c !=
'\t') )
1147 else if( Element.
Find(
'[') >= 0 )
1153 else if( Element.
Find(
']') >= 0 )
1160 else if( Element.
Find(
'{') >= 0 )
1173 else if( Element.
Find(
'}') >= 0 )
1185 if( val.
Find(
'\"') == 0 )
1252 Create(Server, User, Password);
1259 m_pHTTP =
new wxHTTP;
1261 if( !User .is_Empty() ) { m_pHTTP->SetUser (User .wx_str()); }
1262 if( !Password.
is_Empty() ) { m_pHTTP->SetPassword(Password.
wx_str()); }
1264 wxString Host= Server.
wx_str();
unsigned short Port = 80;
1266 #define SERVER_TRIM(s, p) { wxString sp(p); sp += "://"; if( s.Find(p) == 0 ) { s = s.Right(s.Length() - sp.Length()); } }
1271 if( Host.Find(
":") >= 0 )
1275 if( Host.AfterLast(
':').ToLong(&_Port) )
1277 Port = (
unsigned short)_Port;
1280 Host = Host.BeforeLast(
':');
1283 if( !m_pHTTP->Connect(Host, Port) )
1312wxInputStream * CSG_HTTP::_Request(
const CSG_String &Request)
1316 wxString s(
Request.c_str());
if( s[0] !=
'/' ) { s.Prepend(
"/"); }
1318 wxInputStream *pStream = m_pHTTP->GetInputStream(s);
1322 if( pStream->CanRead() )
1337 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1341 if( !XML.Load(*pStream) )
1348 Answer.
Destroy(); Answer._Load(XML.GetRoot());
1358 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1362 while( pStream->CanRead() )
1364 char Byte; pStream->Read(&Byte,
sizeof(Byte)); Answer += Byte;
1375 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1379 while( pStream->CanRead() )
1381 char Byte; pStream->Read(&Byte,
sizeof(Byte)); Answer += Byte;
1392 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1394 wxFileOutputStream *pFile =
new wxFileOutputStream(File);
1403 pFile->Write(*pStream);
1418#include <wx/protocol/ftp.h>
1425 if( _Source.
Find(
"ftp://") == 0 )
1437 if( !User .is_Empty() ) { ftp.SetUser (User .wx_str()); }
1438 if( !Password.
is_Empty() ) { ftp.SetPassword(Password.
wx_str()); }
1440 if( !ftp.Connect(ftpHost.
c_str(), Port) )
1461 if( ftp.GetFileSize(ftpFile.
c_str()) == -1 )
1470 wxInputStream *pStream = ftp.GetInputStream(ftpFile.
c_str());
1483 wxFileOutputStream *pFile =
new wxFileOutputStream(
SG_File_Make_Path(Target_Directory, ftpFile).c_str());
1498 pFile->Write(*pStream);
1529 Create(Server, User, Password);
1540 wxURI URI; URI.SetUserAndPassword(User.
wx_str(), Password.
wx_str());
1542 m_User = URI.GetUser().wx_str(); m_Password = URI.GetPassword().wx_str();
1551 m_Server.
Clear(); m_User.Clear(), m_Password.Clear();
1562#if !wxCHECK_VERSION(3, 3, 0)
1574#include <wx/webrequest.h>
1579 if( !m_Server.
is_Empty() ) { wxWebSessionSync::GetDefault().SetBaseURL(m_Server.
wx_str()); }
auto request = wxWebSessionSync::GetDefault().CreateRequest(
Request.c_str());
1581 #if wxCHECK_VERSION(3, 3, 2)
1582 if( !m_User.is_Empty() || !m_Password.is_Empty() )
1584 request.UseBasicAuth(wxWebCredentials(m_User.wx_str(), wxSecretValue(m_Password.wx_str())));
1588 if( !request.Execute() ) {
return(
false ); }
1591 wxInputStream *pStream = request.GetResponse().GetStream();
1593 if( pStream->IsOk() )
1595 int Byte = pStream->GetC();
1597 while( Byte != wxEOF )
1599 Answer += (BYTE)Byte;
1601 Byte = pStream->GetC();
1613 if( !m_Server.is_Empty() ) { wxWebSessionSync::GetDefault().SetBaseURL(m_Server.wx_str()); }
auto request = wxWebSessionSync::GetDefault().CreateRequest(
Request.c_str());
1615 #if wxCHECK_VERSION(3, 3, 2)
1616 if( !m_User.is_Empty() || !m_Password.is_Empty() )
1618 request.UseBasicAuth(wxWebCredentials(m_User.wx_str(), wxSecretValue(m_Password.wx_str())));
1622 if( !request.Execute() ) {
return(
false ); }
1627 if( XML.Load(*request.GetResponse().GetStream()) )
1629 Answer._Load(XML.GetRoot());
1642 if( !m_Server.is_Empty() ) { wxWebSessionSync::GetDefault().SetBaseURL(m_Server.wx_str()); }
auto request = wxWebSessionSync::GetDefault().CreateRequest(
Request.c_str());
1644 #if wxCHECK_VERSION(3, 3, 2)
1645 if( !m_User.is_Empty() || !m_Password.is_Empty() )
1647 request.UseBasicAuth(wxWebCredentials(m_User.wx_str(), wxSecretValue(m_Password.wx_str())));
1651 if( !request.Execute() ) {
return(
false ); }
1654 Answer = request.GetResponse().AsString().
wx_str();
1662 if( !m_Server.is_Empty() ) { wxWebSessionSync::GetDefault().SetBaseURL(m_Server.wx_str()); }
auto request = wxWebSessionSync::GetDefault().CreateRequest(
Request.c_str());
1664 #if wxCHECK_VERSION(3, 3, 2)
1665 if( !m_User.is_Empty() || !m_Password.is_Empty() )
1667 request.UseBasicAuth(wxWebCredentials(m_User.wx_str(), wxSecretValue(m_Password.wx_str())));
1671 if( !request.Execute() ) {
return(
false ); }
1674 wxFileOutputStream Output(File);
1678 Output.Write(*request.GetResponse().GetStream());
1694 if( !Server.
is_Empty() ) { wxWebSessionSync::GetDefault().SetBaseURL(Server.
wx_str()); }
auto request = wxWebSessionSync::GetDefault().CreateRequest(
Request.c_str());
if( !request.Execute() ) {
return(
false ); }
1696 wxInputStream *pStream = request.GetResponse().GetStream();
1698 if( pStream->IsOk() )
1700 int Byte = pStream->GetC();
1702 while( Byte != wxEOF )
1704 Answer += (BYTE)Byte;
1706 Byte = pStream->GetC();
1718 if( !Server.
is_Empty() ) { wxWebSessionSync::GetDefault().SetBaseURL(Server.
wx_str()); }
auto request = wxWebSessionSync::GetDefault().CreateRequest(
Request.c_str());
if( !request.Execute() ) {
return(
false ); }
1722 if( XML.Load(*request.GetResponse().GetStream()) )
1724 Answer._Load(XML.GetRoot());
1737 if( !Server.
is_Empty() ) { wxWebSessionSync::GetDefault().SetBaseURL(Server.
wx_str()); }
auto request = wxWebSessionSync::GetDefault().CreateRequest(
Request.c_str());
if( !request.Execute() ) {
return(
false ); }
1739 Answer = request.GetResponse().AsString().
wx_str();
1747 if( !Server.
is_Empty() ) { wxWebSessionSync::GetDefault().SetBaseURL(Server.
wx_str()); }
auto request = wxWebSessionSync::GetDefault().CreateRequest(
Request.c_str());
if( !request.Execute() ) {
return(
false ); }
1749 wxFileOutputStream Output(File);
1753 Output.Write(*request.GetResponse().GetStream());
void SG_UI_Msg_Add_Error(const char *Message)
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
SAGA_API_DLL_EXPORT bool SG_File_Cmp_Extension(const CSG_String &File, const CSG_String &Extension)
SAGA_API_DLL_EXPORT CSG_String SG_File_Make_Path(const CSG_String &Directory, const CSG_String &Name)
SAGA_API_DLL_EXPORT CSG_String SG_Get_String(double Value, int Precision=-99)
void * Get_Array(void) const
sLong Get_Size(void) const
virtual bool Open(const SG_Char *FileName, int Mode=SG_FILE_R, bool bBinary=true, int Encoding=SG_FILE_ENCODING_ANSI)
size_t Read(void *Buffer, size_t Size, size_t Count=1) const
class wxStreamBase * Get_Stream(void) const
bool is_Writing(void) const
bool is_Reading(void) const
bool is_Connected(void) const
bool Request(const CSG_String &Request, CSG_Bytes &Answer)
size_t Length(void) const
CSG_String AfterFirst(char Character) const
int CmpNoCase(const CSG_String &String) const
CSG_String AfterLast(char Character) const
int Cmp(const CSG_String &String) const
CSG_String BeforeFirst(char Character) const
size_t Replace(const CSG_String &Old, const CSG_String &New, bool bReplaceAll=true)
CSG_String BeforeLast(char Character) const
static CSG_String Format(const char *Format,...)
int Trim(bool fromRight=false)
int Find(char Character, bool fromEnd=false) const
CSG_String Right(size_t count) const
const SG_Char * c_str(void) const
bool is_Empty(void) const
const class wxString & wx_str(void) const
double asDouble(void) const
sLong asLongLong(void) const
int Get_Count(void) const
bool Set_Value(int Field, const CSG_String &Value)
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
bool Request(const CSG_String &Request, CSG_Bytes &Bytes)