1 /**
2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21 #include "config.h"
22
23 #if ENABLE(WML)
24 #include "WMLSetvarElement.h"
25
26 #include "HTMLNames.h"
27 #include "MappedAttribute.h"
28 #include "WMLErrorHandling.h"
29 #include "WMLTaskElement.h"
30 #include "WMLVariables.h"
31
32 namespace WebCore {
33
WMLSetvarElement(const QualifiedName & tagName,Document * doc)34 WMLSetvarElement::WMLSetvarElement(const QualifiedName& tagName, Document* doc)
35 : WMLElement(tagName, doc)
36 {
37 }
38
~WMLSetvarElement()39 WMLSetvarElement::~WMLSetvarElement()
40 {
41 }
42
parseMappedAttribute(MappedAttribute * attr)43 void WMLSetvarElement::parseMappedAttribute(MappedAttribute* attr)
44 {
45 if (attr->name() == HTMLNames::nameAttr) {
46 if (!isValidVariableName(parseValueSubstitutingVariableReferences(attr->value(), WMLErrorInvalidVariableName))) {
47 reportWMLError(document(), WMLErrorInvalidVariableName);
48 return;
49 }
50 } else
51 WMLElement::parseMappedAttribute(attr);
52 }
53
insertedIntoDocument()54 void WMLSetvarElement::insertedIntoDocument()
55 {
56 WMLElement::insertedIntoDocument();
57
58 Node* parent = parentNode();
59 if (!parent || !parent->isWMLElement())
60 return;
61
62 if (static_cast<WMLElement*>(parent)->isWMLTaskElement())
63 static_cast<WMLTaskElement*>(parent)->registerVariableSetter(this);
64 }
65
removedFromDocument()66 void WMLSetvarElement::removedFromDocument()
67 {
68 Node* parent = parentNode();
69 if (parent && parent->isWMLElement()) {
70 if (static_cast<WMLElement*>(parent)->isWMLTaskElement())
71 static_cast<WMLTaskElement*>(parent)->deregisterVariableSetter(this);
72 }
73
74 WMLElement::removedFromDocument();
75 }
76
name() const77 String WMLSetvarElement::name() const
78 {
79 return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::nameAttr), WMLErrorInvalidVariableName);
80 }
81
value() const82 String WMLSetvarElement::value() const
83 {
84 return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::valueAttr));
85 }
86
87 }
88
89 #endif
90