protected void isEntityReferneceWellFormed ( EntityReference node ) { // Is the EntityReference name a valid XML name if ( ! isXMLName ( node . getNodeName ( ) , fIsXMLVersion11 ) ) { String msg = Utils . messages . createMessage ( MsgKey . ER_WF_INVALID_CHARACTER_IN_NODE_NAME , new Object [ ] { "EntityReference" , node . getNodeName ( ) } ) ; if ( fErrorHandler != null ) { fErrorHandler . handleError ( new DOMErrorImpl ( DOMError . SEVERITY_FATAL_ERROR , msg , MsgKey . ER_WF_INVALID_CHARACTER_IN_NODE_NAME , null , null , null ) ) ; } } // determine the parent node Node parent = node . getParentNode ( ) ; // Traverse the declared entities and check if the nodeName and namespaceURI // of the EntityReference matches an Entity. If so, check the if the notationName // is not null, if so, report an error. DocumentType docType = node . getOwnerDocument ( ) . getDoctype ( ) ; if ( docType != null ) { NamedNodeMap entities = docType . getEntities ( ) ; for ( int i = 0 ; i < entities . getLength ( ) ; i ++ ) { Entity ent = ( Entity ) entities . item ( i ) ; String nodeName = node . getNodeName ( ) == null ? "" : node . getNodeName ( ) ; String nodeNamespaceURI = node . getNamespaceURI ( ) == null ? "" : node . getNamespaceURI ( ) ; String entName = ent . getNodeName ( ) == null ? "" : ent . getNodeName ( ) ; String entNamespaceURI = ent . getNamespaceURI ( ) == null ? "" : ent . getNamespaceURI ( ) ; // If referenced in Element content // WFC: Parsed Entity if ( parent . getNodeType ( ) == Node . ELEMENT_NODE ) { if ( entNamespaceURI . equals ( nodeNamespaceURI ) && entName . equals ( nodeName ) ) { if ( ent . getNotationName ( ) != null ) { String msg = Utils . messages . createMessage ( MsgKey . ER_WF_REF_TO_UNPARSED_ENT , new Object [ ] { node . getNodeName ( ) } ) ; if ( fErrorHandler != null ) { fErrorHandler . handleError ( new DOMErrorImpl ( DOMError . SEVERITY_FATAL_ERROR , msg , MsgKey . ER_WF_REF_TO_UNPARSED_ENT , null , null , null ) ) ; } } } } // end if WFC: Parsed Entity // If referenced in an Attr value // WFC: No External Entity References if ( parent . getNodeType ( ) == Node . ATTRIBUTE_NODE ) { if ( entNamespaceURI . equals ( nodeNamespaceURI ) && entName . equals ( nodeName ) ) { if ( ent . getPublicId ( ) != null || ent . getSystemId ( ) != null || ent . getNotationName ( ) != null ) { String msg = Utils . messages . createMessage ( MsgKey . ER_WF_REF_TO_EXTERNAL_ENT , new Object [ ] { node . getNodeName ( ) } ) ; if ( fErrorHandler != null ) { fErrorHandler . handleError ( new DOMErrorImpl ( DOMError . SEVERITY_FATAL_ERROR , msg , MsgKey . ER_WF_REF_TO_EXTERNAL_ENT , null , null , null ) ) ; } } } } //end if WFC: No External Entity References } } }
Checks if an EntityRefernece node is well - formed by checking it s node name . Then depending on whether it is referenced in Element content or in an Attr Node checks if the EntityReference references an unparsed entity or a external entity and if so throws raises the appropriate well - formedness error .