author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 31204 | jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/functions/FuncHere.java@9afdbf18ad38 |
child 47359 | e1a6c0168741 |
permissions | -rw-r--r-- |
31204
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
1 |
/* |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
3 |
*/ |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
4 |
/** |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
5 |
* Licensed to the Apache Software Foundation (ASF) under one |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
6 |
* or more contributor license agreements. See the NOTICE file |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
7 |
* distributed with this work for additional information |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
8 |
* regarding copyright ownership. The ASF licenses this file |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
9 |
* to you under the Apache License, Version 2.0 (the |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
10 |
* "License"); you may not use this file except in compliance |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
11 |
* with the License. You may obtain a copy of the License at |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
12 |
* |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
14 |
* |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
15 |
* Unless required by applicable law or agreed to in writing, |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
16 |
* software distributed under the License is distributed on an |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
17 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
18 |
* KIND, either express or implied. See the License for the |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
19 |
* specific language governing permissions and limitations |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
20 |
* under the License. |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
21 |
*/ |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
22 |
package com.sun.org.apache.xpath.internal.functions; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
23 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
24 |
import javax.xml.transform.TransformerException; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
25 |
import org.w3c.dom.Document; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
26 |
import org.w3c.dom.Node; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
27 |
import com.sun.org.apache.xml.internal.dtm.DTM; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
28 |
import com.sun.org.apache.xpath.internal.NodeSetDTM; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
29 |
import com.sun.org.apache.xpath.internal.XPathContext; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
30 |
import com.sun.org.apache.xpath.internal.objects.XNodeSet; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
31 |
import com.sun.org.apache.xpath.internal.objects.XObject; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
32 |
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
33 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
34 |
/** |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
35 |
* Execute the XML Signature here() function. |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
36 |
*/ |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
37 |
public final class FuncHere extends Function { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
38 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
39 |
private static final long serialVersionUID = 4328660760070034592L; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
40 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
41 |
@Override |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
42 |
public XObject execute(XPathContext xctxt) throws TransformerException { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
43 |
Node xpathOwnerNode = (Node)xctxt.getOwnerObject(); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
44 |
if (xpathOwnerNode == null) { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
45 |
return null; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
46 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
47 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
48 |
int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
49 |
int currentNode = xctxt.getCurrentNode(); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
50 |
DTM dtm = xctxt.getDTM(currentNode); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
51 |
int docContext = dtm.getDocument(); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
52 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
53 |
if (docContext == DTM.NULL) { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
54 |
error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
55 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
56 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
57 |
// check whether currentNode and the node containing the XPath |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
58 |
// expression are in the same document |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
59 |
Document currentDoc = getOwnerDocument(dtm.getNode(currentNode)); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
60 |
Document xpathOwnerDoc = getOwnerDocument(xpathOwnerNode); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
61 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
62 |
if (currentDoc != xpathOwnerDoc) { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
63 |
throw new TransformerException("Owner documents differ"); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
64 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
65 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
66 |
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager()); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
67 |
NodeSetDTM nodeSet = nodes.mutableNodeset(); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
68 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
69 |
int hereNode = DTM.NULL; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
70 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
71 |
switch (dtm.getNodeType(xpathOwnerNodeDTM)) { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
72 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
73 |
case Node.ATTRIBUTE_NODE: |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
74 |
case Node.PROCESSING_INSTRUCTION_NODE: { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
75 |
// returns a node-set containing the attribute / processing |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
76 |
// instruction node |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
77 |
hereNode = xpathOwnerNodeDTM; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
78 |
nodeSet.addNode(hereNode); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
79 |
break; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
80 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
81 |
case Node.TEXT_NODE : { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
82 |
// returns a node-set containing the parent element of the |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
83 |
// text node that directly bears the XPath expression |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
84 |
hereNode = dtm.getParent(xpathOwnerNodeDTM); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
85 |
nodeSet.addNode(hereNode); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
86 |
break; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
87 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
88 |
default : |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
89 |
break; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
90 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
91 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
92 |
/** $todo$ Do I have to do this detach() call? */ |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
93 |
nodeSet.detach(); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
94 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
95 |
return nodes; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
96 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
97 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
98 |
private static Document getOwnerDocument(Node node) { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
99 |
if (node.getNodeType() == Node.DOCUMENT_NODE) { |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
100 |
return (Document)node; |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
101 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
102 |
return node.getOwnerDocument(); |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
103 |
} |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
104 |
|
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
105 |
@Override |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
106 |
public void fixupVariables(java.util.Vector vars, int globalsSize) { } |
9afdbf18ad38
8087283: Add support for the XML Signature here() function to the JDK XPath implementation
mullan
parents:
diff
changeset
|
107 |
} |