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 91 public class NameFunction implements Function 92 { 93 94 95 98 public NameFunction() {} 99 100 112 public Object call(Context context, 113 List args) throws FunctionCallException 114 { 115 if ( args.size() == 0 ) 116 { 117 return evaluate( context.getNodeSet(), 118 context.getNavigator() ); 119 } 120 121 if ( args.size() == 1 ) 122 { 123 return evaluate( args, 124 context.getNavigator() ); 125 } 126 127 throw new FunctionCallException( "name() requires zero or one argument." ); 128 } 129 130 140 public static String evaluate(List list, 141 Navigator nav) throws FunctionCallException 142 { 143 if ( ! list.isEmpty() ) 144 { 145 Object first = list.get(0); 146 147 if (first instanceof List ) 148 { 149 return evaluate( (List ) first, 150 nav ); 151 } 152 else if ( nav.isElement( first ) ) 153 { 154 return nav.getElementQName( first ); 155 } 156 else if ( nav.isAttribute( first ) ) 157 { 158 return nav.getAttributeQName( first ); 159 } 160 else if ( nav.isProcessingInstruction( first ) ) 161 { 162 return nav.getProcessingInstructionTarget( first ); 163 } 164 else if ( nav.isNamespace( first ) ) 165 { 166 return nav.getNamespacePrefix( first ); 167 } 168 else if ( nav.isDocument( first ) ) 169 { 170 return ""; 171 } 172 else if ( nav.isComment( first ) ) 173 { 174 return ""; 175 } 176 else if ( nav.isText( first ) ) 177 { 178 return ""; 179 } 180 else { 181 throw new FunctionCallException("The argument to the name function must be a node-set"); 182 } 183 } 184 185 return ""; 186 187 } 188 189 } 190 | Popular Tags |