View Javadoc

1   /*
2    * $Id: SimpleNodeList.java 440597 2006-09-06 03:34:39Z wsmoak $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.xslt;
19  
20  import java.util.List;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.w3c.dom.Node;
25  import org.w3c.dom.NodeList;
26  
27  public class SimpleNodeList implements NodeList {
28  
29      private Log log = LogFactory.getLog(SimpleNodeList.class);
30  
31      private List<Node> nodes;
32  
33      public SimpleNodeList(List<Node> nodes) {
34          this.nodes = nodes;
35      }
36  
37      public int getLength() {
38          if (log.isTraceEnabled())
39              log.trace("getLength: " + nodes.size());
40          return nodes.size();
41      }
42  
43      public Node item(int i) {
44          log.trace("getItem: " + i);
45          return nodes.get(i);
46      }
47  
48      public String toString() {
49          StringBuffer sb = new StringBuffer("SimpleNodeList: [");
50          for (int i = 0; i < getLength(); i++)
51              sb.append(item(i).getNodeName() + ',');
52          sb.append("]");
53          return sb.toString();
54      }
55  }