001    /*
002     * Copyright (c) 2009 The openGion Project.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013     * either express or implied. See the License for the specific language
014     * governing permissions and limitations under the License.
015     */
016    package org.opengion.fukurou.xml;
017    
018    import java.util.List;
019    import java.util.ArrayList;
020    
021    /**
022     * ノã?ドã?基底クラスã¨ãªã‚‹ã?OGNode クラスを定義ã—ã¾ã™ã?
023     *
024     * OGElementã€OGDocument ã¯ã€ã“ã®ã€OGNode クラスを継承ã—ã¾ã™ã?
025     * ãŸã ã—ã?OGAttributes ã¯ã€ç‹¬ç«‹ã—ã¦ã?‚‹ãŸã‚ã€ã“ã®ã‚¯ãƒ©ã‚¹ã¯ç¶™æ‰¿ã—ã¦ã?¾ã›ã‚“ã€?
026     *
027     * æœ?‚‚ä¸?ˆ¬çš?ªãƒŽã?ドã?ã€ãƒ†ã‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã§ã‚りã€?
028     *
029     * OGNode ã¯ã€enum OGNodeType ã§åŒºåˆ¥ã•れる状態をæŒã£ã¦ã?¾ã™ã?
030     * ãã?å†??OGElement 㨠OGDocument ã¯ã€ã‚µãƒ–クラスã«ãªã£ã¦ã?¾ã™ã?
031     * OGNodeType ã¯ã€ãれãžã‚Œã?å†è¨­å®šãŒå¯èƒ½ã§ã™ã?
032     * 例ãˆã°ã€æ—¢å­˜ã?エレメントやノã?ドã«å¯¾ã—ã¦ã€ã‚³ãƒ¡ãƒ³ãƒˆã‚¿ã‚¤ãƒ?Comment)を指定ã™ã‚‹ã¨ã€?
033     * ファイル等ã¸ã®å‡ºåŠ›æ™‚ã«ã‚³ãƒ¡ãƒ³ãƒˆã¨ã—ã¦å‡ºåŠ›ã•れã¾ã™ã?
034     *
035     * ã€??Listã€??ã€?å†?ƒ¨ã«ã€OGNode ã® ArrayList ã‚’æŒã¤
036     * ã€??Textã€??ã€?å†?ƒ¨ã¯ã€æ–‡å­—å?ã® BODY 部åˆ?‚’æŒã¤
037     * ã€??Comment ã€?å†?ƒ¨ã¯ã€æ–‡å­—å?ã§ã‚ã‚‹ãŒã?toString() 時ã«ã¯ã€ã‚³ãƒ¡ãƒ³ãƒˆè¨˜å·ã‚’å‰å¾Œã«å‡ºåŠ›ã™ã‚‹ã?
038     * ã€??Cdata ã€??:å†?ƒ¨ã¯ã€TextNodeã®ArrayList ã‚’æŒã¤ã€toString() 時ã«ã¯ã€Cdataã‚’å‰å¾Œã«å‡ºåŠ›ã™ã‚‹ã?
039     * ã€??Element ã€?ã‚¿ã‚°åã?属æ?ã€OGNode ã® ArrayList ã®å…¥ã‚Œå­çŠ¶æ…‹ã‚’ã‚‚ã¤
040     * ã€??Documentã€?トップã?Element ã¨ã—ã¦ã€read/write ã™ã‚‹ã¨ãã«ä½¿ç”¨ã€‚æ§‹é?ã¯ã€å”¯ä¸?? OGElement ã‚’æŒã¤ List タイãƒ?
041     *
042     * @og.rev 5.1.8.0 (2010/07/01) æ–°è¦ä½œæ?
043     * @og.rev 5.6.1.2 (2013/02/22) 構想ã‹ã‚‰ã‚?‚Šç›´ã?
044     *
045     * @version  5.0
046     * @author   Kazuhiko Hasegawa
047     * @since    JDK6.0,
048     */
049    public class OGNode {
050            public static final String CR  = System.getProperty("line.separator");
051    //      public static final String TAB = "\t" ;
052    
053            private final List<OGNode> nodes = new ArrayList<OGNode>();         // ノã?ドリスãƒ?
054            private final String    text;                                                                   // ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ç”¨ã®æ–?­—å?ノã?ドå?
055            private OGNodeType              nodeType ;                                                              // List,Text,Comment,Cdata,Element,Document
056            private OGNode                  parentNode = null;                                              // 自身ã®è¦ªãƒŽã?ãƒ?ãŸã ã—ã?æœ?µ‚ã‚»ãƒ?ƒˆã•れãŸãƒŽãƒ¼ãƒ?
057    
058            /**
059             * ãƒ?ƒ•ォルトコンストラクター
060             *
061             * ã“ã“ã§ã¯ã€NodeType ã¯ã€List ã«è¨­å®šã•れã¾ã™ã?
062             */
063            public OGNode() {
064                    this.text  = null;
065                    nodeType   = OGNodeType.List;
066            }
067    
068            /**
069             * ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã‚’構築ã™ã‚‹ãŸã‚ã?コンストラクター
070             *
071             * ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã?ã€ç°¡æ˜“çš„ã«ã€å?部ã«ã¯ã€ãƒŽãƒ¼ãƒ‰ãƒªã‚¹ãƒˆã§ã¯ãªã文字å?ã‚’æŒã£ã¦ã?¾ã™ã?
072             *
073             * @og.rev 5.6.1.2 (2013/02/22) å†?ƒ¨ãƒ?‚­ã‚¹ãƒˆãŒãªã??åˆã?ã‚¿ã‚°ã®çµ‚äº?™‚ã«ã‚¹ãƒšã?スã¯å…¥ã‚Œãªã??
074             *
075             * ã“ã“ã§ã¯ã€NodeType ã¯ã€Text ã«è¨­å®šã•れã¾ã™ã?
076             * ãŸã ã—ã?引数ã®ãƒ?‚­ã‚¹ãƒˆãŒ null ã®NodeType ã¯ã€List ã«è¨­å®šã•れã¾ã™ã?
077             *
078             * @param       txt     ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã?設定å?
079             */
080            public OGNode( final String txt ) {
081                    text = txt ;
082                    if( text != null )      { nodeType = OGNodeType.Text; }
083                    else                            { nodeType = OGNodeType.List; }
084            }
085    
086            /**
087             * ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã‚’ノã?ドリストã«è¿½åŠ?—ã¾ã™ã?
088             *
089             * å†?ƒ¨çš?«ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã‚’構築ã—ã¦ã€ãƒªã‚¹ãƒˆã«è¿½åŠ?—ã¦ã?¾ã™ã?
090             * 戻りå?ã¯ã€StringBuilder#append(String) ã®æ§˜ã«ã€??çµç™»éŒ²ã§ãるよã†ã«
091             * 自åˆ??身を返ã—ã¦ã?¾ã™ã?
092             * ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã«ã€ã“ã®å‡¦ç?‚’行ã†ã¨ã€ã‚¨ãƒ©ãƒ¼ã«ãªã‚Šã¾ã™ã?
093             * ä¸?—¦ã€ãƒ†ã‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã¨ã—ã¦ä½œæ?ã—ãŸãƒŽã?ドã«ã¯ã€ãƒŽãƒ¼ãƒ‰ã‚’追åŠ?§ãã¾ã›ã‚“ã€?
094             *
095             * @param       txt     ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã?設定å?
096             *
097             * @return      自åˆ??身(this)ã®ãƒŽã?ãƒ?
098             */
099            public OGNode addNode( final String txt ) {
100                    if( txt != null ) {
101                            if( nodeType == OGNodeType.Text ) {
102                                    // ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã«ãƒŽã?ドã?追åŠ?§ãã¾ã›ã‚“ã€?
103                                    String errMsg = "ä¸?—¦ã€ãƒ†ã‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã¨ã—ã¦ä½œæ?ã—ãŸãƒŽã?ドã«ã¯ã€ãƒŽãƒ¼ãƒ‰ã‚’追åŠ?§ãã¾ã›ã‚“ã€?;
104                                    throw new RuntimeException( errMsg );
105                            }
106    
107                            OGNode node = new OGNode( txt );
108                            node.parentNode = this;
109                            nodes.add( node );
110                    }
111                    return this;
112            }
113    
114            /**
115             * ノã?ドをノã?ドリストã«è¿½åŠ?—ã¾ã™ã?
116             *
117             * 追åŠ?™ã‚‹ãƒŽãƒ¼ãƒ‰ã?親ã¨ã—ã¦ã€è?åˆ??身を登録ã—ã¾ã™ã?
118             * ãªãŠã?åŒã˜ã‚ªãƒ–ジェクトをã€è¤?•°ã®è¦ªã«è¿½åŠ?™ã‚‹å?å?ノã?ドリストã«ã¯è¿½åŠ?¯èƒ½)ã¯ã€?
119             * 親ノã?ドã?ã€æœ€å¾Œã«ç™»éŒ²ã•れãŸãƒŽãƒ¼ãƒ‰ã?ã¿ãŒè¨­å®šã•れã¾ã™ã?
120             * ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã«ã€ã“ã®å‡¦ç?‚’行ã†ã¨ã€ã‚¨ãƒ©ãƒ¼ã«ãªã‚Šã¾ã™ã?
121             * ä¸?—¦ã€ãƒ†ã‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã¨ã—ã¦ä½œæ?ã—ãŸãƒŽã?ドã«ã¯ã€ãƒŽãƒ¼ãƒ‰ã‚’追åŠ?§ãã¾ã›ã‚“ã€?
122             *
123             * @param       node    ノã?ãƒ?
124             *
125             * @return      自åˆ??身(this)ã®ãƒŽã?ãƒ?
126             */
127            public OGNode addNode( final OGNode node ) {
128                    if( node != null ) {
129                            if( nodeType == OGNodeType.Text ) {
130                                    // ãƒ?‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã«ãƒŽã?ドã?追åŠ?§ãã¾ã›ã‚“ã€?
131                                    String errMsg = "ä¸?—¦ã€ãƒ†ã‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã¨ã—ã¦ä½œæ?ã—ãŸãƒŽã?ドã«ã¯ã€ãƒŽãƒ¼ãƒ‰ã‚’追åŠ?§ãã¾ã›ã‚“ã€?;
132                                    throw new RuntimeException( errMsg );
133                            }
134    
135                            node.parentNode = this;
136                            nodes.add( node );
137                    }
138                    return this;
139            }
140    
141            /**
142             * ノã?ドリストã«è¿½åŠ?•れã¦ã?‚‹ã€ãƒŽãƒ¼ãƒ‰ã?個数を返ã—ã¾ã™ã?
143             *
144             * @return      ノã?ドリストã?æ•°
145             */
146            public int nodeSize() {
147                    return nodes.size();
148            }
149    
150            /**
151             * ノã?ドリストã«è¿½åŠ?•れã¦ã?‚‹ã€ãƒŽãƒ¼ãƒ‰ã‚’è¿”ã—ã¾ã™ã?
152             *
153             * ノã?ドã?æŒ?®šã«ã¯ã€??列番å·ã‚’使用ã—ã¾ã™ã?
154             * ノã?ドã?個数ã¯ã€äº‹å‰ã«ã€nodeSize() ã§èª¿ã¹ã¦ç½®ã?¦ãã ã•ã„ã€?
155             * 当然ã€ãƒ†ã‚­ã‚¹ãƒˆãƒŽãƒ¼ãƒ‰ã?å ´åˆã?ã€nodeSize()==0 ãªã®ã§ã€?
156             * ã“ã?メソãƒ?ƒ‰ã§ã¯å–å¾—ã§ãã¾ã›ã‚“ã€?
157             *
158             * @param       adrs    ノã?ドリストã?ä½ç½®
159             *
160             * @return      æŒ?®šã?é…å?番å·ã®ãƒŽã?ãƒ?
161             */
162            public OGNode getNode( final int adrs ) {
163                    return nodes.get(adrs);
164            }
165    
166            /**
167             * ノã?ドリストã«ã€ãƒŽãƒ¼ãƒ‰ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?
168             *
169             * ノã?ドリストã?æŒ?®šã?アドレスã«ã€ãƒŽãƒ¼ãƒ‰ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?
170             * ã“れã¯ã€è¿½åŠ?§ã¯ãªãç½®æ›ãˆã«ãªã‚Šã¾ã™ã?
171             * ノã?ドã?æŒ?®šã«ã¯ã€??列番å·ã‚’使用ã—ã¾ã™ã?
172             * ノã?ドã?個数ã¯ã€äº‹å‰ã«ã€nodeSize() ã§èª¿ã¹ã¦ç½®ã?¦ãã ã•ã„ã€?
173             *
174             * @param       adrs    ノã?ドリストã?ä½ç½®
175             * @param       node    ã‚»ãƒ?ƒˆã™ã‚‹ãƒŽã?ãƒ?
176             */
177            public void setNode( final int adrs , final OGNode node ) {
178                    nodes.set(adrs,node);
179            }
180    
181            /**
182             * 自身ã«ã‚»ãƒ?ƒˆã•れã¦ã?‚‹ã€è¦ªãƒŽã?ドを返ã—ã¾ã™ã?
183             *
184             * 親ノã?ドã?ã€è?身ã®ã‚ªãƒ–ジェクトã«ã€ä¸?¤ã—ã‹è¨­å®šã§ãã¾ã›ã‚“ã€?
185             * ã“れã¯ã€ã‚ªãƒ–ジェクトã¨ã—ã¦ã€åŒä¸?ƒŽãƒ¼ãƒ‰ã‚’ã€è¤?•°ã®è¦ªãƒŽã?ドã«
186             * 追åŠ?—ãŸå?å?ã“れã¯ã€ãƒŽãƒ¼ãƒ‰ãƒªã‚¹ãƒˆã¸ã®è¿½åŠ?ªã®ã§å¯èƒ½)æœ?¾Œã«è¿½åŠ?—ã?
187             * 親ノã?ドã?ã¿ã€ä¿æŒã—ã¦ã?‚‹ã“ã¨ã«ãªã‚Šã¾ã™ã?
188             * XML を構築ã™ã‚‹ã¨ãã?ã€åŒä¸??ノã?ドã§ã‚ã£ã¦ã‚‚ã?毎回ã€ä½œæ?ã—ãªãŠã•ãªã?¨ã€?
189             * 親ノã?ドを見ã¤ã‘ã¦ã€ä½•ã‹ã‚’行ã†å ´åˆã«ã¯ã€ãŠã‹ã—ãªå‹•ãã‚’ã™ã‚‹ã“ã¨ã«ãªã‚Šã¾ã™ã?
190             * ãªãŠã?ノã?ドオブジェクトè?体ãŒã€è¦ªãƒŽã?ドã‹ã‚‰å‰Šé™¤ã•れã¦ã‚‚ã?自身ã®
191             * 親ノã?ド情報ã¯ä¿æŒã—ç¶šã‘ã¦ã?¾ã™ã?
192             * ã‚ã‚‹ Element ã‹ã‚‰å‰Šé™¤ã—ãŸãƒŽã?ドを別ã®Elementã«è¿½åŠ?™ã‚‹ã¨ã€ãã®æ™‚点ã§ã€?
193             * 親ノã?ドも更新ã•れã¾ã™ã?
194             *
195             * @return      親ノã?ãƒ?
196             */
197            public OGNode getParentNode() {
198                    return parentNode;
199            }
200    
201            /**
202             * 自身ã«ã‚»ãƒ?ƒˆã•れã¦ã?‚‹ã€è¦ªãƒŽã?ドã?階層数を返ã—ã¾ã™ã?
203             *
204             * 自身ã®ã‚ªãƒ–ジェクトã«è¨­å®šã•れã¦ã?‚‹è¦ªãƒŽã?ドをé ?•ªã«ã•ã‹ã®ã¼ã£ã¦ã€?
205             * 何階層ã‚ã‚‹ã‹è¿”ã—ã¾ã™ã?
206             * ã“れã¯ã€getText(int) ã®å¼•æ•°ã«ä½¿ãˆã¾ã™ã?
207             * 親ノã?ドãŒã²ã¨ã¤ã‚‚ãªã??åˆã?ã¤ã¾ã‚Šè?èº«ãŒæœ€ä¸Šä½ã?å ´åˆã?ã€? ãŒè¿”ã•れã¾ã™ã?
208             *
209             * @return      自身ã®éšŽå±¤
210             */
211            public int getParentCount() {
212                    int para = 0;
213                    OGNode node = getParentNode();
214                    while( node != null ) {
215                            para++ ;
216                            node = node.getParentNode();
217                    }
218                    return para;
219            }
220    
221            /**
222             * ノã?ドリストã‹ã‚‰ã?æŒ?®šã?é…å?番å·ã®ã€ãƒŽãƒ¼ãƒ‰ã‚’削除ã—ã¾ã™ã?
223             *
224             * ノã?ドã?æŒ?®šã«ã¯ã€??列番å·ã‚’使用ã—ã¾ã™ã?
225             * ノã?ドã?個数ã¯ã€äº‹å‰ã«ã€nodeSize() ã§èª¿ã¹ã¦ç½®ã?¦ãã ã•ã„ã€?
226             *
227             * @param       adrs    ノã?ドリストã?ä½ç½®
228             *
229             * @return      削除ã•れãŸãƒŽãƒ¼ãƒ?
230             */
231            public OGNode removeNode( final int adrs ) {
232                    return nodes.remove(adrs);
233            }
234    
235            /**
236             * ノã?ドリストã‹ã‚‰ã?ã™ã¹ã¦ã®ãƒŽã?ドを削除ã—ã¾ã™ã?
237             *
238             * ã“れã¯ã€ãƒŽãƒ¼ãƒ‰ãƒªã‚¹ãƒˆã‚’クリアã—ã¾ã™ã?
239             *
240             */
241            public void clearNode() {
242                    nodes.clear();
243            }
244    
245            /**
246             * ノã?ドリストã‹ã‚‰ã?æŒ?®šã?ノã?ãƒ?orgNode)ã‚’æ–°ã—ã„ノã?ãƒ?newNode)ã«ç½®ãæ›ãˆã¾ã™ã?
247             *
248             * ノã?ドã?ã€ãれãžã‚Œã?ノã?ドãŒä½œæ?ã•れãŸé?番ã§ã€ãƒ¦ãƒ‹ã?クãªç•ªå·ã‚’æŒã£ã¦ã?¾ã™ã?
249             * ãã?番å·ã‚’å?ã«ã€ãƒŽãƒ¼ãƒ‰ã‚’探ã—å?ã—ã¦ã€ç½®ãæ›ãˆã¾ã™ã?
250             * 通常ã®ã€XMLパã?スã‹ã‚‰ä½œæ?ã•れãŸãƒŽãƒ¼ãƒ‰ã?ã€ã™ã¹ã¦ä¸?„ã«ãƒ¦ãƒ‹ã?ク番å·ãŒæŒ¯ã‚‰ã‚Œã¾ã™ãŒã€?
251             * æ–°ã—ãã¤ã£ãŸãƒŽãƒ¼ãƒ‰ã‚’è¤?•°ã®ãƒŽã?ドã¨ç½®ãæ›ãˆã‚‹å ´åˆã?ç½®ãæ›ãˆã‚‰ã‚ŒãŸå¾Œã?ノã?ドã?ã€?
252             * オブジェクトãã®ã‚‚ã?ãŒã?åŒä¸?«ãªã‚‹ãŸã‚ã?注æ„ãŒå¿?¦ã§ã™ã?
253             *
254             * @param       orgNode ç½®æ›å?ã®ã‚ªãƒªã‚¸ãƒŠãƒ«ãƒŽã?ãƒ?
255             * @param       newNode ç½®æ›ã™ã‚‹æ–°ã—ã„ノã?ãƒ?
256             */
257            public void changeNode( final OGNode orgNode , final OGNode newNode ) {
258                    int size = nodes.size();
259                    for( int i=0; i<size; i++ ) {
260                            OGNode node = nodes.get(i);
261    //                      if( node.nodeNo == orgNode.nodeNo ) {
262                            if( node.equals( orgNode ) ) {          // Object.equals ãªã®ã§ã€ã‚ªãƒ–ジェクトãã®ã‚‚ã?ã®ä¸??判å®?
263                                    nodes.set( i,newNode );
264                            }
265                            else {
266                                    node.changeNode( orgNode,newNode );
267                            }
268                    }
269            }
270    
271            /**
272             * ノã?ドリストã‹ã‚‰ã?ç›´ä¸?メンãƒã?)ã®ã‚¨ãƒ¬ãƒ¡ãƒ³ãƒˆã?ã¿ã‚’リストã«ã—ã¦è¿”ã—ã¾ã™ã?
273             *
274             * ノã?ドリストã?第ä¸?ƒ¬ãƒ™ãƒ«ã§ã€ã‚¨ãƒ¬ãƒ¡ãƒ³ãƒˆã?ã¿ã‚’è¿”ã—ã¾ã™ã?
275             * 通常ã¯ã€ã‚るエレメントをã€getElementList( String ) ç­‰ã§æ¤œç´¢ã—ãŸå¾Œã?ãã?å­è¦ç´?‚’
276             * å–り出ã™å?åˆã«ä½¿ç”¨ã—ã¾ã™ã?
277             * 該当ã™ã‚‹ã‚¨ãƒ¬ãƒ¡ãƒ³ãƒˆãŒã€ãªã«ã‚‚存在ã—ãªã??åˆã?ã€ç©ºã®ãƒªã‚¹ãƒˆã‚ªãƒ–ジェクトãŒè¿”ã•れã¾ã™ã?
278             *
279             * @return      ç›´ä¸?メンãƒã?)ã®ã‚¨ãƒ¬ãƒ¡ãƒ³ãƒˆã?リスãƒ?
280             */
281            public List<OGElement> getChildElementList() {
282                    List<OGElement> eles = new ArrayList<OGElement>();
283    
284                    for( OGNode node : nodes ) {
285                            if( node.nodeType == OGNodeType.Element ) {
286                                    eles.add( (OGElement)node );
287                            }
288                    }
289    
290                    return eles;
291            }
292    
293            /**
294             * ノã?ドリストã‹ã‚‰ã?下ä½ã?階層ã«å­˜åœ¨ã™ã‚‹ã™ã¹ã¦ã®ã‚¨ãƒ¬ãƒ¡ãƒ³ãƒˆã‚’リストã«ã—ã¦è¿”ã—ã¾ã™ã?
295             *
296             * エレメントã?ã€åå‰ã‚’æŒ?®šã—ã¦æ¤œç´¢ã—ã¾ã™ã?
297             * 該当ã™ã‚‹ã‚¨ãƒ¬ãƒ¡ãƒ³ãƒˆãŒã€ãªã«ã‚‚存在ã—ãªã??åˆã?ã€ç©ºã®ãƒªã‚¹ãƒˆã‚ªãƒ–ジェクトãŒè¿”ã•れã¾ã™ã?
298             *
299             * @param       qName   エレメントã?åå‰
300             *
301             * @return      下ä½ã?階層ã«å­˜åœ¨ã™ã‚‹ã™ã¹ã¦ã®ã‚¨ãƒ¬ãƒ¡ãƒ³ãƒˆã?リスãƒ?
302             */
303            public List<OGElement> getElementList( final String qName ) {
304                    List<OGElement> eles = new ArrayList<OGElement>();
305    
306                    if( qName != null ) {
307                            for( OGNode node : nodes ) {
308                                    if( node.nodeType == OGNodeType.Element ) {
309                                            OGElement ele = (OGElement)node;
310                                            if( qName.equals( ele.getTagName() ) ) {
311                                                    eles.add( ele );
312                                            }
313                                            eles.addAll( ele.getElementList( qName ) );
314                                    }
315                            }
316                    }
317    
318                    return eles;
319            }
320    
321            /**
322             * ノã?ドタイプを設定ã—ã¾ã™ã?
323             *
324             * ノã?ドタイプã¨ã¯ã€List , Text , Comment , Cdata , Element , Document ãªã©ã®
325             * ノã?ドã?種別を表ã?enum タイプã§ã™ã?
326             * 基本çš?«ã¯ã€ã‚ªãƒ–ジェクトã?å–得時ã«ã€ãƒ•ァクトリメソãƒ?ƒ‰çµŒç”±ã§ã‚れã°ã€è?å‹•çš„ã«è¨­å®?
327             * ã•れã¦ã?¾ã™ã?
328             * ã“ã“ã§ã¯ã€å¯å¤‰è¨­å®šã§ãã¾ã™ã?
329             * 例ãˆã°ã€æ—¢å­˜ã?エレメントやノã?ドã«å¯¾ã—ã¦ã€ã‚³ãƒ¡ãƒ³ãƒˆã‚¿ã‚¤ãƒ?Comment)を指定ã™ã‚‹ã¨ã€?
330             * ファイル等ã¸ã®å‡ºåŠ›æ™‚ã«ã‚³ãƒ¡ãƒ³ãƒˆã¨ã—ã¦å‡ºåŠ›ã•れã¾ã™ã?
331             * null を指定ã™ã‚‹ã¨ã€ãªã«ã‚‚å?ç?•れã¾ã›ã‚“ã€?
332             *
333             * @param       type    enumã®OGNodeType
334             * @see OGNodeType
335             */
336            public void setNodeType( final OGNodeType type ) {
337                    if( type != null ) {
338                            if( type != OGNodeType.Text && nodeType == OGNodeType.Text ) {
339                                    OGNode node = new OGNode( text );
340                                    node.parentNode = this;
341                                    nodes.add( node );
342                            }
343    
344                            nodeType = type ;
345                    }
346            }
347    
348            /**
349             * ノã?ドタイプをå–å¾—ã—ã¾ã™ã?
350             *
351             * ノã?ドタイプã¨ã¯ã€List , Text , Comment , Cdata , Element , Document ãªã©ã®
352             * ノã?ドã?種別を表ã?enum タイプã§ã™ã?
353             * 基本çš?«ã¯ã€ã‚ªãƒ–ジェクトã?å–得時ã«ã€ãƒ•ァクトリメソãƒ?ƒ‰çµŒç”±ã§ã‚れã°ã€è?å‹•çš„ã«è¨­å®?
354             * ã•れã¦ã?¾ã™ã?
355             *
356             * @return      ノã?ドタイãƒ?
357             * @see OGNodeType
358             */
359            public OGNodeType getNodeType() {
360                    return nodeType;
361            }
362    
363            /**
364             * ノã?ドリストã?æ–?­—å?ã‚’è¿”ã—ã¾ã™ã?
365             *
366             * ã“れã¯ã€ã‚¿ã‚°ã§è¨?†ã¨ã“ã‚ã®BODYéƒ¨ã«æ›¸ã‹ã‚ŒãŸæ–‡å­—å?ã«ç›¸å½“ã—ã¾ã™ã?
367             * 該当ã™ã‚‹æ–‡å­—å?ãŒã?存在ã—ãªã??åˆã?ã€ç©ºã®æ–?­—å?(ゼロストリング)ãŒè¿”ã•れã¾ã™ã?
368             *
369             * @param       cnt             Nodeã®éšŽå±¤
370             * @return      ノã?ドリストã?æ–?­—å?(BODYéƒ¨ã«æ›¸ã‹ã‚ŒãŸæ–‡å­—å?)
371             */
372            public String getText( final int cnt ) {
373                    StringBuilder buf = new StringBuilder();
374    
375                    if( nodeType == OGNodeType.Text ) {
376                            buf.append( text );
377                    }
378                    else {
379                            for( OGNode node : nodes ) {
380                                    buf.append( node.getText( cnt ) );
381                            }
382                    }
383    
384                    String rtn = buf.toString();
385                    switch( nodeType ) {
386                            case Comment:   rtn = "<!-- "      + rtn + " -->"; break;
387                            case Cdata:             rtn = "<![CDATA[ " + rtn + " ]]>"; break;
388    //                      case Document:
389    //                      case Text:
390    //                      case DTD:
391    //                      case List:
392                            default:                break;
393                    }
394    
395                    return rtn ;
396            }
397    
398            /**
399             * オブジェクトã?æ–?­—å?表ç¾ã‚’è¿”ã—ã¾ã™ã?
400             *
401             * æ–?­—å?ã¯ã€OGNodeType ã«ã‚ˆã‚Šç•°ãªã‚Šã¾ã™ã?
402             * Comment ノã?ドã?å ´åˆã?ã€ã‚³ãƒ¡ãƒ³ãƒˆè¨˜å·ã‚’ã?Cdata ノã?ドã?å ´åˆã?ã€CDATA ã‚?
403             * ã¤ã‘ã¦å‡ºåŠ›ã—ã¾ã™ã?
404             *
405             * @return      ã“ã?オブジェクトã?æ–?­—å?表ç¾
406             * @see Object#toString()
407             */
408            @Override
409            public String toString() {
410                    return getText( -10 );
411            }
412    }