org.w3c.dom.Entity Java Examples

The following examples show how to use org.w3c.dom.Entity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntitiesCompletionParticipant.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Collect external entities.
 * 
 * @param document    the DOM document.
 * @param entityRange the entity range.
 * @param markdown    true if the documentation can be formatted as markdown and
 *                    false otherwise.
 * @param request     the completion request.
 * @param response    the completion response.
 */
private static void collectExternalEntityProposals(DOMDocument document, Range entityRange, boolean markdown,
		ICompletionRequest request, ICompletionResponse response) {
	ContentModelManager contentModelManager = request.getComponent(ContentModelManager.class);
	Collection<CMDocument> cmDocuments = contentModelManager.findCMDocument(document, null, false);
	for (CMDocument cmDocument : cmDocuments) {
		List<Entity> entities = cmDocument.getEntities();
		for (Entity entity : entities) {
			if (entity.getNodeName() != null) {
				// provide completion for the external declared entity
				MarkupContent documentation = EntitiesDocumentationUtils.getDocumentation((DTDEntityDecl) entity,
						EntityOriginType.EXTERNAL, markdown);
				fillCompletion(entity.getNodeName(), documentation, entityRange, response);
			}
		}
	}
}
 
Example #2
Source File: EntitiesCompletionParticipant.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Collect local entities declared in the DOCTYPE.
 * 
 * @param document    the DOM document.
 * @param entityRange the entity range.
 * @param markdown    true if the documentation can be formatted as markdown and
 *                    false otherwise.
 * @param response    the completion response.
 */
private static void collectLocalEntityProposals(DOMDocument document, Range entityRange, boolean markdown,
		ICompletionResponse response) {
	DOMDocumentType docType = document.getDoctype();
	if (docType == null) {
		return;
	}
	NamedNodeMap entities = docType.getEntities();
	for (int i = 0; i < entities.getLength(); i++) {
		Entity entity = (Entity) entities.item(i);
		if (entity.getNodeName() != null) {
			// provide completion for the locally declared entity
			MarkupContent documentation = EntitiesDocumentationUtils.getDocumentation((DTDEntityDecl) entity,
					EntityOriginType.LOCAL, markdown);
			fillCompletion(entity.getNodeName(), documentation, entityRange, response);
		}
	}
}
 
Example #3
Source File: EntitiesHoverParticipant.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the markup content of the given entity name in the external entities
 * and null otherwise.
 * 
 * @param entityName  the entity name to search.
 * @param entityRange the hovered range.
 * @param document    the DOM document
 * @param request     the hover request.
 * @return the markup content of the given entity name in the external entities
 *         and null otherwise.
 */
private static MarkupContent searchInExternalEntities(String entityName, Range entityRange, DOMDocument document,
		IHoverRequest request) {
	ContentModelManager contentModelManager = request.getComponent(ContentModelManager.class);
	Collection<CMDocument> cmDocuments = contentModelManager.findCMDocument(document, null, false);
	for (CMDocument cmDocument : cmDocuments) {
		List<Entity> entities = cmDocument.getEntities();
		for (Entity ent : entities) {
			DTDEntityDecl entity = (DTDEntityDecl) ent;
			if (entityName.equals(entity.getName())) {
				boolean markdown = request.canSupportMarkupKind(MarkupKind.MARKDOWN);
				return EntitiesDocumentationUtils.getDocumentation(entity, EntityOriginType.EXTERNAL, markdown);
			}
		}
	}
	return null;
}
 
Example #4
Source File: SAXImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The getUnparsedEntityURI function returns the URI of the unparsed
 * entity with the specified name in the same document as the context
 * node (see [3.3 Unparsed Entities]). It returns the empty string if
 * there is no such entity.
 */
public String getUnparsedEntityURI(String name)
{
    // Special handling for DOM input
    if (_document != null) {
        String uri = "";
        DocumentType doctype = _document.getDoctype();
        if (doctype != null) {
            NamedNodeMap entities = doctype.getEntities();

            if (entities == null) {
                return uri;
            }

            Entity entity = (Entity) entities.getNamedItem(name);

            if (entity == null) {
                return uri;
            }

            String notationName = entity.getNotationName();
            if (notationName != null) {
                uri = entity.getSystemId();
                if (uri == null) {
                    uri = entity.getPublicId();
                }
            }
        }
        return uri;
    }
    else {
        return super.getUnparsedEntityURI(name);
    }
}
 
