Chapter II. Advanced Integration
Prev | 3. Direct HTTP Connection API | Next

## 3. Direct HTTP Connection API

The direct HTTP connection API can be used to interface with the applet instead of the JavaScript API. The properties `sethmldataurl` and `gethtmldataurl` allow you to respectively import or export content. They may be defined in the configuration file or using the JavaScript API method `setParam` before initialization of the editor.

In any case, edit-on Pro will perform a request to the URL specified by the `sethtmldataurl` property, and load the data from the document specified by the URL into the editor.

Example II.10. Setting `sethtmldataurl` and `gethtmldataurl`

Setting `sethtmldataurl` using the JavaScript API:

    eop.setHTMLDataFromURL("http://www.w3.org");

Setting `sethmldataurl` in the configuration file:

    <directhttp sethtmldataurl="http://www.w3.org" />

The editor will send its content in a form field called `HTMLDATA` to the URL specified by the `gethtmldataurl` property when the `SAVE` action is triggered. The request made by the editor when sending the content will be a HTTP POST request which will be application/x-www-form-urlencoded. The server application must reply <result>OK</result> to the applet when receiving this request.

Example II.11. Sample `gethtmldataurl` handlers

Sample gehtmldataurl handler in ASP:

    <%@language="JavaScript" %>
    <%
    var filePath = Server.MapPath("save.htm");
    var serverObj = Server.CreateObject("Scripting.FileSystemObject");
    var writeObj = serverObj.OpenTextFile( filePath, 2, true );
    writeObj.Write(Request.Form("HTMLDATA") );
    writeObj.Close();
    %>
    <result>OK</result>

Sample gethtmldataurl handler in PHP:

    <?
    $myfile = fopen("save.htm","wb");
    fwrite($myfile,stripslashes($_POST["HTMLDATA"]));
    fclose($myfile);
    ?>
    <result>OK</result>

Sample gehtmldataurl in JSP:

    <%@page import="javax.servlet.*" %>
    <%@page import="java.net.*" %>
    <%@page import="java.io.*"%>
    <%@page import="java.util.*" %>
    <%
    try {
        /* enter the target file */
        FileWriter fw = new FileWriter(application.getRealPath("save.htm"));
        String strContent = request.getParameter("HTMLDATA");
        OutputStreamWriter outWriter =
            new OutputStreamWriter(outStream,request.getCharacterEncoding());
        outWriter.write(strContent);
        outWriter.flush();
        outWriter.close();
        fw.flush();
        fw.close();
        PrintWriter res = response.getWriter();
        res.write("<result>OK</result>");
        res.flush();
        System.out.println("Request content Length : " + nLength +
        " Content Length : " + nRecLength );
    } catch (Exception e) {
        System.out.println( "SavePost Error : " + (new Date()).toString() );
        e.printStackTrace();
    }
    %>

If an error occured when saving the content, you can return an error message instead of "OK" in the server-side script handling the save. If anything but "OK" is returned by your HTTP POST handler, you can retrieve the string that was returned instead using the JavaScript API method `getPostErrorMessage`.

If neither "OK" nor an error message is returned by your script, `getPostErrorMessage` returns `null`. Example:

    function onUploadFinished() {
        alert(eop.getPostErrorMessage());
    }
    eop.uploadToRepository("UPLOADIMAGES","onUploadFinished");

Prev | Up | Next
2. edit-on Pro CSS Extensions | Home | 4. Localizing edit-on Pro