home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / text / html / HTMLWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  12.6 KB  |  883 lines

  1. package javax.swing.text.html;
  2.  
  3. import java.io.IOException;
  4. import java.io.Writer;
  5. import java.util.Enumeration;
  6. import java.util.Stack;
  7. import java.util.Vector;
  8. import javax.swing.DefaultComboBoxModel;
  9. import javax.swing.DefaultListModel;
  10. import javax.swing.text.AbstractDocument;
  11. import javax.swing.text.AbstractWriter;
  12. import javax.swing.text.AttributeSet;
  13. import javax.swing.text.BadLocationException;
  14. import javax.swing.text.Document;
  15. import javax.swing.text.Element;
  16. import javax.swing.text.ElementIterator;
  17. import javax.swing.text.MutableAttributeSet;
  18. import javax.swing.text.Segment;
  19. import javax.swing.text.SimpleAttributeSet;
  20. import javax.swing.text.Style;
  21. import javax.swing.text.StyleConstants;
  22. import javax.swing.text.StyleContext;
  23. import javax.swing.text.html.HTML.Attribute;
  24. import javax.swing.text.html.HTML.Tag;
  25.  
  26. public class HTMLWriter extends AbstractWriter {
  27.    private Stack blockElementStack;
  28.    private boolean inContent;
  29.    private boolean inPre;
  30.    private int preEndOffset;
  31.    private boolean inTextArea;
  32.    private boolean newlineOutputed;
  33.    private boolean completeDoc;
  34.    private Vector tags;
  35.    private Vector tagValues;
  36.    private Segment segment;
  37.    private Vector tagsToRemove;
  38.    private boolean wroteHead;
  39.    private boolean replaceEntities;
  40.    private char[] tempChars;
  41.    private boolean indentNext;
  42.    private boolean writeCSS;
  43.    private MutableAttributeSet convAttr;
  44.    private MutableAttributeSet oConvAttr;
  45.  
  46.    public HTMLWriter(Writer var1, HTMLDocument var2) {
  47.       this(var1, var2, 0, ((AbstractDocument)var2).getLength());
  48.    }
  49.  
  50.    public HTMLWriter(Writer var1, HTMLDocument var2, int var3, int var4) {
  51.       super(var1, var2, var3, var4);
  52.       this.blockElementStack = new Stack();
  53.       this.inContent = false;
  54.       this.inPre = false;
  55.       this.inTextArea = false;
  56.       this.newlineOutputed = false;
  57.       this.tags = new Vector(10);
  58.       this.tagValues = new Vector(10);
  59.       this.tagsToRemove = new Vector(10);
  60.       this.indentNext = false;
  61.       this.writeCSS = false;
  62.       this.convAttr = new SimpleAttributeSet();
  63.       this.oConvAttr = new SimpleAttributeSet();
  64.       this.completeDoc = var3 == 0 && var4 == ((AbstractDocument)var2).getLength();
  65.       ((AbstractWriter)this).setLineLength(80);
  66.    }
  67.  
  68.    public void write() throws IOException, BadLocationException {
  69.       ElementIterator var1 = ((AbstractWriter)this).getElementIterator();
  70.       Element var2 = null;
  71.       Object var3 = null;
  72.       this.wroteHead = false;
  73.       ((AbstractWriter)this).setCurrentLineLength(0);
  74.       this.replaceEntities = false;
  75.       ((AbstractWriter)this).setCanWrapLines(false);
  76.       if (this.segment == null) {
  77.          this.segment = new Segment();
  78.       }
  79.  
  80.       this.inPre = false;
  81.  
  82.       while((var6 = var1.next()) != null) {
  83.          if (((AbstractWriter)this).inRange(var6)) {
  84.             if (var2 != null) {
  85.                if (this.indentNeedsIncrementing(var2, var6)) {
  86.                   ((AbstractWriter)this).incrIndent();
  87.                } else if (var2.getParentElement() != var6.getParentElement()) {
  88.                   for(Element var7 = (Element)this.blockElementStack.peek(); var7 != var6.getParentElement(); var7 = (Element)this.blockElementStack.peek()) {
  89.                      this.blockElementStack.pop();
  90.                      if (!this.synthesizedElement(var7)) {
  91.                         if (!this.matchNameAttribute(var7.getAttributes(), Tag.PRE)) {
  92.                            ((AbstractWriter)this).decrIndent();
  93.                         }
  94.  
  95.                         this.endTag(var7);
  96.                      }
  97.                   }
  98.                } else if (var2.getParentElement() == var6.getParentElement()) {
  99.                   Element var4 = (Element)this.blockElementStack.peek();
  100.                   if (var4 == var2) {
  101.                      this.blockElementStack.pop();
  102.                      this.endTag(var4);
  103.                   }
  104.                }
  105.             }
  106.  
  107.             if (var6.isLeaf() && !this.isFormElementWithContent(var6.getAttributes())) {
  108.                this.emptyTag(var6);
  109.             } else {
  110.                this.blockElementStack.push(var6);
  111.                this.startTag(var6);
  112.             }
  113.  
  114.             var2 = var6;
  115.          }
  116.       }
  117.  
  118.       this.closeOutUnwantedEmbeddedTags((AttributeSet)null);
  119.  
  120.       while(!this.blockElementStack.empty()) {
  121.          var2 = (Element)this.blockElementStack.pop();
  122.          if (!this.synthesizedElement(var2)) {
  123.             if (!this.matchNameAttribute(var2.getAttributes(), Tag.PRE)) {
  124.                ((AbstractWriter)this).decrIndent();
  125.             }
  126.  
  127.             this.endTag(var2);
  128.          }
  129.       }
  130.  
  131.       if (this.completeDoc) {
  132.          this.writeAdditionalComments();
  133.       }
  134.  
  135.       this.segment.array = null;
  136.    }
  137.  
  138.    protected void writeAttributes(AttributeSet var1) throws IOException {
  139.       this.convAttr.removeAttributes(this.convAttr);
  140.       convertToHTML32(var1, this.convAttr);
  141.       Enumeration var2 = this.convAttr.getAttributeNames();
  142.  
  143.       while(var2.hasMoreElements()) {
  144.          Object var3 = var2.nextElement();
  145.          if (!(var3 instanceof HTML.Tag) && !(var3 instanceof StyleConstants) && var3 != Attribute.ENDTAG) {
  146.             ((AbstractWriter)this).write(" " + var3 + "=\"" + this.convAttr.getAttribute(var3) + "\"");
  147.          }
  148.       }
  149.  
  150.    }
  151.  
  152.    protected void emptyTag(Element var1) throws BadLocationException, IOException {
  153.       if (!this.inContent && !this.inPre) {
  154.          ((AbstractWriter)this).indent();
  155.       }
  156.  
  157.       AttributeSet var2 = var1.getAttributes();
  158.       this.closeOutUnwantedEmbeddedTags(var2);
  159.       this.writeEmbeddedTags(var2);
  160.       if (this.matchNameAttribute(var2, Tag.CONTENT)) {
  161.          this.inContent = true;
  162.          this.text(var1);
  163.       } else if (this.matchNameAttribute(var2, Tag.COMMENT)) {
  164.          this.comment(var1);
  165.       } else {
  166.          boolean var3 = this.isBlockTag(var1.getAttributes());
  167.          if (this.inContent && var3) {
  168.             this.writeLineSeparator();
  169.             ((AbstractWriter)this).indent();
  170.          }
  171.  
  172.          Object var4 = var2 != null ? var2.getAttribute(StyleConstants.NameAttribute) : null;
  173.          Object var5 = var2 != null ? var2.getAttribute(Attribute.ENDTAG) : null;
  174.          boolean var6 = false;
  175.          if (var4 != null && var5 != null && var5 instanceof String && ((String)var5).equals("true")) {
  176.             var6 = true;
  177.          }
  178.  
  179.          if (this.completeDoc && this.matchNameAttribute(var2, Tag.HEAD)) {
  180.             if (var6) {
  181.                this.writeStyles(((HTMLDocument)((AbstractWriter)this).getDocument()).getStyleSheet());
  182.             }
  183.  
  184.             this.wroteHead = true;
  185.          }
  186.  
  187.          ((AbstractWriter)this).write('<');
  188.          if (var6) {
  189.             ((AbstractWriter)this).write('/');
  190.          }
  191.  
  192.          ((AbstractWriter)this).write(var1.getName());
  193.          this.writeAttributes(var2);
  194.          ((AbstractWriter)this).write('>');
  195.          if (this.matchNameAttribute(var2, Tag.TITLE) && !var6) {
  196.             Document var7 = var1.getDocument();
  197.             String var8 = (String)var7.getProperty("title");
  198.             ((AbstractWriter)this).write(var8);
  199.          } else if (!this.inContent || var3) {
  200.             this.writeLineSeparator();
  201.             if (var3 && this.inContent) {
  202.                ((AbstractWriter)this).indent();
  203.             }
  204.          }
  205.       }
  206.  
  207.    }
  208.  
  209.    protected boolean isBlockTag(AttributeSet var1) {
  210.       Object var2 = var1.getAttribute(StyleConstants.NameAttribute);
  211.       if (var2 instanceof HTML.Tag) {
  212.          HTML.Tag var3 = (HTML.Tag)var2;
  213.          return var3.isBlock();
  214.       } else {
  215.          return false;
  216.       }
  217.    }
  218.  
  219.    protected void startTag(Element var1) throws IOException, BadLocationException {
  220.       if (!this.synthesizedElement(var1)) {
  221.          AttributeSet var2 = var1.getAttributes();
  222.          Object var3 = var2.getAttribute(StyleConstants.NameAttribute);
  223.          HTML.Tag var4;
  224.          if (var3 instanceof HTML.Tag) {
  225.             var4 = (HTML.Tag)var3;
  226.          } else {
  227.             var4 = null;
  228.          }
  229.  
  230.          if (var4 == Tag.PRE) {
  231.             this.inPre = true;
  232.             this.preEndOffset = var1.getEndOffset();
  233.          }
  234.  
  235.          this.closeOutUnwantedEmbeddedTags(var2);
  236.          if (this.inContent) {
  237.             this.writeLineSeparator();
  238.             this.inContent = false;
  239.             this.newlineOutputed = false;
  240.          }
  241.  
  242.          if (this.completeDoc && var4 == Tag.BODY && !this.wroteHead) {
  243.             this.wroteHead = true;
  244.             ((AbstractWriter)this).indent();
  245.             ((AbstractWriter)this).write("<head>");
  246.             this.writeLineSeparator();
  247.             ((AbstractWriter)this).incrIndent();
  248.             this.writeStyles(((HTMLDocument)((AbstractWriter)this).getDocument()).getStyleSheet());
  249.             ((AbstractWriter)this).decrIndent();
  250.             this.writeLineSeparator();
  251.             ((AbstractWriter)this).indent();
  252.             ((AbstractWriter)this).write("</head>");
  253.             this.writeLineSeparator();
  254.          }
  255.  
  256.          ((AbstractWriter)this).indent();
  257.          ((AbstractWriter)this).write('<');
  258.          ((AbstractWriter)this).write(var1.getName());
  259.          this.writeAttributes(var2);
  260.          ((AbstractWriter)this).write('>');
  261.          if (var4 != Tag.PRE) {
  262.             this.writeLineSeparator();
  263.          }
  264.  
  265.          if (var4 == Tag.TEXTAREA) {
  266.             this.textAreaContent(var1.getAttributes());
  267.          } else if (var4 == Tag.SELECT) {
  268.             this.selectContent(var1.getAttributes());
  269.          } else if (this.completeDoc && var4 == Tag.BODY) {
  270.             this.writeMaps(((HTMLDocument)((AbstractWriter)this).getDocument()).getMaps());
  271.          } else if (var4 == Tag.HEAD) {
  272.             this.wroteHead = true;
  273.          }
  274.  
  275.       }
  276.    }
  277.  
  278.    protected void textAreaContent(AttributeSet var1) throws BadLocationException, IOException {
  279.       Document var2 = (Document)var1.getAttribute(StyleConstants.ModelAttribute);
  280.       if (var2 != null && var2.getLength() > 0) {
  281.          if (this.segment == null) {
  282.             this.segment = new Segment();
  283.          }
  284.  
  285.          var2.getText(0, var2.getLength(), this.segment);
  286.          if (this.segment.count > 0) {
  287.             this.inTextArea = true;
  288.             ((AbstractWriter)this).incrIndent();
  289.             ((AbstractWriter)this).indent();
  290.             ((AbstractWriter)this).setCanWrapLines(true);
  291.             this.replaceEntities = true;
  292.             ((AbstractWriter)this).write(this.segment.array, this.segment.offset, this.segment.count);
  293.             this.replaceEntities = false;
  294.             ((AbstractWriter)this).setCanWrapLines(false);
  295.             this.writeLineSeparator();
  296.             this.inTextArea = false;
  297.             ((AbstractWriter)this).decrIndent();
  298.          }
  299.       }
  300.  
  301.    }
  302.  
  303.    protected void text(Element var1) throws BadLocationException, IOException {
  304.       int var2 = Math.max(((AbstractWriter)this).getStartOffset(), var1.getStartOffset());
  305.       int var3 = Math.min(((AbstractWriter)this).getEndOffset(), var1.getEndOffset());
  306.       if (var2 < var3) {
  307.          if (this.segment == null) {
  308.             this.segment = new Segment();
  309.          }
  310.  
  311.          ((AbstractWriter)this).getDocument().getText(var2, var3 - var2, this.segment);
  312.          this.newlineOutputed = false;
  313.          if (this.segment.count > 0) {
  314.             if (this.segment.array[this.segment.offset + this.segment.count - 1] == '\n') {
  315.                this.newlineOutputed = true;
  316.             }
  317.  
  318.             if (this.inPre && var3 == this.preEndOffset) {
  319.                if (this.segment.count <= 1) {
  320.                   return;
  321.                }
  322.  
  323.                --this.segment.count;
  324.             }
  325.  
  326.             this.replaceEntities = true;
  327.             ((AbstractWriter)this).setCanWrapLines(!this.inPre);
  328.             ((AbstractWriter)this).write(this.segment.array, this.segment.offset, this.segment.count);
  329.             ((AbstractWriter)this).setCanWrapLines(false);
  330.             this.replaceEntities = false;
  331.          }
  332.       }
  333.  
  334.    }
  335.  
  336.    protected void selectContent(AttributeSet var1) throws IOException {
  337.       Object var2 = var1.getAttribute(StyleConstants.ModelAttribute);
  338.       ((AbstractWriter)this).incrIndent();
  339.       if (var2 instanceof OptionListModel) {
  340.          OptionListModel var3 = (OptionListModel)var2;
  341.          int var4 = ((DefaultListModel)var3).getSize();
  342.  
  343.          for(int var5 = 0; var5 < var4; ++var5) {
  344.             Option var6 = (Option)((DefaultListModel)var3).getElementAt(var5);
  345.             this.writeOption(var6);
  346.          }
  347.       } else if (var2 instanceof OptionComboBoxModel) {
  348.          OptionComboBoxModel var7 = (OptionComboBoxModel)var2;
  349.          int var8 = ((DefaultComboBoxModel)var7).getSize();
  350.  
  351.          for(int var9 = 0; var9 < var8; ++var9) {
  352.             Option var10 = (Option)((DefaultComboBoxModel)var7).getElementAt(var9);
  353.             this.writeOption(var10);
  354.          }
  355.       }
  356.  
  357.       ((AbstractWriter)this).decrIndent();
  358.    }
  359.  
  360.    protected void writeOption(Option var1) throws IOException {
  361.       ((AbstractWriter)this).indent();
  362.       ((AbstractWriter)this).write('<');
  363.       ((AbstractWriter)this).write("option ");
  364.       if (var1.getValue() != null) {
  365.          ((AbstractWriter)this).write("value=" + var1.getValue());
  366.       }
  367.  
  368.       if (var1.isSelected()) {
  369.          ((AbstractWriter)this).write(" selected");
  370.       }
  371.  
  372.       ((AbstractWriter)this).write('>');
  373.       if (var1.getLabel() != null) {
  374.          ((AbstractWriter)this).write(var1.getLabel());
  375.       }
  376.  
  377.       this.writeLineSeparator();
  378.    }
  379.  
  380.    protected void endTag(Element var1) throws IOException {
  381.       if (!this.synthesizedElement(var1)) {
  382.          if (this.matchNameAttribute(var1.getAttributes(), Tag.PRE)) {
  383.             this.inPre = false;
  384.          }
  385.  
  386.          this.closeOutUnwantedEmbeddedTags(var1.getAttributes());
  387.          if (this.inContent) {
  388.             if (!this.newlineOutputed) {
  389.                this.writeLineSeparator();
  390.             }
  391.  
  392.             this.newlineOutputed = false;
  393.             this.inContent = false;
  394.          }
  395.  
  396.          ((AbstractWriter)this).indent();
  397.          ((AbstractWriter)this).write('<');
  398.          ((AbstractWriter)this).write('/');
  399.          ((AbstractWriter)this).write(var1.getName());
  400.          ((AbstractWriter)this).write('>');
  401.          this.writeLineSeparator();
  402.       }
  403.    }
  404.  
  405.    protected void comment(Element var1) throws BadLocationException, IOException {
  406.       AttributeSet var2 = var1.getAttributes();
  407.       if (this.matchNameAttribute(var2, Tag.COMMENT)) {
  408.          Object var3 = var2.getAttribute(Attribute.COMMENT);
  409.          if (var3 instanceof String) {
  410.             this.writeComment((String)var3);
  411.          } else {
  412.             this.writeComment((String)null);
  413.          }
  414.       }
  415.  
  416.    }
  417.  
  418.    void writeComment(String var1) throws IOException {
  419.       ((AbstractWriter)this).write("<!--");
  420.       if (var1 != null) {
  421.          ((AbstractWriter)this).write(var1);
  422.       }
  423.  
  424.       ((AbstractWriter)this).write("-->");
  425.       this.writeLineSeparator();
  426.    }
  427.  
  428.    void writeAdditionalComments() throws IOException {
  429.       Object var1 = ((AbstractWriter)this).getDocument().getProperty("AdditionalComments");
  430.       if (var1 instanceof Vector) {
  431.          Vector var2 = (Vector)var1;
  432.          int var3 = 0;
  433.  
  434.          for(int var4 = var2.size(); var3 < var4; ++var3) {
  435.             this.writeComment(var2.elementAt(var3).toString());
  436.          }
  437.       }
  438.  
  439.    }
  440.  
  441.    protected boolean synthesizedElement(Element var1) {
  442.       return this.matchNameAttribute(var1.getAttributes(), Tag.IMPLIED);
  443.    }
  444.  
  445.    protected boolean matchNameAttribute(AttributeSet var1, HTML.Tag var2) {
  446.       Object var3 = var1.getAttribute(StyleConstants.NameAttribute);
  447.       if (var3 instanceof HTML.Tag) {
  448.          HTML.Tag var4 = (HTML.Tag)var3;
  449.          if (var4 == var2) {
  450.             return true;
  451.          }
  452.       }
  453.  
  454.       return false;
  455.    }
  456.  
  457.    protected void writeEmbeddedTags(AttributeSet var1) throws IOException {
  458.       var1 = this.convertToHTML(var1, this.oConvAttr);
  459.       Enumeration var2 = var1.getAttributeNames();
  460.  
  461.       while(var2.hasMoreElements()) {
  462.          Object var3 = var2.nextElement();
  463.          if (var3 instanceof HTML.Tag) {
  464.             HTML.Tag var4 = (HTML.Tag)var3;
  465.             if (var4 != Tag.FORM && !this.tags.contains(var4)) {
  466.                ((AbstractWriter)this).write('<');
  467.                ((AbstractWriter)this).write(var4.toString());
  468.                Object var5 = var1.getAttribute(var4);
  469.                if (var5 != null && var5 instanceof AttributeSet) {
  470.                   this.writeAttributes((AttributeSet)var5);
  471.                }
  472.  
  473.                ((AbstractWriter)this).write('>');
  474.                this.tags.addElement(var4);
  475.                this.tagValues.addElement(var5);
  476.             }
  477.          }
  478.       }
  479.  
  480.    }
  481.  
  482.    private boolean noMatchForTagInAttributes(AttributeSet var1, HTML.Tag var2, Object var3) {
  483.       if (var1 != null && var1.isDefined(var2)) {
  484.          Object var4 = var1.getAttribute(var2);
  485.          if (var3 == null ? var4 == null : var4 != null && var3.equals(var4)) {
  486.             return false;
  487.          }
  488.       }
  489.  
  490.       return true;
  491.    }
  492.  
  493.    protected void closeOutUnwantedEmbeddedTags(AttributeSet var1) throws IOException {
  494.       this.tagsToRemove.removeAllElements();
  495.       var1 = this.convertToHTML(var1, (MutableAttributeSet)null);
  496.       int var4 = -1;
  497.       int var5 = this.tags.size();
  498.  
  499.       for(int var6 = var5 - 1; var6 >= 0; --var6) {
  500.          HTML.Tag var2 = (HTML.Tag)this.tags.elementAt(var6);
  501.          Object var3 = this.tagValues.elementAt(var6);
  502.          if (var1 == null || this.noMatchForTagInAttributes(var1, var2, var3)) {
  503.             var4 = var6;
  504.             this.tagsToRemove.addElement(var2);
  505.          }
  506.       }
  507.  
  508.       if (var4 != -1) {
  509.          boolean var7 = var5 - var4 == this.tagsToRemove.size();
  510.  
  511.          for(int var8 = var5 - 1; var8 >= var4; --var8) {
  512.             HTML.Tag var12 = (HTML.Tag)this.tags.elementAt(var8);
  513.             if (var7 || this.tagsToRemove.contains(var12)) {
  514.                this.tags.removeElementAt(var8);
  515.                this.tagValues.removeElementAt(var8);
  516.             }
  517.  
  518.             ((AbstractWriter)this).write('<');
  519.             ((AbstractWriter)this).write('/');
  520.             ((AbstractWriter)this).write(var12.toString());
  521.             ((AbstractWriter)this).write('>');
  522.          }
  523.  
  524.          var5 = this.tags.size();
  525.  
  526.          for(int var9 = var4; var9 < var5; ++var9) {
  527.             HTML.Tag var13 = (HTML.Tag)this.tags.elementAt(var9);
  528.             ((AbstractWriter)this).write('<');
  529.             ((AbstractWriter)this).write(var13.toString());
  530.             Object var10 = this.tagValues.elementAt(var9);
  531.             if (var10 != null && var10 instanceof AttributeSet) {
  532.                this.writeAttributes((AttributeSet)var10);
  533.             }
  534.  
  535.             ((AbstractWriter)this).write('>');
  536.          }
  537.       }
  538.  
  539.    }
  540.  
  541.    private boolean isFormElementWithContent(AttributeSet var1) {
  542.       return this.matchNameAttribute(var1, Tag.TEXTAREA) || this.matchNameAttribute(var1, Tag.SELECT);
  543.    }
  544.  
  545.    private boolean indentNeedsIncrementing(Element var1, Element var2) {
  546.       if (var2.getParentElement() == var1 && !this.inPre) {
  547.          if (this.indentNext) {
  548.             this.indentNext = false;
  549.             return true;
  550.          }
  551.  
  552.          if (this.synthesizedElement(var2)) {
  553.             this.indentNext = true;
  554.          } else if (!this.synthesizedElement(var1)) {
  555.             return true;
  556.          }
  557.       }
  558.  
  559.       return false;
  560.    }
  561.  
  562.    void writeMaps(Enumeration var1) throws IOException {
  563.       if (var1 != null) {
  564.          while(var1.hasMoreElements()) {
  565.             Map var2 = (Map)var1.nextElement();
  566.             String var3 = var2.getName();
  567.             ((AbstractWriter)this).incrIndent();
  568.             ((AbstractWriter)this).indent();
  569.             ((AbstractWriter)this).write("<map");
  570.             if (var3 != null) {
  571.                ((AbstractWriter)this).write(" name=\"");
  572.                ((AbstractWriter)this).write(var3);
  573.                ((AbstractWriter)this).write("\">");
  574.             } else {
  575.                ((AbstractWriter)this).write('>');
  576.             }
  577.  
  578.             this.writeLineSeparator();
  579.             ((AbstractWriter)this).incrIndent();
  580.             AttributeSet[] var4 = var2.getAreas();
  581.             if (var4 != null) {
  582.                int var5 = 0;
  583.  
  584.                for(int var6 = var4.length; var5 < var6; ++var5) {
  585.                   ((AbstractWriter)this).indent();
  586.                   ((AbstractWriter)this).write("<area");
  587.                   this.writeAttributes(var4[var5]);
  588.                   ((AbstractWriter)this).write("></area>");
  589.                   this.writeLineSeparator();
  590.                }
  591.             }
  592.  
  593.             ((AbstractWriter)this).decrIndent();
  594.             ((AbstractWriter)this).indent();
  595.             ((AbstractWriter)this).write("</map>");
  596.             this.writeLineSeparator();
  597.             ((AbstractWriter)this).decrIndent();
  598.          }
  599.       }
  600.  
  601.    }
  602.  
  603.    void writeStyles(StyleSheet var1) throws IOException {
  604.       if (var1 != null) {
  605.          Enumeration var2 = ((StyleContext)var1).getStyleNames();
  606.          if (var2 != null) {
  607.             boolean var3 = false;
  608.  
  609.             while(var2.hasMoreElements()) {
  610.                String var4 = (String)var2.nextElement();
  611.                if (!"default".equals(var4) && this.writeStyle(var4, ((StyleContext)var1).getStyle(var4), var3)) {
  612.                   var3 = true;
  613.                }
  614.             }
  615.  
  616.             if (var3) {
  617.                this.writeStyleEndTag();
  618.             }
  619.          }
  620.       }
  621.  
  622.    }
  623.  
  624.    boolean writeStyle(String var1, Style var2, boolean var3) throws IOException {
  625.       boolean var4 = false;
  626.       Enumeration var5 = var2.getAttributeNames();
  627.       if (var5 != null) {
  628.          while(var5.hasMoreElements()) {
  629.             Object var6 = var5.nextElement();
  630.             if (var6 instanceof CSS.Attribute) {
  631.                String var7 = var2.getAttribute(var6).toString();
  632.                if (var7 != null) {
  633.                   if (!var3) {
  634.                      this.writeStyleStartTag();
  635.                      var3 = true;
  636.                   }
  637.  
  638.                   if (!var4) {
  639.                      var4 = true;
  640.                      ((AbstractWriter)this).indent();
  641.                      ((AbstractWriter)this).write(var1);
  642.                      ((AbstractWriter)this).write(" {");
  643.                   } else {
  644.                      ((AbstractWriter)this).write(";");
  645.                   }
  646.  
  647.                   ((AbstractWriter)this).write(' ');
  648.                   ((AbstractWriter)this).write(var6.toString());
  649.                   ((AbstractWriter)this).write(": ");
  650.                   ((AbstractWriter)this).write(var7);
  651.                }
  652.             }
  653.          }
  654.       }
  655.  
  656.       if (var4) {
  657.          ((AbstractWriter)this).write(" }");
  658.          this.writeLineSeparator();
  659.       }
  660.  
  661.       return var4;
  662.    }
  663.  
  664.    void writeStyleStartTag() throws IOException {
  665.       ((AbstractWriter)this).indent();
  666.       ((AbstractWriter)this).write("<style type=\"text/css\">");
  667.       ((AbstractWriter)this).incrIndent();
  668.       this.writeLineSeparator();
  669.       ((AbstractWriter)this).indent();
  670.       ((AbstractWriter)this).write("<!--");
  671.       ((AbstractWriter)this).incrIndent();
  672.       this.writeLineSeparator();
  673.    }
  674.  
  675.    void writeStyleEndTag() throws IOException {
  676.       ((AbstractWriter)this).decrIndent();
  677.       ((AbstractWriter)this).indent();
  678.       ((AbstractWriter)this).write("-->");
  679.       this.writeLineSeparator();
  680.       ((AbstractWriter)this).decrIndent();
  681.       ((AbstractWriter)this).indent();
  682.       ((AbstractWriter)this).write("</style>");
  683.       this.writeLineSeparator();
  684.       ((AbstractWriter)this).indent();
  685.    }
  686.  
  687.    AttributeSet convertToHTML(AttributeSet var1, MutableAttributeSet var2) {
  688.       if (var2 == null) {
  689.          var2 = this.convAttr;
  690.       }
  691.  
  692.       var2.removeAttributes(var2);
  693.       if (this.writeCSS) {
  694.          convertToHTML40(var1, var2);
  695.       } else {
  696.          convertToHTML32(var1, var2);
  697.       }
  698.  
  699.       return var2;
  700.    }
  701.  
  702.    private static void convertToHTML32(AttributeSet var0, MutableAttributeSet var1) {
  703.       if (var0 != null) {
  704.          Enumeration var2 = var0.getAttributeNames();
  705.          String var3 = "";
  706.  
  707.          while(var2.hasMoreElements()) {
  708.             Object var4 = var2.nextElement();
  709.             if (var4 instanceof CSS.Attribute) {
  710.                if (var4 != javax.swing.text.html.CSS.Attribute.FONT_FAMILY && var4 != javax.swing.text.html.CSS.Attribute.FONT_SIZE && var4 != javax.swing.text.html.CSS.Attribute.COLOR) {
  711.                   if (var4 == javax.swing.text.html.CSS.Attribute.FONT_WEIGHT) {
  712.                      CSS.FontWeight var5 = (CSS.FontWeight)var0.getAttribute(javax.swing.text.html.CSS.Attribute.FONT_WEIGHT);
  713.                      if (var5 != null && var5.getValue() > 400) {
  714.                         var1.addAttribute(Tag.B, SimpleAttributeSet.EMPTY);
  715.                      }
  716.                   } else if (var4 == javax.swing.text.html.CSS.Attribute.FONT_STYLE) {
  717.                      String var6 = var0.getAttribute(var4).toString();
  718.                      if (var6.indexOf("italic") >= 0) {
  719.                         var1.addAttribute(Tag.I, SimpleAttributeSet.EMPTY);
  720.                      }
  721.                   } else if (var4 == javax.swing.text.html.CSS.Attribute.TEXT_DECORATION) {
  722.                      String var7 = var0.getAttribute(var4).toString();
  723.                      if (var7.indexOf("underline") >= 0) {
  724.                         var1.addAttribute(Tag.U, SimpleAttributeSet.EMPTY);
  725.                      }
  726.  
  727.                      if (var7.indexOf("line-through") >= 0) {
  728.                         var1.addAttribute(Tag.STRIKE, SimpleAttributeSet.EMPTY);
  729.                      }
  730.                   } else if (var4 == javax.swing.text.html.CSS.Attribute.VERTICAL_ALIGN) {
  731.                      String var8 = var0.getAttribute(var4).toString();
  732.                      if (var8.indexOf("sup") >= 0) {
  733.                         var1.addAttribute(Tag.SUP, SimpleAttributeSet.EMPTY);
  734.                      }
  735.  
  736.                      if (var8.indexOf("sub") >= 0) {
  737.                         var1.addAttribute(Tag.SUB, SimpleAttributeSet.EMPTY);
  738.                      }
  739.                   } else if (var4 == javax.swing.text.html.CSS.Attribute.TEXT_ALIGN) {
  740.                      var1.addAttribute(Attribute.ALIGN, var0.getAttribute(var4).toString());
  741.                   } else {
  742.                      if (var3.length() > 0) {
  743.                         var3 = var3 + "; ";
  744.                      }
  745.  
  746.                      var3 = var3 + var4 + ": " + var0.getAttribute(var4);
  747.                   }
  748.                } else {
  749.                   createFontAttribute((CSS.Attribute)var4, var0, var1);
  750.                }
  751.             } else {
  752.                var1.addAttribute(var4, var0.getAttribute(var4));
  753.             }
  754.          }
  755.  
  756.          if (var3.length() > 0) {
  757.             var1.addAttribute(Attribute.STYLE, var3);
  758.          }
  759.  
  760.       }
  761.    }
  762.  
  763.    private static void createFontAttribute(CSS.Attribute var0, AttributeSet var1, MutableAttributeSet var2) {
  764.       Object var3 = (MutableAttributeSet)var2.getAttribute(Tag.FONT);
  765.       if (var3 == null) {
  766.          var3 = new SimpleAttributeSet();
  767.          var2.addAttribute(Tag.FONT, var3);
  768.       }
  769.  
  770.       String var4 = var1.getAttribute(var0).toString();
  771.       if (var0 == javax.swing.text.html.CSS.Attribute.FONT_FAMILY) {
  772.          ((MutableAttributeSet)var3).addAttribute(Attribute.FACE, var4);
  773.       } else if (var0 == javax.swing.text.html.CSS.Attribute.FONT_SIZE) {
  774.          ((MutableAttributeSet)var3).addAttribute(Attribute.SIZE, var4);
  775.       } else if (var0 == javax.swing.text.html.CSS.Attribute.COLOR) {
  776.          ((MutableAttributeSet)var3).addAttribute(Attribute.COLOR, var4);
  777.       }
  778.  
  779.    }
  780.  
  781.    private static void convertToHTML40(AttributeSet var0, MutableAttributeSet var1) {
  782.       Enumeration var2 = var0.getAttributeNames();
  783.       String var3 = "";
  784.  
  785.       while(var2.hasMoreElements()) {
  786.          Object var4 = var2.nextElement();
  787.          if (var4 instanceof CSS.Attribute) {
  788.             var3 = var3 + " " + var4 + "=" + var0.getAttribute(var4) + ";";
  789.          } else {
  790.             var1.addAttribute(var4, var0.getAttribute(var4));
  791.          }
  792.       }
  793.  
  794.       if (var3.length() > 0) {
  795.          var1.addAttribute(Attribute.STYLE, var3);
  796.       }
  797.  
  798.    }
  799.  
  800.    protected void writeLineSeparator() throws IOException {
  801.       boolean var1 = this.replaceEntities;
  802.       this.replaceEntities = false;
  803.       super.writeLineSeparator();
  804.       this.replaceEntities = var1;
  805.    }
  806.  
  807.    protected void output(char[] var1, int var2, int var3) throws IOException {
  808.       if (!this.replaceEntities) {
  809.          super.output(var1, var2, var3);
  810.       } else {
  811.          int var4 = var2;
  812.          var3 += var2;
  813.  
  814.          for(int var5 = var2; var5 < var3; ++var5) {
  815.             switch (var1[var5]) {
  816.                case '\t':
  817.                case '\n':
  818.                case '\r':
  819.                   break;
  820.                case '"':
  821.                   if (var5 > var4) {
  822.                      super.output(var1, var4, var5 - var4);
  823.                   }
  824.  
  825.                   var4 = var5 + 1;
  826.                   this.output(""");
  827.                   break;
  828.                case '&':
  829.                   if (var5 > var4) {
  830.                      super.output(var1, var4, var5 - var4);
  831.                   }
  832.  
  833.                   var4 = var5 + 1;
  834.                   this.output("&");
  835.                   break;
  836.                case '<':
  837.                   if (var5 > var4) {
  838.                      super.output(var1, var4, var5 - var4);
  839.                   }
  840.  
  841.                   var4 = var5 + 1;
  842.                   this.output("<");
  843.                   break;
  844.                case '>':
  845.                   if (var5 > var4) {
  846.                      super.output(var1, var4, var5 - var4);
  847.                   }
  848.  
  849.                   var4 = var5 + 1;
  850.                   this.output(">");
  851.                   break;
  852.                default:
  853.                   if (var1[var5] < ' ' || var1[var5] > 127) {
  854.                      if (var5 > var4) {
  855.                         super.output(var1, var4, var5 - var4);
  856.                      }
  857.  
  858.                      var4 = var5 + 1;
  859.                      this.output("&#");
  860.                      this.output(String.valueOf(var1[var5]));
  861.                      this.output(";");
  862.                   }
  863.             }
  864.          }
  865.  
  866.          if (var4 < var3) {
  867.             super.output(var1, var4, var3 - var4);
  868.          }
  869.  
  870.       }
  871.    }
  872.  
  873.    private void output(String var1) throws IOException {
  874.       int var2 = var1.length();
  875.       if (this.tempChars == null || this.tempChars.length < var2) {
  876.          this.tempChars = new char[var2];
  877.       }
  878.  
  879.       var1.getChars(0, var2, this.tempChars, 0);
  880.       super.output(this.tempChars, 0, var2);
  881.    }
  882. }
  883.