1 61 62 63 package org.jaxen.function; 64 65 import java.util.List ; 66 67 import org.jaxen.Context; 68 import org.jaxen.Function; 69 import org.jaxen.FunctionCallException; 70 import org.jaxen.Navigator; 71 72 101 public class NamespaceUriFunction implements Function 102 { 103 104 107 public NamespaceUriFunction() {} 108 109 121 public Object call(Context context, 122 List args) throws FunctionCallException 123 { 124 if (args.size() == 0) 125 { 126 return evaluate( context.getNodeSet(), 127 context.getNavigator() ); 128 } 129 130 if ( args.size() == 1 ) 131 { 132 return evaluate( args, 133 context.getNavigator() ); 134 } 135 136 throw new FunctionCallException( "namespace-uri() requires zero or one argument." ); 137 } 138 139 149 public static String evaluate(List list, 150 Navigator nav) throws FunctionCallException 151 { 152 if ( ! list.isEmpty() ) 153 { 154 Object first = list.get(0); 155 156 if ( first instanceof List ) 157 { 158 return evaluate( (List ) first, 159 nav ); 160 } 161 else if ( nav.isElement( first ) ) 162 { 163 return nav.getElementNamespaceUri( first ); 164 } 165 else if ( nav.isAttribute( first ) ) 166 { 167 String uri = nav.getAttributeNamespaceUri( first ); 168 if (uri == null) return ""; 169 return uri; 170 } 171 else if ( nav.isProcessingInstruction( first ) ) 172 { 173 return ""; 174 } 175 else if ( nav.isNamespace( first ) ) 176 { 177 return ""; 178 } 179 else if ( nav.isDocument( first ) ) 180 { 181 return ""; 182 } 183 else if ( nav.isComment( first ) ) 184 { 185 return ""; 186 } 187 else if ( nav.isText( first ) ) 188 { 189 return ""; 190 } 191 else { 192 throw new FunctionCallException( 193 "The argument to the namespace-uri function must be a node-set"); 194 } 195 196 } 197 198 return ""; 199 200 } 201 } 202 203 | Popular Tags |