org.w3c.dom.DocumentType#getEntities ( )源码实例Demo

下面列出了org.w3c.dom.DocumentType#getEntities ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: DOMResultBuilder.java
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);
    }
}
 
/**
 * Returns the absolute base URI of this node or null if the implementation
 * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
 * null is returned.
 *
 * @return The absolute base URI of this node or null.
 * @since DOM Level 3
 */
public String getBaseURI() {
    if (needsSyncData()) {
        synchronizeData();
    }
    if (baseURI == null) {
        DocumentType doctype;
        NamedNodeMap entities;
        EntityImpl entDef;
        if (null != (doctype = getOwnerDocument().getDoctype()) &&
            null != (entities = doctype.getEntities())) {

            entDef = (EntityImpl)entities.getNamedItem(getNodeName());
            if (entDef !=null) {
                return entDef.getBaseURI();
            }
        }
    } else if (baseURI != null && baseURI.length() != 0 ) {// attribute value is always empty string
        try {
            return new URI(baseURI).toString();
        }
        catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){
            // REVISIT: what should happen in this case?
            return null;
        }
    }
    return baseURI;
}
 
源代码3 项目: openjdk-8   文件: EntityReferenceImpl.java
/**
 * EntityReference's children are a reflection of those defined in the
 * named Entity. This method creates them if they haven't been created yet.
 * This doesn't support editing the Entity though, since this only called
 * once for all.
 */
protected void synchronizeChildren() {
    // no need to synchronize again
    needsSyncChildren(false);

    DocumentType doctype;
    NamedNodeMap entities;
    EntityImpl entDef;
    if (null != (doctype = getOwnerDocument().getDoctype()) &&
        null != (entities = doctype.getEntities())) {

        entDef = (EntityImpl)entities.getNamedItem(getNodeName());

        // No Entity by this name, stop here.
        if (entDef == null)
            return;

        // If entity's definition exists, clone its kids
        isReadOnly(false);
        for (Node defkid = entDef.getFirstChild();
            defkid != null;
            defkid = defkid.getNextSibling()) {
            Node newkid = defkid.cloneNode(true);
            insertBefore(newkid, null);
        }
        setReadOnly(true, true);
    }
}
 
/**
 * Extracts NamedNodeMap of entities. We need this to validate
 * elements and attributes of type xs:ENTITY, xs:ENTITIES or
 * types dervied from them.
 */
private void setupEntityMap(Document doc) {
    if (doc != null) {
        DocumentType docType = doc.getDoctype();
        if (docType != null) {
            fEntities = docType.getEntities();
            return;
        }
    }
    fEntities = null;
}
 
源代码5 项目: openjdk-jdk9   文件: DOMValidatorHelper.java
/**
 * Extracts NamedNodeMap of entities. We need this to validate
 * elements and attributes of type xs:ENTITY, xs:ENTITIES or
 * types dervied from them.
 */
private void setupEntityMap(Document doc) {
    if (doc != null) {
        DocumentType docType = doc.getDoctype();
        if (docType != null) {
            fEntities = docType.getEntities();
            return;
        }
    }
    fEntities = null;
}
 
源代码6 项目: JDKSourceCode1.8   文件: EntityReferenceImpl.java
/**
 * Returns the absolute base URI of this node or null if the implementation
 * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
 * null is returned.
 *
 * @return The absolute base URI of this node or null.
 * @since DOM Level 3
 */
public String getBaseURI() {
    if (needsSyncData()) {
        synchronizeData();
    }
    if (baseURI == null) {
        DocumentType doctype;
        NamedNodeMap entities;
        EntityImpl entDef;
        if (null != (doctype = getOwnerDocument().getDoctype()) &&
            null != (entities = doctype.getEntities())) {

            entDef = (EntityImpl)entities.getNamedItem(getNodeName());
            if (entDef !=null) {
                return entDef.getBaseURI();
            }
        }
    } else if (baseURI != null && baseURI.length() != 0 ) {// attribute value is always empty string
        try {
            return new URI(baseURI).toString();
        }
        catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){
            // REVISIT: what should happen in this case?
            return null;
        }
    }
    return baseURI;
}
 
源代码7 项目: TencentKona-8   文件: SAXImpl.java
/**
 * 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);
    }
}
 
源代码8 项目: openjdk-jdk8u-backup   文件: SAXImpl.java
/**
 * 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);
    }
}
 
源代码9 项目: openjdk-jdk8u   文件: SAXImpl.java
/**
 * 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);
    }
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: EntityReferenceImpl.java
/**
 * Returns the absolute base URI of this node or null if the implementation
 * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
 * null is returned.
 *
 * @return The absolute base URI of this node or null.
 * @since DOM Level 3
 */
