DITA Storm Reference

Editor Integration

Integrating Developer into an HTML Page

A simple procedure allows you to integrate Developer into a Web application or Content Management System by either attaching the editor to the text field of your HTML form, or loading DITA documents directly via an HTTP request. Basic required steps:

  1. Include Developer libraries.

    <LINK href="DITAStorm/styles.css" rel="stylesheet" type="text/css"/>
    <SCRIPT src="DITAStorm/DITAStorm.js" type="text/javascript"></SCRIPT>
  2. Render Developer. At the selected location of the HTML page place the following code:

    <SCRIPT> ditaStorm.render( 'DITAStorm','100%','300','simple.css','simple.xsl.js'); </SCRIPT>

    Function render<path>,<width>,<height>,<css_file>,<compiled_xsl_file>) accepts the following parameters:

    1. path to the location of the Developer libraries
    2. editor width (pixels or percents)
    3. editor height (pixels or percents)

      Please remember, as on any HTML page, your element will take the specified 100% of available vertical space only if the outermost element expands to the entire page (height attribute set to 100%). For example, to make an HTML element (Developer) consume the entire remaining space on the page use a code similar to this:

      <body>
        <table ... height='100%'>
          <tr height='10%'>...</tr> <tr height='90%'>...[dita editor]...</tr>
        </table>
      </body>
    4. stylesheet to be used (by default the editor is supplied with simple.css)
    5. compiled version of the stylesheet to be used by the editor (by default the editor is supplied with simple.xsl.js)

  3. Load DITA document. Either directly from the server:

    <SCRIPT> ditaStorm.loadXmlFile('/cm/content/product.xml'); </SCRIPT>

    or from the pre-populated text field:

    <INPUT name='ditaField' type='hidden' value='<topic><title>Lorem Ipsum</title><body><p>...</p></body> </topic>'>
    <SCRIPT> ditaStorm.attachField('myForm','ditaField'); </SCRIPT>
  4. Retrieve modified DITA content. Either use the call JavaScript method:

    <SCRIPT> // Use getXml() or getFormattedXml() to retrieve content
      var xmlString = ditaStorm.getXml();
      alert('Content: '+xmlString);
    </SCRIPT>

    or if you previously attached Developer to the form field, you can store the value back to the field:

    <SCRIPT> ditaStorm.updateField(); </SCRIPT>

Example: Attaching to HTML Form Field

This example uses an HTML form with a text field and modifies it using Developer. Original HTML form:

<HTML>
  <HEAD>
    <SCRIPT>
      function verifyAndSubmit() { ... }
    </SCRIPT>
  </HEAD>
  <BODY onLoad='init()'>
    <FORM name='myForm' onSubmit='verifyAndSubmit()'>
      <INPUT name='ditaField' type='text'
      value='<topic><title>Lorem Ipsum</title><body> <p>Morbi et lacus nec.</p></body></topic>'>
      ...
    </FORM>
  </BODY>
</HTML>

This HTML can be easily modified to enable DITA editing with Developer:

<HTML>
  <HEAD>
    <LINK href="DITAStorm/styles.css" rel="stylesheet" type="text/css"/>
    <SCRIPT src="DITAStorm/DITAStorm.js" type="text/javascript"></SCRIPT> <SCRIPT>
      function verifyAndSubmit() { // store XML back to the field and proceed with regular
      // form submission
      ditaStorm.updateField(); ... }
    </SCRIPT>
  </HEAD>
  <BODY>
    <FORM name='myForm' onSubmit='verifyAndSubmit()'>
      <INPUT name='ditaField' type='hidden'
      value='<topic><title>Lorem</title><body><p>...</p></body> </topic>'>
      <SCRIPT> // Render editor and get value from the field
        ditaStorm.render('DITAStorm','100%','300','simple.css', 'simple.xsl.js');
        ditaStorm.attachField('myForm','ditaField');
      </SCRIPT>
    </FORM>
  </BODY>
</HTML>

Example: Loading a DITA Document via HTTP

Developer can load XML content directly from a server via an HTTP request. JavaScript function loadXmlFile() retrieves the XML over HTTP and loads it into the editor. Sample code:

