OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [gnu/] [xml/] [transform/] [ForEachNode.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* ForEachNode.java --
2
   Copyright (C) 2004 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package gnu.xml.transform;
39
 
40
import java.util.ArrayList;
41
import java.util.Collection;
42
import java.util.Collections;
43
import java.util.Iterator;
44
import java.util.List;
45
import javax.xml.namespace.QName;
46
import javax.xml.transform.TransformerException;
47
import org.w3c.dom.Node;
48
import gnu.xml.xpath.Expr;
49
 
50
/**
51
 * A template node representing an XSLT <code>for-each</code> instruction.
52
 *
53
 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
54
 */
55
final class ForEachNode
56
  extends TemplateNode
57
{
58
 
59
  final Expr select;
60
  final List sortKeys;
61
 
62
  ForEachNode(Expr select, List sortKeys)
63
  {
64
    this.select = select;
65
    this.sortKeys = sortKeys;
66
  }
67
 
68
  TemplateNode clone(Stylesheet stylesheet)
69
  {
70
    int len = sortKeys.size();
71
    List sortKeys2 = new ArrayList(len);
72
    for (int i = 0; i < len; i++)
73
      {
74
        sortKeys2.add(((Key) sortKeys.get(i)).clone(stylesheet));
75
      }
76
    TemplateNode ret = new ForEachNode(select.clone(stylesheet),
77
                                       sortKeys2);
78
    if (children != null)
79
      {
80
        ret.children = children.clone(stylesheet);
81
      }
82
    if (next != null)
83
      {
84
        ret.next = next.clone(stylesheet);
85
      }
86
    return ret;
87
  }
88
 
89
  void doApply(Stylesheet stylesheet, QName mode,
90
             Node context, int pos, int len,
91
             Node parent, Node nextSibling)
92
    throws TransformerException
93
  {
94
    if (children != null)
95
      {
96
        // Set current template to null
97
        Template saved = stylesheet.currentTemplate;
98
        stylesheet.currentTemplate = null;
99
        Object ret = select.evaluate(context, pos, len);
100
        //System.err.println(toString() + ": " + context+" -> "+ret);
101
        if (ret instanceof Collection)
102
          {
103
            Collection ns = (Collection) ret;
104
            List list = new ArrayList(ns);
105
            if (sortKeys != null)
106
              {
107
                for (Iterator i = sortKeys.iterator(); i.hasNext(); )
108
                  {
109
                    SortKey sortKey = (SortKey) i.next();
110
                    sortKey.init(stylesheet, mode, context, pos, len, parent,
111
                                 nextSibling);
112
                  }
113
                Collections.sort(list, new XSLComparator(sortKeys));
114
              }
115
            else
116
              {
117
                Collections.sort(list, documentOrderComparator);
118
              }
119
            // Perform children for each node
120
            int l = list.size();
121
            int p = 1;
122
            for (Iterator i = list.iterator(); i.hasNext(); )
123
              {
124
                Node node = (Node) i.next();
125
                stylesheet.current = node;
126
                children.apply(stylesheet, mode,
127
                               node, p++, l,
128
                               parent, nextSibling);
129
              }
130
          }
131
        // Restore current template
132
        stylesheet.currentTemplate = saved;
133
      }
134
    if (next != null)
135
      {
136
        next.apply(stylesheet, mode,
137
                   context, pos, len,
138
                   parent, nextSibling);
139
      }
140
  }
141
 
142
  public boolean references(QName var)
143
  {
144
    if (select != null && select.references(var))
145
      {
146
        return true;
147
      }
148
    if (sortKeys != null)
149
      {
150
        for (Iterator i = sortKeys.iterator(); i.hasNext(); )
151
          {
152
            if (((SortKey) i.next()).references(var))
153
              {
154
                return true;
155
              }
156
          }
157
      }
158
    return super.references(var);
159
  }
160
 
161
  public String toString()
162
  {
163
    StringBuffer buf = new StringBuffer(getClass().getName());
164
    buf.append('[');
165
    buf.append("select=");
166
    buf.append(select);
167
    buf.append(']');
168
    return buf.toString();
169
  }
170
 
171
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.