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 QuoteAttributeValueState 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: int start = index;
46:
47: while (nextState == null) {
48: if (index == length) {
49: print(buf);
50: return this ;
51: }
52:
53: if (index != start) {
54: if ((length != index + 1)
55: && (line.charAt(index) == '\"')
56: && (line.charAt(index + 1) == '>')) {
57: nextState = TagState.getState();
58: } else if ((length != index + 1)
59: && (line.charAt(index) == '\"')
60: && (line.charAt(index + 1) == '?')) {
61: nextState = TagState.getState();
62: } else if ((length != index + 1)
63: && (line.charAt(index) == '\"')) {
64: nextState = AttributeState.getState();
65: }
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 QuoteAttributeValueState();
86: }
87: return state;
88: }
89: }
|