summaryrefslogtreecommitdiffstats
path: root/klinkstatus/src/parser/node_impl.h
blob: 6001bef19289a24d38e9b314a0ff651e828bd91b (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/***************************************************************************
 *   Copyright (C) 2004 by Paulo Moura Guedes                              *
 *   [email protected]                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

inline Node::Node()
        : is_redirection_(false), malformed_(false)
{}

inline Node::~Node()
{
    //kdDebug(23100) <<  "/";
}

inline Node::Node(TQString const& content)
        : content_(content), is_redirection_(false), malformed_(false)
{}

inline void Node::setNode(TQString const& content)
{
    content_ = content;
    parse();
}

inline TQString const& Node::content() const
{
    return content_;
}

inline bool Node::malformed() const
{
    return malformed_;
}

inline void Node::setMalformed(bool flag)
{
    malformed_ = flag;
}

inline Node::LinkType Node::linkType() const
{
    return linktype_;
}

inline Node::Element Node::element() const
{
    return element_;
}

inline void Node::setLinkType(Node::LinkType const& lt)
{
    linktype_ = lt;
}

inline bool Node::isRedirection() const
{
    return is_redirection_;
}

// class NodeLink_______________________________________________________

inline NodeLink::NodeLink()
        : Node()
{}

inline NodeLink::NodeLink(TQString const& content)
        : Node(content)
{
    parse();
}

inline void NodeLink::parse()
{
    parseAttributeHREF();
}

inline TQString const& NodeLink::url() const
{
    return attribute_href_;
}

inline TQString const& NodeLink::linkLabel() const
{
    return link_label_;
}

inline TQString NodeLink::mailto() const
{
    Q_ASSERT(linktype_ == Node::mailto);

    TQString href = KCharsets::resolveEntities(attribute_href_);

    int inicio = findWord(href, "MAILTO:");
    Q_ASSERT(inicio != -1);

    return href.mid(inicio);
}

inline bool NodeLink::isLink() const
{
    if(Node::linkType() != Node::mailto && !url().isEmpty())
        return true;
    else
        return false;
}

// class NodeA_______________________________________________________

inline NodeA::NodeA(TQString const& content)
        : NodeLink(content)
{
    element_ = A;
    parse();
}

inline TQString const& NodeA::attributeNAME() const
{
    return attribute_name_;
}

inline void NodeA::parse()
{
    parseAttributeNAME();
}

inline void NodeA::parseAttributeNAME()
{
    attribute_name_ = getAttribute("NAME=");
    //kdDebug(23100) << "NodeA::parseAttributeNAME: " << attribute_name_ << endl;
}

// class NodeAREA_______________________________________________________
        
inline NodeAREA::NodeAREA(TQString const& content)
    : NodeLink(content)
{
    element_ = AREA;
    parse();
}
            
inline TQString const& NodeAREA::attributeTITLE() const
{
    return attribute_title_;
}
                
inline void NodeAREA::parse()
{
    parseAttributeTITLE();
}
                    
inline void NodeAREA::parseAttributeTITLE()
{
    attribute_title_ = getAttribute("TITLE=");
//kdDebug(23100) << "NodeAREA::parseAttributeTITLE: " << attribute_title_ << endl;
}

// class NodeLINK________________________________________

inline NodeLINK::NodeLINK(TQString const& content)
        : NodeLink(content)
{
    element_ = LINK;
}

// class NodeMeta________________________________________

inline NodeMETA::NodeMETA()
    : Node()
{
    element_ = META;
}

inline NodeMETA::NodeMETA(TQString const& content)
        : Node(content)
{
    element_ = META;
    parse();
}

inline TQString const& NodeMETA::url() const
{
    return attribute_url_;
}

inline const TQString& NodeMETA::linkLabel() const
{
    return link_label_;
}

inline bool NodeMETA::isLink() const
{
    if(upperCase(attribute_http_equiv_) == "REFRESH" &&
            findWord(content(), "URL") != -1)
    {
        // Q_ASSERT(findWord(content(), "URL") != -1); // not necessarily
        return true;
    }
    else
        return false;
}

inline TQString const& NodeMETA::atributoHTTP_EQUIV() const
{
    return attribute_http_equiv_;
}

inline TQString const& NodeMETA::atributoNAME() const
{
    return attribute_name_;
}

inline TQString const& NodeMETA::atributoCONTENT() const
{
    return attribute_content_;
}

inline bool NodeMETA::isRedirection() const
{
    return
        upperCase(attribute_http_equiv_) == "REFRESH";
}

inline void NodeMETA::parse()
{
    parseAttributeHTTP_EQUIV();
    parseAttributeNAME();
    parseAttributeCONTENT();

    parseAttributeURL();
}

inline void NodeMETA::parseAttributeHTTP_EQUIV()
{
    attribute_http_equiv_ = getAttribute("HTTP-EQUIV=");
}

inline void NodeMETA::parseAttributeNAME()
{
    attribute_name_ = getAttribute("NAME=");
}

inline void NodeMETA::parseAttributeCONTENT()
{
    attribute_content_ = getAttribute("CONTENT=");
//     kdDebug(23100) << "CONTENT: " << attribute_content_ << endl;
}


// class NodeIMG________________________________________

inline NodeIMG::NodeIMG(TQString const& content)
        : Node(content)
{
    element_ = IMG;
    parse();
}

inline void NodeIMG::parse()
{
    parseAttributeSRC();
    parseAttributeTITLE();
    parseAttributeALT();
}

inline TQString const& NodeIMG::url() const
{
    return attribute_src_;
}

inline TQString const& NodeIMG::linkLabel() const
{
    if(!attribute_title_.isEmpty())
        return attribute_title_;
    else
        return attribute_alt_;
}

inline bool NodeIMG::isLink() const
{
    if(!url().isEmpty())
        return true;
    else
        return false;
}

inline void NodeIMG::parseAttributeTITLE()
{
    attribute_title_ = getAttribute("TITLE=");
}

inline void NodeIMG::parseAttributeALT()
{
    attribute_alt_ = getAttribute("ALT=");
}


// class NodeFRAME________________________________________

inline NodeFRAME::NodeFRAME(TQString const& content)
        : Node(content)
{
    element_ = FRAME;
    parse();
}

inline void NodeFRAME::parse()
{
    parseAttributeSRC();
}

inline TQString const& NodeFRAME::url() const
{
    return attribute_src_;
}

inline TQString const& NodeFRAME::linkLabel() const
{
    return link_label_;
}

inline bool NodeFRAME::isLink() const
{
    if(!url().isEmpty())
        return true;
    else
        return false;
}

// class NodeBASE________________________________________

inline NodeBASE::NodeBASE()
        : NodeLink()
{
    element_ = BASE;
}

inline NodeBASE::NodeBASE(TQString const& content)
        : NodeLink(content)
{
    element_ = BASE;
}

inline bool NodeBASE::isLink() const
{
    return false;
}

// class NodeTITLE________________________________________

inline NodeTITLE::NodeTITLE()
        : Node()
{
    element_ = TITLE;
    parse();
}

inline NodeTITLE::NodeTITLE(TQString const& content)
        : Node(content)
{
    element_ = TITLE;
    parse();
}

inline TQString const& NodeTITLE::url() const
{
    return TQString();
}

inline TQString const& NodeTITLE::linkLabel() const
{
    return TQString();
}

inline void NodeTITLE::parse()
{
    parseAttributeTITLE();
}

inline bool NodeTITLE::isLink() const
{
    return false;   
}

inline TQString const& NodeTITLE::attributeTITLE() const
{
    return attribute_title_;   
}

inline void NodeTITLE::parseAttributeTITLE()
{
    attribute_title_ = content_;
    attribute_title_.replace("<TITLE>", "", false);
    attribute_title_.replace("</TITLE>", "", false);
    attribute_title_.stripWhiteSpace();
    
    //kdDebug(23100) << "TITLE: " << attribute_title_ << endl;
}