1 16 19 package org.apache.xpath.functions; 20 21 import org.apache.xalan.res.XSLMessages; 22 import org.apache.xml.dtm.DTM; 23 import org.apache.xml.utils.XMLString; 24 import org.apache.xpath.XPathContext; 25 import org.apache.xpath.objects.XString; 26 import org.apache.xpath.res.XPATHErrorResources; 27 28 33 public class FunctionDef1Arg extends FunctionOneArg 34 { 35 36 48 protected int getArg0AsNode(XPathContext xctxt) 49 throws javax.xml.transform.TransformerException 50 { 51 52 return (null == m_arg0) 53 ? xctxt.getCurrentNode() : m_arg0.asNode(xctxt); 54 } 55 56 60 public boolean Arg0IsNodesetExpr() 61 { 62 return (null == m_arg0) ? true : m_arg0.isNodesetExpr(); 63 } 64 65 78 protected XMLString getArg0AsString(XPathContext xctxt) 79 throws javax.xml.transform.TransformerException 80 { 81 if(null == m_arg0) 82 { 83 int currentNode = xctxt.getCurrentNode(); 84 if(DTM.NULL == currentNode) 85 return XString.EMPTYSTRING; 86 else 87 { 88 DTM dtm = xctxt.getDTM(currentNode); 89 return dtm.getStringValue(currentNode); 90 } 91 92 } 93 else 94 return m_arg0.execute(xctxt).xstr(); 95 } 96 97 110 protected double getArg0AsNumber(XPathContext xctxt) 111 throws javax.xml.transform.TransformerException 112 { 113 114 if(null == m_arg0) 115 { 116 int currentNode = xctxt.getCurrentNode(); 117 if(DTM.NULL == currentNode) 118 return 0; 119 else 120 { 121 DTM dtm = xctxt.getDTM(currentNode); 122 XMLString str = dtm.getStringValue(currentNode); 123 return str.toDouble(); 124 } 125 126 } 127 else 128 return m_arg0.execute(xctxt).num(); 129 } 130 131 138 public void checkNumberArgs(int argNum) throws WrongNumberArgsException 139 { 140 if (argNum > 1) 141 reportWrongNumberArgs(); 142 } 143 144 150 protected void reportWrongNumberArgs() throws WrongNumberArgsException { 151 throw new WrongNumberArgsException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ZERO_OR_ONE, null)); } 153 154 160 public boolean canTraverseOutsideSubtree() 161 { 162 return (null == m_arg0) ? false : super.canTraverseOutsideSubtree(); 163 } 164 } 165 | Popular Tags |