< prev index next >

src/java.base/share/classes/jdk/internal/util/xml/impl/Parser.java

Print this page




1824                     {
1825                         panic(FAULT);
1826                     }
1827                     ids.value = null;
1828                     break;
1829             }
1830             return ids;
1831         } else if ("SYSTEM".equals(str) == true) {
1832             ids.name = null;
1833             bqstr(' ');
1834             ids.value = new String(mBuff, 1, mBuffIdx);
1835             return ids;
1836         }
1837         panic(FAULT);
1838         return null;
1839     }
1840 
1841     /**
1842      * Reads an attribute value.
1843      *
1844      * The grammar which this method can read is:<br />
1845      * <code>eqstr := S &quot;=&quot; qstr</code><br />
1846      * <code>qstr  := S (&quot;'&quot; string &quot;'&quot;) |
1847      *  ('&quot;' string '&quot;')</code><br /> This method resolves entities


1848      * inside a string unless the parser parses DTD.
1849      *
1850      * @param flag The '=' character forces the method to accept the '='
1851      * character before quoted string and read the following string as not an
1852      * attribute ('-'), 'c' - CDATA, 'i' - non CDATA, ' ' - no normalization;
1853      * '-' - not an attribute value; 'd' - in DTD context.
1854      * @return The content of the quoted strign as a string.
1855      * @exception Exception is parser specific exception form panic method.
1856      * @exception IOException
1857      */
1858     protected String eqstr(char flag) throws Exception {
1859         if (flag == '=') {
1860             wsskip();
1861             if (getch() != '=') {
1862                 panic(FAULT);
1863             }
1864         }
1865         bqstr((flag == '=') ? '-' : flag);
1866         return new String(mBuff, 1, mBuffIdx);
1867     }