public String getBaseURI() {
    if (needsSyncData()) {
        synchronizeData();
    }
    if (baseURI == null) {
        DocumentType doctype;
        NamedNodeMap entities;
        EntityImpl entDef;
        if (null != (doctype = getOwnerDocument().getDoctype()) &&
            null != (entities = doctype.getEntities())) {

            entDef = (EntityImpl)entities.getNamedItem(getNodeName());
            if (entDef !=null) {
                return entDef.getBaseURI();
            }
        }
    } else if (baseURI != null && baseURI.length() != 0 ) {// attribute value is always empty string
        try {
            return new URI(baseURI).toString();
        }
        catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){
            // REVISIT: what should happen in this case?
            return null;
        }
    }
    return baseURI;
}
 
源代码11 项目: Bytecoder   文件: EntityReferenceImpl.java
/**
 * EntityReference's children are a reflection of those defined in the
 * named Entity. This method creates them if they haven't been created yet.
 * This doesn't support editing the Entity though, since this only called
 * once for all.
 */
protected void synchronizeChildren() {
    // no need to synchronize again
    needsSyncChildren(false);

    DocumentType doctype;
    NamedNodeMap entities;
    EntityImpl entDef;
    if (null != (doctype = getOwnerDocument().getDoctype()) &&
        null != (entities = doctype.getEntities())) {

        entDef = (EntityImpl)entities.getNamedItem(getNodeName());

        // No Entity by this name, stop here.
        if (entDef == null)
            return;

        // If entity's definition exists, clone its kids
        isReadOnly(false);
        for (Node defkid = entDef.getFirstChild();
            defkid != null;
            defkid = defkid.getNextSibling()) {
            Node newkid = defkid.cloneNode(true);
            insertBefore(newkid, null);
        }
        setReadOnly(true, true);
    }
}
 
源代码12 项目: openjdk-jdk8u   文件: DOMResultBuilder.java
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);
    }
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: DOMValidatorHelper.java
/**
 * Extracts NamedNodeMap of entities. We need this to validate
 * elements and attributes of type xs:ENTITY, xs:ENTITIES or
 * types dervied from them.
 */
private void setupEntityMap(Document doc) {
    if (doc != null) {
        DocumentType docType = doc.getDoctype();
        if (docType != null) {
            fEntities = docType.getEntities();
            return;
        }
    }
    fEntities = null;
}
 
源代码14 项目: hottub   文件: DOMResultBuilder.java
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);
    }
}
 
源代码15 项目: openjdk-8   文件: DOMHelper.java
/**
 * 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.
 * <p>
 * XML processors may choose to use the System Identifier (if one
 * is provided) to resolve the entity, rather than the URI in the
 * Public Identifier. The details are dependent on the processor, and
 * we would have to support some form of plug-in resolver to handle
 * this properly. Currently, we simply return the System Identifier if
 * present, and hope that it a usable URI or that our caller can
 * map it to one.
 * TODO: Resolve Public Identifiers... or consider changing function name.
 * <p>
 * If we find a relative URI
 * reference, XML expects it to be resolved in terms of the base URI
 * of the document. The DOM doesn't do that for us, and it isn't
 * entirely clear whether that should be done here; currently that's
 * pushed up to a higher levelof our application. (Note that DOM Level
 * 1 didn't store the document's base URI.)
 * TODO: Consider resolving Relative URIs.
 * <p>
 * (The DOM's statement that "An XML processor may choose to
 * completely expand entities before the structure model is passed
 * to the DOM" refers only to parsed entities, not unparsed, and hence
 * doesn't affect this function.)
 *
 * @param name A string containing the Entity Name of the unparsed
 * entity.
 * @param doc Document node for the document to be searched.
 *
 * @return String containing the URI of the Unparsed Entity, or an
 * empty string if no such entity exists.
 */
