< prev index next >

src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLDOMWriterImpl.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()
Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad


 202      */
 203     public void writeAttribute(String namespaceURI,String localName,String value)throws XMLStreamException {
 204         if(currentNode.getNodeType() == Node.ELEMENT_NODE){
 205             String prefix = null;
 206             if(namespaceURI == null ){
 207                 throw new XMLStreamException("NamespaceURI cannot be null");
 208             }
 209             if(localName == null){
 210                 throw new XMLStreamException("Local name cannot be null");
 211             }
 212             if(namespaceContext != null){
 213                 prefix = namespaceContext.getPrefix(namespaceURI);
 214             }
 215 
 216             if(prefix == null){
 217                 throw new XMLStreamException("Namespace URI "+namespaceURI +
 218                         "is not bound to any prefix" );
 219             }
 220 
 221             String qualifiedName = null;
 222             if(prefix.equals("")){
 223                 qualifiedName = localName;
 224             }else{
 225                 qualifiedName = getQName(prefix,localName);
 226             }
 227             Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
 228             attr.setValue(value);
 229             ((Element)currentNode).setAttributeNode(attr);
 230         }else{
 231             //Convert node type to String
 232             throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
 233                     "and does not allow attributes to be set ");
 234         }
 235     }
 236 
 237     /**
 238      * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
 239      * @param prefix {@inheritDoc}
 240      * @param namespaceURI {@inheritDoc}
 241      * @param localName {@inheritDoc}
 242      * @param value {@inheritDoc}
 243      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 244      */
 245     public void writeAttribute(String prefix,String namespaceURI,String localName,String value)throws XMLStreamException {
 246         if(currentNode.getNodeType() == Node.ELEMENT_NODE){
 247             if(namespaceURI == null ){
 248                 throw new XMLStreamException("NamespaceURI cannot be null");
 249             }
 250             if(localName == null){
 251                 throw new XMLStreamException("Local name cannot be null");
 252             }
 253             if(prefix == null){
 254                 throw new XMLStreamException("prefix cannot be null");
 255             }
 256             String qualifiedName = null;
 257             if(prefix.equals("")){
 258                 qualifiedName = localName;
 259             }else{
 260 
 261                 qualifiedName = getQName(prefix,localName);
 262             }
 263             Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
 264             attr.setValue(value);
 265             ((Element)currentNode).setAttributeNodeNS(attr);
 266         }else{
 267             //Convert node type to String
 268             throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
 269                     "and does not allow attributes to be set ");
 270         }
 271 
 272     }
 273 
 274     /**
 275      * Creates a CDATA object @see org.w3c.dom.CDATASection.
 276      * @param data {@inheritDoc}
 277      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}


 485 
 486     /**
 487      * creates a namespace attribute and will associate it with the current element in
 488      * the DOM tree.
 489      * @param prefix {@inheritDoc}
 490      * @param namespaceURI {@inheritDoc}
 491      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 492      */
 493     public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
 494 
 495         if (prefix == null) {
 496             throw new XMLStreamException("prefix cannot be null");
 497         }
 498 
 499         if (namespaceURI == null) {
 500             throw new XMLStreamException("NamespaceURI cannot be null");
 501         }
 502 
 503         String qname = null;
 504 
 505         if (prefix.equals("")) {
 506             qname = XMLConstants.XMLNS_ATTRIBUTE;
 507         } else {
 508             qname = getQName(XMLConstants.XMLNS_ATTRIBUTE,prefix);
 509         }
 510 
 511         ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
 512     }
 513 
 514     /**
 515      * is not supported in this release.
 516      * @param target {@inheritDoc}
 517      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 518      */
 519     public void writeProcessingInstruction(String target) throws XMLStreamException {
 520         if(target == null){
 521             throw new XMLStreamException("Target cannot be null");
 522         }
 523         ProcessingInstruction pi = ownerDoc.createProcessingInstruction(target, "");
 524         currentNode.appendChild(pi);
 525     }


 652      * creates a DOM Element and appends it to the current element in the tree.
 653      * @param prefix {@inheritDoc}
 654      * @param localName {@inheritDoc}
 655      * @param namespaceURI {@inheritDoc}
 656      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 657      */
 658     public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
 659 
 660         if(ownerDoc != null){
 661             String qname = null;
 662             if(namespaceURI == null ){
 663                 throw new XMLStreamException("NamespaceURI cannot be null");
 664             }
 665             if(localName == null){
 666                 throw new XMLStreamException("Local name cannot be null");
 667             }
 668             if(prefix == null){
 669                 throw new XMLStreamException("Prefix cannot be null");
 670             }
 671 
 672             if(prefix.equals("")){
 673                 qname = localName;
 674             }else{
 675                 qname = getQName(prefix,localName);
 676             }
 677 
 678             Element el = ownerDoc.createElementNS(namespaceURI,qname);
 679 
 680             if(currentNode!=null){
 681                 currentNode.appendChild(el);
 682             }else{
 683                 ownerDoc.appendChild(el);
 684             }
 685             currentNode = el;
 686             if(needContextPop[depth]){
 687                 namespaceContext.pushContext();
 688             }
 689             incDepth();
 690 
 691         }
 692     }




 202      */
 203     public void writeAttribute(String namespaceURI,String localName,String value)throws XMLStreamException {
 204         if(currentNode.getNodeType() == Node.ELEMENT_NODE){
 205             String prefix = null;
 206             if(namespaceURI == null ){
 207                 throw new XMLStreamException("NamespaceURI cannot be null");
 208             }
 209             if(localName == null){
 210                 throw new XMLStreamException("Local name cannot be null");
 211             }
 212             if(namespaceContext != null){
 213                 prefix = namespaceContext.getPrefix(namespaceURI);
 214             }
 215 
 216             if(prefix == null){
 217                 throw new XMLStreamException("Namespace URI "+namespaceURI +
 218                         "is not bound to any prefix" );
 219             }
 220 
 221             String qualifiedName = null;
 222             if(prefix.isEmpty()){
 223                 qualifiedName = localName;
 224             }else{
 225                 qualifiedName = getQName(prefix,localName);
 226             }
 227             Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
 228             attr.setValue(value);
 229             ((Element)currentNode).setAttributeNode(attr);
 230         }else{
 231             //Convert node type to String
 232             throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
 233                     "and does not allow attributes to be set ");
 234         }
 235     }
 236 
 237     /**
 238      * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
 239      * @param prefix {@inheritDoc}
 240      * @param namespaceURI {@inheritDoc}
 241      * @param localName {@inheritDoc}
 242      * @param value {@inheritDoc}
 243      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 244      */
 245     public void writeAttribute(String prefix,String namespaceURI,String localName,String value)throws XMLStreamException {
 246         if(currentNode.getNodeType() == Node.ELEMENT_NODE){
 247             if(namespaceURI == null ){
 248                 throw new XMLStreamException("NamespaceURI cannot be null");
 249             }
 250             if(localName == null){
 251                 throw new XMLStreamException("Local name cannot be null");
 252             }
 253             if(prefix == null){
 254                 throw new XMLStreamException("prefix cannot be null");
 255             }
 256             String qualifiedName = null;
 257             if(prefix.isEmpty()){
 258                 qualifiedName = localName;
 259             }else{
 260 
 261                 qualifiedName = getQName(prefix,localName);
 262             }
 263             Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
 264             attr.setValue(value);
 265             ((Element)currentNode).setAttributeNodeNS(attr);
 266         }else{
 267             //Convert node type to String
 268             throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
 269                     "and does not allow attributes to be set ");
 270         }
 271 
 272     }
 273 
 274     /**
 275      * Creates a CDATA object @see org.w3c.dom.CDATASection.
 276      * @param data {@inheritDoc}
 277      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}


 485 
 486     /**
 487      * creates a namespace attribute and will associate it with the current element in
 488      * the DOM tree.
 489      * @param prefix {@inheritDoc}
 490      * @param namespaceURI {@inheritDoc}
 491      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 492      */
 493     public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
 494 
 495         if (prefix == null) {
 496             throw new XMLStreamException("prefix cannot be null");
 497         }
 498 
 499         if (namespaceURI == null) {
 500             throw new XMLStreamException("NamespaceURI cannot be null");
 501         }
 502 
 503         String qname = null;
 504 
 505         if (prefix.isEmpty()) {
 506             qname = XMLConstants.XMLNS_ATTRIBUTE;
 507         } else {
 508             qname = getQName(XMLConstants.XMLNS_ATTRIBUTE,prefix);
 509         }
 510 
 511         ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
 512     }
 513 
 514     /**
 515      * is not supported in this release.
 516      * @param target {@inheritDoc}
 517      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 518      */
 519     public void writeProcessingInstruction(String target) throws XMLStreamException {
 520         if(target == null){
 521             throw new XMLStreamException("Target cannot be null");
 522         }
 523         ProcessingInstruction pi = ownerDoc.createProcessingInstruction(target, "");
 524         currentNode.appendChild(pi);
 525     }


 652      * creates a DOM Element and appends it to the current element in the tree.
 653      * @param prefix {@inheritDoc}
 654      * @param localName {@inheritDoc}
 655      * @param namespaceURI {@inheritDoc}
 656      * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 657      */
 658     public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
 659 
 660         if(ownerDoc != null){
 661             String qname = null;
 662             if(namespaceURI == null ){
 663                 throw new XMLStreamException("NamespaceURI cannot be null");
 664             }
 665             if(localName == null){
 666                 throw new XMLStreamException("Local name cannot be null");
 667             }
 668             if(prefix == null){
 669                 throw new XMLStreamException("Prefix cannot be null");
 670             }
 671 
 672             if(prefix.isEmpty()){
 673                 qname = localName;
 674             }else{
 675                 qname = getQName(prefix,localName);
 676             }
 677 
 678             Element el = ownerDoc.createElementNS(namespaceURI,qname);
 679 
 680             if(currentNode!=null){
 681                 currentNode.appendChild(el);
 682             }else{
 683                 ownerDoc.appendChild(el);
 684             }
 685             currentNode = el;
 686             if(needContextPop[depth]){
 687                 namespaceContext.pushContext();
 688             }
 689             incDepth();
 690 
 691         }
 692     }


< prev index next >