b311480e |
1 | // Created on: 2001-08-01 |
2 | // Created by: Julia DOROVSKIKH |
973c2be1 |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
16 | //AGV 130202: Changed prototype LDOM_Node::getOwnerDocument() |
7fd59977 |
17 | |
18 | #include <XmlObjMgt.hxx> |
42cf5bc1 |
19 | #include <XmlObjMgt_Array1.hxx> |
3804f298 |
20 | #include <XmlObjMgt_Document.hxx> |
42cf5bc1 |
21 | #include <XmlObjMgt_DOMString.hxx> |
7fd59977 |
22 | |
23 | IMPLEMENT_DOMSTRING (LowerString, "lower") |
24 | IMPLEMENT_DOMSTRING (UpperString, "upper") |
25 | IMPLEMENT_DOMSTRING (IndString, "index") |
26 | |
27 | //======================================================================= |
28 | //function : XmlObjMgt_Array1 |
29 | //purpose : Constructor |
30 | //======================================================================= |
31 | |
32 | XmlObjMgt_Array1::XmlObjMgt_Array1 (const XmlObjMgt_Element& theParent, |
33 | const XmlObjMgt_DOMString& theName) |
34 | : myElement (XmlObjMgt::FindChildByName (theParent, theName)), |
35 | myFirst (1), |
36 | myLast (0) |
37 | { |
38 | if (myElement != NULL) { |
39 | if (!myElement.getAttribute(::LowerString()).GetInteger(myFirst)) |
40 | myFirst = 1; |
41 | if (!myElement.getAttribute(::UpperString()).GetInteger (myLast)) |
42 | myLast = 1; |
43 | } |
44 | } |
45 | |
46 | //======================================================================= |
47 | //function : XmlObjMgt_Array1 |
48 | //purpose : Constructor |
49 | //======================================================================= |
50 | |
51 | XmlObjMgt_Array1::XmlObjMgt_Array1 (const Standard_Integer aFirst, |
52 | const Standard_Integer aLast) |
53 | : myFirst (aFirst), myLast (aLast) |
54 | {} |
55 | |
56 | //======================================================================= |
57 | //function : CreateArrayElement |
58 | //purpose : Create DOM_Element representing the array, under 'theParent' |
59 | //======================================================================= |
60 | |
61 | void XmlObjMgt_Array1::CreateArrayElement (XmlObjMgt_Element& theParent, |
62 | const XmlObjMgt_DOMString& theName) |
63 | { |
64 | if (myLast > 0) |
65 | { |
66 | //AGV XmlObjMgt_Document& anOwnerDoc = |
67 | //AGV (XmlObjMgt_Document&)theParent.getOwnerDocument(); |
68 | XmlObjMgt_Document anOwnerDoc = |
69 | XmlObjMgt_Document (theParent.getOwnerDocument()); |
70 | myElement = anOwnerDoc.createElement (theName); |
71 | theParent.appendChild (myElement); |
72 | if (myLast > 1) { |
73 | myElement.setAttribute (::UpperString(), myLast); |
74 | if (myFirst != 1) |
75 | myElement.setAttribute (::LowerString(), myFirst); |
76 | } |
77 | } |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : SetValue |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | void XmlObjMgt_Array1::SetValue |
86 | (const Standard_Integer theIndex, XmlObjMgt_Element& theValue) |
87 | { |
88 | myElement.appendChild (theValue); |
89 | theValue.setAttribute(::IndString(), theIndex); |
90 | } |
91 | |
92 | //======================================================================= |
93 | //function : Value |
94 | //purpose : |
95 | //======================================================================= |
96 | |
97 | XmlObjMgt_Element XmlObjMgt_Array1::Value(const Standard_Integer theIndex) const |
98 | { |
99 | XmlObjMgt_Element anElem; |
100 | |
101 | if (theIndex >= myFirst && theIndex <= myLast) |
102 | { |
103 | Standard_Integer ind; |
104 | LDOM_Node aNode = myElement.getFirstChild(); |
105 | while (!aNode.isNull()) |
106 | { |
107 | if (aNode.getNodeType() == LDOM_Node::ELEMENT_NODE) |
108 | { |
109 | anElem = (XmlObjMgt_Element &) aNode; |
110 | if (anElem.getAttribute(::IndString()).GetInteger(ind)) |
111 | if (ind == theIndex) |
112 | break; |
113 | } |
114 | aNode = aNode.getNextSibling(); |
115 | } |
116 | } |
117 | return anElem; |
118 | } |