1 52 53 package freemarker.ext.dom; 54 55 import freemarker.template.*; 56 import freemarker.core.Environment; 57 import org.w3c.dom.*; 58 59 class AttributeNodeModel extends NodeModel implements TemplateScalarModel { 60 61 public AttributeNodeModel(Attr att) { 62 super(att); 63 } 64 65 public String getAsString() { 66 return ((Attr) node).getValue(); 67 } 68 69 public String getNodeName() { 70 String result = node.getLocalName(); 71 if (result == null || result.equals("")) { 72 result = node.getNodeName(); 73 } 74 return result; 75 } 76 77 public boolean isEmpty() { 78 return true; 79 } 80 81 String getQualifiedName() { 82 String nsURI = node.getNamespaceURI(); 83 if (nsURI == null || nsURI.equals("")) 84 return node.getNodeName(); 85 Environment env = Environment.getCurrentEnvironment(); 86 String defaultNS = env.getDefaultNS(); 87 String prefix = null; 88 if (nsURI.equals(defaultNS)) { 89 prefix = "D"; 90 } else { 91 prefix = env.getPrefixForNamespace(nsURI); 92 } 93 if (prefix == null) { 94 return null; 95 } 96 return prefix + ":" + node.getLocalName(); 97 } 98 } | Popular Tags |