Example #5
Source File: SAXImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The getUnparsedEntityURI function returns the URI of the unparsed
 * entity with the specified name in the same document as the context
 * node (see [3.3 Unparsed Entities]). It returns the empty string if
 * there is no such entity.
 */
public String getUnparsedEntityURI(String name)
{
    // Special handling for DOM input
    if (_document != null) {
        String uri = "";
        DocumentType doctype = _document.getDoctype();
        if (doctype != null) {
            NamedNodeMap entities = doctype.getEntities();

            if (entities == null) {
                return uri;
            }

            Entity entity = (Entity) entities.getNamedItem(name);

            if (entity == null) {
                return uri;
            }

            String notationName = entity.getNotationName();
            if (notationName != null) {
                uri = entity.getSystemId();
                if (uri == null) {
                    uri = entity.getPublicId();
                }
            }
        }
        return uri;
    }
    else {
        return super.getUnparsedEntityURI(name);
    }
}
 
Example #6
Source File: DOMValidatorHelper.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public boolean isEntityUnparsed(String name) {
    if (fEntities != null) {
        Entity entity = (Entity) fEntities.getNamedItem(name);
        if (entity != null) {
            return (entity.getNotationName() != null);
        }
    }
    return false;
}
 
Example #7
Source File: DOMResultBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}
 
Example #8
Source File: SAXImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The getUnparsedEntityURI function returns the URI of the unparsed
 * entity with the specified name in the same document as the context
 * node (see [3.3 Unparsed Entities]). It returns the empty string if
 * there is no such entity.
 */
public String getUnparsedEntityURI(String name)
{
    // Special handling for DOM input
    if (_document != null) {
        String uri = "";
        DocumentType doctype = _document.getDoctype();
        if (doctype != null) {
            NamedNodeMap entities = doctype.getEntities();

            if (entities == null) {
                return uri;
            }

            Entity entity = (Entity) entities.getNamedItem(name);

            if (entity == null) {
                return uri;
            }

            String notationName = entity.getNotationName();
            if (notationName != null) {
                uri = entity.getSystemId();
                if (uri == null) {
                    uri = entity.getPublicId();
                }
            }
        }
        return uri;
    }
    else {
        return super.getUnparsedEntityURI(name);
    }
}
 
Example #9
Source File: CoreDocumentImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * NON-DOM Factory method; creates an Entity having this Document as its
 * OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
 * information unspecified.)
 *
 * @param name The name of the Entity we wish to provide a value for.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * nonstandard entities are not permitted. (HTML not yet implemented.)
 */
public Entity createEntity(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name, xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new EntityImpl(this, name);

}
 
Example #10
Source File: DOMValidatorHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean isEntityUnparsed(String name) {
    if (fEntities != null) {
        Entity entity = (Entity) fEntities.getNamedItem(name);
        if (entity != null) {
            return (entity.getNotationName() != null);
        }
    }
    return false;
}
 
Example #11
Source File: DOMResultBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}
 
Example #12
Source File: SAXImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * The getUnparsedEntityURI function returns the URI of the unparsed
 * entity with the specified name in the same document as the context
 * node (see [3.3 Unparsed Entities]). It returns the empty string if
 * there is no such entity.
 */
public String getUnparsedEntityURI(String name)
{
    // Special handling for DOM input
    if (_document != null) {
        String uri = "";
        DocumentType doctype = _document.getDoctype();
        if (doctype != null) {
            NamedNodeMap entities = doctype.getEntities();

            if (entities == null) {
                return uri;
            }

            Entity entity = (Entity) entities.getNamedItem(name);

            if (entity == null) {
                return uri;
            }

            String notationName = entity.getNotationName();
            if (notationName != null) {
                uri = entity.getSystemId();
                if (uri == null) {
                    uri = entity.getPublicId();
                }
            }
        }
        return uri;
    }
    else {
        return super.getUnparsedEntityURI(name);
    }
}
 
Example #13
Source File: CoreDocumentImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * NON-DOM Factory method; creates an Entity having this Document as its
 * OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
 * information unspecified.)
 *
 * @param name The name of the Entity we wish to provide a value for.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * nonstandard entities are not permitted. (HTML not yet implemented.)
 */
public Entity createEntity(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name, xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new EntityImpl(this, name);

}
 
