-
Notifications
You must be signed in to change notification settings - Fork 1
/
linkparser.cpp
117 lines (101 loc) · 1.95 KB
/
linkparser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "linkparser.h"
TLinkTagHandler::TLinkTagHandler()
{
m_Parser = NULL;
}
TLinkTagHandler::TLinkTagHandler(TLinkParser *p)
{
m_Parser = p;
}
wxString TLinkTagHandler::GetSupportedTags()
{
return "A";
}
bool TLinkTagHandler::HandleTag(const wxHtmlTag& tag)
{
if (tag.HasParam( wxT("HREF") ))
{
wxString href(tag.GetParam( wxT("HREF") ));
m_Parser->AddString(href);
ParseInner(tag);
return true;
}
else
return false;
}
///////////////////////////////////////
TImageTagHandler::TImageTagHandler()
{
m_Parser = NULL;
}
TImageTagHandler::TImageTagHandler(TLinkParser *p)
{
m_Parser = p;
}
wxString TImageTagHandler::GetSupportedTags()
{
return "IMG";
}
bool TImageTagHandler::HandleTag(const wxHtmlTag& tag)
{
if (tag.HasParam( wxT("SRC") ))
{
wxString href(tag.GetParam( wxT("SRC") ));
m_Parser->AddString(href);
ParseInner(tag);
return true;
}
else
return false;
}
///////////////////////////////////////////////////////////////////////////////
TLinkParser::TLinkParser(const wxString& url, htmlParserOption option)
:m_src(url)
{
bool ImgOk = true;
bool PageOk = true ;
if (option == ParseBoth)
{
ImgOk = true;
PageOk = true ;
}
if (option == ParseOnlyImages)
{
ImgOk = true;
PageOk = false ;
}
if (option == ParseOnlyPages)
{
ImgOk = false;
PageOk = true ;
}
if (PageOk == true)
AddTagHandler( new TLinkTagHandler(this) );
if (ImgOk == true)
AddTagHandler( new TImageTagHandler(this) );
}
void TLinkParser::AddString(wxString txt)
{
stringArray.Add(txt);
}
void TLinkParser::AddText(const wxChar* txt)
{
}
TStringList TLinkParser::GetLinks(wxString hostUrl)
{
Parse(m_src);
wxString newItem,hostStr;
//hostStr = ;
TStringList resultArrayString;
for (int i =0 ; i < stringArray.GetCount(); i++)
{
newItem = stringArray.Item(i);
resultArrayString.Add(newItem);
}
return resultArrayString;
}
TStringList TLinkParser::GetLinks(void)
{
Parse(m_src);
return stringArray;
}