1 28 29 package com.caucho.xsl.fun; 30 31 import com.caucho.xpath.Expr; 32 import com.caucho.xpath.ExprEnvironment; 33 import com.caucho.xpath.XPathException; 34 import com.caucho.xpath.XPathFun; 35 import com.caucho.xpath.pattern.AbstractPattern; 36 37 import org.w3c.dom.Document ; 38 import org.w3c.dom.DocumentType ; 39 import org.w3c.dom.Entity ; 40 import org.w3c.dom.NamedNodeMap ; 41 import org.w3c.dom.Node ; 42 43 import java.util.ArrayList ; 44 45 48 public class UnparsedEntityFun extends XPathFun { 49 55 public Object eval(Node node, ExprEnvironment env, 56 AbstractPattern pattern, ArrayList args) 57 throws XPathException 58 { 59 if (args.size() < 1) 60 return ""; 61 62 String name = Expr.toString(args.get(0)); 63 Document doc = node.getOwnerDocument(); 64 DocumentType dtd = doc.getDoctype(); 65 NamedNodeMap map = dtd.getEntities(); 66 Entity entity = (Entity ) map.getNamedItem(name); 67 68 if (entity == null) 69 return ""; 70 else if (entity.getSystemId() != null && ! entity.getSystemId().equals("")) 71 return entity.getSystemId(); 72 else 73 return entity.getPublicId(); 74 } 75 } 76 | Popular Tags |