jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltCommon.java
author duke
Wed, 05 Jul 2017 19:04:46 +0200
changeset 18896 98b0babd0565
parent 12457 c348e06f0e82
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: ExsltCommon.java,v 1.2.4.1 2005/09/15 02:45:24 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xalan.internal.lib;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xpath.internal.NodeSet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * This class contains EXSLT common extension functions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * It is accessed by specifying a namespace URI as follows:
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *    xmlns:exslt="http://exslt.org/common"
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * The documentation for each function has been copied from the relevant
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * EXSLT Implementer page.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * @see <a href="http://www.exslt.org/">EXSLT</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * @xsl.usage general
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
public class ExsltCommon
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
   * The exsl:object-type function returns a string giving the type of the object passed
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
   * as the argument. The possible object types are: 'string', 'number', 'boolean',
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * 'node-set', 'RTF', or 'external'.
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   * Most XSLT object types can be coerced to each other without error. However, there are
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
   * certain coercions that raise errors, most importantly treating anything other than a
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
   * node set as a node set. Authors of utilities such as named templates or user-defined
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
   * extension functions may wish to give some flexibility in the parameter and argument values
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
   * that are accepted by the utility; the exsl:object-type function enables them to do so.
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
   * The Xalan extensions MethodResolver converts 'object-type' to 'objectType'.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
   * @param obj The object to be typed.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
   * @return objectType 'string', 'number', 'boolean', 'node-set', 'RTF', or 'external'.
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * @see <a href="http://www.exslt.org/">EXSLT</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  public static String objectType (Object obj)
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    if (obj instanceof String)
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
      return "string";
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    else if (obj instanceof Boolean)
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
      return "boolean";
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    else if (obj instanceof Number)
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
      return "number";
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    else if (obj instanceof DTMNodeIterator)
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
      DTMIterator dtmI = ((DTMNodeIterator)obj).getDTMIterator();
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
      if (dtmI instanceof com.sun.org.apache.xpath.internal.axes.RTFIterator)
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
        return "RTF";
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        return "node-set";
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
      return "unknown";
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * The exsl:node-set function converts a result tree fragment (which is what you get
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   * when you use the content of xsl:variable rather than its select attribute to give
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   * a variable value) into a node set. This enables you to process the XML that you create
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   * within a variable, and therefore do multi-step processing.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   * You can also use this function to turn a string into a text node, which is helpful
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
   * if you want to pass a string to a function that only accepts a node set.
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * The Xalan extensions MethodResolver converts 'node-set' to 'nodeSet'.
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * @param myProcessor is passed in by the Xalan extension processor
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   * @param rtf The result tree fragment to be converted to a node-set.
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
   * @return node-set with the contents of the result tree fragment.
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   * Note: Already implemented in the xalan namespace as nodeset.
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * @see <a href="http://www.exslt.org/">EXSLT</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  public static NodeSet nodeSet(ExpressionContext myProcessor, Object rtf)
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    return Extensions.nodeset(myProcessor, rtf);
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
}