Author: Alex.Kolonitsky
Date: 2009-04-23 10:26:05 -0400 (Thu, 23 Apr 2009)
New Revision: 13798
Added:
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/EmptyHtmlTag.java
Modified:
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/HtmlTag.java
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/TagFactory.java
trunk/ui/editor/src/test/java/org/richfaces/seamparser/HtmlSeamParserTest.java
Log:
Editor: unnecessary images appear in editor after rerender in seamText mode.
https://jira.jboss.org/jira/browse/RF-6907
Modified:
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java
===================================================================
---
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java 2009-04-23
14:07:45 UTC (rev 13797)
+++
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java 2009-04-23
14:26:05 UTC (rev 13798)
@@ -59,7 +59,7 @@
}
try {
- return new HtmlToSeamSAXParser().convertHtmlToSeamText(value);
+ return HtmlToSeamSAXParser.convertHtmlToSeamText(value);
} catch (Exception e) {
FacesMessage message = new FacesMessage(
Added:
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/EmptyHtmlTag.java
===================================================================
--- trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/EmptyHtmlTag.java
(rev 0)
+++
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/EmptyHtmlTag.java 2009-04-23
14:26:05 UTC (rev 13798)
@@ -0,0 +1,28 @@
+package org.richfaces.convert.seamtext.tags;
+
+public class EmptyHtmlTag extends HtmlTag {
+
+ private static final long serialVersionUID = 6885598850897971629L;
+
+ EmptyHtmlTag(String name) {
+ super(name);
+ }
+
+ @Override
+ public String print() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append('<').append(getName());
+
+ if (!getAttributes().isEmpty()) {
+ builder.append(' ').append(printAttributes());
+ }
+ builder.append("/>");
+
+ return builder.toString();
+ }
+
+ @Override
+ public String printPlain() {
+ return print();
+ }
+}
Modified: trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/HtmlTag.java
===================================================================
---
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/HtmlTag.java 2009-04-23
14:07:45 UTC (rev 13797)
+++
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/HtmlTag.java 2009-04-23
14:26:05 UTC (rev 13798)
@@ -1,7 +1,7 @@
package org.richfaces.convert.seamtext.tags;
import java.io.Serializable;
-import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -15,6 +15,12 @@
private static final long serialVersionUID = -372761460000118889L;
+ public static final String HR = "hr";
+ public static final String BR = "br";
+ public static final String IMG = "img";
+ public static final String AREA = "area";
+ public static final String COL = "col";
+
public static final String A = "a";
public static final String H1 = "h1";
public static final String H2 = "h2";
@@ -57,7 +63,7 @@
setAttributes(attributes);
}
- public String printPlainStart(){
+ protected String printPlainStart(){
final StringBuilder builder = new StringBuilder();
builder.append('<').append(getName());
@@ -69,15 +75,15 @@
return builder.toString();
}
- public String printStartSuffix(){
+ protected String printStartSuffix(){
return ">";
}
- public String printStart(){
+ protected String printStart(){
return printPlainStart();
}
- private String printAttributes() {
+ protected String printAttributes() {
if (attributes == null) {
return "";
}
@@ -90,7 +96,7 @@
return builder.substring(0, builder.length() - 1);
}
- private String prepareValue(String value) {
+ protected String prepareValue(String value) {
return value.replace('"', '^');
}
@@ -98,7 +104,7 @@
res.append(child);
}
- public String printBody() {
+ protected String printBody() {
final StringBuilder res = new StringBuilder();
for (Object child : body) {
if (child instanceof HtmlTag) {
@@ -119,7 +125,7 @@
}
public void cleanBody() {
- body = new ArrayList<Object>();
+ body = new LinkedList<Object>();
}
public boolean isBodyEmpty() {
@@ -132,7 +138,7 @@
return true;
}
- public String printPlainEnd(){
+ protected String printPlainEnd(){
if (isEmpty) {
// return "/>";
}
@@ -143,7 +149,7 @@
return builder.toString();
}
- public String printEnd(){
+ protected String printEnd(){
return printPlainEnd();
}
Modified:
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/TagFactory.java
===================================================================
---
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/TagFactory.java 2009-04-23
14:07:45 UTC (rev 13797)
+++
trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/tags/TagFactory.java 2009-04-23
14:26:05 UTC (rev 13798)
@@ -29,6 +29,12 @@
* */
private static final Collection<HtmlTag> TAGS = Arrays.asList(
getNewTagDefinition("root", "", ""),
+ new EmptyHtmlTag(HR),
+ new EmptyHtmlTag(BR),
+ new EmptyHtmlTag(IMG),
+ new EmptyHtmlTag(AREA),
+ new EmptyHtmlTag(COL),
+
new LineTag(H1, "+ "),
new LineTag(H2, "++ "),
new LineTag(H3, "+++ "),
@@ -54,7 +60,7 @@
new FormattingTag(DEL, SEAM_TWIDDLE),
new FormattingTag(SUP, SEAM_HAT),
new FormattingTag(U, SEAM_UNDERSCORE),
- new FormattingTag(TT, SEAM_MONOSPACE){
+ new FormattingTag(TT, SEAM_MONOSPACE) {
@Override
public boolean isFormating() {
Modified: trunk/ui/editor/src/test/java/org/richfaces/seamparser/HtmlSeamParserTest.java
===================================================================
---
trunk/ui/editor/src/test/java/org/richfaces/seamparser/HtmlSeamParserTest.java 2009-04-23
14:07:45 UTC (rev 13797)
+++
trunk/ui/editor/src/test/java/org/richfaces/seamparser/HtmlSeamParserTest.java 2009-04-23
14:26:05 UTC (rev 13798)
@@ -246,6 +246,20 @@
assertHtml2SeamConverting("<ul><li><ul><li
/></ul></li></ul>");
}
+ public void testEmrtyTags() throws Exception {
+ final String html = "<br/>";
+ final String result = assertHtml2SeamConverting(html);
+
+ assertEquals(html, result);
+ }
+
+ public void testEmrtyTags02() throws Exception {
+ final String html = " <br/>Hello <hr/><img/><area/>
World! <col/>";
+ final String result = assertHtml2SeamConverting(html);
+
+ assertTrue(result.contains(html));
+ }
+
public void testUglyTextFromWord() throws Exception {
final String str = "<p><meta content=\"text/html;
charset=utf-8\" http-equiv=\"Content-Type\"/><meta
content=\"Word.Document\" name=\"ProgId\"/><meta
content=\"Microsoft Word 12\" name=\"Generator\"/><meta
content=\"Microsoft Word 12\" name=\"Originator\"/><link
href=\"file:///E:\\TEMP~1\\msohtmlclip1\\01\\clip_filelist.xml\"
rel=\"File-List\"/><link
href=\"file:///E:\\TEMP~1\\msohtmlclip1\\01\\clip_themedata.thmx\"
rel=\"themeData\"/><link
href=\"file:///E:\\TEMP~1\\msohtmlclip1\\01\\clip_colorschememapping.xml\"
rel=\"colorSchemeMapping\"/>"
+ "<!--[if gte mso 9]><xml>\n"