public String getUnparsedEntityURI(String name, Document doc)
{

  String url = "";
  DocumentType doctype = doc.getDoctype();

  if (null != doctype)
  {
    NamedNodeMap entities = doctype.getEntities();
    if(null == entities)
      return url;
    Entity entity = (Entity) entities.getNamedItem(name);
    if(null == entity)
      return url;

    String notationName = entity.getNotationName();

    if (null != notationName)  // then it's unparsed
    {
      // The draft says: "The XSLT processor may use the public
      // identifier to generate a URI for the entity instead of the URI
      // specified in the system identifier. If the XSLT processor does
      // not use the public identifier to generate the URI, it must use
      // the system identifier; if the system identifier is a relative
      // URI, it must be resolved into an absolute URI using the URI of
      // the resource containing the entity declaration as the base
      // URI [RFC2396]."
      // So I'm falling a bit short here.
      url = entity.getSystemId();

      if (null == url)
      {
        url = entity.getPublicId();
      }
      else
      {
        // This should be resolved to an absolute URL, but that's hard
        // to do from here.
      }
    }
  }

  return url;
}
 
源代码16 项目: openjdk-jdk9   文件: DOM2DTM.java
/**
 * 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.
 * <p>
 * XML processors may choose to use the System Identifier (if one
 * is provided) to resolve the entity, rather than the URI in the
 * Public Identifier. The details are dependent on the processor, and
 * we would have to support some form of plug-in resolver to handle
 * this properly. Currently, we simply return the System Identifier if
 * present, and hope that it a usable URI or that our caller can
 * map it to one.
 * TODO: Resolve Public Identifiers... or consider changing function name.
 * <p>
 * If we find a relative URI
 * reference, XML expects it to be resolved in terms of the base URI
 * of the document. The DOM doesn't do that for us, and it isn't
 * entirely clear whether that should be done here; currently that's
 * pushed up to a higher level of our application. (Note that DOM Level
 * 1 didn't store the document's base URI.)
 * TODO: Consider resolving Relative URIs.
 * <p>
 * (The DOM's statement that "An XML processor may choose to
 * completely expand entities before the structure model is passed
 * to the DOM" refers only to parsed entities, not unparsed, and hence
 * doesn't affect this function.)
 *
 * @param name A string containing the Entity Name of the unparsed
 * entity.
 *
 * @return String containing the URI of the Unparsed Entity, or an
 * empty string if no such entity exists.
 */
public String getUnparsedEntityURI(String name)
{

  String url = "";
  Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE)
      ? (Document) m_root : m_root.getOwnerDocument();

  if (null != doc)
  {
    DocumentType doctype = doc.getDoctype();

    if (null != doctype)
    {
      NamedNodeMap entities = doctype.getEntities();
      if(null == entities)
        return url;
      Entity entity = (Entity) entities.getNamedItem(name);
      if(null == entity)
        return url;

      String notationName = entity.getNotationName();

      if (null != notationName)  // then it's unparsed
      {
        // The draft says: "The XSLT processor may use the public
        // identifier to generate a URI for the entity instead of the URI
        // specified in the system identifier. If the XSLT processor does
        // not use the public identifier to generate the URI, it must use
        // the system identifier; if the system identifier is a relative
        // URI, it must be resolved into an absolute URI using the URI of
        // the resource containing the entity declaration as the base
        // URI [RFC2396]."
        // So I'm falling a bit short here.
        url = entity.getSystemId();

        if (null == url)
        {
          url = entity.getPublicId();
        }
        else
        {
          // This should be resolved to an absolute URL, but that's hard
          // to do from here.
        }
      }
    }
  }

  return url;
}
 
源代码17 项目: hottub   文件: DOM2DTM.java
/**
 * 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.
 * <p>
 * XML processors may choose to use the System Identifier (if one
 * is provided) to resolve the entity, rather than the URI in the
 * Public Identifier. The details are dependent on the processor, and
 * we would have to support some form of plug-in resolver to handle
 * this properly. Currently, we simply return the System Identifier if
 * present, and hope that it a usable URI or that our caller can
 * map it to one.
 * TODO: Resolve Public Identifiers... or consider changing function name.
 * <p>
 * If we find a relative URI
 * reference, XML expects it to be resolved in terms of the base URI
 * of the document. The DOM doesn't do that for us, and it isn't
 * entirely clear whether that should be done here; currently that's
 * pushed up to a higher level of our application. (Note that DOM Level
 * 1 didn't store the document's base URI.)
 * TODO: Consider resolving Relative URIs.
 * <p>
 * (The DOM's statement that "An XML processor may choose to
 * completely expand entities before the structure model is passed
 * to the DOM" refers only to parsed entities, not unparsed, and hence
 * doesn't affect this function.)
 *
 * @param name A string containing the Entity Name of the unparsed
 * entity.
 *
 * @return String containing the URI of the Unparsed Entity, or an
 * empty string if no such entity exists.
 */
