KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > generator > TagGenerator


1 /**
2  * copyright 2002 2004 Laboratoire d'Informatique Paris 6 (LIP6)
3  *
4  * This file is part of ModFact.
5  *
6  * ModFact is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * at your option) any later version.
10  *
11  * ModFact is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with ModFact; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20 package org.objectweb.modfact.jmi.generator;
21
22 /**
23  * An abstract implementation of a generator.
24  * This class allows the generation of files with tags (like XML).
25  *
26  * @author Pierre Carpentier
27  */

28 public abstract class TagGenerator extends PrintGenerator {
29
30     /**
31      * Print the output to the global PrintWriter (replace out.print(String)).
32      * @param out The string to print.
33      */

34     protected void output(String JavaDoc outputString) {
35         if (outputString.startsWith("</"))
36             level--;
37         if (newLine) {
38             for (int i = 0; i < level; i++)
39                 out.print(TABULATION);
40             newLine = false;
41         }
42         out.print(outputString);
43
44         for (int i = 0; i < outputString.length(); i++) {
45             switch (outputString.charAt(i)) {
46                 case '\n' :
47                     newLine = true;
48                     break;
49                 case '<' :
50                     if (i < outputString.length() - 1) {
51                         if (outputString.charAt(i + 1) != '/' && outputString.charAt(i + 1) != '?')
52                             level++;
53                     } else {
54                         level++;
55                     }
56                     break;
57                 case '/' :
58                     if (i < outputString.length() - 1) {
59                         if (outputString.charAt(i + 1) == '>')
60                             level--;
61                     }
62                     if (i > 0) {
63                         if (outputString.charAt(i - 1) == '<' && i != 1) // i!=1 for _out.startsWith("</")
64
level--;
65                     }
66                     break;
67             }
68         }
69     }
70     
71 }
72
Popular Tags