There are several methods in which content can be retrieved from an instance of the EditLive! applet:
- Using the Save and Save As... Menu and Toolbar Items.
- Using the EditLive! Run Time Functions
EditLive! provides run-time functions to allow access to an editor's content at any time.
- Through Hidden Form Fields Created During a HTTP Post.
When the HTML form containing an instance of EditLive! is submitted, several hidden form fields are generated containing content from the editor. These fields are available when:
- The onsubmit function of the form is called and client-side scripting can be used to access the hidden form fields before the form is posted, or
- The form is submitted and server-side scripting can be used to access the fields sent through HTTP Post.
- Allowing EditLive! to Explicitly Call a HTTP Post.
EditLive! can explicitly call a HTTP Post (as opposed to the HTML form containing the instance of EditLive! calling a HTTP Post). To do this, you will need to use a custom created menu or toolbar item.
Using the Save and Save As... Menu and Toolbar Items
Using the Save and Save As... menu and toolbar items, users can save the entire XHTML document stored in EditLive! to their local machine.
These items are specified through an EditLive! configuration file. These items can be added by Manually Editing Configuration Files. See the Menu and Toolbar Item List, <menuItem> and <toolbarButton> sections of this SDK for more information.
Using the EditLive! Run Time Functions
EditLive! provides two run-time functions to extract the content of the editor:
- getDocument Method
This property returns the entire XHTML document currently stored in EditLive!.
- getBody Method
This property returns only the content nested between the <body> tags in EditLive!. The actual <body> tags are not included.
Both of these functions take two parameters:
This example shows how to use the getDocument Method.
Using the HTML Form HTTP Post
By default, the content of the EditLive! applet are retrieved when a HTML form containing the instance of EditLive! is submitted. Because of the lack of LiveConnect support on various operating systems and browsers, EditLive! populates a hidden field with its contents automatically rather than the developer calling for the contents explicitly. The name of this generated hidden field (contained within the same HTML form as the EditLive! instance) is given the same name that was specified by the developer when the EditLive! instance was created.
This example shows an instance of EditLive! being created with the name ELApplet1.
If ELApplet1 was specified as the name for the instance of the EditLive! applet, then the applet would store its contents in the hidden field named ELApplet1. This hidden field is then posted with the rest of the form data when the submit button is pressed.
When a form containing an instance of EditLive! is submitted, a hidden field containing all style information for the document is also created and posted with the form data. This hidden field will be called ELAPPLETNAME_styles, where ELAPPLETNAME is the name specified by the developer when the instance of EditLive! was created.
By default, the content that is retrieved from the EditLive! applet will be the contents of the <BODY> element for the HTML Document. This behavior can be modified through setting the setReturnBodyOnly Method.
The automatic submission of the content of the EditLive! applet can be disabled through the use of the setAutoSubmit Method. By setting the AutoSubmit property to false, the automatic content submission can be disabled. Automatic submission of content by the applet is enabled by default.
Retrieving EditLive!'s Content Using Client-Side Scripting Before the HTTP Post
By using the onsubmit() handler for the HTML form containing EditLive! client-side scripting can be used to access the hidden field containing EditLive!'s content.
If a HTML form's onsubmit() handler returns false, the HTML form won't submit. This technique can be used to extract the content of EditLive! without submitting the HTML form.
The following example shows how to use the onsubmit() handler for a HTML form (containing an instance of EditLive!) to extract EditLive!'s content. In this example, the onsubmit() handler also cancels the HTML form submission using return false.
The showBodyOnly attribute of the EditLive! <sourceEditor> Configuration File Element defines how the editor will store its contents in the hidden form fields identified above. If showBodyOnly is set to true, only the contents of the <BODY> element (for the HTML document stored in EditLive!) will be stored in the hidden form field. If showBodyOnly is set to false, the entire HTML document stored in EditLive! will be stored in the hidden form field.
Retrieving EditLive!'s Content Using the HTTP Post's Server-Side Script
The following examples show using a server-side language to access the hidden HTML form field generated by instance of EditLive! named ELApplet1.
Using EditLive! to Explicitly Call a HTTP Post
EditLive! can be configured to post its content directly to a Post Acceptor Script on a Web server. This is useful in situations where EditLive! cannot post its content as part of the HTML form submission architecture.
This technique creates two separate methods for retrieving the content of the EditLive! for Java editor:
- Accessing the content via the Post Acceptor Script.
Examples of how to access the content sent from EditLive! to the Post Acceptor Script is given in the Retrieving EditLive! for Java's Content Using the HTTP Post's Server-Side Script section of this article.
Important Considerations When Using An Explicit EditLive! HTTP Post
Developers must consider several things when using the EditLive! applet to make the HTTP POST instead of using the browser's submit mechanisms:
- If it is required that other form variables be submitted with the content of EditLive!, it is best to avoid using the explicit HTTP functionality of EditLive!. This is because when using the EditLive! explicit HTTP Post, the post of EditLive! occurs separately to the browser's post. This can unnecessarily complicate the server-side processing involved in receiving and processing the posted content.
- The Post functionality can be used to submit the content of EditLive! to a completely different Post Acceptor Script than the browser's post. Thus, EditLive! can submit its content easily to two separate processes. This can be useful when using EditLive! in association with a related server-side process which produces a response which should be saved to the client.
Ensuring Output is XHTML or XML Compliant
In order to ensure that the output of content in EditLive! is XHTML or XML compliant, specific attributes in the <htmlFilter> configuration file element have to be set.
For XHTML compliant output, the following filter settings are required:
- Set outputXHTML to true - This ensures that XHTML tags are used (i.e. <br/> instead of <br>).
- Set allowUnknownTags to false - This ensures that no tags outside of the XHTML standard are used, i.e. custom tags. Instead, custom tags are HTML encoded.
- Set encloseText to true - This ensures content is correctly nested inside the relevant parent tags.
For XML compliant output the following filter settings are required:
- Set outputXML to true - this ensures that special characters are encoded as numeric entities and that XML style tags are used (i.e. <br/> instead of <br>).
- Set encloseText to true - This ensures that the content is correctly nested inside the relevant parent tags.