public String getUnparsedEntityURI(String name)
{

  String url = "";
  Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE)
      ? (Document) m_root : m_root.getOwnerDocument();

  if (null != doc)
  {
    DocumentType doctype = doc.getDoctype();

    if (null != doctype)
    {
      NamedNodeMap entities = doctype.getEntities();
      if(null == entities)
        return url;
      Entity entity = (Entity) entities.getNamedItem(name);
      if(null == entity)
        return url;

      String notationName = entity.getNotationName();

      if (null != notationName)  // then it's unparsed
      {
        // The draft says: "The XSLT processor may use the public
        // identifier to generate a URI for the entity instead of the URI
        // specified in the system identifier. If the XSLT processor does
        // not use the public identifier to generate the URI, it must use
        // the system identifier; if the system identifier is a relative
        // URI, it must be resolved into an absolute URI using the URI of
        // the resource containing the entity declaration as the base
        // URI [RFC2396]."
        // So I'm falling a bit short here.
        url = entity.getSystemId();

        if (null == url)
        {
          url = entity.getPublicId();
        }
        else
        {
          // This should be resolved to an absolute URL, but that's hard
          // to do from here.
        }
      }
    }
  }

  return url;
}
 
源代码18 项目: hottub   文件: DOMHelper.java
/**
 * 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.
 * <p>
 * XML processors may choose to use the System Identifier (if one
 * is provided) to resolve the entity, rather than the URI in the
 * Public Identifier. The details are dependent on the processor, and
 * we would have to support some form of plug-in resolver to handle
 * this properly. Currently, we simply return the System Identifier if
 * present, and hope that it a usable URI or that our caller can
 * map it to one.
 * TODO: Resolve Public Identifiers... or consider changing function name.
 * <p>
 * If we find a relative URI
 * reference, XML expects it to be resolved in terms of the base URI
 * of the document. The DOM doesn't do that for us, and it isn't
 * entirely clear whether that should be done here; currently that's
 * pushed up to a higher levelof our application. (Note that DOM Level
 * 1 didn't store the document's base URI.)
 * TODO: Consider resolving Relative URIs.
 * <p>
 * (The DOM's statement that "An XML processor may choose to
 * completely expand entities before the structure model is passed
 * to the DOM" refers only to parsed entities, not unparsed, and hence
 * doesn't affect this function.)
 *
 * @param name A string containing the Entity Name of the unparsed
 * entity.
 * @param doc Document node for the document to be searched.
 *
 * @return String containing the URI of the Unparsed Entity, or an
 * empty string if no such entity exists.
 */
public String getUnparsedEntityURI(String name, Document doc)
{

  String url = "";
  DocumentType doctype = doc.getDoctype();

  if (null != doctype)
  {
    NamedNodeMap entities = doctype.getEntities();
    if(null == entities)
      return url;
    Entity entity = (Entity) entities.getNamedItem(name);
    if(null == entity)
      return url;

    String notationName = entity.getNotationName();

    if (null != notationName)  // then it's unparsed
    {
      // The draft says: "The XSLT processor may use the public
      // identifier to generate a URI for the entity instead of the URI
      // specified in the system identifier. If the XSLT processor does
      // not use the public identifier to generate the URI, it must use
      // the system identifier; if the system identifier is a relative
      // URI, it must be resolved into an absolute URI using the URI of
      // the resource containing the entity declaration as the base
      // URI [RFC2396]."
      // So I'm falling a bit short here.
      url = entity.getSystemId();

      if (null == url)
      {
        url = entity.getPublicId();
      }
      else
      {
        // This should be resolved to an absolute URL, but that's hard
        // to do from here.
      }
    }
  }

  return url;
}
 
