01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.print.xml;
10:
11: import java.awt.Color;
12: import java.awt.Font;
13:
14: /**
15: * State pattern that is used to print the XML file
16: *
17: *@author Chris Seguin
18: */
19: public class AttributeState extends State {
20: private static State state = null;
21:
22: public AttributeState() {
23: super ();
24: color = Color.gray;
25: }
26:
27: /**
28: * Gets the Font attribute of the State object
29: *
30: *@return The Font value
31: */
32: public Font getFont() {
33: if (font == null) {
34: font = new Font("SansSerif", Font.PLAIN, getFontSize());
35: }
36: return font;
37: }
38:
39: /**
40: * The actual worker method that processes the line. This is what is defined
41: * by the various states
42: *
43: *@param line the line
44: *@param index the index of the character
45: *@param buf the buffer
46: *@return the state at the end of the line
47: */
48: protected State processLine(String line, int index, StringBuffer buf) {
49: State nextState = null;
50: int length = line.length();
51:
52: while (nextState == null) {
53: if (index == length) {
54: print(buf);
55: return this ;
56: }
57:
58: if ((length != index + 1) && (line.charAt(index) == '=')
59: && (line.charAt(index + 1) == '\"')) {
60: nextState = QuoteAttributeValueState.getState();
61: } else if (line.charAt(index) == '=') {
62: nextState = AttributeValueState.getState();
63: } else if ((length != index + 1)
64: && (line.charAt(index + 1) == '>')) {
65: nextState = TagState.getState();
66: }
67:
68: buf.append(line.charAt(index));
69: index++;
70: }
71:
72: print(buf);
73: initState(nextState);
74: buf.setLength(0);
75: return nextState.processLine(line, index, buf);
76: }
77:
78: /**
79: * Gets the State attribute of the TextState class
80: *
81: *@return The State value
82: */
83: public static State getState() {
84: if (state == null) {
85: state = new AttributeState();
86: }
87: return state;
88: }
89: }
|