001package com.hfg.xml;
002
003import com.hfg.exception.ProgrammingException;
004import com.hfg.html.Table;
005
006import java.io.OutputStream;
007import java.io.IOException;
008import java.io.Writer;
009
010
011public class XMLComment implements XMLizable
012{
013   private String mComment;
014
015   //##########################################################################
016   // CONSTRUCTORS
017   //##########################################################################
018
019   //--------------------------------------------------------------------------
020   public XMLComment()
021   {
022
023   }
024
025   //--------------------------------------------------------------------------
026   public XMLComment(String inComment)
027   {
028      mComment = inComment;
029   }
030
031   //##########################################################################
032   // PUBLIC METHODS
033   //##########################################################################
034
035
036   //---------------------------------------------------------------------------
037   public XMLComment clone()
038   {
039      XMLComment cloneObj;
040      try
041      {
042         cloneObj = (XMLComment) super.clone();
043      }
044      catch (CloneNotSupportedException e)
045      {
046         throw new ProgrammingException(e);
047      }
048
049      return cloneObj;
050   }
051
052   //---------------------------------------------------------------------------
053   public boolean hasContent()
054   {
055      return true;
056   }
057
058
059   //---------------------------------------------------------------------------
060   public void setContent(String inContent)
061   {
062      mComment = inContent;
063   }
064
065   //---------------------------------------------------------------------------
066   /**
067    Clears content (not subtags).
068    */
069   public void clearContent()
070   {
071      mComment = null;
072   }
073
074   //---------------------------------------------------------------------------
075   public void addContent(String inContent)
076   {
077      mComment += inContent;
078   }
079
080   //---------------------------------------------------------------------------
081   /**
082    The returned content does not contain any embedded subtags.
083    */
084   public String getContent()
085   {
086      return mComment;
087   }
088
089
090   //---------------------------------------------------------------------------
091   public String toXML()
092   {
093      return "<!--" + mComment + "-->";
094   }
095
096   //---------------------------------------------------------------------------
097   public void toXML(Writer inWriter)
098   {
099      try
100      {
101         inWriter.write(toXML());
102      }
103      catch (IOException e)
104      {
105         throw new RuntimeException(e);
106      }
107   }
108
109   //---------------------------------------------------------------------------
110   public void toXML(OutputStream inStream)
111   {
112      try
113      {
114         inStream.write(toXML().getBytes());
115      }
116      catch (Exception e)
117      {
118         throw new XMLException(e);
119      }
120   }
121
122
123
124   //--------------------------------------------------------------------------
125   public String toIndentedXML(int inInitialIndentLevel, int inIndentSize)
126   {
127      return toXML();
128   }
129
130   //--------------------------------------------------------------------------
131   public void toIndentedXML(OutputStream inOutputStream, int inInitialIndentLevel, int inIndentSize)
132   {
133      toXML(inOutputStream);
134   }
135
136   //--------------------------------------------------------------------------
137   public void toIndentedXML(Writer inWriter, int inInitialIndentLevel, int inIndentSize)
138   {
139      toXML(inWriter);
140   }
141
142
143}