59 #include <wx/xml/xml.h>
60 #include <wx/wfstream.h>
61 #include <wx/sstream.h>
62 #include <wx/mstream.h>
63 #include <wx/protocol/http.h>
96 return(
Assign(MetaData) );
109 return(
Load(File, Extension) );
122 return(
Load(Stream) );
134 void CSG_MetaData::_On_Construction(
void)
154 delete(m_pChildren[i]);
164 m_Prop_Names .
Clear();
165 m_Prop_Values .
Clear();
206 return(
Ins_Child(MetaData, -1, bAddChildren) );
231 pChildren[i] = pChildren[i - 1];
244 pChild->m_Name = Name;
245 pChild->m_Content = Content;
277 pChild->
Assign(MetaData, bAddChildren);
297 if( from_Index != to_Index )
302 if( from_Index < to_Index )
304 for(
int i=from_Index; i<to_Index; i++)
306 pChildren[i] = pChildren[i + 1];
311 for(
int i=from_Index; i>to_Index; i--)
313 pChildren[i] = pChildren[i - 1];
317 pChildren[to_Index] = pChild;
335 delete(pChildren[Index]);
339 pChildren[i] = pChildren[j];
353 if( &MetaData !=
this )
379 else if( Name && *Name )
418 int CSG_MetaData::_Get_Child(
const CSG_String &Name)
const
439 return( bNoCase ? !m_Name.
CmpNoCase(String) : !m_Name.
Cmp(String) );
498 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
499 va_start(argptr, _Format);
500 s.PrintfV(_Format, argptr);
502 va_start(argptr, Format);
503 s.PrintfV(Format, argptr);
519 wxString _Format(Format); _Format.Replace(
"%s",
"%ls");
520 va_start(argptr, _Format);
521 s.PrintfV(_Format, argptr);
523 va_start(argptr, Format);
524 s.PrintfV(Format, argptr);
535 return( bNoCase ? !m_Content.
CmpNoCase(String) : !m_Content.
Cmp(String) );
546 if( !Value.
is_Empty() &&_Get_Property(Name) < 0 )
548 m_Prop_Names .
Add(Name );
549 m_Prop_Values.
Add(Value);
590 m_Prop_Names .
Del(i);
591 m_Prop_Values.
Del(i);
604 if( (Index = _Get_Property(Name)) >= 0 )
606 m_Prop_Values[Index] = Value;
610 else if( bAddIfNotExists )
612 m_Prop_Names .
Add(Name);
613 m_Prop_Values .
Add(Value);
681 int CSG_MetaData::_Get_Property(
const CSG_String &Name)
const
683 for(
int i=0; i<m_Prop_Names.
Get_Count(); i++)
685 if( Name.
CmpNoCase(m_Prop_Names[i]) == 0 )
715 wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
721 wxStringOutputStream Stream;
725 s = &Stream.GetString();
763 if( &MetaData !=
this )
795 if( File.
Find(
"http://") == 0 )
819 if( XML.Load(_File.
c_str()) )
821 _Load(XML.GetRoot());
839 _Load(XML.GetRoot());
848 void CSG_MetaData::_Load(wxXmlNode *pNode)
850 m_Name = pNode->GetName ().wc_str();
851 m_Content = pNode->GetNodeContent().wc_str();
854 wxXmlAttribute *pProperty = pNode->GetAttributes();
858 Add_Property(&pProperty->GetName(), &pProperty->GetValue());
860 pProperty = pProperty->GetNext();
864 wxXmlNode *pChild = pNode->GetChildren();
868 if( pChild->GetType() != wxXML_TEXT_NODE )
873 pChild = pChild->GetNext();
887 wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
906 wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
921 void CSG_MetaData::_Save(wxXmlNode *pNode)
const
931 wxXmlNode *pChild =
new wxXmlNode(pNode, wxXML_TEXT_NODE,
SG_T(
"TEXT"));
961 wxMemoryInputStream Stream((
const void *)_XML.
b_str(), (
size_t)_XML.
Length());
963 if( XML.Load(Stream) )
965 _Load(XML.GetRoot());
978 wxXmlNode *pRoot =
new wxXmlNode(NULL, wxXML_ELEMENT_NODE,
Get_Name().c_str());
984 wxMemoryOutputStream Stream;
986 if( XML.Save(Stream) )
988 CSG_Array s(
sizeof(
char), Stream.GetSize());
1013 if( Username && *Username ) { HTTP.SetUser (Username); }
1014 if( Password && *Password ) { HTTP.SetPassword(Password); }
1016 wxString s = Server.
c_str();
1018 if( s.Find(
"http://") == 0 )
1020 s = s.Right(s.Length() - wxString(
"http://").Length());
1023 if( !HTTP.Connect(s) )
1036 wxInputStream *pStream = HTTP.GetInputStream(s);
1045 if( XML.Load(*pStream) )
1047 _Load(XML.GetRoot());
1115 for(
bool bQuota=
false;;)
1119 if( !c || c ==
'\n' ) {
break; }
else
1123 Element += c; bQuota = !bQuota;
1125 else if( bQuota || (c !=
' ' && c !=
'\t' && c !=
',') )
1137 else if( Element.
Find(
'[') >= 0 )
1143 else if( Element.
Find(
']') >= 0 )
1150 else if( Element.
Find(
'{') >= 0 )
1163 else if( Element.
Find(
'}') >= 0 )
1175 if( Value.
Find(
'\"') > -1 )
1217 Create(Server, Username, Password);
1227 if( Username && *Username ) {
m_pHTTP->SetUser (Username); }
1228 if( Password && *Password ) {
m_pHTTP->SetPassword(Password); }
1230 wxString Host = Server.
c_str();
1232 unsigned short Port = 80;
1234 #define SERVER_TRIM(s, p) { wxString sp(p); sp += "://"; if( s.Find(p) == 0 ) { s = s.Right(s.Length() - sp.Length()); } }
1239 if( Host.Find(
":") >= 0 )
1243 if( Host.AfterLast(
':').ToLong(&_Port) )
1245 Port = (
unsigned short)_Port;
1248 Host = Host.BeforeLast(
':');
1251 if( !
m_pHTTP->Connect(Host, Port) )
1287 wxInputStream * CSG_HTTP::_Request(
const CSG_String &Request)
1301 wxInputStream *pStream =
m_pHTTP->GetInputStream(s);
1303 if( pStream && !pStream->CanRead() )
1316 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1320 if( !XML.Load(*pStream) )
1327 Answer.
Destroy(); Answer._Load(XML.GetRoot());
1337 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1348 while( pStream->CanRead() )
1352 pStream->Read(&Byte,
sizeof(Byte));
1365 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1376 while( pStream->CanRead() )
1380 pStream->Read(&Byte,
sizeof(Byte));
1393 wxInputStream *pStream = _Request(
Request);
if( !pStream ) {
return(
false ); }
1395 wxFileOutputStream *pFile =
new wxFileOutputStream(File);
1404 pFile->Write(*pStream);
1421 #include <wx/protocol/ftp.h>
1428 if( _Source.
Find(
"ftp://") == 0 )
1440 if( Username && *Username ) { ftp.SetUser (Username); }
1441 if( Password && *Password ) { ftp.SetPassword(Password); }
1443 if( !ftp.Connect(ftpHost.
c_str(), Port) )
1464 if( ftp.GetFileSize(ftpFile.
c_str()) == -1 )
1473 wxInputStream *pStream = ftp.GetInputStream(ftpFile.
c_str());
1486 wxFileOutputStream *pFile =
new wxFileOutputStream(
SG_File_Make_Path(Target_Directory, ftpFile).c_str());
1501 pFile->Write(*pStream);