2616                             bappend(ch, flag);
2617                             break;
2618                     }
2619                     break;
2620 
2621                 default:
2622                     panic(FAULT);
2623             }
2624         }
2625         //              There is maximum one space at the end of the string in
2626         //              i-mode (non CDATA normalization) and it has to be removed.
2627         if ((flag == 'i') && (mBuff[mBuffIdx] == ' ')) {
2628             mBuffIdx -= 1;
2629         }
2630     }
2631 
2632     /**
2633      * Reports characters and empties the parser's buffer. This method is called
2634      * only if parser is going to return control to the main loop. This means
2635      * that this method may use parser buffer to report white space without
2636      * copeing characters to temporary buffer.
2637      */
2638     protected abstract void bflash()
2639             throws Exception;
2640 
2641     /**
2642      * Reports white space characters and empties the parser's buffer. This
2643      * method is called only if parser is going to return control to the main
2644      * loop. This means that this method may use parser buffer to report white
2645      * space without copeing characters to temporary buffer.
2646      */
2647     protected abstract void bflash_ws()
2648             throws Exception;
2649 
2650     /**
2651      * Appends a character to parser's buffer with normalization.
2652      *
2653      * @param ch The character to append to the buffer.
2654      * @param mode The normalization mode.
2655      */
2656     private void bappend(char ch, char mode) {
2657         //              This implements attribute value normalization as
2658         //              described in the XML specification [#3.3.3].
2659         switch (mode) {
2660             case 'i':  // non CDATA normalization
2661                 switch (ch) {
2662                     case ' ':
2663                     case '\n':
2664                     case '\r':
2665                     case '\t':


3273         if (mInp.src != null) {
3274             try {
3275                 mInp.src.close();
3276             } catch (IOException ioe) {
3277             }
3278             mInp.src = null;
3279         }
3280         mInp = mInp.next;
3281         if (mInp != null) {
3282             mChars = mInp.chars;
3283             mChLen = mInp.chLen;
3284             mChIdx = mInp.chIdx;
3285         } else {
3286             mChars = null;
3287             mChLen = 0;
3288             mChIdx = 0;
3289         }
3290     }
3291 
3292     /**
3293      * Maps a character to it's type.
3294      *
3295      * Possible character type values are:<br /> - ' ' for any kind of white
3296      * space character;<br /> - 'a' for any lower case alphabetical character
3297      * value;<br /> - 'A' for any upper case alphabetical character value;<br />
3298      * - 'd' for any decimal digit character value;<br /> - 'z' for any
3299      * character less then ' ' except '\t', '\n', '\r';<br /> - 'X' for any not
3300      * ASCII character;<br /> - 'Z' for EOS character.<br /> An ASCII (7 bit)
3301      * character which does not fall in any category listed above is mapped to
3302      * it self.




3303      *
3304      * @param ch The character to map.
3305      * @return The type of character.
3306      */
3307     protected char chtyp(char ch) {
3308         if (ch < 0x80) {
3309             return (char) asctyp[ch];
3310         }
3311         return (ch != EOS) ? 'X' : 'Z';
3312     }
3313 
3314     /**
3315      * Retrives the next character in the document.
3316      *
3317      * @return The next character in the document.
3318      */
3319     protected char getch()
3320             throws IOException {
3321         if (mChIdx >= mChLen) {
3322             if (mInp.src == null) {




1824                     {
1825                         panic(FAULT);
1826                     }
1827                     ids.value = null;
1828                     break;
1829             }
1830             return ids;
1831         } else if ("SYSTEM".equals(str) == true) {
1832             ids.name = null;
1833             bqstr(' ');
1834             ids.value = new String(mBuff, 1, mBuffIdx);
1835             return ids;
1836         }
1837         panic(FAULT);
1838         return null;
1839     }
1840 
1841     /**
1842      * Reads an attribute value.
1843      *
1844      * The grammar which this method can read is:
1845      * <pre>{@code
1846      * eqstr := S "=" qstr
1847      * qstr  := S ("'" string "'") | ('"' string '"')
1848      * }</pre>
1849      * This method resolves entities
1850      * inside a string unless the parser parses DTD.
1851      *
1852      * @param flag The '=' character forces the method to accept the '='
1853      * character before quoted string and read the following string as not an
1854      * attribute ('-'), 'c' - CDATA, 'i' - non CDATA, ' ' - no normalization;
1855      * '-' - not an attribute value; 'd' - in DTD context.
1856      * @return The content of the quoted strign as a string.
1857      * @exception Exception is parser specific exception form panic method.
1858      * @exception IOException
1859      */
1860     protected String eqstr(char flag) throws Exception {
1861         if (flag == '=') {
1862             wsskip();
1863             if (getch() != '=') {
1864                 panic(FAULT);
1865             }
1866         }
1867         bqstr((flag == '=') ? '-' : flag);
1868         return new String(mBuff, 1, mBuffIdx);
1869     }


2618                             bappend(ch, flag);
2619                             break;
2620                     }
2621                     break;
2622 
2623                 default:
2624                     panic(FAULT);
2625             }
2626         }
2627         //              There is maximum one space at the end of the string in
2628         //              i-mode (non CDATA normalization) and it has to be removed.
2629         if ((flag == 'i') && (mBuff[mBuffIdx] == ' ')) {
2630             mBuffIdx -= 1;
2631         }
2632     }
2633 
2634     /**
2635      * Reports characters and empties the parser's buffer. This method is called
2636      * only if parser is going to return control to the main loop. This means
2637      * that this method may use parser buffer to report white space without
2638      * copying characters to temporary buffer.
2639      */
2640     protected abstract void bflash()
2641             throws Exception;
2642 
2643     /**
2644      * Reports white space characters and empties the parser's buffer. This
2645      * method is called only if parser is going to return control to the main
2646      * loop. This means that this method may use parser buffer to report white
2647      * space without copying characters to temporary buffer.
2648      */
2649     protected abstract void bflash_ws()
2650             throws Exception;
2651 
2652     /**
2653      * Appends a character to parser's buffer with normalization.
2654      *
2655      * @param ch The character to append to the buffer.
2656      * @param mode The normalization mode.
2657      */
2658     private void bappend(char ch, char mode) {
2659         //              This implements attribute value normalization as
2660         //              described in the XML specification [#3.3.3].
2661         switch (mode) {
2662             case 'i':  // non CDATA normalization
2663                 switch (ch) {
2664                     case ' ':
2665                     case '\n':
2666                     case '\r':
2667                     case '\t':


3275         if (mInp.src != null) {
3276             try {
3277                 mInp.src.close();
3278             } catch (IOException ioe) {
3279             }
3280             mInp.src = null;
3281         }
3282         mInp = mInp.next;
3283         if (mInp != null) {
3284             mChars = mInp.chars;
3285             mChLen = mInp.chLen;
3286             mChIdx = mInp.chIdx;
3287         } else {
3288             mChars = null;
3289             mChLen = 0;
3290             mChIdx = 0;
3291         }
3292     }
3293 
3294     /**
3295      * Maps a character to its type.
3296      *
3297      * Possible character type values are:
3298      * <ul>
3299      * <li>' ' - for any kind of whitespace character;</li>
3300      * <li>'a' - for any lower case alphabetical character value;</li>
3301      * <li>'A' - for any upper case alphabetical character value;</li>
3302      * <li>'d' - for any decimal digit character value;</li>
3303      * <li>'z' - for any character less than ' ' except '\t', '\n', '\r';</li>
3304      * <li>'X' - for any not ASCII character;</li>
3305      * <li>'Z' - for EOS character.</li>
3306      * </ul>
3307      * An ASCII (7 bit) character which does not fall in any category 
3308      * listed above is mapped to itself.
3309      *
3310      * @param ch The character to map.
3311      * @return The type of character.
3312      */
3313     protected char chtyp(char ch) {
3314         if (ch < 0x80) {
3315             return (char) asctyp[ch];
3316         }
3317         return (ch != EOS) ? 'X' : 'Z';
3318     }
3319 
3320     /**
3321      * Retrives the next character in the document.
3322      *
3323      * @return The next character in the document.
3324      */
3325     protected char getch()
3326             throws IOException {
3327         if (mChIdx >= mChLen) {
3328             if (mInp.src == null) {


< prev index next >