3 Replies Latest reply on Jul 29, 2011 8:35 AM by lfryc

    Editor and resource paths handling

    lfryc

      Hi guys,

       

      I have got stuck with problem of CKEditor's resource paths generation.

       

      CKEditor loads own resources from paths which are generated at runtime and thus may be redefined, mainly in two ways, using:

       

      • window.CKEDITOR_BASEPATH
        • defines the base path of the request, e.g. basePath + resourcePath
        • this is useful when you have prefix-style mapped servlet (e.g. /faces/)
      • window.CKEDITOR_GETURL
        • defines the function which generates resource paths
        • this is useful when you have suffix-style mapped servlet (e.g. .jsf)
        • more complex for usage then previous option (function must handle URLs appropriately)
        • does not work for CKEditor's CSS files referencing PNG images (url(images/*.png)) since these are not processed by CKEDITOR_GETURL

       

      Currently, rich:editor is using first variant and thus relies on default FacesServlet mapping /faces/.

      But when user redefines servlet mapping, it will got invalid.

       

       

      ========================

       

      Basically there are several options:

       

      1. rewrite CSS files of CKEditor to be generated dynamically (use ECSS)
        • hard to maintain during component upgrade
      2. search all the FacesServlet mappings and try to find suitable absolute mapping (e.g. /faces/)
      3. register custom servlet mapping for FacesServlet at runtime (e.g. /org.richfaces.resources/)
      4. hybrid of (1) and (3)
        • search for suitable or use custom servlet mapping as fallback

       

      I would prefer (3), but would like to hear any opinions and objections on this topic.

        • 1. Re: Editor and resource paths handling
          bleathem

          Hey Lukas - that's a tricky problem to solve!  Here are my thoughts:

           

          1) Agreed would be hard to maintain. 

           

          2) is too fragile - who knows what mappings some people might use.

           

          3) The problem is it can circumvent an applications page security if they are using web.xml to secure their resources.  Imgine they put protection on /admin/* and un benownst to them, there admin section is now available under /org.richfaces.resources/

           

          Rather than a FacesServlet mapping, can we provide our own custom servlet to serve only these resources?  This would be mapped to a url as you proposed above, but would be secure as it would only serve the resources you intend.

          • 2. Re: Editor and resource paths handling
            nbelaevski

            Hi all,

             

            1) WDYT about interpreting links in common CSS files as JSF resource links? This can be a runtime/compile time enhancement over standard CSS (maybe just for selected resource libraries).

             

            2) IMHO most people use suffix mapping, so this won't work.

             

            3) I agree this can conflict with either security configuration as integration with 3rd party libraries.

            • 3. Re: Editor and resource paths handling
              lfryc

              Thanks for sharing your thoughts,

               

              I have implemented ResourceServlet which serves resources only from /org.richfaces.ckeditor/ library and which delegates to FacesServlet.

               

              https://github.com/richfaces/core/blob/2bd64aacd89f49640a12cd3607ef5912b5c3f3be/impl/src/main/java/org/richfaces/webapp/ResourceServlet.java

               

              I'm going also reference common CSS and JS files as JSF resource links so browser will be able to pre-cache them.