1 19 20 package org.netbeans.modules.xml.xdm.nodes; 21 22 import java.lang.ref.SoftReference ; 23 import java.util.Map ; 24 import javax.xml.XMLConstants ; 25 import org.netbeans.modules.xml.xdm.visitor.FindNamespaceVisitor; 26 import org.netbeans.modules.xml.xdm.visitor.XMLNodeVisitor; 27 import org.w3c.dom.DOMException ; 28 import org.w3c.dom.NodeList ; 29 30 34 public class Document extends NodeImpl implements Node, org.w3c.dom.Document { 35 36 37 Document() { 38 super(); 39 resetNamespaceCache(); 40 } 41 42 public Document clone(boolean cloneContent, boolean cloneAttributes, boolean cloneChildren) { 43 Document ret = (Document) super.clone(cloneContent, cloneAttributes, cloneChildren); 44 ret.resetNamespaceCache(); 45 return ret; 46 } 47 48 void resetNamespaceCache() { 49 fnv = null; 50 } 51 52 public short getNodeType() { 53 return Node.DOCUMENT_NODE; 54 } 55 56 public String getNodeName() { 57 return "#document"; } 59 60 public void accept(XMLNodeVisitor visitor) { 61 visitor.visit(this); 62 } 63 64 133 public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) { 134 return null; 136 } 137 138 249 public org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode, boolean deep) { 250 return null; 252 } 253 254 321 public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName) { 322 return null; 324 } 325 326 331 public org.w3c.dom.Text createTextNode(String data) { 332 return new Text(data); 333 } 334 335 360 public org.w3c.dom.EntityReference createEntityReference(String name) { 361 return null; 363 } 364 365 388 public org.w3c.dom.Element createElement(String tagName) { 389 return new Element(tagName); 390 } 391 392 397 public org.w3c.dom.Comment createComment(String data) { 398 return new Comment(data); 399 } 400 401 409 public org.w3c.dom.CDATASection createCDATASection(String data) { 410 return new CData(data); 411 } 412 413 429 public org.w3c.dom.Attr createAttribute(String name) { 430 return new Attribute(name); 431 } 432 433 451 public org.w3c.dom.ProcessingInstruction createProcessingInstruction(String target, String data) { 452 return null; 454 } 455 456 516 public org.w3c.dom.Element createElementNS(String namespaceURI, String qualifiedName) { 517 Element ret = new Element(qualifiedName); 518 String prefix = ret.getPrefix(); 519 if (prefix != null) { 520 if (namespaceURI == null) { 521 throw new DOMException (DOMException.NAMESPACE_ERR, null); 522 } 523 ret.appendAttribute(new Attribute("xmlns:"+prefix, namespaceURI)); } else { 525 ret = new Element(ret.getLocalName()); 526 if (namespaceURI != null && ! namespaceURI.equals(XMLConstants.NULL_NS_URI)) { 527 ret.appendAttribute(new Attribute(XMLNS, namespaceURI)); 528 } 529 } 530 return ret; 531 } 532 533 537 public org.w3c.dom.DocumentFragment createDocumentFragment() { 538 return null; 540 } 541 542 607 public org.w3c.dom.Attr createAttributeNS(String namespaceURI, String qualifiedName) { 608 return new Attribute(qualifiedName); 610 } 611 612 625 public org.w3c.dom.Element getElementById(String elementId) { 626 return null; 628 } 629 630 641 public org.w3c.dom.NodeList getElementsByTagName(String tagname) { 642 return null; 644 } 645 646 657 public org.w3c.dom.NodeList getElementsByTagNameNS(String namespaceURI, String localName) { 658 return null; 660 } 661 662 694 public void normalizeDocument() { 695 } 697 698 702 public org.w3c.dom.Element getDocumentElement() { 703 if(hasChildNodes()) { 704 NodeList childNodes = getChildNodes(); 705 for (int i=0;i<childNodes.getLength(); i++) { 706 Node child = (Node)childNodes.item(i); 707 if (child instanceof org.w3c.dom.Element ) 708 return (org.w3c.dom.Element )child; 709 } 710 } 711 return null; 712 } 713 714 734 public org.w3c.dom.DocumentType getDoctype() { 735 return null; 737 } 738 739 752 public void setDocumentURI(String documentURI) { 753 } 754 755 768 public String getDocumentURI() { 769 return null; 771 } 772 773 778 public org.w3c.dom.DOMConfiguration getDomConfig() { 779 return null; 781 } 782 783 787 public org.w3c.dom.DOMImplementation getImplementation() { 788 return null; 790 } 791 792 798 public String getInputEncoding() { 799 return null; 801 } 802 803 813 public void setStrictErrorChecking(boolean strictErrorChecking) { 814 } 815 816 826 public boolean getStrictErrorChecking() { 827 return false; 829 } 830 831 837 public String getXmlEncoding() { 838 for (Token token : super.getTokens()) { 839 if(token.getType() == TokenType.TOKEN_PI_VAL) { 840 String versionImage = token.getValue(); 841 int versionIndex = versionImage.indexOf("encoding"); 842 if(versionIndex == -1) return null; 843 versionIndex = versionImage.indexOf('=',versionIndex); 844 if(versionIndex == -1) return null; 845 versionImage = versionImage.substring(versionIndex+1).trim(); 846 if(versionImage.startsWith("\"")) { 847 int versionEndIndex = versionImage.indexOf('"',1); 848 if(versionEndIndex == -1) return null; 849 return versionImage.substring(1,versionEndIndex); 850 } else if(versionImage.startsWith("'")) { 851 int versionEndIndex = versionImage.indexOf('\'',1); 852 if(versionEndIndex == -1) return null; 853 return versionImage.substring(1,versionEndIndex); 854 } 855 } 856 } 857 return null; 858 } 859 860 873 public void setXmlStandalone(boolean xmlStandalone) { 874 } 876 877 887 public boolean getXmlStandalone() { 888 for (Token token : super.getTokens()) { 889 if(token.getType() == TokenType.TOKEN_PI_VAL) { 890 String versionImage = token.getValue(); 891 int versionIndex = versionImage.indexOf("standalone"); 892 if(versionIndex == -1) return false; 893 versionIndex = versionImage.indexOf('=',versionIndex); 894 if(versionIndex == -1) return false; 895 versionImage = versionImage.substring(versionIndex+1).trim(); 896 if(versionImage.startsWith("\"")) { 897 int versionEndIndex = versionImage.indexOf('"',1); 898 if(versionEndIndex == -1) return false; 899 return versionImage.substring(1,versionEndIndex).equals("yes"); 900 } else if(versionImage.startsWith("'")) { 901 int versionEndIndex = versionImage.indexOf('\'',1); 902 if(versionEndIndex == -1) return false; 903 return versionImage.substring(1,versionEndIndex).equals("yes"); 904 } 905 } 906 } 907 return false; 908 } 909 910 938 public void setXmlVersion(String xmlVersion) { 939 } 941 942 966 public String getXmlVersion() { 967 for (Token token : super.getTokens()) { 968 if(token.getType() == TokenType.TOKEN_PI_VAL) { 969 String versionImage = token.getValue(); 970 int versionIndex = versionImage.indexOf("version"); 971 if(versionIndex == -1) return null; 972 versionIndex = versionImage.indexOf('=',versionIndex); 973 if(versionIndex == -1) return null; 974 versionImage = versionImage.substring(versionIndex+1).trim(); 975 if(versionImage.startsWith("\"")) { 976 int versionEndIndex = versionImage.indexOf('"',1); 977 if(versionEndIndex == -1) return null; 978 return versionImage.substring(1,versionEndIndex); 979 } else if(versionImage.startsWith("'")) { 980 int versionEndIndex = versionImage.indexOf('\'',1); 981 if(versionEndIndex == -1) return null; 982 return versionImage.substring(1,versionEndIndex); 983 } 984 } 985 } 986 return null; 987 } 988 989 994 public String getNamespaceURI(Node node) { 995 return getNamespaceCache().findNamespace(node); 996 } 997 998 private FindNamespaceVisitor getNamespaceCache() { 999 if (fnv == null || fnv.get() == null) { 1000 fnv = new SoftReference (new FindNamespaceVisitor(this)); 1001 } 1002 return fnv.get(); 1003 } 1004 1005 Map <Integer ,String > getNamespaceMap() { 1006 return getNamespaceCache().getNamespaceMap(); 1007 } 1008 1009 1012 private SoftReference <FindNamespaceVisitor> fnv; 1013} 1014 | Popular Tags |