Simpler deployment.
[redakcja.git] / redakcja / static / filebrowser / uploadify / com / adobe / utils / XMLUtil.as
1 /*\r
2   Copyright (c) 2008, Adobe Systems Incorporated\r
3   All rights reserved.\r
4 \r
5   Redistribution and use in source and binary forms, with or without \r
6   modification, are permitted provided that the following conditions are\r
7   met:\r
8 \r
9   * Redistributions of source code must retain the above copyright notice, \r
10     this list of conditions and the following disclaimer.\r
11   \r
12   * Redistributions in binary form must reproduce the above copyright\r
13     notice, this list of conditions and the following disclaimer in the \r
14     documentation and/or other materials provided with the distribution.\r
15   \r
16   * Neither the name of Adobe Systems Incorporated nor the names of its \r
17     contributors may be used to endorse or promote products derived from \r
18     this software without specific prior written permission.\r
19 \r
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
21   IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
22   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
23   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR \r
24   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
25   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
26   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
27   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
28   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
29   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
30   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31 */\r
32 \r
33 package com.adobe.utils\r
34 {\r
35 \r
36         public class XMLUtil\r
37         {\r
38                 /**\r
39                  * Constant representing a text node type returned from XML.nodeKind.\r
40                  * \r
41                  * @see XML.nodeKind()\r
42                  * \r
43                  * @langversion ActionScript 3.0\r
44                  * @playerversion Flash 9.0\r
45                  */\r
46                 public static const TEXT:String = "text";\r
47                 \r
48                 /**\r
49                  * Constant representing a comment node type returned from XML.nodeKind.\r
50                  * \r
51                  * @see XML.nodeKind()\r
52                  * \r
53                  * @langversion ActionScript 3.0\r
54                  * @playerversion Flash 9.0\r
55                  */             \r
56                 public static const COMMENT:String = "comment";\r
57                 \r
58                 /**\r
59                  * Constant representing a processing instruction type returned from XML.nodeKind.\r
60                  * \r
61                  * @see XML.nodeKind()\r
62                  * \r
63                  * @langversion ActionScript 3.0\r
64                  * @playerversion Flash 9.0\r
65                  */             \r
66                 public static const PROCESSING_INSTRUCTION:String = "processing-instruction";\r
67                 \r
68                 /**\r
69                  * Constant representing an attribute type returned from XML.nodeKind.\r
70                  * \r
71                  * @see XML.nodeKind()\r
72                  * \r
73                  * @langversion ActionScript 3.0\r
74                  * @playerversion Flash 9.0\r
75                  */             \r
76                 public static const ATTRIBUTE:String = "attribute";\r
77                 \r
78                 /**\r
79                  * Constant representing a element type returned from XML.nodeKind.\r
80                  * \r
81                  * @see XML.nodeKind()\r
82                  * \r
83                  * @langversion ActionScript 3.0\r
84                  * @playerversion Flash 9.0\r
85                  */             \r
86                 public static const ELEMENT:String = "element";\r
87                 \r
88                 /**\r
89                  * Checks whether the specified string is valid and well formed XML.\r
90                  * \r
91                  * @param data The string that is being checked to see if it is valid XML.\r
92                  * \r
93                  * @return A Boolean value indicating whether the specified string is\r
94                  * valid XML.\r
95                  * \r
96                  * @langversion ActionScript 3.0\r
97                  * @playerversion Flash 9.0\r
98                  */\r
99                 public static function isValidXML(data:String):Boolean\r
100                 {\r
101                         var xml:XML;\r
102                         \r
103                         try\r
104                         {\r
105                                 xml = new XML(data);\r
106                         }\r
107                         catch(e:Error)\r
108                         {\r
109                                 return false;\r
110                         }\r
111                         \r
112                         if(xml.nodeKind() != XMLUtil.ELEMENT)\r
113                         {\r
114                                 return false;\r
115                         }\r
116                         \r
117                         return true;\r
118                 }\r
119                 \r
120                 /**\r
121                  * Returns the next sibling of the specified node relative to the node's parent.\r
122                  * \r
123                  * @param x The node whose next sibling will be returned.\r
124                  * \r
125                  * @return The next sibling of the node. null if the node does not have \r
126                  * a sibling after it, or if the node has no parent.\r
127                  * \r
128                  * @langversion ActionScript 3.0\r
129                  * @playerversion Flash 9.0\r
130                  */             \r
131                 public static function getNextSibling(x:XML):XML\r
132                 {       \r
133                         return XMLUtil.getSiblingByIndex(x, 1);\r
134                 }\r
135                 \r
136                 /**\r
137                  * Returns the sibling before the specified node relative to the node's parent.\r
138                  * \r
139                  * @param x The node whose sibling before it will be returned.\r
140                  * \r
141                  * @return The sibling before the node. null if the node does not have \r
142                  * a sibling before it, or if the node has no parent.\r
143                  * \r
144                  * @langversion ActionScript 3.0\r
145                  * @playerversion Flash 9.0\r
146                  */                     \r
147                 public static function getPreviousSibling(x:XML):XML\r
148                 {       \r
149                         return XMLUtil.getSiblingByIndex(x, -1);\r
150                 }               \r
151                 \r
152                 protected static function getSiblingByIndex(x:XML, count:int):XML       \r
153                 {\r
154                         var out:XML;\r
155                         \r
156                         try\r
157                         {\r
158                                 out = x.parent().children()[x.childIndex() + count];    \r
159                         }               \r
160                         catch(e:Error)\r
161                         {\r
162                                 return null;\r
163                         }\r
164                         \r
165                         return out;                     \r
166                 }\r
167         }\r
168 }