Chapter II. Advanced Integration
Prev | 6. The Clean-Up Process | Next

## 6. The Clean-Up Process

edit-on Pro will automatically validate any content inserted against the XHTML transitional DTD. Depending on the configuration, the editor will perform a clean-up on the document and remove any attributes and elements not allowed according to the DocType set in the document. In this section we will see which types of clean-up processes are available when they will be invoked and how custom clean-up processes can be configured.

### 6.1. Types of Clean-Up Processes

Four types of clean-up processes are invoked depending on the situation:

- while importing content into the editor

- while pasting content from the clipboard into the editor

- while pasting content from the clipboard using the `PASTEWITHFILTER` action

- while exporting content

Each of these clean-up processes can be overridden by custom clean-up processes. A custom clean-up can occur either on the server using a server side scripting language or on the client using custom Java classes. Default clean-up processes are configured in the configuration using the element cleanupprocess. For details see the chapter Configuration File .

### 6.2. Configuring Custom Clean-Up Processes

#### 6.2.1. Customizing the Client Side Clean-Up Process

edit-on Pro allows you to fully customize the client side clean process by providing an own implementation of the process. To do so you can write an own Java class extending the class `com.realobjects.eop.bean.custom.CleanUpProcess` . For a description of the methods available in this class, see the chapter Methods and Properties of the Client Side Clean-Up Base Class .

The example below shows how to can configure a custom clean-up process in the configuration file:

Example II.12. Configuring a custom client side clean-up process in the configuration file

    <cleanupprocess
        class="com.mycompany.cleanupextension.MyCleanUp" />

The following code snippet shows a skeleton of a custom clean-up class extending the `com.realobjects.eop.bean.custom.CleanUpProcess` class. All clean-up methods available are provided in this example without an implementation. It is possible to override each of these methods individually, i.e. you do not have to override all four methods while implementing a custom clean-up process.

Example II.13. Extending the `com.realobjects.eop.bean.custom.CleanUpProcess` class

    package com.mycompany.cleanupextension;automatically
    import com.realobjects.eop.bean.custom.CleanUpProcess;
    /*...*/
    public class CleanUp
        extends CleanUpProcess {
        /*...*/
        /**
         * Cleans up the raw data received when importing content
         * and returns the cleaned data if no exception occurs.
         * This method should be overridden for a
         * custom implementation of the clean-up process.
         * @param strRawData raw data to be cleaned
         * @return clean data
         * @throws Exception thrown if clean up process fails
         */
        public String cleanUpOnLoad(String strRawData)
                                        throws Exception {
            //TODO: implement your clean-up process
        }
        /**
         * Cleans the raw data received from the clipboard when the
         * PASTEWITHFILTER action is fired and returns the cleaned
         * data as if no exception occurs.
         * This method should be overridden for a custom
         * implementation of the clean-up process.
         * @param strRawData raw data to be cleaned up
         * @return clean data
         * @throws Exception thrown if clean up process fails
         */
        public String cleanUpClipboardWithFilter(String strRawData)
                                                     throws Exception {
            //TODO: implement your clean-up process
        }
        /**
         * Cleans the raw data received from the clipboard and
         * returns the cleaned data if no exception occurs.
         * This method should be overridden for a custom
         * implementation of the clean-up process.
         * @param strRawData raw data to be cleaned up
         * @return clean data
         * @throws Exception thrown if clean up process fails
         */
        public String cleanUpClipboard(String strRawData)
                                           throws Exception {
            //TODO: implement your clean-up process
        }
        /**
         * Cleans the raw data received from the editor when saving
         * and returns the cleaned data if no exception occurs.
         * This method should be overridden for a custom
         * implementation of the clean-up process.
         * @param strRawData raw data to be cleaned up
         * @return clean data
         * @throws Exception thrown if clean up process fails
         */
        public String cleanUpOnSave(String strRawData)
                                        throws Exception {
            //TODO: implement your clean-up process
        }
    }

#### 6.2.2. Customizing a Server Side Clean-Up Process

Instead of customizing the clean-up process on the client, you can perform a clean-up on the server. In this case you have to modify your configuration file appropriately, i.e. you have to determine the location of the script handling the clean-up using the `url` attribute of this element.

Example II.14. Configuring a custom server-side clean-up process in the configuration file

    <cleanupprocess
        url="http://myserver.com/customCleanUp.jsp" />

Once you have configured a clean-up process, the clean-up information will be sent to the server by a POST request. For details about the fields that are sent to the server please see the chapter Form Fields Sent to the Server by the Server Side Clean-Up Process . On the server you have to parse the content to be cleaned and return the cleaned content to the applet.

Below you find a code snippet showing a skeleton of a sample JSP server side clean-up process handler.

