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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
/**
* This file is part of the DOM implementation for KDE.
*
* Copyright (C) 2000 Peter Kelly (pmk@post.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "dom/dom_exception.h"
#include "xml/dom_xmlimpl.h"
#include "xml/dom_docimpl.h"
#include "xml/dom_stringimpl.h"
#include "css/css_stylesheetimpl.h"
#include "misc/loader.h"
using namespace DOM;
EntityImpl::EntityImpl(DocumentImpl *doc) : NodeBaseImpl(doc)
{
m_publicId = 0;
m_systemId = 0;
m_notationName = 0;
m_name = 0;
}
EntityImpl::EntityImpl(DocumentImpl *doc, DOMString _name) : NodeBaseImpl(doc)
{
m_publicId = 0;
m_systemId = 0;
m_notationName = 0;
m_name = _name.implementation();
if (m_name)
m_name->ref();
}
EntityImpl::EntityImpl(DocumentImpl *doc, DOMString _publicId, DOMString _systemId, DOMString _notationName) : NodeBaseImpl(doc)
{
m_publicId = _publicId.implementation();
if (m_publicId)
m_publicId->ref();
m_systemId = _systemId.implementation();
if (m_systemId)
m_systemId->ref();
m_notationName = _notationName.implementation();
if (m_notationName)
m_notationName->ref();
m_name = 0;
}
EntityImpl::~EntityImpl()
{
if (m_publicId)
m_publicId->deref();
if (m_systemId)
m_systemId->deref();
if (m_notationName)
m_notationName->deref();
if (m_name)
m_name->deref();
}
DOMString EntityImpl::publicId() const
{
return m_publicId;
}
DOMString EntityImpl::systemId() const
{
return m_systemId;
}
DOMString EntityImpl::notationName() const
{
return m_notationName;
}
DOMString EntityImpl::nodeName() const
{
return m_name;
}
unsigned short EntityImpl::nodeType() const
{
return Node::ENTITY_NODE;
}
NodeImpl *EntityImpl::cloneNode ( bool /*deep*/)
{
// Spec says cloning Document nodes is "implementation dependent"
// so we do not support it...
return 0;
}
// DOM Section 1.1.1
bool EntityImpl::childTypeAllowed( unsigned short type )
{
switch (type) {
case Node::ELEMENT_NODE:
case Node::PROCESSING_INSTRUCTION_NODE:
case Node::COMMENT_NODE:
case Node::TEXT_NODE:
case Node::CDATA_SECTION_NODE:
case Node::ENTITY_REFERENCE_NODE:
return true;
break;
default:
return false;
}
}
DOMString EntityImpl::toString() const
{
DOMString result = "<!ENTITY' ";
if (m_name && m_name->l != 0) {
result += " ";
result += m_name;
}
if (m_publicId && m_publicId->l != 0) {
result += " PUBLIC \"";
result += m_publicId;
result += "\" \"";
result += m_systemId;
result += "\"";
} else if (m_systemId && m_systemId->l != 0) {
result += " SYSTEM \"";
result += m_systemId;
result += "\"";
}
if (m_notationName && m_notationName->l != 0) {
result += " NDATA ";
result += m_notationName;
}
result += ">";
return result;
}
// -------------------------------------------------------------------------
EntityReferenceImpl::EntityReferenceImpl(DocumentImpl *doc) : NodeBaseImpl(doc)
{
m_entityName = 0;
}
EntityReferenceImpl::EntityReferenceImpl(DocumentImpl *doc, DOMStringImpl *_entityName) : NodeBaseImpl(doc)
{
m_entityName = _entityName;
if (m_entityName)
m_entityName->ref();
}
EntityReferenceImpl::~EntityReferenceImpl()
{
if (m_entityName)
m_entityName->deref();
}
DOMString EntityReferenceImpl::nodeName() const
{
return m_entityName;
}
unsigned short EntityReferenceImpl::nodeType() const
{
return Node::ENTITY_REFERENCE_NODE;
}
NodeImpl *EntityReferenceImpl::cloneNode ( bool deep )
{
EntityReferenceImpl *clone = new EntityReferenceImpl(docPtr(),m_entityName);
// ### make sure children are readonly
// ### since we are a reference, should we clone children anyway (even if not deep?)
if (deep)
cloneChildNodes(clone);
return clone;
}
// DOM Section 1.1.1
bool EntityReferenceImpl::childTypeAllowed( unsigned short type )
{
switch (type) {
case Node::ELEMENT_NODE:
case Node::PROCESSING_INSTRUCTION_NODE:
case Node::COMMENT_NODE:
case Node::TEXT_NODE:
case Node::CDATA_SECTION_NODE:
case Node::ENTITY_REFERENCE_NODE:
return true;
break;
default:
return false;
}
}
DOMString EntityReferenceImpl::toString() const
{
DOMString result = "&";
result += m_entityName;
result += ";";
return result;
}
// -------------------------------------------------------------------------
NotationImpl::NotationImpl(DocumentImpl *doc) : NodeBaseImpl(doc)
{
m_publicId = 0;
m_systemId = 0;
m_name = 0;
}
NotationImpl::NotationImpl(DocumentImpl *doc, DOMString _name, DOMString _publicId, DOMString _systemId) : NodeBaseImpl(doc)
{
m_name = _name.implementation();
if (m_name)
m_name->ref();
m_publicId = _publicId.implementation();
if (m_publicId)
m_publicId->ref();
m_systemId = _systemId.implementation();
if (m_systemId)
m_systemId->ref();
}
NotationImpl::~NotationImpl()
{
if (m_name)
m_name->deref();
if (m_publicId)
m_publicId->deref();
if (m_systemId)
m_systemId->deref();
}
DOMString NotationImpl::publicId() const
{
return m_publicId;
}
DOMString NotationImpl::systemId() const
{
return m_systemId;
}
DOMString NotationImpl::nodeName() const
{
return m_name;
}
unsigned short NotationImpl::nodeType() const
{
return Node::NOTATION_NODE;
}
NodeImpl *NotationImpl::cloneNode ( bool /*deep*/)
{
// Spec says cloning Document nodes is "implementation dependent"
// so we do not support it...
return 0;
}
// DOM Section 1.1.1
bool NotationImpl::childTypeAllowed( unsigned short /*type*/ )
{
return false;
}
// -------------------------------------------------------------------------
// ### need a way of updating these properly whenever child nodes of the processing instruction
// change or are added/removed
ProcessingInstructionImpl::ProcessingInstructionImpl(DocumentImpl *doc) : NodeBaseImpl(doc)
{
m_target = 0;
m_data = 0;
m_localHref = 0;
m_sheet = 0;
m_cachedSheet = 0;
}
ProcessingInstructionImpl::ProcessingInstructionImpl(DocumentImpl *doc, DOMString _target, DOMString _data) : NodeBaseImpl(doc)
{
m_target = _target.implementation();
if (m_target)
m_target->ref();
m_data = _data.implementation();
if (m_data)
m_data->ref();
m_sheet = 0;
m_cachedSheet = 0;
m_localHref = 0;
}
ProcessingInstructionImpl::~ProcessingInstructionImpl()
{
if (m_target)
m_target->deref();
if (m_data)
m_data->deref();
if (m_cachedSheet)
m_cachedSheet->deref(this);
if (m_sheet)
m_sheet->deref();
}
DOMString ProcessingInstructionImpl::target() const
{
return m_target;
}
void ProcessingInstructionImpl::setData( const DOMString &_data, int &exceptioncode )
{
// NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
if (isReadOnly()) {
exceptioncode = DOMException::NO_MODIFICATION_ALLOWED_ERR;
return;
}
if (m_data)
m_data->deref();
m_data = _data.implementation();
if (m_data)
m_data->ref();
}
DOMString ProcessingInstructionImpl::nodeName() const
{
return m_target;
}
unsigned short ProcessingInstructionImpl::nodeType() const
{
return Node::PROCESSING_INSTRUCTION_NODE;
}
DOMString ProcessingInstructionImpl::nodeValue() const
{
return m_data;
}
void ProcessingInstructionImpl::setNodeValue( const DOMString &_nodeValue, int &exceptioncode )
{
// NO_MODIFICATION_ALLOWED_ERR: taken care of by setData()
setData(_nodeValue, exceptioncode);
}
NodeImpl *ProcessingInstructionImpl::cloneNode ( bool /*deep*/)
{
// ### copy m_localHref
return new ProcessingInstructionImpl(docPtr(),m_target,m_data);
}
DOMString ProcessingInstructionImpl::localHref() const
{
return m_localHref;
}
// DOM Section 1.1.1
bool ProcessingInstructionImpl::childTypeAllowed( unsigned short /*type*/ )
{
return false;
}
void ProcessingInstructionImpl::checkStyleSheet()
{
if (m_target && DOMString(m_target) == "xml-stylesheet") {
// see http://www.w3.org/TR/xml-stylesheet/
// ### check that this occurs only in the prolog
// ### support stylesheet included in a fragment of this (or another) document
// ### make sure this gets called when adding from javascript
XMLAttributeReader attrReader(DOMString(m_data).string());
bool attrsOk;
QXmlAttributes attrs = attrReader.readAttrs(attrsOk);
if (!attrsOk)
return;
if (attrs.value("type") != "text/css" && !attrs.value("type").isEmpty())
return;
DOMString href = attrs.value("href");
if (href.length()>1)
{
if (href[0]=='#')
{
if (m_localHref)
m_localHref->deref();
m_localHref=href.implementation()->split(1);
if (m_localHref)
m_localHref->ref();
}
else
{
// ### some validation on the URL?
// ### FIXME charset
if (m_cachedSheet) m_cachedSheet->deref(this);
m_cachedSheet = getDocument()->docLoader()->requestStyleSheet(getDocument()->completeURL(href.string()), QString::null);
if (m_cachedSheet) {
getDocument()->addPendingSheet(); //before ref, because during the ref it might load!
m_cachedSheet->ref( this );
}
}
}
}
}
StyleSheetImpl *ProcessingInstructionImpl::sheet() const
{
return m_sheet;
}
void ProcessingInstructionImpl::setStyleSheet(const DOM::DOMString &url, const DOM::DOMString &sheet, const DOM::DOMString &charset)
{
if (m_sheet)
m_sheet->deref();
m_sheet = new CSSStyleSheetImpl(getDocument(), url);
m_sheet->ref();
m_sheet->setCharset(charset);
m_sheet->parseString(sheet);
if (m_cachedSheet)
m_cachedSheet->deref(this);
m_cachedSheet = 0;
getDocument()->styleSheetLoaded();
}
void ProcessingInstructionImpl::setStyleSheet(CSSStyleSheetImpl* sheet)
{
if (m_sheet)
m_sheet->deref();
m_sheet = sheet;
if (m_sheet)
m_sheet->ref();
}
DOMString ProcessingInstructionImpl::toString() const
{
DOMString result = "<?";
result += m_target;
result += " ";
result += m_data;
result += ">";
return result;
}
// -------------------------------------------------------------------------
XMLAttributeReader::XMLAttributeReader(const QString& _attrString)
{
m_attrString = _attrString;
}
XMLAttributeReader::~XMLAttributeReader()
{
}
QXmlAttributes XMLAttributeReader::readAttrs(bool &ok)
{
// parse xml file
QXmlInputSource source;
source.setData("<?xml version=\"1.0\"?><attrs "+m_attrString+" />");
QXmlSimpleReader reader;
reader.setContentHandler( this );
ok = reader.parse( source );
return attrs;
}
bool XMLAttributeReader::startElement(const QString& /*namespaceURI*/, const QString& localName,
const QString& /*qName*/, const QXmlAttributes& atts)
{
if (localName == "attrs") {
attrs = atts;
return true;
}
else
return false; // we shouldn't have any other elements
}
|