<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brett Johnson &#187; dynamic-help</title>
	<atom:link href="http://mrscripter.com/tag/dynamic-help/feed" rel="self" type="application/rss+xml" />
	<link>http://mrscripter.com</link>
	<description>Technical writing and web development</description>
	<lastBuildDate>Thu, 09 Feb 2012 03:20:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating dynamic documentation plugins for the Eclipse Help System using Java</title>
		<link>http://mrscripter.com/2009/12/creating-dynamic-documentation-plugins-for-the-eclipse-help-system-using-java/eclipse-help-system</link>
		<comments>http://mrscripter.com/2009/12/creating-dynamic-documentation-plugins-for-the-eclipse-help-system-using-java/eclipse-help-system#comments</comments>
		<pubDate>Fri, 18 Dec 2009 21:05:56 +0000</pubDate>
		<dc:creator>brett</dc:creator>
				<category><![CDATA[eclipse-help-system]]></category>
		<category><![CDATA[dita-ot transform]]></category>
		<category><![CDATA[dynamic-help]]></category>
		<category><![CDATA[eclipse-help]]></category>
		<category><![CDATA[IHelpContentProducer]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[org.eclipse.help.contentProducer]]></category>
		<category><![CDATA[org.eclipse.help.IHelpContentProducer]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://mrscripter.com/?p=162</guid>
		<description><![CDATA[Eclipse documentation plug-ins can contain Java for creating dynamic content. You can extend the Eclipse help system by taking advantage of the org.eclipse.help.contentProducer extension point. The examples in this article demonstrate how to create a simple template that is parsed &#8230; <a href="http://mrscripter.com/2009/12/creating-dynamic-documentation-plugins-for-the-eclipse-help-system-using-java/eclipse-help-system">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fmrscripter.com%2F2009%2F12%2Fcreating-dynamic-documentation-plugins-for-the-eclipse-help-system-using-java%2Feclipse-help-system"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fmrscripter.com%2F2009%2F12%2Fcreating-dynamic-documentation-plugins-for-the-eclipse-help-system-using-java%2Feclipse-help-system&amp;source=mrscripter&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Eclipse documentation plug-ins can contain Java for creating dynamic content. You can extend the Eclipse help system by taking advantage of the <a href="http://help.eclipse.org/help32/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_help_contentProducer.html" target="_blank">org.eclipse.help.contentProducer</a> extension point. The examples in this article demonstrate how to create a simple template that is parsed at run time to display dynamic text.</p>
<p><span id="more-162"></span></p>
<h1>Skill level: intermediate</h1>
<p>You can download the sample project that provides a simple framework for getting started with your own plug-in. If you have a basic level of Java programming experience or experience with other programming languages, you should be able to understand the concepts and examples.</p>
<h1>Getting Started</h1>
<p>This article assumes that you are using <a href="http://www.eclipse.org/downloads/">Eclipse 3.5 IDE for Java EE Developers (Galileo)</a>, but you can use other versions if they contain the <a href="http://www.eclipse.org/pde/">Plugin Development Environment (PDE)</a>. The screenshots and steps might differ for other versions.</p>
<ol>
<li>Extract the Eclipse ZIP file and launch the Eclipse executable.</li>
<li><a href="http://mrscripter.com/wp-content/uploads/2009/12/com.mrscripter.dynamicsample.doc.zip">Download the sample Eclipse project for a dynamic documentation plugin</a>.</li>
<li>Import the zip file as an archived project: <strong>File</strong>-&gt;<strong>Import</strong>-&gt;<strong>Existing Projects into Workspace</strong>. Choose the <strong>Select archive file </strong>option and browse to the downloaded sample project zip file.<a href="http://mrscripter.com/wp-content/uploads/2009/12/import_workspace.jpg" rel="lightbox[162]"><img class="alignnone size-full wp-image-167" title="Import the sample project into your workspace" src="http://mrscripter.com/wp-content/uploads/2009/12/import_workspace.jpg" alt="Displays a screen shot of the options for importing an archived project into the Eclipse workspace" width="515" height="463" /></a></li>
<li>Click <strong>Finish </strong>and the project <em>com.mrscripter.dynamicsample.doc</em> will be added to your workspace and available for browsing within the Project Explorer view.</li>
</ol>
<p>This sample provides a basic example of producing dynamic content using Java and Eclipse extension points.</p>
<h1>Run the sample project</h1>
<p>When you build the project, the compiled version of the plug-in will go into your eclipse/plugins directory so that you can test the dynamic content in the Eclipse help system.</p>
<ol>
<li>Right-click the project folder in the Project Explorer view and select <strong>Export</strong>.</li>
<li>Select <strong>Plug-in Development-&gt;Deployable plug-ins and fragments</strong><a href="http://mrscripter.com/wp-content/uploads/2009/12/export_deploy.jpg" rel="lightbox[162]"><img class="alignnone size-full wp-image-168" title="Export the plugin to your Eclipse environment" src="http://mrscripter.com/wp-content/uploads/2009/12/export_deploy.jpg" alt="Exporting the plugin compiles the Java source and makes it available to the Eclipse environment" width="371" height="316" /></a></li>
<li>
<p style="margin-bottom: 0in;">In the export destination area, choose the <strong>Directory </strong>option and select the directory that you previously extracted your Eclipse download. You should select the folder that contains your eclipse.exe file. The export wizard creates the output jar file in the plugins subfolder, for example: C:\<em>my_dir\</em>eclipse\plugins\com.mrscripter.dynamicsample.doc_1.0.0.jar.</p>
</li>
<li>
<p style="margin-bottom: 0in;">Restart Eclipse to register this new plugin with the help system.</p>
</li>
<li>After Eclipse restarts, click <strong>Help</strong>-&gt;<strong>Help Contents</strong> to display the help system.</li>
</ol>
<p>In the help system, you will see a top-level navigation entry titled “Dynamic Documentation Sample.” Each table of contents entry within this section links to what appears to be different files; however, the contentProducer extension designates the HelloDynamicWorld class as the responder for all content requests. Each table of contents link uses a different query string title parameter that the HelloDynamicWorld class uses to populate in the text for the title and body.</p>
<p>The following sections explain in more detail how the plug-in works. If you have a good understanding of Java, you might choose to explore the source code at your own pace.</p>
<p>If you modify the plug-in code, you must re-export and restart Eclipse each time that you would like to view the results of the change.</p>
<h1>Dissecting the plugin</h1>
<p>The plugin.xml file contains directions that allow the Eclipse runtime environment to understand how to process the files contained within a directory or JAR file that is in the plugins directory. These instructions take the form of extensions and extension points.</p>
<p>The <span style="font-family: courier new,courier;">org.eclipse.help.contentProducer</span> extension point is the key to creating dynamic output. You add this extension point to your plugin.xml and register a content producer by specifying the name of the Java class that you want to control the dynamic processing:</p>
<pre>&lt;extension
   id="com.mrscripter.dynamicsample.doc"
   name="Dynamic documentation sample plugin"
   point="org.eclipse.help.contentProducer"&gt;
     &lt;contentProducer producer="HelloDynamicWorld"/&gt;
 &lt;/extension&gt;</pre>
<h2>Content producer</h2>
<p>In the sample project, the content producer extension points to the HelloDynamicWorld class. This class must extend the <span style="font-family: courier new,courier;">IHelpContentProducer</span> interface and provide the required <span style="font-family: courier new,courier;">getInputStream</span> method, which allows the plugin to send its content to the browser:</p>
<pre>public InputStream getInputStream(String pluginID, String href, Locale locale)</pre>
<p>You return an InputStream from your own Java class to Eclipse for display. An InputStream is a byte representation of your text.</p>
<p>The HelloDynamicWorld.java class contains two important methods: <span style="font-family: courier new,courier;">getInputStream</span> and <span style="font-family: courier new,courier;">createMyDynamicOutput</span>.</p>
<pre>import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.net.URL;
import java.util.Locale;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.IHelpContentProducer;
import org.osgi.framework.Bundle;

public class HelloDynamicWorld implements IHelpContentProducer{

    private static Bundle bundle = Platform.getBundle("com.mrscripter.dynamicsample.doc");
    private static Path path = new Path("template/template.html");
    private static URL url = Platform.find(bundle, path);
    private static File templateFile=null;
    private static StringBuffer templateBuffer=null;

	public InputStream getInputStream(String pluginID, String href, Locale locale) {
		InputStream is = null;
		String title = QueryStringHelper.getValue(href,"title");
	      try{
	          return createMyDynamicOutput(href,title);
	      }
	      catch(Exception e){
	          e.printStackTrace();
	      }
	      return is;
	}

	private InputStream createMyDynamicOutput(String href, String title) throws Exception{
	    try{
        	templateBuffer = new StringBuffer();
        	templateFile = new File(FileLocator.toFileURL(url).getFile());
                BufferedReader in = new BufferedReader(new FileReader(templateFile));
                String s=null;
                while((s = in.readLine()) != null){
            	    templateBuffer.append(s);
                }
            }
            catch(Exception e){
                System.out.println(e.getMessage());
                e.printStackTrace();
            }

	    String tempOut = templateBuffer.toString().replaceAll("%TITLE%", title);
	    return new ByteArrayInputStream(tempOut.toString().getBytes("UTF-8"));
	}
}</pre>
<p>The typical HelloWorld application is not dynamic so the sample project adds a little more code to demonstrate changing the output based on some simple input.  This sample looks for a query string parameter named &#8220;title&#8221; and gets the value of the parameter and then inserts that value into a template response. The result is returned as an InputStream for passing back to Eclipse for further processing prior to rendering.</p>
<p>The URL that is called is http://&#8230;../help/topic/com.mrscripter.dynamicsample.doc/<em>something.html</em>?title=Testing+A+Title. The content producer class intercepts all URL requests for the plug-in. You can change <em>something.html</em> to any name and it will still work as long as you provide the title in the querystring.</p>
<p>If you request a URL with an extension other than .html, some browsers won&#8217;t display the result as HTML but rather as plain text because our sample does not adjust the response type in the response header.</p>
<h2>Template</h2>
<p>The sample project includes a simple template file that uses basic <span style="font-family: courier new,courier;">%variable%</span> replacement. The <span style="font-family: courier new,courier;">getInputStream</span> method uses the <span style="font-family: courier new,courier;">QueryStringHelper</span> class to read the title parameter from the querystring and pass the title parameter to the createMyDynamicOutput method. The createMyDynamicOutput method reads the template file to a string buffer, templateBuffer. All instances of %title% within the template/template.html file are replaced title parameter.  The string is converted into a UTF-8 encoded ByeArrayInputStream and returned to Eclipse for display.</p>
<h2>Expanding on the HelloDynamicWorld sample</h2>
<p>The sample project demonstrates how documentation plug-s that run within the context of the Eclipse help system or in the Eclipse information center mode can response to dynamic input from a user. The org.eclipse.help.contentProducer extension point provides the ability to create a more dynamic and response help system. New content producers could include remote content from feed, local content or external information. For example, you could integrate your online Knowledge base contents directly into your help contents to provide in-context support documents.</p>
<h2>Ideas for implementations</h2>
<p>For corporations that author their help content in DITA-XM, instead of using a build framework such as the DITA Open Toolkit, they could instead render DITA content dynamically on-the-fly and produce targeted content based on metadata about a users configuration or environment to create custom documentation.</p>
<p>Using the contentProducer as a proxy, you can eliminate the cross-domain communication limitation that Javascript frameworks face. You could query and retrieve remote content and display within your help system. You could generate a dynamic XML table of contents based on content hosted on your own website, but users would be able to see it locally on their workstations. This approach can enable a push model for some content.</p>
]]></content:encoded>
			<wfw:commentRss>http://mrscripter.com/2009/12/creating-dynamic-documentation-plugins-for-the-eclipse-help-system-using-java/eclipse-help-system/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