Example II.15. Sample server-side clean-up process script

    <%@page import="javax.servlet.*" %>
    <%@page import="java.net.*" %>
    <%@page import="java.io.*" %>
    <%@page import="java.util.*" %>

    <%!
    /**
    * Cleans up the raw data received when importing content
    * and returns the cleaned data if no exception occurs.
    * This method should be overridden for a
    * custom implementation of the clean-up process.
    * @param strRawData raw data to be cleaned
    * @return clean data
    * @throws Exception thrown if clean up process fails
    */
    public String cleanUp(String strRawData)
                              throws Exception {
        //TODO: implement your clean-up process
        return strResult;
    }

    /**
    * Cleans up the raw data received when importing content
    * and returns the cleaned data if no exception occurs.
    * This method should be overridden for a
    * custom implementation of the clean-up process.
    * @param strRawData raw data to be cleaned
    * @return clean data
    * @throws Exception thrown if clean up process fails
    */
    public String cleanUpWithFilter(String strRawData)
                                        throws Exception {
        //TODO: implement your clean-up process
        return strResult;
    }
    %>
    <%
    String content = request.getParameter("HTMLDATA");
    String type = request.getParameter("TYPE");
    String cleanedData = null;
    PrintWriter res = response.getWriter();

    try {
        if ( "cleanuponsave".equalsIgnoreCase(type) )
            cleanedData = cleanUp(content);

        if ( "cleanuponload".equalsIgnoreCase(type) )
            cleanedData = cleanUp(content);

        if ( "cleanupclipboard".equalsIgnoreCase(type) )
            cleanedData = cleanUp(content);

        if ( "cleanclipboardwithfilter".equalsIgnoreCase(type) )
            cleanedData = cleanUpWithFilter(content);
    } catch ( Exception e ) {
        e.printStackTrace();
    }

    if ( cleanedData != null )
        res.write(cleanedData);
    else
        res.write("An error occured during the clean up process.");

    res.flush();
    %>

### 6.3. Clean-up Process Flow Charts

The following flow charts show when the clean-up process is called while importing or exporting content.

#### 6.3.1. Clean-Up Process when Content is Imported

#### 6.3.2. Clean-Up Process when Content is Exported

### 6.4. Configuring Drag & Drop

#### 6.4.1. Available Drag & Drop Handlers

When content is dragged and dropped inside edit-on Pro, it will trigger the `DRAGNDROP` action by default. Inserting content in the editor with the `DRAGNDROP` action as drag & drop handler corresponds to pasting content using the `PASTE` action as paste handler, i.e. this allows to insert formatted content, which will only be cleaned by the clean-up process if necessary. The other available drag & drop handlers are `DRAGNDROPWITHFILTER` and `DRAGNDROPPLAINTEXT` . `DRAGNDROPWITHFILTER` will remove all inline styles from the content that is inserted via drag & drop, while `DRAGNDROPPLAINTEXT` will insert it as plain text without any formatting. The drag & drop handler is configured in the "uiconfig.xml".

Example II.16. Configuring the drag & drop handler

    <actions>
        <dragndropaction actionid="DRAGNDROPPLAINTEXT" />
    </actions>

#### 6.4.2. Customizing Drag & Drop

Instead of uising the default drag & drop handlers available in the editor, you can in fact use any action as drag & drop handler - even custom actions. To do so, you need to specify the action that should be used as drag & drop handler in the "uiconfig.xml" (see example above). This action will be triggered whenever content is dragged & dropped in the editor. For example, you could fire the `BOLD` action when content is dragged and dropped in the editor. Note this would not cause the content that was dragged & dropped in the editor to be inserted as bold content, it would only trigger the `BOLD` action as described in the chapter Actions .

If the action that is specified as drag & drop handler is custom Java action, the following data will be passed to the custom action:

- The transferable data passed in DropTargetDropEvent

- The action mode (either move or copy, depending on whether the control key was pressed down when dragging the content)

- The start location of the Drag source

- The stop location of the Drag source

- The target location of the Drop target

These properties will be available as the following key-value pairs in the `EOPDATA` Hashtable using the getKeys method (instead of the properties normally available in a custom Java action):

Keys available in EOPDATA for custom drag & drop handlers

transferable:

  The Transferable data passed in `DropTargetDropEvent` , may contain a string, a List of the file that was dragged, or a URL, depending on the data flavor that was the Drag source. The supported data flavors are: text/html (data is dragged into the editor), application-x-java-file-list (a file is opened from the file sytsem via drag & drop), application-x-java-url (a link is inserted in the editor).

action:

  An Integer specifying the action type passed in `DropTargetDropEvent` . `DropTargetDropEvent` will either pass `DnDConstants.ACTION_COPY` or `DnDConstants.ACTION_MOVE` depending on whether the content was copied or moved into the editor via drag & drop.

sourceStart:

  Integer describing the start offset of the Drag source.

sourceEnd:

  Integer describing the end offset of the Drag source.

targetLocation:

  Integer describing offset of the Drop target.

  ### Note:

  For details about custom actions and custom dialogs, see the chapter Creating Custom Dialogs .

Prev | Up | Next
5. Accessibility | Home | 7. Using Custom DTDs