|
|
|
|
|
*/ |
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
* (the "License"); you may not use this file except in compliance with |
|
* the License. You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.sun.org.apache.xerces.internal.impl.dtd; |
|
|
|
import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl; |
|
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; |
|
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; |
|
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; |
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class XMLDTDDescription extends XMLResourceIdentifierImpl |
|
implements com.sun.org.apache.xerces.internal.xni.grammars.XMLDTDDescription { |
|
|
|
// Data |
|
|
|
// pieces of information needed to make this usable as a Grammar key |
|
|
|
protected String fRootName = null; |
|
|
|
// if we don't know the root name, this stores all elements that |
|
|
|
protected List<String> fPossibleRoots = null; |
|
|
|
|
|
public XMLDTDDescription(XMLResourceIdentifier id, String rootName) { |
|
this.setValues(id.getPublicId(), id.getLiteralSystemId(), |
|
id.getBaseSystemId(), id.getExpandedSystemId()); |
|
this.fRootName = rootName; |
|
this.fPossibleRoots = null; |
|
} // init(XMLResourceIdentifier, String) |
|
|
|
public XMLDTDDescription(String publicId, String literalId, |
|
String baseId, String expandedId, String rootName) { |
|
this.setValues(publicId, literalId, baseId, expandedId); |
|
this.fRootName = rootName; |
|
this.fPossibleRoots = null; |
|
} // init(String, String, String, String, String) |
|
|
|
public XMLDTDDescription(XMLInputSource source) { |
|
this.setValues(source.getPublicId(), null, |
|
source.getBaseSystemId(), source.getSystemId()); |
|
this.fRootName = null; |
|
this.fPossibleRoots = null; |
|
} // init(XMLInputSource) |
|
|
|
// XMLGrammarDescription methods |
|
|
|
public String getGrammarType () { |
|
return XMLGrammarDescription.XML_DTD; |
|
} // getGrammarType(): String |
|
|
|
|
|
|
|
*/ |
|
public String getRootName() { |
|
return fRootName; |
|
} // getRootName(): String |
|
|
|
|
|
public void setRootName(String rootName) { |
|
fRootName = rootName; |
|
fPossibleRoots = null; |
|
} |
|
|
|
|
|
public void setPossibleRoots(List<String> possibleRoots) { |
|
fPossibleRoots = possibleRoots; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public boolean equals(Object desc) { |
|
if (!(desc instanceof XMLGrammarDescription)) return false; |
|
if (!getGrammarType().equals(((XMLGrammarDescription)desc).getGrammarType())) { |
|
return false; |
|
} |
|
|
|
XMLDTDDescription dtdDesc = (XMLDTDDescription)desc; |
|
if (fRootName != null) { |
|
if ((dtdDesc.fRootName) != null && !dtdDesc.fRootName.equals(fRootName)) { |
|
return false; |
|
} |
|
else if (dtdDesc.fPossibleRoots != null && !dtdDesc.fPossibleRoots.contains(fRootName)) { |
|
return false; |
|
} |
|
} |
|
else if (fPossibleRoots != null) { |
|
if (dtdDesc.fRootName != null) { |
|
if (!fPossibleRoots.contains(dtdDesc.fRootName)) { |
|
return false; |
|
} |
|
} |
|
else if (dtdDesc.fPossibleRoots == null) { |
|
return false; |
|
} |
|
else { |
|
boolean found = false; |
|
for (String root : fPossibleRoots) { |
|
found = dtdDesc.fPossibleRoots.contains(root); |
|
if (found) break; |
|
} |
|
if (!found) return false; |
|
} |
|
} |
|
// if we got this far we've got a root match... try other two fields, |
|
|
|
if (fExpandedSystemId != null) { |
|
if (!fExpandedSystemId.equals(dtdDesc.fExpandedSystemId)) { |
|
return false; |
|
} |
|
} |
|
else if (dtdDesc.fExpandedSystemId != null) { |
|
return false; |
|
} |
|
if (fPublicId != null) { |
|
if (!fPublicId.equals(dtdDesc.fPublicId)) { |
|
return false; |
|
} |
|
} |
|
else if (dtdDesc.fPublicId != null) { |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public int hashCode() { |
|
if (fExpandedSystemId != null) { |
|
return fExpandedSystemId.hashCode(); |
|
} |
|
if (fPublicId != null) { |
|
return fPublicId.hashCode(); |
|
} |
|
|
|
return 0; |
|
} |
|
} // class XMLDTDDescription |