#22 Unable to register custom editor class

closed
Rogan Dawes
5
2008-01-24
2008-01-24
jpstotz
No

I wrote a custom content editor panel and now I am trying to register it using org.owasp.webscarab.ui.swing.editors.EditorFactory.registerEditor(c,e).
I want to register my custom edit class befor starting WebScarab - the problem is that at that time EditFactory._editors is null. It is initialized only upon first reception of a packet, therefore the current implementation of registerEditor() is useless.

IMHO it would be better to directly initialize EditFactory._editors with new LinkedHashMap() or to initialize it when Editfactory.registerEditor() is called the first time.

Discussion

  • Rogan Dawes
    Rogan Dawes
    2008-01-24

    • status: open --> closed
     
  • Rogan Dawes
    Rogan Dawes
    2008-01-24

    Logged In: YES
    user_id=438260
    Originator: NO

    Hi,

    I have modified this to use a static class initialiser, rather than being initialised on demand. Please check to see if this has fixed it for you. You can download the latest snapshot from http://dawes.za.net/rogan/webscarab/webscarab-src-current.tar.gz

     
  • jpstotz
    jpstotz
    2008-01-25

    Logged In: YES
    user_id=1008319
    Originator: YES

    Hi Rogan,

    thanks for your quick fix. Unfortunately I am unable to detect any changes made to the EditorFactory class in the source code package you provided. Are you sure that it already includes the modified file?

     
  • Rogan Dawes
    Rogan Dawes
    2008-01-25

    Logged In: YES
    user_id=438260
    Originator: NO

    Please note that I am not using Sourceforge's CVS anymore, the change was made directly to my git repository, held on my personal site: http://dawes.za.net/gitweb.cgi

    I checked the tarball that I pointed you to, and the change is definitely there. This is the diff that I committed:

    commit 5e1f883d45292dea10bfce0e744a6132cea7a57d
    Author: Rogan Dawes <rogan@dawes.za.net>
    Date: Thu Jan 24 15:25:33 2008 +0200

    Make EditorFactory register edtors using a static class initialiser

    diff --git a/src/org/owasp/webscarab/ui/swing/editors/EditorFactory.java b/src/org/owasp/webscarab/ui/swing/editors/EditorFactory.java
    index e9802a9..17729df 100644
    --- a/src/org/owasp/webscarab/ui/swing/editors/EditorFactory.java
    +++ b/src/org/owasp/webscarab/ui/swing/editors/EditorFactory.java
    @@ -31,7 +31,7 @@ public class EditorFactory {
    private EditorFactory() {
    }

    - private static void registerEditors() {
    + static {
    _editors = new LinkedHashMap(); // this helps to maintainthe order of the editors
    registerEditor("multipart/form-data; .*", "org.owasp.webscarab.ui.swing.editors.MultiPartPanel");
    registerEditor("application/x-serialized-object", "org.owasp.webscarab.ui.swing.editors.SerializedObjectPanel");
    @@ -59,7 +59,6 @@ public class EditorFactory {

    public static ByteArrayEditor[] getEditors(String contentType) {
    if (contentType == null) return new ByteArrayEditor[] { new HexPanel() };
    - if (_editors == null) registerEditors();
    Iterator it = _editors.keySet().iterator();
    List editors = new ArrayList();
    while (it.hasNext()) {

    Regards,

    Rogan

     
  • jpstotz
    jpstotz
    2008-01-25

    Logged In: YES
    user_id=1008319
    Originator: YES

    Right - now I see the difference.