<HTML>
  <HEAD>
    <LINK href="/cm/lib/DITAStorm/styles.css" rel="stylesheet" type="text/css"/>
    <SCRIPT src="/cm/lib/DITAStorm/DITAStorm.js" type="text/javascript"></SCRIPT>
  </HEAD>
  <BODY>
    <SCRIPT>
      ditaStorm.render( '/cm/lib/DITAStorm','100%','300','simple.css', 'simple.xsl.js');
      ditaStorm.loadXmlFile('/cm/content/product.xml');
    </SCRIPT>
  </BODY>
</HTML>

loadXmlFile function can also be called at any time during the lifetime of Developer control on the Web page.


Example: Retrieving Modified XML via JavaScript

You can retrieve currently edited DITA XML as text via a JavaScript call using getXml() function. For example:

<SCRIPT> var xmlString = ditaStorm.getXml(); alert('Content: '+xmlString); </SCRIPT>

Expected Configuration

  • Web Server: Apache 2.2.4 as tested (earlier versions will do)
  • Web Server extensions: PHP5 with XSL enabled
  • Source code size: 4K
  • Client: Internet Explorer, Firefox

This example contains a simple prototype of a Web application utilizing Developer to provide in-place editing for a set of topics. The entire application is very simple, containing one PHP file (index.php - 3Kb) and Developer. DITA topics are stored in a file system.

File index.php contains both XML-to-HTML conversion and Developer rendering logic, switching between view and edit mode depending on the context:

Edit Content in Place

Download InlineEditingPHP.zip »


Installation

Make sure PHP is configured to support XSL Unpack contents of the archive into a Web server directory. Then open index.php file in your browser.

Configuration

  • App Server: Apache Tomcat 5.0.28 as tested
  • J2EE Support: comes with Tomcat - Servlet 2.4 and JSP 2.0
  • Source code size: 5K
  • Client: Internet Explorer, Firefox

This is an example of a very simple (4 JSP files) Content Management System. This package does not contain in-place editing functionality, but allows users to browse directories and modify .dita files using Developer.

Download SampleDitaCMS.zip »


Installation

