Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/tripi/asp/msxml2/DOMNodeType.java


1   /*
2    * Created on Mar 14, 2003
3    *
4    * To change this generated comment go to 
5    * Window>Preferences>Java>Code Generation>Code Template
6    */
7   package com.tripi.asp.msxml2;
8   
9   /**
10   * @author jhorner
11   * 
12   * 
13  NODE_ELEMENT (1)
14  The node represents an element (its nodeTypeString property is "element"). 
15  An Element node can have the following child node types: Element, Text, 
16  Comment, ProcessingInstruction, CDATASection, and EntityReference. 
17  The Element node can be the child of the Document, DocumentFragment, 
18  EntityReference, and Element nodes.
19  
20  NODE_ATTRIBUTE (2)
21  The node represents an attribute of an element (its nodeTypeString 
22  property is "attribute"). An Attribute node can have the following child 
23  node types: Text and EntityReference. The Attribute node does not appear as 
24  the child node of any other node type; it is not considered a 
25  child node of an Element.
26  
27  NODE_TEXT (3)
28  The node represents the text content of a tag (its nodeTypeString property 
29  is "text"). A Text node cannot have any child nodes. The Text node can appear 
30  as the child node of the Attribute, DocumentFragment, Element, and EntityReference nodes.
31  
32  NODE_CDATA_SECTION (4)
33  The node represents a CDATA section in the XML source (its nodeTypeString 
34  property is "cdatasection"). CDATA sections are used to escape blocks of text 
35  that would otherwise be recognized as markup. A CDATASection node cannot have 
36  any child nodes. The CDATASection node can appear as the child of the 
37  DocumentFragment, EntityReference, and Element nodes.
38  
39  NODE_ENTITY_REFERENCE (5)
40  The node represents a reference to an entity in the XML document (its 
41  nodeTypeString property is "entityreference"). This applies to all entities, 
42  including character entity references. An EntityReference node can have the 
43  following child node types: Element, ProcessingInstruction, Comment, Text, 
44  CDATASection, and EntityReference. The EntityReference node can appear as the 
45  child of the Attribute, DocumentFragment, Element, and EntityReference nodes.
46  
47  NODE_ENTITY (6)
48  The node represents an expanded entity (its nodeTypeString property is 
49  "entity"). An Entity node can have child nodes that represent the expanded 
50  entity (for example, Text and EntityReference nodes). The Entity node can 
51  appear as the child of the DocumentType node.
52  
53  NODE_PROCESSING_INSTRUCTION (7)
54  The node represents a processing instruction from the XML document (its 
55  nodeTypeString property is "processinginstruction"). A ProcessingInstruction 
56  node cannot have any child nodes. The ProcessingInstruction node can appear 
57  as the child of the Document, DocumentFragment, Element, and EntityReference nodes.
58  
59  NODE_COMMENT (8)
60  The node represents a comment in the XML document (its nodeTypeString 
61  property is "comment"). A Comment node cannot have any child nodes. The 
62  Comment node can appear as the child of the Document, DocumentFragment, 
63  Element, and EntityReference nodes.
64  
65  NODE_DOCUMENT (9)
66  The node represents a document object, that as the root of the document 
67  tree, provides access to the entire XML document (its nodeTypeString 
68  property is "document"). It is created using the progID "Microsoft.XMLDOM" 
69  or through a data island using <XML> or <SCRIPT LANGUAGE=XML>. 
70  A Document node can have the following child node types: 
71  Element (maximum of one), ProcessingInstruction, Comment, and DocumentType. 
72  The Document node cannot appear as the child of any node types.
73  
74  NODE_DOCUMENT_TYPE (10)
75  The node represents the document type declaration, indicated by the 
76  <!DOCTYPE> tag (its nodeTypeString property is "documenttype"). 
77  A DocumentType node can have the following child node types: 
78  Notation and Entity. The DocumentType node can appear as the 
79  child of the Document node.
80  
81  NODE_DOCUMENT_FRAGMENT (11)
82  The node represents a document fragment (its nodeTypeString property 
83  is "documentfragment"). The DocumentFragment node associates a node 
84  or subtree with a document without actually being contained within 
85  the document. A DocumentFragment node can have the following 
86  child node types: Element, ProcessingInstruction, Comment, 
87  Text, CDATASection, and EntityReference. The DocumentFragment node 
88  cannot appear as the child of any node types.
89  
90  NODE_NOTATION (12)
91  The node represents a notation in the document type declaration 
92  (its nodeTypeString property is "notation"). A Notation node cannot 
93  have any child nodes. The Notation node can appear as the 
94  child of the DocumentType node.
95   *
96   * 
97   **/
98  public class DOMNodeType {
99  
100   protected int type = 0;
101   
102   public DOMNodeType(String nodeTypeString) {
103     this.type = convertToInteger(nodeTypeString);
104   }
105   
106   public DOMNodeType(int nodeTypeValue) {
107     this.type = convertToInteger(toString(nodeTypeValue));
108   }
109 
110   public int toInteger() {
111     return this.type;
112   }  
113 
114   public String toString() {
115     return toString(this.type);
116   }
117 
118   private String toString(int mytype) {
119     String result = "unknown";
120     
121     switch (mytype) {
122       case 1:
123         result = "element";
124         break;
125       case 2:
126         result = "attribute";
127         break;
128       case 3:
129         result = "text";
130         break;
131       case 4:
132         result = "cdatasection";
133         break;
134       case 5:
135         result = "entityreference";
136         break;
137       case 6:
138         result = "entity";
139         break;
140       case 7:
141         result = "processinginstruction";
142         break;
143       case 8:
144         result = "comment";
145         break;
146       case 9:
147         result = "document";
148         break;
149       case 10:
150         result = "documenttype";
151         break;
152       case 11:
153         result = "documentfragement";
154         break;
155       case 12:
156         result = "notation";
157         break;
158     }
159     
160     return result;
161   }
162   
163   private int convertToInteger(String str) {
164     int result = -1;
165     
166     if ( str.equalsIgnoreCase("element") ){
167       result = 1;
168     }
169     else if ( str.equalsIgnoreCase("attribute") ) {
170       result = 2;
171     }
172     else if ( str.equalsIgnoreCase("text") ) {
173       result = 3;
174     }
175     else if ( str.equalsIgnoreCase("cdatasection") ) {
176       result = 4;
177     }
178     else if ( str.equalsIgnoreCase("entityreference") ) {
179       result = 5;
180     }
181     else if ( str.equalsIgnoreCase("entity") ) {
182       result = 6;
183     }
184     else if ( str.equalsIgnoreCase("processinginstruction") ) {
185       result = 7;
186     }
187     else if ( str.equalsIgnoreCase("comment") ) {
188       result = 8;
189     }
190     else if ( str.equalsIgnoreCase("document") ) {
191       result = 9;
192     }
193     else if ( str.equalsIgnoreCase("documenttype") ) {
194       result = 10;
195     }
196     else if ( str.equalsIgnoreCase("documentfragment") ) {
197       result = 11;
198     }
199     else if ( str.equalsIgnoreCase("notation") ) {
200       result = 12;
201     }
202     
203     return result;  
204   }  
205 
206 }