1 3 package com.nwalsh.xalan; 4 5 import org.apache.xpath.objects.XObject; 6 import org.apache.xpath.XPathContext; 7 import org.apache.xalan.extensions.ExpressionContext; 8 import org.apache.xml.utils.QName; 9 10 import javax.xml.transform.TransformerException ; 11 12 public class Params { 13 14 public static String getString(ExpressionContext context, 15 String varName) { 16 try { 17 XObject var = context.getVariableOrParam(new QName(varName)); 18 if (var != null) { 19 return var.toString(); 20 } else { 21 System.out.println("$" + varName + " is not a defined parameter."); 22 return ""; 23 } 24 } catch (TransformerException te) { 25 return ""; 28 } 29 } 30 31 public static int getInt(ExpressionContext context, 32 String varName) { 33 String stringValue = getString(context, varName); 34 if (stringValue != null) { 35 try { 36 int value = Integer.parseInt(stringValue); 37 return value; 38 } catch (NumberFormatException e) { 39 System.out.println("$" + varName + " is not an integer."); 40 } 41 } 42 return 0; 43 } 44 45 public static boolean getBoolean(ExpressionContext context, 46 String varName) { 47 String stringValue = getString(context, varName); 48 if (stringValue != null) { 49 if (stringValue.equals("0") || stringValue.equals("")) { 50 return false; 51 } else { 52 return true; 53 } 54 } else { 55 return false; 56 } 57 } 58 } 59 | Popular Tags |