1 6 7 11 package com.hp.hpl.jena.rdql.parser; 12 13 import java.io.PrintWriter ; 14 import com.hp.hpl.jena.graph.Node; 15 import com.hp.hpl.jena.graph.query.Expression; 16 import com.hp.hpl.jena.graph.query.IndexValues; 17 import com.hp.hpl.jena.rdql.Query; 18 import com.hp.hpl.jena.rdql.QueryException; 19 import com.hp.hpl.jena.rdql.QueryPrintUtils; 20 21 public class Q_StringLangEqual extends ExprNode implements Expr, ExprBoolean 22 { 23 Expr left ; 24 Expr right ; 25 26 protected static String printName = "lang=" ; 27 protected static String opSymbol = "langeq" ; 28 29 Q_StringLangEqual(int id) { super(id); } 30 31 Q_StringLangEqual(RDQLParser p, int id) { super(p, id); } 32 33 protected boolean rawEval(NodeValue x, NodeValue y) 34 { 35 if ( x.isNode() && x.getNode().isLiteral() && 36 y.isNode() && y.getNode().isLiteral() ) 37 { 38 Node xNode = x.getNode() ; 39 Node yNode = y.getNode() ; 40 String nodeLang = xNode.getLiteral().language().toUpperCase(); 41 String queryLang = yNode.getLiteral().getLexicalForm().toUpperCase(); 42 49 if (queryLang.indexOf("-") >= 0) 50 { 51 return nodeLang.equals(queryLang); 52 } 53 else 54 { 55 int pos = nodeLang.indexOf("-"); 56 if (pos > 0) 57 nodeLang = nodeLang.substring(0, pos); 58 return nodeLang.equals(queryLang); 59 } 60 } 61 return false; 62 } 63 64 public NodeValue eval(Query q, IndexValues env) 65 { 66 NodeValue x = left.eval(q, env) ; 67 NodeValue y = right.eval(q, env) ; 68 69 boolean b = rawEval(x, y) ; 70 71 NodeValueSettable result ; 72 if ( x instanceof NodeValueSettable ) 73 result = (NodeValueSettable)x ; 74 else if ( y instanceof NodeValueSettable ) 75 result = (NodeValueSettable)y ; 76 else 77 result = new WorkingVar() ; 78 result.setBoolean(b) ; 79 return result ; 80 } 81 public void jjtClose() 82 { 83 int n = jjtGetNumChildren() ; 84 if ( n != 2 ) 85 throw new QueryException("Q_StringLangEqual: Wrong number of children: "+n) ; 86 left = (Expr)jjtGetChild(0) ; 87 right = (Expr)jjtGetChild(1) ; 88 } 89 90 public boolean isApply() { return true ; } 92 public String getFun() { return this.getClass().getName() ; } public int argCount() { return 2; } 94 public Expression getArg(int i) 95 { 96 if ( i == 0 && left instanceof Expression ) 97 return (Expression)left ; 98 if ( i == 1 && right instanceof Expression ) 99 return (Expression)right ; 100 return null; 101 } 102 104 public String asInfixString() 105 { 106 return QueryPrintUtils.asInfixString2(left, right, printName, opSymbol) ; 107 } 108 public String asPrefixString() 109 { 110 return QueryPrintUtils.asPrefixString(left, right, printName, opSymbol) ; 111 } 112 public void print(PrintWriter pw, int level) 113 { 114 QueryPrintUtils.print(pw, left, right, printName, opSymbol, level) ; 115 } 116 public String toString() 117 { 118 return asInfixString() ; 119 } 120 } 121 122 156 157 183 | Popular Tags |