< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/AbstractDOMParser.java

Print this page


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.parsers;
  23 


1914      * @param name The name of the entity. Parameter entity names start with
1915      *             '%', whereas the name of a general entity is just the
1916      *             entity name.
1917      * @param text The value of the entity.
1918      * @param nonNormalizedText The non-normalized value of the entity. This
1919      *             value contains the same sequence of characters that was in
1920      *             the internal entity declaration, without any entity
1921      *             references expanded.
1922      * @param augs Additional information that may include infoset
1923      *                      augmentations.
1924      *
1925      * @throws XNIException Thrown by handler to signal an error.
1926      */
1927     public void internalEntityDecl (String name, XMLString text,
1928     XMLString nonNormalizedText,
1929     Augmentations augs) throws XNIException {
1930 
1931         if (DEBUG_EVENTS) {
1932             System.out.println ("==>internalEntityDecl: "+name);
1933             if (DEBUG_BASEURI) {
1934                 System.out.println ("   baseURI:"+ (String)fBaseURIStack.peek ());
1935             }
1936         }
1937         // internal subset string
1938         if (fInternalSubset != null && !fInDTDExternalSubset) {
1939             fInternalSubset.append ("<!ENTITY ");
1940             if (name.startsWith ("%")) {
1941                 fInternalSubset.append ("% ");
1942                 fInternalSubset.append (name.substring (1));
1943             }
1944             else {
1945                 fInternalSubset.append (name);
1946             }
1947             fInternalSubset.append (' ');
1948             String value = nonNormalizedText.toString ();
1949             boolean singleQuote = value.indexOf ('\'') == -1;
1950             fInternalSubset.append (singleQuote ? '\'' : '"');
1951             fInternalSubset.append (value);
1952             fInternalSubset.append (singleQuote ? '\'' : '"');
1953             fInternalSubset.append (">\n");
1954         }
1955 
1956         // NOTE: We only know how to create these nodes for the Xerces
1957         //       DOM implementation because DOM Level 2 does not specify
1958         //       that functionality. -Ac
1959 
1960         // create full node
1961         // don't add parameter entities!
1962         if(name.startsWith ("%"))
1963             return;
1964         if (fDocumentType != null) {
1965             NamedNodeMap entities = fDocumentType.getEntities ();
1966             EntityImpl entity = (EntityImpl)entities.getNamedItem (name);
1967             if (entity == null) {
1968                 entity = (EntityImpl)fDocumentImpl.createEntity (name);
1969                 entity.setBaseURI ((String)fBaseURIStack.peek ());
1970                 entities.setNamedItem (entity);
1971             }
1972         }
1973 
1974         // create deferred node
1975         if (fDocumentTypeIndex != -1) {
1976             boolean found = false;
1977             int node = fDeferredDocumentImpl.getLastChild (fDocumentTypeIndex, false);
1978             while (node != -1) {
1979                 short nodeType = fDeferredDocumentImpl.getNodeType (node, false);
1980                 if (nodeType == Node.ENTITY_NODE) {
1981                     String nodeName = fDeferredDocumentImpl.getNodeName (node, false);
1982                     if (nodeName.equals (name)) {
1983                         found = true;
1984                         break;
1985                     }
1986                 }
1987                 node = fDeferredDocumentImpl.getRealPrevSibling (node, false);
1988             }
1989             if (!found) {
1990                 int entityIndex =
1991                 fDeferredDocumentImpl.createDeferredEntity (name, null, null, null, (String)fBaseURIStack.peek ());
1992                 fDeferredDocumentImpl.appendChild (fDocumentTypeIndex, entityIndex);
1993             }
1994         }
1995 
1996     } // internalEntityDecl(String,XMLString,XMLString)
1997 
1998     /**
1999      * An external entity declaration.
2000      *
2001      * @param name     The name of the entity. Parameter entity names start
2002      *                 with '%', whereas the name of a general entity is just
2003      *                 the entity name.
2004      * @param identifier    An object containing all location information
2005      *                      pertinent to this notation.
2006      * @param augs Additional information that may include infoset
2007      *                      augmentations.
2008      *
2009      * @throws XNIException Thrown by handler to signal an error.
2010      */
2011     public void externalEntityDecl (String name, XMLResourceIdentifier identifier,


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.parsers;
  23 


1914      * @param name The name of the entity. Parameter entity names start with
1915      *             '%', whereas the name of a general entity is just the
1916      *             entity name.
1917      * @param text The value of the entity.
1918      * @param nonNormalizedText The non-normalized value of the entity. This
1919      *             value contains the same sequence of characters that was in
1920      *             the internal entity declaration, without any entity
1921      *             references expanded.
1922      * @param augs Additional information that may include infoset
1923      *                      augmentations.
1924      *
1925      * @throws XNIException Thrown by handler to signal an error.
1926      */
1927     public void internalEntityDecl (String name, XMLString text,
1928     XMLString nonNormalizedText,
1929     Augmentations augs) throws XNIException {
1930 
1931         if (DEBUG_EVENTS) {
1932             System.out.println ("==>internalEntityDecl: "+name);
1933             if (DEBUG_BASEURI) {
1934                 System.out.println ("   baseURI:"+ fBaseURIStack.peek ());
1935             }
1936         }
1937         // internal subset string
1938         if (fInternalSubset != null && !fInDTDExternalSubset) {
1939             fInternalSubset.append ("<!ENTITY ");
1940             if (name.startsWith ("%")) {
1941                 fInternalSubset.append ("% ");
1942                 fInternalSubset.append (name.substring (1));
1943             }
1944             else {
1945                 fInternalSubset.append (name);
1946             }
1947             fInternalSubset.append (' ');
1948             String value = nonNormalizedText.toString ();
1949             boolean singleQuote = value.indexOf ('\'') == -1;
1950             fInternalSubset.append (singleQuote ? '\'' : '"');
1951             fInternalSubset.append (value);
1952             fInternalSubset.append (singleQuote ? '\'' : '"');
1953             fInternalSubset.append (">\n");
1954         }
1955 
1956         // NOTE: We only know how to create these nodes for the Xerces
1957         //       DOM implementation because DOM Level 2 does not specify
1958         //       that functionality. -Ac
1959 
1960         // create full node
1961         // don't add parameter entities!
1962         if(name.startsWith ("%"))
1963             return;
1964         if (fDocumentType != null) {
1965             NamedNodeMap entities = fDocumentType.getEntities ();
1966             EntityImpl entity = (EntityImpl)entities.getNamedItem (name);
1967             if (entity == null) {
1968                 entity = (EntityImpl)fDocumentImpl.createEntity (name);
1969                 entity.setBaseURI (fBaseURIStack.peek ());
1970                 entities.setNamedItem (entity);
1971             }
1972         }
1973 
1974         // create deferred node
1975         if (fDocumentTypeIndex != -1) {
1976             boolean found = false;
1977             int node = fDeferredDocumentImpl.getLastChild (fDocumentTypeIndex, false);
1978             while (node != -1) {
1979                 short nodeType = fDeferredDocumentImpl.getNodeType (node, false);
1980                 if (nodeType == Node.ENTITY_NODE) {
1981                     String nodeName = fDeferredDocumentImpl.getNodeName (node, false);
1982                     if (nodeName.equals (name)) {
1983                         found = true;
1984                         break;
1985                     }
1986                 }
1987                 node = fDeferredDocumentImpl.getRealPrevSibling (node, false);
1988             }
1989             if (!found) {
1990                 int entityIndex =
1991                 fDeferredDocumentImpl.createDeferredEntity (name, null, null, null, fBaseURIStack.peek ());
1992                 fDeferredDocumentImpl.appendChild (fDocumentTypeIndex, entityIndex);
1993             }
1994         }
1995 
1996     } // internalEntityDecl(String,XMLString,XMLString)
1997 
1998     /**
1999      * An external entity declaration.
2000      *
2001      * @param name     The name of the entity. Parameter entity names start
2002      *                 with '%', whereas the name of a general entity is just
2003      *                 the entity name.
2004      * @param identifier    An object containing all location information
2005      *                      pertinent to this notation.
2006      * @param augs Additional information that may include infoset
2007      *                      augmentations.
2008      *
2009      * @throws XNIException Thrown by handler to signal an error.
2010      */
2011     public void externalEntityDecl (String name, XMLResourceIdentifier identifier,


< prev index next >