Menu

#25 [Web] FckEditor parsing

WebV1.0
open
nobody
None
8
2008-03-25
2008-02-19
No

Some problems happen after editing by FCKeditor.

For example:
1. Income data
<table border="1" width="100%">
2. Output result after saving in FCKeditor
<table border="\&amp;quot;1\&amp;quot;">
Some properties were removed.
3. Again try to edit previous result
4. Output result for the second saving
<table border="\&amp;quot;\\&amp;quot;1\\&amp;quot;\&amp;quot;">

Discussion

  • Alexey Prokopenko

    • priority: 5 --> 8
     
  • Vladimir

    Vladimir - 2008-03-13
    • summary: FckEditor parsing --> [Eclipse] FckEditor parsing
     
  • Amanda Wilson

    Amanda Wilson - 2008-03-13
    • assigned_to: dsmain --> nobody
     
  • Alexey Prokopenko

    • summary: [Eclipse] FckEditor parsing --> [Web] FckEditor parsing
     
  • Nobody/Anonymous

    Logged In: NO

    Resolved this issue by editing HTMLEditorUI, so that the JavascriptEscape get's undone when pulling the html out:

    public String getContent() {
    // temporarily add a listener on the status text to retrieve the
    // contents of the design editor
    browser.addStatusTextListener(new StatusTextListener() {
    public void changed(final StatusTextEvent event) {
    browser.setData("content", event.text);
    browser.removeStatusTextListener(this);
    }
    });
    browser.execute("getContent()");
    return unescape((String) browser.getData("content"));
    }

    private String unescape(String content) {
    return StringEscapeUtils.unescapeJavaScript(content);
    }

    Addionally I altered fckconfig.js. So that no automatic conversion takes place.

    FCKConfig.FormatSource = false ;
    FCKConfig.FormatOutput = false ;

    FCKConfig.ProcessHTMLEntities = false ;
    FCKConfig.IncludeLatinEntities = false ;
    FCKConfig.IncludeGreekEntities = false ;

    FCKConfig.AutoDetectLanguage = false ;

     
  • Nobody/Anonymous

    Logged In: NO

    Hallo,

    I developed a HtmlContentEscaper to fix this issue. I commented already yesterday. This is fix of the fix ... . If you have questions: dschuma78@googlemail.com

    It is integrated in the HtmlEditorUI:
    private String escape(String content) {
    String htmlEscape = new HtmlContentEscaper().escapeHtmlContent(content);
    String scriptEscape = StringEscapeUtils.escapeJavaScript(htmlEscape);
    return scriptEscape;
    }

    And here:
    public String getContent() {
    // temporarily add a listener on the status text to retrieve the
    // contents of the design editor
    browser.addStatusTextListener(new StatusTextListener() {
    public void changed(final StatusTextEvent event) {
    browser.setData("content", event.text);
    browser.removeStatusTextListener(this);
    }
    });
    browser.execute("getContent()");
    return unescape((String) browser.getData("content"));
    }

    private String unescape(String content) {
    String scriptUnescape = StringEscapeUtils.unescapeJavaScript(content);
    String htmlUnescape = new HtmlContentEscaper().unescapeHtmlContent(scriptUnescape);
    return htmlUnescape;
    }

    Here the HtmlContentEscaper itself:

    package tools;

    import org.apache.commons.lang.StringEscapeUtils;

    public class HtmlContentEscaper {

    public String unescapeHtmlContent(String html){
    return transform(html, false);
    }

    public String escapeHtmlContent(String html){
    return transform(html, true);
    }

    private String transform(String body, boolean escape){

    StringBuffer ergebnis = new StringBuffer();

    char[] chars = body.toCharArray();

    StringBuffer umzuwandeln = new StringBuffer();

    boolean imTag = false;
    for (int i = 0; i < chars.length; i++) {
    char c = chars[i];

    if(c == '<'){
    imTag = true;
    if(escape){
    ergebnis.append(StringEscapeUtils.escapeHtml(umzuwandeln.toString()));
    }
    else {
    ergebnis.append(StringEscapeUtils.unescapeHtml(umzuwandeln.toString()));
    }
    ergebnis.append(c);

    umzuwandeln = new StringBuffer();
    }
    else if( c == '>'){
    imTag = false;
    ergebnis.append(c);
    }
    else if(imTag){
    ergebnis.append(c);
    }
    else if(!imTag) {
    umzuwandeln.append(c);
    }
    }

    return ergebnis.toString();
    }
    }

    Best regards
    Dirk Schumacher

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.