1 28 29 package com.caucho.xpath.functions; 30 31 import com.caucho.util.L10N; 32 import com.caucho.xml.QAbstractNode; 33 import com.caucho.xpath.Expr; 34 import com.caucho.xpath.ExprEnvironment; 35 import com.caucho.xpath.XPathException; 36 import com.caucho.xpath.XPathParseException; 37 import com.caucho.xpath.expr.AbstractStringExpr; 38 39 import org.w3c.dom.Node ; 40 41 44 public class ResolveURI extends AbstractStringExpr { 45 private static final L10N L = new L10N(ResolveURI.class); 46 47 private Expr _relExpr; 48 private Expr _baseExpr; 49 50 public ResolveURI(Expr relExpr, Expr baseExpr) 51 throws XPathParseException 52 { 53 _relExpr = relExpr; 54 _baseExpr = baseExpr; 55 56 if (relExpr == null) 57 throw new XPathParseException(L.l("fn:resolve-uri(relative,[base])")); 58 } 59 60 68 public String evalString(Node node, ExprEnvironment env) 69 throws XPathException 70 { 71 String rel = _relExpr.evalString(node, env); 72 73 if (rel.startsWith("/") || 74 rel.indexOf(':') > 0 && rel.indexOf(':') < '/') 75 return rel; 76 77 String base; 78 79 if (_baseExpr != null) 80 base = _baseExpr.evalString(node, env); 81 else 82 base = QAbstractNode.baseURI(node); 83 84 int last = base.lastIndexOf('/'); 85 86 if (last < 0) 87 return rel; 88 else 89 return base.substring(0, last + 1) + rel; 90 } 91 92 public String toString() 93 { 94 if (_baseExpr != null) 95 return "fn:resolve-uri(" + _relExpr + "," + _baseExpr + ")"; 96 else 97 return "fn:resolve-uri(" + _relExpr + ")"; 98 } 99 } 100 | Popular Tags |