You can unpack contents into any J2EE Web application. Before using, update utils.jsp, which includes an absolute path to the directory containing the DITA files (`content' directory like the one in the package):

public String contentRespositoryPath = "E:/Projects/.../WebContent/content";

Package Contents

  • index.jsp - entry point and file system navigation
  • edit.jsp - editing screen with embedded Developer
  • save.jsp - saves data to the file system
  • utils.jsp - a couple of utility methods
  • DITAStorm/* - directory with Developer product
  • content/* - directory with sample DITA content

Developer exposes the following methods to enclose the HTML page:

Method Description
enableDoctype(<dtd_base_location>)

Enables generation of DOCTYPE header for XML documents. Takes one parameter - path to the directory containing DITA DTD files. Example:

<SCRIPT>
  // specify directory for DTD files:
  // /content/dtd/topic.dtd
  // /content/dtd/map.dtd
  // ...
  ditaStorm.enableDoctype('/content/dtd');
</SCRIPT>

If this method is not called the editor will not generate DOCTYPE header or will keep the original XML document header.

registerExension(<extension_name>,...)

Registers Developer extension point. See the editor Customization section for details.

enablePhpFileOperations(<ditastorm_home_path>)

Enables file Open/Save operations implemented in PHP. This option turns on built-in file handling routines supplied with the product. Accepts one parameter specifying a Web browser path to the Developer home directory. For example:

<SCRIPT> ditaStorm.enablePhpFileOperations( '../DitaStorm') </SCRIPT>
This method should be called before the editor is rendered with render() method.

PHP implementation for file open/save operations comes with the editor out-of-the-box. Similar functionality can be implemented with other application/Web servers. You can request the same implementations for JSP and other technologies.

render(<ditastorm_home_path>,<width>,<height>,<css_styles>,<compliled_xsl_styles>)

This method renders Developer into an HTML page. It accepts the following parameters:

  • path to the location of the Developer home directory
  • editor width (pixels or percents)
  • editor height (pixels or percents)
  • stylesheet to be used (editor is supplied with simple.css)
  • compiled version of stylesheet to be used by the editor (supplied with simple.xsl.js)

Here is the example:

<SCRIPT> ditaStorm.render( '../DITAStorm','100%','300', 'simple.css','simple.xsl.js'); </SCRIPT>
Please remember, as on any HTML page, your element will take the specified 100% of available vertical space only if the outermost element expands to the entire page (height attribute set to 100%). For example, to make an HTML element (Developer) consume the entire remaining space on the page use a code similar to this:

<body>
  <table ... height='100%'>
    <tr height='10%'>...</tr>
    <tr height='90%'>...[dita editor]...</tr>
  </table>
</body>
loadXmlFile(<xml_file_path>)

Loads an XML file from a specified URL, provided as a first parameter of the function call. Example:

<SCRIPT>
  ditaStorm.render(...);
  ditaStorm.loadXmlFile('/content/default.xml');
</SCRIPT>
getXml()

Retrieves current contents of the editor as an XML string. For example:

<SCRIPT>
  var xmlString = ditaStorm.getXml();
  alert('Content: '+xmlString);
</SCRIPT>
By default the editor will return indentation-formatted XML. You can switch between compact and formatted output using ditaStorm.setOutputFormatted() method.

This method will return null if valid XML text can not be returned (such as when editing raw XML produced an error). By this time the user has already been notified about the error.

getFormattedXml()

DITA IdentingRetrieves indentation-formatted contents of the editor as an XML string. Contents returned by this method are similar to the raw content editable in 'XML' mode.

<SCRIPT>
  var xmlString = ditaStorm.getFormattedXml();
  alert('Formatted content: '+xmlString);
</SCRIPT>

This method will return null if valid XML text can not be returned (such as when editing raw XML produced an error). By this time the user has already been notified about the error.

setOutputFormatted(<formatted>)

Enables or disables output formatting. This method affects both getXml() and updateField(). By default Developer will generate formatted XML.

<SCRIPT>
  ditaStorm.setOutputFormatted(false);
  var xmlCompact = ditaStorm.getXml();
  ditaStorm.setOutputFormatted(true);
  var xmlFormatted = ditaStorm.getXml();
</SCRIPT>
setXml(<xml_content_as_string>)

Sets contents of the editor accepting XML as a string. For example:

<SCRIPT> ditaStorm.setXml('<topic><title/></topic>'); </SCRIPT>
attachField(<form_name>,<field_name>)

Attaches Developer to the specified form field. Accepts two parameters - form and field name.

<FORM name='myForm' ...>
  <INPUT name='ditaField' type='hidden' value='<topic><title>Lorem</title></topic>'>
  ...
  <SCRIPT>
    ditaStorm.attachField('myForm','ditaField');
  </SCRIPT>
updateField()

Updates form field previously attached with attachField() method. Often called onSubmit when updated data is ready to be sent to the server.

<SCRIPT>
  function verfyAndSubmit() {
    ...
    ditaStorm.updateField();
    myForm.submit(); }
</SCRIPT>
By default the editor will return indentation-formatted XML. You can switch between compact and formatted output using ditaStorm.setOutputFormatted() method.
isModified()

Returns true if contents of the editor have been modified since the last load file or load XML operation.

<SCRIPT>
  function onUnload() {
    if( ditaStorm.isModified() ) {
      confirm('Do you want to save changes?');
    }
  }
</SCRIPT>
setModified(<modified_indicator>)

Explicitly sets current status of the ‘modified&rsquo' flag of the editor. Developer will automatically change it to 'true' when content is changed or to 'false' when a new file or XML is loaded.

<SCRIPT>
  function quickSave() {
    // Save data ...
    // Set indication that data has been saved
    ditaStorm.setModified(false);
  }
</SCRIPT>
enableUnloadConfirmation()

Convenience method assigning simple 'on page unload' handler asking the user to confirm page navigation if the editor's 'modified' flag is set to true. If required, you can clear the flag with setModified() method call.

<SCRIPT>
  ditaStorm.enableUnloadConfirmation();
  ditaStorm.render('../DITAStorm','100%','100%', 'simple.css','simple.xsl.js');
</SCRIPT>
This method sets window's onbeforeunload event handler. If your application uses it for other purposes we suggest using isModified() method and explicitly ask for the user's confirmation instead.