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.Font;
12:
13: /**
14: * State pattern that is used to print the XML file
15: *
16: *@author Chris Seguin
17: */
18: public class AttributeValueState extends State {
19: private static State state = null;
20:
21: /**
22: * Gets the Font attribute of the State object
23: *
24: *@return The Font value
25: */
26: public Font getFont() {
27: if (font == null) {
28: font = new Font("SansSerif", Font.ITALIC, getFontSize());
29: }
30: return font;
31: }
32:
33: /**
34: * The actual worker method that processes the line. This is what is defined
35: * by the various states
36: *
37: *@param line the line
38: *@param index the index of the character
39: *@param buf the buffer
40: *@return the state at the end of the line
41: */
42: protected State processLine(String line, int index, StringBuffer buf) {
43: State nextState = null;
44: int length = line.length();
45:
46: while (nextState == null) {
47: if (index == length) {
48: print(buf);
49: return this ;
50: }
51:
52: if ((length != index + 1)
53: && (line.charAt(index + 1) == ' ')) {
54: nextState = AttributeState.getState();
55: } else if ((length != index + 1)
56: && (line.charAt(index + 1) == '>')) {
57: nextState = TagState.getState();
58: }
59:
60: buf.append(line.charAt(index));
61: index++;
62: }
63:
64: print(buf);
65: initState(nextState);
66: buf.setLength(0);
67: return nextState.processLine(line, index, buf);
68: }
69:
70: /**
71: * Gets the State attribute of the TextState class
72: *
73: *@return The State value
74: */
75: public static State getState() {
76: if (state == null) {
77: state = new AttributeValueState();
78: }
79: return state;
80: }
81: }
|