1 16 17 package org.apache.xerces.impl.dtd; 18 19 import org.apache.xerces.xni.grammars.XMLGrammarDescription; 20 import org.apache.xerces.xni.XMLResourceIdentifier; 21 import org.apache.xerces.xni.parser.XMLInputSource; 22 23 import org.apache.xerces.util.XMLResourceIdentifierImpl; 24 import java.util.Vector ; 25 26 34 public class XMLDTDDescription extends XMLResourceIdentifierImpl 35 implements org.apache.xerces.xni.grammars.XMLDTDDescription { 36 37 39 protected String fRootName = null; 42 43 protected Vector fPossibleRoots = null; 46 47 public XMLDTDDescription(XMLResourceIdentifier id, String rootName) { 49 this.setValues(id.getPublicId(), id.getLiteralSystemId(), 50 id.getBaseSystemId(), id.getExpandedSystemId()); 51 this.fRootName = rootName; 52 this.fPossibleRoots = null; 53 } 55 public XMLDTDDescription(String publicId, String literalId, 56 String baseId, String expandedId, String rootName) { 57 this.setValues(publicId, literalId, baseId, expandedId); 58 this.fRootName = rootName; 59 this.fPossibleRoots = null; 60 } 62 public XMLDTDDescription(XMLInputSource source) { 63 this.setValues(source.getPublicId(), null, 64 source.getBaseSystemId(), source.getSystemId()); 65 this.fRootName = null; 66 this.fPossibleRoots = null; 67 } 69 71 public String getGrammarType () { 72 return XMLGrammarDescription.XML_DTD; 73 } 75 78 public String getRootName() { 79 return fRootName; 80 } 82 83 public void setRootName(String rootName) { 84 fRootName = rootName; 85 fPossibleRoots = null; 86 } 87 88 89 public void setPossibleRoots(Vector possibleRoots) { 90 fPossibleRoots = possibleRoots; 91 } 92 93 106 public boolean equals(Object desc) { 107 if(!(desc instanceof XMLGrammarDescription)) return false; 108 if (!getGrammarType().equals(((XMLGrammarDescription)desc).getGrammarType())) { 109 return false; 110 } 111 XMLDTDDescription dtdDesc = (XMLDTDDescription)desc; 113 if(fRootName != null) { 114 if((dtdDesc.fRootName) != null && !dtdDesc.fRootName.equals(fRootName)) { 115 return false; 116 } else if(dtdDesc.fPossibleRoots != null && !dtdDesc.fPossibleRoots.contains(fRootName)) { 117 return false; 118 } 119 } else if(fPossibleRoots != null) { 120 if(dtdDesc.fRootName != null) { 121 if(!fPossibleRoots.contains(dtdDesc.fRootName)) { 122 return false; 123 } 124 } else if(dtdDesc.fPossibleRoots == null) { 125 return false; 126 } else { 127 boolean found = false; 128 for(int i = 0; i<fPossibleRoots.size(); i++) { 129 String root = (String )fPossibleRoots.elementAt(i); 130 found = dtdDesc.fPossibleRoots.contains(root); 131 if(found) break; 132 } 133 if(!found) return false; 134 } 135 } 136 if(fExpandedSystemId != null) { 139 if(!fExpandedSystemId.equals(dtdDesc.fExpandedSystemId)) 140 return false; 141 } 142 else if(dtdDesc.fExpandedSystemId != null) 143 return false; 144 if(fPublicId != null) { 145 if(!fPublicId.equals(dtdDesc.fPublicId)) 146 return false; 147 } 148 else if(dtdDesc.fPublicId != null) 149 return false; 150 return true; 151 } 152 153 159 public int hashCode() { 160 if(fExpandedSystemId != null) 161 return fExpandedSystemId.hashCode(); 162 if(fPublicId != null) 163 return fPublicId.hashCode(); 164 return 0; 166 } 167 } 169 | Popular Tags |