Back to index

wims  3.65+svn20090927
XmlWriter.java
Go to the documentation of this file.
00001 package rene.util.xml;
00002 
00003 import java.io.PrintWriter;
00004 import java.util.Vector;
00005 
00006 import rene.util.parser.StringParser;
00007 
00008 public class XmlWriter
00009 {      PrintWriter Out;
00010        public XmlWriter (PrintWriter o)
00011        {      Out=o;
00012        }
00013        public void printTag (String tag, String content)
00014        {      startTag(tag);
00015               print(content);
00016               endTag(tag);
00017        }
00018        public void printTagNewLine (String tag, String content)
00019        {      printTag(tag,content);
00020               Out.println();
00021        }
00022        public void printTag (String tag, String arg, String value, String content)
00023        {      startTag(tag,arg,value);
00024               print(content);
00025               endTag(tag);
00026        }
00027        public void printTagNewLine (String tag, String arg, String value, String content)
00028        {      printTag(tag,arg,value,content);
00029               Out.println();
00030        }
00031        public void startTag (String tag)
00032        {      Out.print("<");
00033               Out.print(tag);
00034               Out.print(">");
00035        }
00036        public void startTag (String tag, String arg, String value)
00037        {      Out.print("<");
00038               Out.print(tag);
00039               printArg(arg,value);
00040               Out.print(">");
00041        }
00042        public void finishTag (String tag, String arg, String value)
00043        {      Out.print("<");
00044               Out.print(tag);
00045               printArg(arg,value);
00046               Out.println("/>");
00047        }
00048        public void finishTag (String tag)
00049        {      Out.print("<");
00050               Out.print(tag);
00051               Out.print("/>");
00052        }
00053        public void finishTagNewLine (String tag)
00054        {      Out.print("<");
00055               Out.print(tag);
00056               Out.println("/>");
00057        }
00058        public void startTagStart (String tag)
00059        {      Out.print("<");
00060               Out.print(tag);
00061        }
00062        public void startTagEnd ()
00063        {      Out.print(">");
00064        }
00065        public void finishTag ()
00066        {      Out.print("/>");
00067        }
00068        public void finishTagNewLine ()
00069        {      Out.println("/>");
00070        }
00071        public void startTagEndNewLine ()
00072        {      Out.println(">");
00073        }
00074        public void printArg (String arg, String value)
00075        {      Out.print(" ");
00076               print(arg);
00077               Out.print("=\"");
00078               print(value);
00079               Out.print("\"");
00080        }
00081        public void startTagNewLine (String tag, String arg, String value)
00082        {      startTag(tag,arg,value);
00083               Out.println();
00084        }
00085        public void startTagNewLine (String tag)
00086        {      startTag(tag);
00087               Out.println();
00088        }
00089        public void endTag (String tag)
00090        {      Out.print("</");
00091               Out.print(tag);
00092               Out.print(">");
00093        }
00094        public void endTagNewLine (String tag)
00095        {      endTag(tag);
00096               Out.println();
00097        }
00098        public void println ()
00099        {      Out.println();
00100        }
00101        public void print (String s)
00102        {      Out.print(XmlTranslator.toXml(s));
00103        }
00104        public void println (String s)
00105        {      Out.println(XmlTranslator.toXml(s));
00106        }
00107        public void printEncoding (String s)
00108        {      if (s.equals("")) Out.println("<?xml version=\"1.0\"?>");
00109               else Out.println("<?xml version=\"1.0\" encoding=\""+s+"\"?>");
00110        }
00111        public void printXml()
00112        {      printEncoding("");
00113        }
00114        public void printEncoding ()
00115        {      printEncoding("utf-8");
00116        }
00117        public void printXls (String s)
00118        {      Out.println("<?xml-stylesheet href=\""+s+"\" type=\"text/xsl\"?>");
00119        }
00120        public void printParagraphs (String s, int linelength)
00121        {      StringParser p=new StringParser(s);
00122               Vector v=p.wrapwords(linelength);
00123               for (int i=0; i<v.size(); i++)
00124               {      startTag("P");
00125                      s=(String)v.elementAt(i);
00126                      StringParser q=new StringParser(s);
00127                      Vector w=q.wraplines(linelength);
00128                      for (int j=0; j<w.size(); j++)
00129                      {      if (j>0) println();
00130                             s=(String)w.elementAt(j);
00131                             print(s);
00132                      }
00133                      endTagNewLine("P");
00134               }
00135        }
00136        public void printDoctype (String top, String dtd)
00137        {      Out.print("<!DOCTYPE ");
00138               Out.print(top);
00139               Out.print(" SYSTEM \"");
00140               Out.print(dtd);
00141               Out.println("\">");
00142        }
00143        
00144        public void close ()
00145        {      Out.close();
00146        }
00147 }