1 /* |
1 /* |
2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
39 * This code and its internal interfaces are subject to change or |
39 * This code and its internal interfaces are subject to change or |
40 * deletion without notice.</b> |
40 * deletion without notice.</b> |
41 * |
41 * |
42 * @author Bhavesh Patel |
42 * @author Bhavesh Patel |
43 */ |
43 */ |
44 public class RawHtml extends Content{ |
44 public class RawHtml extends Content { |
45 |
45 |
46 private String rawHtmlContent; |
46 private String rawHtmlContent; |
47 |
47 |
48 public static final Content nbsp = new RawHtml(" "); |
48 public static final Content nbsp = new RawHtml(" "); |
49 |
49 |
88 } |
88 } |
89 |
89 |
90 /** |
90 /** |
91 * {@inheritDoc} |
91 * {@inheritDoc} |
92 */ |
92 */ |
|
93 @Override |
93 public String toString() { |
94 public String toString() { |
94 return rawHtmlContent; |
95 return rawHtmlContent; |
|
96 } |
|
97 |
|
98 private enum State { TEXT, ENTITY, TAG, STRING }; |
|
99 |
|
100 @Override |
|
101 public int charCount() { |
|
102 State state = State.TEXT; |
|
103 int count = 0; |
|
104 for (int i = 0; i < rawHtmlContent.length(); i++) { |
|
105 char c = rawHtmlContent.charAt(i); |
|
106 switch (state) { |
|
107 case TEXT: |
|
108 switch (c) { |
|
109 case '<': |
|
110 state = State.TAG; |
|
111 break; |
|
112 case '&': |
|
113 state = State.ENTITY; |
|
114 count++; |
|
115 break; |
|
116 default: |
|
117 count++; |
|
118 } |
|
119 break; |
|
120 |
|
121 case ENTITY: |
|
122 if (!Character.isLetterOrDigit(c)) |
|
123 state = State.TEXT; |
|
124 break; |
|
125 |
|
126 case TAG: |
|
127 switch (c) { |
|
128 case '"': |
|
129 state = State.STRING; |
|
130 break; |
|
131 case '>': |
|
132 state = State.TEXT; |
|
133 break; |
|
134 } |
|
135 break; |
|
136 |
|
137 case STRING: |
|
138 switch (c) { |
|
139 case '"': |
|
140 state = State.TAG; |
|
141 break; |
|
142 } |
|
143 } |
|
144 } |
|
145 return count; |
95 } |
146 } |
96 |
147 |
97 /** |
148 /** |
98 * {@inheritDoc} |
149 * {@inheritDoc} |
99 */ |
150 */ |