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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [xml/] [transform/] [ElementAvailableFunction.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* ElementAvailableFunction.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 java.util.TreeSet;
46
import javax.xml.namespace.QName;
47
import javax.xml.namespace.NamespaceContext;
48
import javax.xml.xpath.XPathFunction;
49
import javax.xml.xpath.XPathFunctionException;
50
import org.w3c.dom.Node;
51
import gnu.xml.xpath.Expr;
52
import gnu.xml.xpath.Function;
53
 
54
/**
55
 * The XSLT <code>element-available</code> function.
56
 *
57
 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
58
 */
59
class ElementAvailableFunction
60
  extends Expr
61
  implements Function, XPathFunction
62
{
63
 
64
  static final Collection elements;
65
  static
66
  {
67
    TreeSet acc = new TreeSet();
68
    acc.add("stylesheet");
69
    acc.add("template");
70
    acc.add("param");
71
    acc.add("variable");
72
    acc.add("include");
73
    acc.add("import");
74
    acc.add("output");
75
    acc.add("preserve-space");
76
    acc.add("strip-space");
77
    acc.add("key");
78
    acc.add("decimal-format");
79
    acc.add("namespace-alias");
80
    acc.add("attribute-set");
81
    acc.add("apply-templates");
82
    acc.add("call-template");
83
    acc.add("value-of");
84
    acc.add("for-each");
85
    acc.add("if");
86
    acc.add("choose");
87
    acc.add("when");
88
    acc.add("otherwise");
89
    acc.add("element");
90
    acc.add("attribute");
91
    acc.add("text");
92
    acc.add("copy");
93
    acc.add("processing-instruction");
94
    acc.add("comment");
95
    acc.add("number");
96
    acc.add("copy-of");
97
    acc.add("message");
98
    acc.add("sort");
99
    acc.add("with-param");
100
    acc.add("fallback");
101
    acc.add("apply-imports");
102
    elements = Collections.unmodifiableSet(acc);
103
  }
104
 
105
  final NamespaceContext nsctx;
106
  List args;
107
 
108
  ElementAvailableFunction(NamespaceContext nsctx)
109
  {
110
    this.nsctx = nsctx;
111
  }
112
 
113
  public Object evaluate(List args)
114
    throws XPathFunctionException
115
  {
116
    // Useless...
117
    return Collections.EMPTY_SET;
118
  }
119
 
120
  public void setArguments(List args)
121
  {
122
    this.args = args;
123
  }
124
 
125
  public Object evaluate(Node context, int pos, int len)
126
  {
127
    Expr arg = (Expr) args.get(0);
128
    Object val = arg.evaluate(context, pos, len);
129
    String name = _string(context, val);
130
    String prefix, localName, uri;
131
    int ci = name.indexOf(':');
132
    if (ci == -1)
133
      {
134
        prefix = null;
135
        localName = name;
136
      }
137
    else
138
      {
139
        prefix = name.substring(0, ci);
140
        localName = name.substring(ci + 1);
141
      }
142
    uri = nsctx.getNamespaceURI(prefix);
143
    if (Stylesheet.XSL_NS.equals(uri))
144
      {
145
        return elements.contains(localName) ?
146
          Boolean.TRUE : Boolean.FALSE;
147
      }
148
    // TODO extension elements
149
    return Boolean.FALSE;
150
  }
151
 
152
  public Expr clone(Object context)
153
  {
154
    NamespaceContext n = nsctx;
155
    if (context instanceof NamespaceContext)
156
      n = (NamespaceContext) context;
157
    ElementAvailableFunction f = new ElementAvailableFunction(n);
158
    int len = args.size();
159
    List args2 = new ArrayList(len);
160
    for (int i = 0; i < len; i++)
161
      args2.add(((Expr) args.get(i)).clone(context));
162
    f.setArguments(args2);
163
    return f;
164
  }
165
 
166
  public boolean references(QName var)
167
  {
168
    for (Iterator i = args.iterator(); i.hasNext(); )
169
      {
170
        if (((Expr) i.next()).references(var))
171
          return true;
172
      }
173
    return false;
174
  }
175
 
176
  public String toString()
177
  {
178
    return "element-available(" + args.get(0) + ")";
179
  }
180
 
181
}

powered by: WebSVN 2.1.0

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