1 17 package com.sun.org.apache.xml.internal.security.transforms.implementations; 18 19 20 21 import javax.xml.transform.TransformerException ; 22 23 import com.sun.org.apache.xml.internal.dtm.DTM; 24 import com.sun.org.apache.xml.internal.security.utils.I18n; 25 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 26 import com.sun.org.apache.xpath.internal.NodeSetDTM; 27 import com.sun.org.apache.xpath.internal.XPathContext; 28 import com.sun.org.apache.xpath.internal.functions.Function; 29 import com.sun.org.apache.xpath.internal.objects.XNodeSet; 30 import com.sun.org.apache.xpath.internal.objects.XObject; 31 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; 32 import org.w3c.dom.Document ; 33 import org.w3c.dom.Node ; 34 35 36 53 public class FuncHere extends Function { 54 55 58 private static final long serialVersionUID = 1L; 59 60 71 public XObject execute(XPathContext xctxt) 72 throws javax.xml.transform.TransformerException { 73 74 Node xpathOwnerNode = (Node ) xctxt.getOwnerObject(); 75 76 if (xpathOwnerNode == null) { 77 return null; 78 } 79 80 int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode); 81 82 int currentNode = xctxt.getCurrentNode(); 83 DTM dtm = xctxt.getDTM(currentNode); 84 int docContext = dtm.getDocument(); 85 86 if (DTM.NULL == docContext) { 87 error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null); 88 } 89 90 { 91 92 Document currentDoc = 95 XMLUtils.getOwnerDocument(dtm.getNode(currentNode)); 96 Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode); 97 98 if (currentDoc != xpathOwnerDoc) { 99 throw new TransformerException (I18n 100 .translate("xpath.funcHere.documentsDiffer")); 101 } 102 } 103 104 XNodeSet nodes = new XNodeSet(xctxt.getDTMManager()); 105 NodeSetDTM nodeSet = nodes.mutableNodeset(); 106 107 { 108 int hereNode = DTM.NULL; 109 110 switch (dtm.getNodeType(xpathOwnerNodeDTM)) { 111 112 case Node.ATTRIBUTE_NODE : { 113 hereNode = xpathOwnerNodeDTM; 115 116 nodeSet.addNode(hereNode); 117 118 break; 119 } 120 case Node.PROCESSING_INSTRUCTION_NODE : { 121 hereNode = xpathOwnerNodeDTM; 123 124 nodeSet.addNode(hereNode); 125 126 break; 127 } 128 case Node.TEXT_NODE : { 129 hereNode = dtm.getParent(xpathOwnerNodeDTM); 132 133 nodeSet.addNode(hereNode); 134 135 break; 136 } 137 default : 138 break; 139 } 140 } 141 142 143 nodeSet.detach(); 144 145 return nodes; 146 } 147 148 153 public void fixupVariables(java.util.Vector vars, int globalsSize) { 154 155 } 157 } 158 | Popular Tags |