< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltSets.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *     http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 /*
  21  * $Id: ExsltSets.java,v 1.1.2.1 2005/08/01 02:08:50 jeffsuttor Exp $
  22  */
  23 package com.sun.org.apache.xalan.internal.lib;
  24 
  25 import com.sun.org.apache.xml.internal.utils.DOMHelper;
  26 import com.sun.org.apache.xpath.internal.NodeSet;
  27 import java.util.HashMap;
  28 import java.util.Map;
  29 import org.w3c.dom.Node;
  30 import org.w3c.dom.NodeList;
  31 
  32 /**
  33  * This class contains EXSLT set extension functions.
  34  * It is accessed by specifying a namespace URI as follows:
  35  * <pre>
  36  *    xmlns:set="http://exslt.org/sets"
  37  * </pre>
  38  *
  39  * The documentation for each function has been copied from the relevant
  40  * EXSLT Implementer page.
  41  *
  42  * @see <a href="http://www.exslt.org/">EXSLT</a>
  43  * @xsl.usage general
  44  */
  45 public class ExsltSets extends ExsltBase


  55    * @return a NodeList containing the nodes in nl1 that precede in document order the first
  56    * node in nl2; an empty node-set if the first node in nl2 is not in nl1; all of nl1 if nl2
  57    * is empty.
  58    *
  59    * @see <a href="http://www.exslt.org/">EXSLT</a>
  60    */
  61   public static NodeList leading (NodeList nl1, NodeList nl2)
  62   {
  63     if (nl2.getLength() == 0)
  64       return nl1;
  65 
  66     NodeSet ns1 = new NodeSet(nl1);
  67     NodeSet leadNodes = new NodeSet();
  68     Node endNode = nl2.item(0);
  69     if (!ns1.contains(endNode))
  70       return leadNodes; // empty NodeSet
  71 
  72     for (int i = 0; i < nl1.getLength(); i++)
  73     {
  74       Node testNode = nl1.item(i);
  75       if (DOMHelper.isNodeAfter(testNode, endNode)
  76           && !DOMHelper.isNodeTheSame(testNode, endNode))
  77         leadNodes.addElement(testNode);
  78     }
  79     return leadNodes;
  80   }
  81 
  82   /**
  83    * The set:trailing function returns the nodes in the node set passed as the first argument that
  84    * follow, in document order, the first node in the node set passed as the second argument. If
  85    * the first node in the second node set is not contained in the first node set, then an empty
  86    * node set is returned. If the second node set is empty, then the first node set is returned.
  87    *
  88    * @param nl1 NodeList for first node-set.
  89    * @param nl2 NodeList for second node-set.
  90    * @return a NodeList containing the nodes in nl1 that follow in document order the first
  91    * node in nl2; an empty node-set if the first node in nl2 is not in nl1; all of nl1 if nl2
  92    * is empty.
  93    *
  94    * @see <a href="http://www.exslt.org/">EXSLT</a>
  95    */
  96   public static NodeList trailing (NodeList nl1, NodeList nl2)
  97   {
  98     if (nl2.getLength() == 0)
  99       return nl1;
 100 
 101     NodeSet ns1 = new NodeSet(nl1);
 102     NodeSet trailNodes = new NodeSet();
 103     Node startNode = nl2.item(0);
 104     if (!ns1.contains(startNode))
 105       return trailNodes; // empty NodeSet
 106 
 107     for (int i = 0; i < nl1.getLength(); i++)
 108     {
 109       Node testNode = nl1.item(i);
 110       if (DOMHelper.isNodeAfter(startNode, testNode)
 111           && !DOMHelper.isNodeTheSame(startNode, testNode))
 112         trailNodes.addElement(testNode);
 113     }
 114     return trailNodes;
 115   }
 116 
 117   /**
 118    * The set:intersection function returns a node set comprising the nodes that are within
 119    * both the node sets passed as arguments to it.
 120    *
 121    * @param nl1 NodeList for first node-set.
 122    * @param nl2 NodeList for second node-set.
 123    * @return a NodeList containing the nodes in nl1 that are also
 124    * in nl2.
 125    *
 126    * @see <a href="http://www.exslt.org/">EXSLT</a>
 127    */
 128   public static NodeList intersection(NodeList nl1, NodeList nl2)
 129   {
 130     NodeSet ns1 = new NodeSet(nl1);
 131     NodeSet ns2 = new NodeSet(nl2);


   1 /*
   2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *     http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 /*
  21  * $Id: ExsltSets.java,v 1.1.2.1 2005/08/01 02:08:50 jeffsuttor Exp $
  22  */
  23 package com.sun.org.apache.xalan.internal.lib;
  24 
  25 import com.sun.org.apache.xml.internal.utils.DOM2Helper;
  26 import com.sun.org.apache.xpath.internal.NodeSet;
  27 import java.util.HashMap;
  28 import java.util.Map;
  29 import org.w3c.dom.Node;
  30 import org.w3c.dom.NodeList;
  31 
  32 /**
  33  * This class contains EXSLT set extension functions.
  34  * It is accessed by specifying a namespace URI as follows:
  35  * <pre>
  36  *    xmlns:set="http://exslt.org/sets"
  37  * </pre>
  38  *
  39  * The documentation for each function has been copied from the relevant
  40  * EXSLT Implementer page.
  41  *
  42  * @see <a href="http://www.exslt.org/">EXSLT</a>
  43  * @xsl.usage general
  44  */
  45 public class ExsltSets extends ExsltBase


  55    * @return a NodeList containing the nodes in nl1 that precede in document order the first
  56    * node in nl2; an empty node-set if the first node in nl2 is not in nl1; all of nl1 if nl2
  57    * is empty.
  58    *
  59    * @see <a href="http://www.exslt.org/">EXSLT</a>
  60    */
  61   public static NodeList leading (NodeList nl1, NodeList nl2)
  62   {
  63     if (nl2.getLength() == 0)
  64       return nl1;
  65 
  66     NodeSet ns1 = new NodeSet(nl1);
  67     NodeSet leadNodes = new NodeSet();
  68     Node endNode = nl2.item(0);
  69     if (!ns1.contains(endNode))
  70       return leadNodes; // empty NodeSet
  71 
  72     for (int i = 0; i < nl1.getLength(); i++)
  73     {
  74       Node testNode = nl1.item(i);
  75       if (DOM2Helper.isNodeAfter(testNode, endNode)
  76           && !DOM2Helper.isNodeTheSame(testNode, endNode))
  77         leadNodes.addElement(testNode);
  78     }
  79     return leadNodes;
  80   }
  81 
  82   /**
  83    * The set:trailing function returns the nodes in the node set passed as the first argument that
  84    * follow, in document order, the first node in the node set passed as the second argument. If
  85    * the first node in the second node set is not contained in the first node set, then an empty
  86    * node set is returned. If the second node set is empty, then the first node set is returned.
  87    *
  88    * @param nl1 NodeList for first node-set.
  89    * @param nl2 NodeList for second node-set.
  90    * @return a NodeList containing the nodes in nl1 that follow in document order the first
  91    * node in nl2; an empty node-set if the first node in nl2 is not in nl1; all of nl1 if nl2
  92    * is empty.
  93    *
  94    * @see <a href="http://www.exslt.org/">EXSLT</a>
  95    */
  96   public static NodeList trailing (NodeList nl1, NodeList nl2)
  97   {
  98     if (nl2.getLength() == 0)
  99       return nl1;
 100 
 101     NodeSet ns1 = new NodeSet(nl1);
 102     NodeSet trailNodes = new NodeSet();
 103     Node startNode = nl2.item(0);
 104     if (!ns1.contains(startNode))
 105       return trailNodes; // empty NodeSet
 106 
 107     for (int i = 0; i < nl1.getLength(); i++)
 108     {
 109       Node testNode = nl1.item(i);
 110       if (DOM2Helper.isNodeAfter(startNode, testNode)
 111           && !DOM2Helper.isNodeTheSame(startNode, testNode))
 112         trailNodes.addElement(testNode);
 113     }
 114     return trailNodes;
 115   }
 116 
 117   /**
 118    * The set:intersection function returns a node set comprising the nodes that are within
 119    * both the node sets passed as arguments to it.
 120    *
 121    * @param nl1 NodeList for first node-set.
 122    * @param nl2 NodeList for second node-set.
 123    * @return a NodeList containing the nodes in nl1 that are also
 124    * in nl2.
 125    *
 126    * @see <a href="http://www.exslt.org/">EXSLT</a>
 127    */
 128   public static NodeList intersection(NodeList nl1, NodeList nl2)
 129   {
 130     NodeSet ns1 = new NodeSet(nl1);
 131     NodeSet ns2 = new NodeSet(nl2);


< prev index next >