Example #14
Source File: DOMValidatorHelper.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public boolean isEntityUnparsed(String name) {
    if (fEntities != null) {
        Entity entity = (Entity) fEntities.getNamedItem(name);
        if (entity != null) {
            return (entity.getNotationName() != null);
        }
    }
    return false;
}
 
Example #15
Source File: DOMResultBuilder.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}
 
Example #16
Source File: CoreDocumentImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * NON-DOM Factory method; creates an Entity having this Document as its
 * OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
 * information unspecified.)
 *
 * @param name The name of the Entity we wish to provide a value for.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * nonstandard entities are not permitted. (HTML not yet implemented.)
 */
public Entity createEntity(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name, xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new EntityImpl(this, name);

}
 
Example #17
Source File: CoreDocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * NON-DOM Factory method; creates an Entity having this Document as its
 * OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
 * information unspecified.)
 *
 * @param name The name of the Entity we wish to provide a value for.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * nonstandard entities are not permitted. (HTML not yet implemented.)
 */
public Entity createEntity(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name, xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new EntityImpl(this, name);

}
 
Example #18
Source File: DOMValidatorHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean isEntityUnparsed(String name) {
    if (fEntities != null) {
        Entity entity = (Entity) fEntities.getNamedItem(name);
        if (entity != null) {
            return (entity.getNotationName() != null);
        }
    }
    return false;
}
 
Example #19
Source File: DOMResultBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}
 
Example #20
Source File: SAXImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The getUnparsedEntityURI function returns the URI of the unparsed
 * entity with the specified name in the same document as the context
 * node (see [3.3 Unparsed Entities]). It returns the empty string if
 * there is no such entity.
 */
public String getUnparsedEntityURI(String name)
{
    // Special handling for DOM input
    if (_document != null) {
        String uri = "";
        DocumentType doctype = _document.getDoctype();
        if (doctype != null) {
            NamedNodeMap entities = doctype.getEntities();

            if (entities == null) {
                return uri;
            }

            Entity entity = (Entity) entities.getNamedItem(name);

            if (entity == null) {
                return uri;
            }

            String notationName = entity.getNotationName();
            if (notationName != null) {
                uri = entity.getSystemId();
                if (uri == null) {
                    uri = entity.getPublicId();
                }
            }
        }
        return uri;
    }
    else {
        return super.getUnparsedEntityURI(name);
    }
}
 
Example #21
Source File: CoreDocumentImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * NON-DOM Factory method; creates an Entity having this Document as its
 * OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
 * information unspecified.)
 *
 * @param name The name of the Entity we wish to provide a value for.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * nonstandard entities are not permitted. (HTML not yet implemented.)
 */
public Entity createEntity(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name, xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new EntityImpl(this, name);

}
 
Example #22
Source File: DOMValidatorHelper.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean isEntityUnparsed(String name) {
    if (fEntities != null) {
        Entity entity = (Entity) fEntities.getNamedItem(name);
        if (entity != null) {
            return (entity.getNotationName() != null);
        }
    }
    return false;
}
 
Example #23
Source File: DOMResultBuilder.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}
 
Example #24
Source File: SAXImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The getUnparsedEntityURI function returns the URI of the unparsed
 * entity with the specified name in the same document as the context
 * node (see [3.3 Unparsed Entities]). It returns the empty string if
 * there is no such entity.
 */
public String getUnparsedEntityURI(String name)
{
    // Special handling for DOM input
    if (_document != null) {
        String uri = "";
        DocumentType doctype = _document.getDoctype();
        if (doctype != null) {
            NamedNodeMap entities = doctype.getEntities();

            if (entities == null) {
                return uri;
            }

            Entity entity = (Entity) entities.getNamedItem(name);

            if (entity == null) {
                return uri;
            }

            String notationName = entity.getNotationName();
            if (notationName != null) {
                uri = entity.getSystemId();
                if (uri == null) {
                    uri = entity.getPublicId();
                }
            }
        }
        return uri;
    }
    else {
        return super.getUnparsedEntityURI(name);
    }
}
 
Example #25
Source File: DOMValidatorHelper.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public boolean isEntityUnparsed(String name) {
    if (fEntities != null) {
        Entity entity = (Entity) fEntities.getNamedItem(name);
        if (entity != null) {
            return (entity.getNotationName() != null);
        }
    }
    return false;
}
 
Example #26
Source File: DOMResultBuilder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}
 
