~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/mxml/element.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2009-04-22 21:39:19 UTC
  • mto: (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090422213919-52m015y6gcpv1m1g
Tags: upstream-0.12.0~svn2018
ImportĀ upstreamĀ versionĀ 0.12.0~svn2018

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
8
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
9
9
    
10
 
    Copyright (C) 2006-2008 Gena Batyan <bgeradz@mediatomb.cc>,
 
10
    Copyright (C) 2006-2009 Gena Batyan <bgeradz@mediatomb.cc>,
11
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
12
12
                            Leonhard Wimmer <leo@mediatomb.cc>
13
13
    
24
24
    version 2 along with MediaTomb; if not, write to the Free Software
25
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
26
26
    
27
 
    $Id: element.cc 1702 2008-02-23 22:00:57Z lww $
 
27
    $Id: element.cc 2010 2009-01-11 19:10:43Z lww $
28
28
*/
29
29
 
30
30
/// \file element.cc
45
45
{
46
46
    type = mxml_node_element;
47
47
    this->name = name;
 
48
    arrayType = false;
 
49
    arrayName = nil;
 
50
    textKey = nil;
48
51
}
49
52
Element::Element(String name, Ref<Context> context) : Node()
50
53
{
51
54
    type = mxml_node_element;
52
55
    this->name = name;
53
56
    this->context = context;
 
57
    arrayType = false;
 
58
    arrayName = nil;
 
59
    textKey = nil;
54
60
}
55
61
String Element::getAttribute(String name)
56
62
{
65
71
    }
66
72
    return nil;
67
73
}
68
 
void Element::addAttribute(String name, String value)
 
74
void Element::addAttribute(String name, String value, enum mxml_value_type type)
69
75
{
70
 
    Ref<Attribute> attr = Ref<Attribute>(new Attribute(name, value));
 
76
    Ref<Attribute> attr = Ref<Attribute>(new Attribute(name, value, type));
71
77
    addAttribute(attr);
72
78
}
73
79
 
78
84
    attributes->append(attr);
79
85
}
80
86
 
81
 
void Element::setAttribute(String name, String value)
 
87
void Element::setAttribute(String name, String value, enum mxml_value_type type)
82
88
{
83
89
    if (attributes == nil)
84
90
        attributes = Ref<Array<Attribute> >(new Array<Attribute>());
89
95
        if(attr->name == name)
90
96
        {
91
97
            attr->setValue(value);
 
98
            attr->setVType(type);
92
99
            return;
93
100
        }
94
101
    }
95
 
    addAttribute(name, value);
 
102
    addAttribute(name, value, type);
96
103
}
97
104
 
98
105
int Element::childCount(enum mxml_node_types type)
292
299
        return nil;
293
300
}
294
301
 
 
302
enum mxml_value_type Element::getVTypeText()
 
303
{
 
304
    Ref<Text> text;
 
305
    int i = 0;
 
306
    bool someText = false;
 
307
    enum mxml_value_type vtype = mxml_string_type;
 
308
    while ((text = RefCast(getChild(i++, mxml_node_text), Text)) != nil)
 
309
    {
 
310
        if (! someText)
 
311
        {
 
312
            someText = true;
 
313
            vtype = text->getVType();
 
314
        }
 
315
        else
 
316
        {
 
317
            if (vtype != text->getVType())
 
318
                vtype = mxml_string_type;
 
319
        }
 
320
    }
 
321
    return vtype;
 
322
}
 
323
 
295
324
int Element::attributeCount()
296
325
{
297
326
    if (attributes == nil)
308
337
    return attributes->get(index);
309
338
}
310
339
 
311
 
void Element::setText(String str)
 
340
void Element::setText(String str, enum mxml_value_type type)
312
341
{
313
342
    if (childCount() > 1)
314
343
        throw _Exception(_("Element::setText() cannot be called on an element which has more than one child"));
323
352
    }
324
353
    else
325
354
    {
326
 
        Ref<Text> text(new Text(str));
 
355
        Ref<Text> text(new Text(str, type));
327
356
        appendChild(RefCast(text, Node));
328
357
    }
329
358
}
330
359
 
331
 
void Element::appendTextChild(String name, String text)
 
360
void Element::appendTextChild(String name, String text, enum mxml_value_type type)
332
361
{
333
362
    Ref<Element> el = Ref<Element>(new Element(name));
334
 
    el->setText(text);
 
363
    el->setText(text, type);
335
364
    appendElementChild(el);
336
365
}
337
366