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.
b_str(), (
size_t)_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 )
1253 Create(Server, Username, Password);
1263 if( Username && *Username ) {
m_pHTTP->SetUser (Username); }
1264 if( Password && *Password ) {
m_pHTTP->SetPassword(Password); }
1266 wxString Host = Server.
c_str();
1268 unsigned short Port = 80;
1270 #define SERVER_TRIM(s, p) { wxString sp(p); sp += "://"; if( s.Find(p) == 0 ) { s = s.Right(s.Length() - sp.Length()); } }
1275 if( Host.Find(
":") >= 0 )
1279 if( Host.AfterLast(
':').ToLong(&_Port) )
1281 Port = (
unsigned short)_Port;
1284 Host = Host.BeforeLast(
':');
1287 if( !
m_pHTTP->Connect(Host, Port) )
1323wxInputStream * CSG_HTTP::_Request(
const CSG_String &Request)
1337 wxInputStream *pStream =
m_pHTTP->GetInputStream(s);
1339 if( pStream && !pStream->CanRead() )
1352 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1356 if( !XML.Load(*pStream) )
1363 Answer.
Destroy(); Answer._Load(XML.GetRoot());
1373 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1384 while( pStream->CanRead() )
1388 pStream->Read(&Byte,
sizeof(Byte));
1401 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1412 while( pStream->CanRead() )
1416 pStream->Read(&Byte,
sizeof(Byte));
1429 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1431 wxFileOutputStream *pFile =
new wxFileOutputStream(File);
1440 pFile->Write(*pStream);
1457#include <wx/protocol/ftp.h>
1464 if( _Source.
Find(
"ftp://") == 0 )
1476 if( Username && *Username ) { ftp.SetUser (Username); }
1477 if( Password && *Password ) { ftp.SetPassword(Password); }
1479 if( !ftp.Connect(ftpHost.
c_str(), Port) )
1500 if( ftp.GetFileSize(ftpFile.
c_str()) == -1 )
1509 wxInputStream *pStream = ftp.GetInputStream(ftpFile.
c_str());
1522 wxFileOutputStream *pFile =
new wxFileOutputStream(
SG_File_Make_Path(Target_Directory, ftpFile).c_str());
1537 pFile->Write(*pStream);
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
const char * b_str(void) 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
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)