Example #27
Source File: SAXImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The getUnparsedEntityURI function returns the URI of the unparsed
 * entity with the specified name in the same document as the context
 * node (see [3.3 Unparsed Entities]). It returns the empty string if
 * there is no such entity.
 */
public String getUnparsedEntityURI(String name)
{
    // Special handling for DOM input
    if (_document != null) {
        String uri = "";
        DocumentType doctype = _document.getDoctype();
        if (doctype != null) {
            NamedNodeMap entities = doctype.getEntities();

            if (entities == null) {
                return uri;
            }

            Entity entity = (Entity) entities.getNamedItem(name);

            if (entity == null) {
                return uri;
            }

            String notationName = entity.getNotationName();
            if (notationName != null) {
                uri = entity.getSystemId();
                if (uri == null) {
                    uri = entity.getPublicId();
                }
            }
        }
        return uri;
    }
    else {
        return super.getUnparsedEntityURI(name);
    }
}
 
Example #28
Source File: DOMValidatorHelper.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean isEntityUnparsed(String name) {
    if (fEntities != null) {
        Entity entity = (Entity) fEntities.getNamedItem(name);
        if (entity != null) {
            return (entity.getNotationName() != null);
        }
    }
    return false;
}
 
Example #29
Source File: DOMResultBuilder.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void doctypeDecl(DocumentType node) throws XNIException {
    /** Create new DocumentType node for the target. */
    if (fDocumentImpl != null) {
        DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
        final String internalSubset = node.getInternalSubset();
        /** Copy internal subset. */
        if (internalSubset != null) {
            ((DocumentTypeImpl) docType).setInternalSubset(internalSubset);
        }
        /** Copy entities. */
        NamedNodeMap oldMap = node.getEntities();
        NamedNodeMap newMap = docType.getEntities();
        int length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Entity oldEntity = (Entity) oldMap.item(i);
            EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
            newEntity.setPublicId(oldEntity.getPublicId());
            newEntity.setSystemId(oldEntity.getSystemId());
            newEntity.setNotationName(oldEntity.getNotationName());
            newMap.setNamedItem(newEntity);
        }
        /** Copy notations. */
        oldMap = node.getNotations();
        newMap = docType.getNotations();
        length = oldMap.getLength();
        for (int i = 0; i < length; ++i) {
            Notation oldNotation = (Notation) oldMap.item(i);
            NotationImpl newNotation = (NotationImpl) fDocumentImpl.createNotation(oldNotation.getNodeName());
            newNotation.setPublicId(oldNotation.getPublicId());
            newNotation.setSystemId(oldNotation.getSystemId());
            newMap.setNamedItem(newNotation);
        }
        append(docType);
    }
}
 
Example #30
Source File: AbstractNodeTester.java    From xmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Validate a single Node by delegating to node type specific methods.
 * @see #testAttribute(Attr)
 * @see #testCDATASection(CDATASection)
 * @see #testComment(Comment)
 * @see #testDocumentType(DocumentType)
 * @see #testElement(Element)
 * @see #testEntity(Entity)
 * @see #testEntityReference(EntityReference)
 * @see #testNotation(Notation)
 * @see #testProcessingInstruction(ProcessingInstruction)
 * @see #testText(Text)
 */
public void testNode(Node aNode, NodeTest forTest) throws NodeTestException {
    switch (aNode.getNodeType()) {
    case Node.ATTRIBUTE_NODE:
        // should not happen as attributes are not exposed by DOM traversal
        testAttribute((Attr)aNode);
        break;
    case Node.CDATA_SECTION_NODE:
        testCDATASection((CDATASection)aNode);
        break;
    case Node.COMMENT_NODE:
        testComment((Comment)aNode);
        break;
    case Node.DOCUMENT_TYPE_NODE:
        testDocumentType((DocumentType)aNode);
        break;
    case Node.ELEMENT_NODE:
        testElement((Element)aNode);
        break;
    case Node.ENTITY_NODE:
        testEntity((Entity)aNode);
        break;
    case Node.ENTITY_REFERENCE_NODE:
        testEntityReference((EntityReference)aNode);
        break;
    case Node.NOTATION_NODE:
        testNotation((Notation)aNode);
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        testProcessingInstruction(
                                  (ProcessingInstruction) aNode);
        break;
    case Node.TEXT_NODE:
        testText((Text)aNode);
        break;
    default:
        throw new NodeTestException("No delegate method for Node type",
                                    aNode);
    }
}