< prev index next >

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

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 188      * Write a DTD section.  This string represents the entire doctypedecl production
 189      * from the XML 1.0 specification.
 190      *
 191      * @param dtd the DTD to be written
 192      * @throws XMLStreamException
 193      */
 194     public void writeDTD(String dtd) throws XMLStreamException {
 195         if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
 196             closeStartTag();
 197         }
 198         _writer.write(dtd);
 199         writeLineSeparator();
 200     }
 201 
 202     /**
 203      * Writes a start tag to the output.
 204      * @param localName local name of the tag, may not be null
 205      * @throws XMLStreamException
 206      */
 207     public void writeStartElement(String localName) throws XMLStreamException {
 208         if (localName == null || localName.length() == 0) {
 209             throw new XMLStreamException("Local Name cannot be null or empty");
 210         }
 211 
 212         _state = STATE_ELEMENT;
 213         if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
 214             closeStartTag();
 215         }
 216 
 217         _currentEle = new Element(_currentEle, localName, false);
 218         openStartTag();
 219 
 220         _writer.write(localName);
 221     }
 222 
 223     /**
 224      * Writes an empty element tag to the output
 225      * @param localName local name of the tag, may not be null
 226      * @throws XMLStreamException
 227      */
 228     public void writeEmptyElement(String localName) throws XMLStreamException {


 403                     _writer.write(content, startWritePos, index - startWritePos);
 404                     _writer.write("&amp;");
 405                     startWritePos = index + 1;
 406 
 407                     break;
 408 
 409                 case CLOSE_START_TAG:
 410                     _writer.write(content, startWritePos, index - startWritePos);
 411                     _writer.write("&gt;");
 412                     startWritePos = index + 1;
 413 
 414                     break;
 415             }
 416         }
 417 
 418         // Write any pending data
 419         _writer.write(content, startWritePos, end - startWritePos);
 420     }
 421 
 422     private void writeXMLContent(String content) throws XMLStreamException {
 423         if ((content != null) && (content.length() > 0)) {
 424             writeXMLContent(content,
 425                     _escapeCharacters, // boolean = escapeChars
 426                     false);             // false = escapeDoubleQuotes
 427         }
 428     }
 429 
 430     /**
 431      * Writes XML content to underlying writer. Escapes characters unless
 432      * escaping character feature is turned off.
 433      */
 434     private void writeXMLContent(
 435             String content,
 436             boolean escapeChars,
 437             boolean escapeDoubleQuotes)
 438         throws XMLStreamException
 439     {
 440 
 441         if (!escapeChars) {
 442             _writer.write(content);
 443 




 188      * Write a DTD section.  This string represents the entire doctypedecl production
 189      * from the XML 1.0 specification.
 190      *
 191      * @param dtd the DTD to be written
 192      * @throws XMLStreamException
 193      */
 194     public void writeDTD(String dtd) throws XMLStreamException {
 195         if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
 196             closeStartTag();
 197         }
 198         _writer.write(dtd);
 199         writeLineSeparator();
 200     }
 201 
 202     /**
 203      * Writes a start tag to the output.
 204      * @param localName local name of the tag, may not be null
 205      * @throws XMLStreamException
 206      */
 207     public void writeStartElement(String localName) throws XMLStreamException {
 208         if (localName == null || localName.isEmpty()) {
 209             throw new XMLStreamException("Local Name cannot be null or empty");
 210         }
 211 
 212         _state = STATE_ELEMENT;
 213         if (_currentEle != null && _currentEle.getState() == ELEMENT_STARTTAG_OPEN) {
 214             closeStartTag();
 215         }
 216 
 217         _currentEle = new Element(_currentEle, localName, false);
 218         openStartTag();
 219 
 220         _writer.write(localName);
 221     }
 222 
 223     /**
 224      * Writes an empty element tag to the output
 225      * @param localName local name of the tag, may not be null
 226      * @throws XMLStreamException
 227      */
 228     public void writeEmptyElement(String localName) throws XMLStreamException {


 403                     _writer.write(content, startWritePos, index - startWritePos);
 404                     _writer.write("&amp;");
 405                     startWritePos = index + 1;
 406 
 407                     break;
 408 
 409                 case CLOSE_START_TAG:
 410                     _writer.write(content, startWritePos, index - startWritePos);
 411                     _writer.write("&gt;");
 412                     startWritePos = index + 1;
 413 
 414                     break;
 415             }
 416         }
 417 
 418         // Write any pending data
 419         _writer.write(content, startWritePos, end - startWritePos);
 420     }
 421 
 422     private void writeXMLContent(String content) throws XMLStreamException {
 423         if (content != null && !content.isEmpty()) {
 424             writeXMLContent(content,
 425                     _escapeCharacters, // boolean = escapeChars
 426                     false);             // false = escapeDoubleQuotes
 427         }
 428     }
 429 
 430     /**
 431      * Writes XML content to underlying writer. Escapes characters unless
 432      * escaping character feature is turned off.
 433      */
 434     private void writeXMLContent(
 435             String content,
 436             boolean escapeChars,
 437             boolean escapeDoubleQuotes)
 438         throws XMLStreamException
 439     {
 440 
 441         if (!escapeChars) {
 442             _writer.write(content);
 443 


< prev index next >