Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package com.sun.xml.bind.marshaller;
  /*     */ 
  /*     */ import java.io.IOException;
  /*     */ import java.io.OutputStreamWriter;
  /*     */ import java.io.Writer;
  /*     */ import java.util.HashMap;
  /*     */ import java.util.Map.Entry;
  /*     */ import org.xml.sax.Attributes;
  /*     */ import org.xml.sax.SAXException;
 /*     */ import org.xml.sax.helpers.AttributesImpl;
 /*     */ import org.xml.sax.helpers.XMLFilterImpl;
 /*     */ 
 /*     */ public class XMLWriter extends XMLFilterImpl
 /*     */ {
 /* 409 */   private final HashMap<StringStringlocallyDeclaredPrefix = new HashMap();
 /*     */ 
 /* 963 */   private final Attributes EMPTY_ATTS = new AttributesImpl();
 /*     */ 
 /* 971 */   private int elementLevel = 0;
 /*     */   private Writer output;
 /*     */   private String encoding;
 /* 974 */   private boolean writeXmlDecl = true;
 /*     */ 
 /* 980 */   private String header = null;
 /*     */   private final CharacterEscapeHandler escapeHandler;
 /* 984 */   private boolean startTagIsClosed = true;
 /*     */ 
 /*     */   public XMLWriter(Writer writerString encodingCharacterEscapeHandler _escapeHandler)
 /*     */   {
 /* 290 */     init(writerencoding);
 /* 291 */     this. = _escapeHandler;
 /*     */   }
 /*     */ 
 /*     */   public XMLWriter(Writer writerString encoding) {
 /* 295 */     this(writerencoding.);
 /*     */   }
 /*     */ 
 /*     */   private void init(Writer writerString encoding)
 /*     */   {
 /* 310 */     setOutput(writerencoding);
 /*     */   }
 /*     */ 
 /*     */   public void reset()
 /*     */   {
 /* 341 */     this. = 0;
 /* 342 */     this. = true;
 /*     */   }
 /*     */ 
 /*     */   public void flush()
 /*     */     throws IOException
 /*     */   {
 /* 363 */     this..flush();
 /*     */   }
 /*     */ 
 /*     */   public void setOutput(Writer writerString _encoding)
 /*     */   {
 /* 376 */     if (writer == null)
 /* 377 */       this. = new OutputStreamWriter(.);
 /*     */     else {
 /* 379 */       this. = writer;
 /*     */     }
 /* 381 */     this. = _encoding;
 /*     */   }
 /*     */ 
 /*     */   public void setXmlDecl(boolean _writeXmlDecl)
 /*     */   {
 /* 391 */     this. = _writeXmlDecl;
 /*     */   }
 /*     */ 
 /*     */   public void setHeader(String _header)
 /*     */   {
 /* 405 */     this. = _header;
 /*     */   }
 /*     */ 
 /*     */   public void startPrefixMapping(String prefixString uri)
 /*     */     throws SAXException
 /*     */   {
 /* 411 */     this..put(prefixuri);
 /*     */   }
 /*     */ 
 /*     */   public void startDocument()
 /*     */     throws SAXException
 /*     */   {
 /*     */     try
 /*     */     {
 /* 433 */       reset();
 /*     */ 
 /* 435 */       if (this.) {
 /* 436 */         String e = "";
 /* 437 */         if (this. != null) {
 /* 438 */           e = " encoding=\"" + this. + '"';
 /*     */         }
 /* 440 */         writeXmlDecl("<?xml version=\"1.0\"" + e + " standalone=\"yes\"?>");
 /*     */       }
 /*     */ 
 /* 443 */       if (this. != null) {
 /* 444 */         write(this.);
 /*     */       }
 /* 446 */       super.startDocument();
/*     */     } catch (IOException e) {
/* 448 */       throw new SAXException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   protected void writeXmlDecl(String declthrows IOException {
/* 453 */     write(decl);
/*     */   }
/*     */ 
/*     */   public void endDocument()
/*     */     throws SAXException
/*     */   {
/*     */     try
/*     */     {
/* 471 */       super.endDocument();
/* 472 */       flush();
/*     */     } catch (IOException e) {
/* 474 */       throw new SAXException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void startElement(String uriString localNameString qNameAttributes atts)
/*     */     throws SAXException
/*     */   {
/*     */     try
/*     */     {
/* 503 */       if (!this.) {
/* 504 */         write(">");
/*     */       }
/* 506 */       this. += 1;
/*     */ 
/* 509 */       write('<');
/* 510 */       write(qName);
/* 511 */       writeAttributes(atts);
/*     */ 
/* 514 */       if (!this..isEmpty()) {
/* 515 */         for (Map.Entry e : this..entrySet()) {
/* 516 */           String p = (String)e.getKey();
/* 517 */           String u = (String)e.getValue();
/* 518 */           if (u == null) {
/* 519 */             u = "";
/*     */           }
/* 521 */           write(' ');
/* 522 */           if ("".equals(p)) {
/* 523 */             write("xmlns=\"");
/*     */           } else {
/* 525 */             write("xmlns:");
/* 526 */             write(p);
/* 527 */             write("=\"");
/*     */           }
/* 529 */           char[] ch = u.toCharArray();
/* 530 */           writeEsc(ch, 0, ch.lengthtrue);
/* 531 */           write('"');
/*     */         }
/* 533 */         this..clear();
/*     */       }
/*     */ 
/* 540 */       super.startElement(urilocalNameqNameatts);
/* 541 */       this. = false;
/*     */     } catch (IOException e) {
/* 543 */       throw new SAXException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void endElement(String uriString localNameString qName)
/*     */     throws SAXException
/*     */   {
/*     */     try
/*     */     {
/* 570 */       if (this.) {
/* 571 */         write("</");
/* 572 */         write(qName);
/* 573 */         write('>');
/*     */       } else {
/* 575 */         write("/>");
/* 576 */         this. = true;
/*     */       }
/* 578 */       super.endElement(urilocalNameqName);
/*     */ 
/* 580 */       this. -= 1;
/*     */     } catch (IOException e) {
/* 582 */       throw new SAXException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void characters(char[] chint startint len)
/*     */     throws SAXException
/*     */   {
/*     */     try
/*     */     {
/* 604 */       if (!this.) {
/* 605 */         write('>');
/* 606 */         this. = true;
/*     */       }
/* 608 */       writeEsc(chstartlenfalse);
/* 609 */       super.characters(chstartlen);
/*     */     } catch (IOException e) {
/* 611 */       throw new SAXException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void ignorableWhitespace(char[] chint startint length)
/*     */     throws SAXException
/*     */   {
/*     */     try
/*     */     {
/* 633 */       writeEsc(chstartlengthfalse);
/* 634 */       super.ignorableWhitespace(chstartlength);
/*     */     } catch (IOException e) {
/* 636 */       throw new SAXException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void processingInstruction(String targetString data)
/*     */     throws SAXException
/*     */   {
/*     */     try
/*     */     {
/* 658 */       if (!this.) {
/* 659 */         write('>');
/* 660 */         this. = true;
/*     */       }
/* 662 */       write("<?");
/* 663 */       write(target);
/* 664 */       write(' ');
/* 665 */       write(data);
/* 666 */       write("?>");
/* 667 */       if (this. < 1) {
/* 668 */         write('\n');
/*     */       }
/* 670 */       super.processingInstruction(targetdata);
/*     */     } catch (IOException e) {
/* 672 */       throw new SAXException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void startElement(String uriString localName)
/*     */     throws SAXException
/*     */   {
/* 703 */     startElement(urilocalName""this.);
/*     */   }
/*     */ 
/*     */   public void startElement(String localName)
/*     */     throws SAXException
/*     */   {
/* 725 */     startElement(""localName""this.);
/*     */   }
/*     */ 
/*     */   public void endElement(String uriString localName)
/*     */     throws SAXException
/*     */   {
/* 746 */     endElement(urilocalName"");
/*     */   }
/*     */ 
/*     */   public void endElement(String localName)
/*     */     throws SAXException
/*     */   {
/* 767 */     endElement(""localName"");
/*     */   }
/*     */ 
/*     */   public void dataElement(String uriString localNameString qNameAttributes attsString content)
/*     */     throws SAXException
/*     */   {
/* 801 */     startElement(urilocalNameqNameatts);
/* 802 */     characters(content);
/* 803 */     endElement(urilocalNameqName);
/*     */   }
/*     */ 
/*     */   public void dataElement(String uriString localNameString content)
/*     */     throws SAXException
/*     */   {
/* 834 */     dataElement(urilocalName""this.content);
/*     */   }
/*     */ 
/*     */   public void dataElement(String localNameString content)
/*     */     throws SAXException
/*     */   {
/* 865 */     dataElement(""localName""this.content);
/*     */   }
/*     */ 
/*     */   public void characters(String data)
/*     */     throws SAXException
/*     */   {
/*     */     try
/*     */     {
/* 884 */       if (!this.) {
/* 885 */         write('>');
/* 886 */         this. = true;
/*     */       }
/* 888 */       char[] ch = data.toCharArray();
/* 889 */       characters(ch, 0, ch.length);
/*     */     } catch (IOException e) {
/* 891 */       throw new SAXException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   protected final void write(char c)
/*     */     throws IOException
/*     */   {
/* 910 */     this..write(c);
/*     */   }
/*     */ 
/*     */   protected final void write(String s)
/*     */     throws IOException
/*     */   {
/* 918 */     this..write(s);
/*     */   }
/*     */ 
/*     */   private void writeAttributes(Attributes atts)
/*     */     throws IOException
/*     */   {
/* 930 */     int len = atts.getLength();
/* 931 */     for (int i = 0; i < leni++) {
/* 932 */       char[] ch = atts.getValue(i).toCharArray();
/* 933 */       write(' ');
/* 934 */       write(atts.getQName(i));
/* 935 */       write("=\"");
/* 936 */       writeEsc(ch, 0, ch.lengthtrue);
/* 937 */       write('"');
/*     */     }
/*     */   }
/*     */ 
/*     */   private void writeEsc(char[] chint startint lengthboolean isAttVal)
/*     */     throws IOException
/*     */   {
/* 954 */     this..escape(chstartlengthisAttValthis.);
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/thirdparty-all.jar
 * Qualified Name:     com.sun.xml.bind.marshaller.XMLWriter
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X