## Apache Zeta Components Manual :: File Source for xml_internal.php

## Source for file xml_internal.php

Documentation is available at xml_internal.php

1. <?php
2. /**
3. * File containing the ezcTreeXmlInternalDataStore class.
4. *
5. * Licensed to the Apache Software Foundation (ASF) under one
6. * or more contributor license agreements. See the NOTICE file
7. * distributed with this work for additional information
8. * regarding copyright ownership. The ASF licenses this file
9. * to you under the Apache License, Version 2.0 (the
10. * "License"); you may not use this file except in compliance
11. * with the License. You may obtain a copy of the License at
12. *
13. * http://www.apache.org/licenses/LICENSE-2.0
14. *
15. * Unless required by applicable law or agreed to in writing,
16. * software distributed under the License is distributed on an
17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18. * KIND, either express or implied. See the License for the
19. * specific language governing permissions and limitations
20. * under the License.
21. *
22. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
23. * @version //autogentag//
24. * @filesource
25. * @package Tree
26. */
28. /**
29. * ezcTreeXmlInternalDataStore is an implementation of a tree node data store
30. * that stores node information in child elements of the XML elements
31. * containing the tree nodes.
32. *
33. * @package Tree
34. * @version //autogentag//
35. */
36. class ezcTreeXmlInternalDataStore implements ezcTreeXmlDataStore
37. {
38. /**
39. * Contains the DOM representing this tree this data store stores data for.
40. *
41. * @var DOMDocument
42. */
43. protected $dom ;
45. /**
46. * Associates the DOM tree for which this data store stores data for with
47. * this store.
48. *
49. * @param DOMDocument $dom
50. */
51. public function setDomTree ( DOMDocument $dom )
52. {
53. $this-> dom = $dom;
54. }
56. /**
57. * Deletes the data for the node $node from the data store.
58. *
59. * @param ezcTreeNode $node
60. public function deleteDataForNode( ezcTreeNode $node )
61. {
62. }
63. */
65. /**
66. * Deletes the data for all the nodes in the node list $nodeList.
67. *
68. * @param ezcTreeNodeList $nodeList
69. */
70. public function deleteDataForNodes ( ezcTreeNodeList $nodeList )
71. {
72. // This is a no-op as the data is part of the nodes
73. }
75. /**
76. * Deletes the data for all the nodes in the store.
77. */
78. public function deleteDataForAllNodes ()
79. {
80. // This is a no-op as the data is part of the nodes
81. }
83. /**
84. * Retrieves the data for the node $node from the data store and assigns it
85. * to the node's 'data' property.
86. *
87. * @param ezcTreeNode $node
88. */
89. public function fetchDataForNode ( ezcTreeNode $node )
90. {
91. $id = $node->id;
92. $elem = $this-> dom ->getElementById( "{$node->tree->prefix}{$id}" );
93. $dataElem = $elem->getElementsByTagNameNS( 'http://components.ez.no/Tree/data', 'data' )->item( 0 );
94. if ( $dataElem === null || ( (string) $dataElem->parentNode->getAttribute( 'id' ) !== "{$node->tree->prefix}{$id}" ) )
95. {
96. throw new ezcTreeDataStoreMissingDataException ( $node->id );
97. }
99. $node->injectData( $dataElem->firstChild->data );
100. $node->dataFetched = true;
101. }
103. /**
104. * Retrieves the data for all the nodes in the node list $nodeList and
105. * assigns this data to the nodes' 'data' properties.
106. *
107. * @param ezcTreeNodeList $nodeList
108. */
109. public function fetchDataForNodes ( ezcTreeNodeList $nodeList )
110. {
111. foreach ( $nodeList->nodes as $node )
112. {
113. if ( $node->dataFetched === false )
114. {
115. $this-> fetchDataForNode ( $node );
116. }
117. }
118. }
120. /**
121. * Stores the data in the node to the data store.
122. *
123. * @param ezcTreeNode $node
124. */
125. public function storeDataForNode ( ezcTreeNode $node )
126. {
127. // Locate the element
128. $id = $node->id;
129. $elem = $this-> dom ->getElementById( "{$node->tree->prefix}{$id}" );
131. // Create the new element
132. $dataNode = $elem->ownerDocument->createElementNS( 'http://components.ez.no/Tree/data', 'etd:data', $node->data );
134. // Locate the data element, and remove it
135. $dataElem = $elem->getElementsByTagNameNS( 'http://components.ez.no/Tree/data', 'data' )->item( 0 );
136. if ( $dataElem !== null )
137. {
138. $dataElem->parentNode->replaceChild( $dataNode, $dataElem );
139. }
140. else
141. {
142. $elem->appendChild( $dataNode );
143. }
145. // Create the new data element and add it
146. $node->dataStored = true;
147. if ( !$node->tree->inTransactionCommit() )
148. {
149. $node->tree->saveFile();
150. }
151. }
152. }
153. ?>

Documentation generated by phpDocumentor 1.4.3