源代码19 项目: openjdk-8   文件: DOM2DTM.java
/**
 * 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.
 * <p>
 * XML processors may choose to use the System Identifier (if one
 * is provided) to resolve the entity, rather than the URI in the
 * Public Identifier. The details are dependent on the processor, and
 * we would have to support some form of plug-in resolver to handle
 * this properly. Currently, we simply return the System Identifier if
 * present, and hope that it a usable URI or that our caller can
 * map it to one.
 * TODO: Resolve Public Identifiers... or consider changing function name.
 * <p>
 * If we find a relative URI
 * reference, XML expects it to be resolved in terms of the base URI
 * of the document. The DOM doesn't do that for us, and it isn't
 * entirely clear whether that should be done here; currently that's
 * pushed up to a higher level of our application. (Note that DOM Level
 * 1 didn't store the document's base URI.)
 * TODO: Consider resolving Relative URIs.
 * <p>
 * (The DOM's statement that "An XML processor may choose to
 * completely expand entities before the structure model is passed
 * to the DOM" refers only to parsed entities, not unparsed, and hence
 * doesn't affect this function.)
 *
 * @param name A string containing the Entity Name of the unparsed
 * entity.
 *
 * @return String containing the URI of the Unparsed Entity, or an
 * empty string if no such entity exists.
 */
public String getUnparsedEntityURI(String name)
{

  String url = "";
  Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE)
      ? (Document) m_root : m_root.getOwnerDocument();

  if (null != doc)
  {
    DocumentType doctype = doc.getDoctype();

    if (null != doctype)
    {
      NamedNodeMap entities = doctype.getEntities();
      if(null == entities)
        return url;
      Entity entity = (Entity) entities.getNamedItem(name);
      if(null == entity)
        return url;

      String notationName = entity.getNotationName();

      if (null != notationName)  // then it's unparsed
      {
        // The draft says: "The XSLT processor may use the public
        // identifier to generate a URI for the entity instead of the URI
        // specified in the system identifier. If the XSLT processor does
        // not use the public identifier to generate the URI, it must use
        // the system identifier; if the system identifier is a relative
        // URI, it must be resolved into an absolute URI using the URI of
        // the resource containing the entity declaration as the base
        // URI [RFC2396]."
        // So I'm falling a bit short here.
        url = entity.getSystemId();

        if (null == url)
        {
          url = entity.getPublicId();
        }
        else
        {
          // This should be resolved to an absolute URL, but that's hard
          // to do from here.
        }
      }
    }
  }

  return url;
}
 
源代码20 项目: jdk8u60   文件: DOM2DTM.java
/**
 * 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.
 * <p>
 * XML processors may choose to use the System Identifier (if one
 * is provided) to resolve the entity, rather than the URI in the
 * Public Identifier. The details are dependent on the processor, and
 * we would have to support some form of plug-in resolver to handle
 * this properly. Currently, we simply return the System Identifier if
 * present, and hope that it a usable URI or that our caller can
 * map it to one.
 * TODO: Resolve Public Identifiers... or consider changing function name.
 * <p>
 * If we find a relative URI
 * reference, XML expects it to be resolved in terms of the base URI
 * of the document. The DOM doesn't do that for us, and it isn't
 * entirely clear whether that should be done here; currently that's
 * pushed up to a higher level of our application. (Note that DOM Level
 * 1 didn't store the document's base URI.)
 * TODO: Consider resolving Relative URIs.
 * <p>
 * (The DOM's statement that "An XML processor may choose to
 * completely expand entities before the structure model is passed
 * to the DOM" refers only to parsed entities, not unparsed, and hence
 * doesn't affect this function.)
 *
 * @param name A string containing the Entity Name of the unparsed
 * entity.
 *
 * @return String containing the URI of the Unparsed Entity, or an
 * empty string if no such entity exists.
 */
public String getUnparsedEntityURI(String name)
{

  String url = "";
  Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE)
      ? (Document) m_root : m_root.getOwnerDocument();

  if (null != doc)
  {
    DocumentType doctype = doc.getDoctype();

    if (null != doctype)
    {
      NamedNodeMap entities = doctype.getEntities();
      if(null == entities)
        return url;
      Entity entity = (Entity) entities.getNamedItem(name);
      if(null == entity)
        return url;

      String notationName = entity.getNotationName();

      if (null != notationName)  // then it's unparsed
      {
        // The draft says: "The XSLT processor may use the public
        // identifier to generate a URI for the entity instead of the URI
        // specified in the system identifier. If the XSLT processor does
        // not use the public identifier to generate the URI, it must use
        // the system identifier; if the system identifier is a relative
        // URI, it must be resolved into an absolute URI using the URI of
        // the resource containing the entity declaration as the base
        // URI [RFC2396]."
        // So I'm falling a bit short here.
        url = entity.getSystemId();

        if (null == url)
        {
          url = entity.getPublicId();
        }
        else
        {
          // This should be resolved to an absolute URL, but that's hard
          // to do from here.
        }
      }
    }
  }

  return url;
}