📄 documenttypeimpl.java
字号:
}
/**
* Creates a new internal parameter and returns it. The entity value is given
* after character reference substitution.
*
* @param name The notation name
* @param value The entity value
* @return Returns a new entity node
*/
public ParamEntity createParamEntity( String name, String value ) {
ParamEntityProxy entity;
try {
entity = (ParamEntityProxy)database().createObject( ParamEntity.class.getName() );
entity.init( this, name, value );
} catch (Exception except) {
throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
}
return (ParamEntity)entity;
}
/**
* Declares a new parameter entity. If a parameter entity with the same name
* is already declared, it remains intact and the existing entity is returned.
* If no such entity exists, the entity is declared and returned.
*
* @param param The parameter entity to declare
* @return The declared entity
*/
public ParamEntity declareParamEntity( ParamEntity param ) {
ParamEntity old;
isReadOnly();
if (_params == null) {
_params = new Hashtable();
old = null;
} else {
old = (ParamEntity)_params.get( param.getNodeName() );
}
if (old == null) {
_params.put( param.getNodeName(), param );
return param;
} else {
return old;
}
}
/**
* Returns the named parameter entity if one has been declared.
*
*
* @param name The entity name
* @return The named parameter entity
*/
public ParamEntity findParamEntity( String name ) {
if (_params == null) {
return null;
}
return (ParamEntity)_params.get( name );
}
/**
* Returns a dictionary of all the parameter entitites declared in this
* DTD. If no PEs were declared, null is returned.
*
*
* @return Dictionary of param entities, or null
*/
public Dictionary getParamEntities() {
return _params;
}
public boolean isStandalone() {
return _standalone;
}
public Element getDocumentElement() {
return null;
}
/*
public Element createElement( String tagName )
throws DOMException
{
throw new DOMExceptionImpl( DOMException.NOT_SUPPORTED_ERR );
}
*/
public synchronized boolean equals( Object other ) {
DocumentTypeProxy otherX;
boolean equal;
// Use Node's equals method to perform the first tests of equality.
// If these tests do not pass, return false.
if (!super.equals( other )) {
return false;
}
// Very simple equality test: are the document types equal.
// There's nothing else about the document to compare.
synchronized (other) {
otherX = (DocumentTypeProxy)other;
equal = _standalone == otherX.getStandalone() && (_systemId == null && otherX.getSystemId() == null
|| _systemId != null && otherX.getSystemId() != null && _systemId.equals( otherX.getSystemId() )
&& (_publicId == null && otherX.getPublicId() == null || _publicId != null && otherX.getPublicId()
!= null && _publicId.equals( otherX.getPublicId() )));
if (equal) {
equal = _entities == null && otherX.getEntities() == null || _entities != null && otherX.getEntities()
!= null && _entities.equals( otherX.getEntities() );
}
if (equal) {
equal = _notations == null && otherX.getNotations() == null || _notations != null
&& otherX.getNotations() != null && _notations.equals( otherX.getNotations() );
}
if (equal) {
equal = _params == null && otherX.getParams() == null || _params != null && otherX.getParams() != null
&& _params.equals( otherX.getParams() );
}
}
return equal;
}
public Object clone() {
DocumentTypeProxy clone = null;
try {
clone = (DocumentTypeProxy)database().createObject( DocumentTypeImpl.class.getName(), 0, null );
clone.init( _systemId );
cloneInto( clone, true );
} catch (Exception except) {
throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
}
return clone;
}
public Node cloneNode( boolean deep ) {
DocumentTypeProxy clone = null;
try {
clone = (DocumentTypeProxy)database().createObject( DocumentTypeImpl.class.getName() );
clone.init( _systemId );
cloneInto( clone, deep );
} catch (Exception except) {
throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
}
return clone;
}
public String toString() {
String name;
name = getName();
if (name.length() > 32) {
name = name.substring( 0, 32 ) + "..";
}
name = name.replace( '\n', '|' );
return "Doctype { " + name + " }";
}
public synchronized void cloneInto( NodeProxy into, boolean deep ) {
Hashtable dictionary;
Enumeration enum;
Node node;
// Use the parent to clone the object. If the clone is shallow, the cloned
// will contain reference to the same node maps. If the clone is deep,
// these node maps must be duplicated.
super.cloneInto( into, deep );
((DocumentTypeProxy)into).setStandalone( _standalone );
((DocumentTypeProxy)into).setSystemId( _systemId );
((DocumentTypeProxy)into).setPublicId( _publicId );
if (deep) {
// Repeat this for each node map. Create a new dictionary, get an
// enumeration of the elements in the node map, one by one clone each
// element and place it in the new dictionary. Create a new node map
// with that new dictionary and associate it with the clone.
if (_entities != null) {
dictionary = new Hashtable();
enum = _entities.elements();
while (enum.hasMoreElements()) {
node = ((Node)enum.nextElement()).cloneNode( deep );
dictionary.put( node.getNodeName(), node );
}
try {
NamedNodeMapProxy entities =
(NamedNodeMapProxy)database().createObject( NamedNodeMapImpl.class.getName() );
entities.init( into, dictionary );
((DocumentTypeProxy)into).setEntities( entities );
} catch (Exception except) {
throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
}
}
// Repeat after me...
if (_notations != null) {
dictionary = new Hashtable();
enum = _notations.elements();
while (enum.hasMoreElements()) {
node = ((Node)enum.nextElement()).cloneNode( deep );
dictionary.put( node.getNodeName(), node );
}
try {
NamedNodeMapProxy notations =
(NamedNodeMapProxy)database().createObject( NamedNodeMapImpl.class.getName() );
notations.init( into, dictionary );
((DocumentTypeProxy)into).setNotations( notations );
} catch (Exception except) {
throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() );
}
}
// Repeat after me...
if (_params != null) {
dictionary = new Hashtable();
enum = _params.elements();
while (enum.hasMoreElements()) {
node = ((Node)enum.nextElement()).cloneNode( deep );
dictionary.put( node.getNodeName(), node );
}
((DocumentTypeProxy)into).setParams( dictionary );
}
} else {
((DocumentTypeProxy)into).setEntities( _entities );
((DocumentTypeProxy)into).setNotations( _notations );
((DocumentTypeProxy)into).setParams( _params );
}
}
protected Node castNewChild( Node newChild ) throws DOMException {
// New children can either be an entity, a notation, an element or an
// attribute definition.
if (newChild == null) {
throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR, "Child reference is null." );
}
if (!(newChild instanceof Node)) {
throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR,
"Child is not a compatible type for this node." );
}
if (!(newChild instanceof Entity || newChild instanceof ParamEntity || newChild instanceof Notation
|| newChild instanceof ElementDeclProxy || newChild instanceof AttlistDecl || newChild instanceof Text
|| newChild instanceof Comment || newChild instanceof ProcessingInstruction)) {
throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR,
"Child is not a compatible type for this node." );
}
return newChild;
}
public DocumentTypeImpl( String systemId ) {
super( null );
_ownerDocument = this;
_standalone = true;
_systemId = systemId;
}
public DocumentTypeImpl( Document owner, String rootElement, boolean standalone, String systemId,
String publicId ) {
super( rootElement );
_standalone = standalone;
_systemId = systemId;
_publicId = publicId;
}
public DocumentTypeImpl() {
super();
}
public void init( String systemId ) {
_ownerDocument = this;
_standalone = true;
_systemId = systemId;
}
/**
* Named node map provides access to an underlying hashtable that holds
* all the entities related with this DTD.
*/
private NamedNodeMapProxy _entities;
/**
* Named node map provides access to an underlying hashtable that holds
* all the notations related with this DTD.
*/
private NamedNodeMapProxy _notations;
/**
* The system identifier of this entity, if specified.
*/
private String _systemId;
/**
* The public identifier of this entity, if specified.
*/
private String _publicId;
/**
* True if the document type has been declared as standalone. Allows the
* document to be delivered with its DTD and no external subset.
*/
private boolean _standalone;
/**
* Named node map provides access to an underlying hashtable that holds
* all the parameter entities related with this DTD.
*/
private Hashtable _params;
/**
* Named node map provides access to an underlying hashtable that holds
* all the element definitions related with this DTD.
*/
// private Hashtable _elements;
/**
* Named node map provides access to an underlying hashtable that holds
* all the attribute definitions related with this DTD.
*/
// private Hashtable _attributes;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -