1| public class HelloWorldMarkup extends DefaultMarkupType { 2| 3| private static final DefaultMarkup MARKUP; 4| 5| static { 6| MARKUP = new DefaultMarkup("HelloWorld"); 7| } 8| 9| public HelloWorldMarkup() { 10| super(MARKUP); 11| } 12| }
A private instance of a DefaultMarkup is required (line 3). The initialization of the DefaultMarkup object in the static block (line 6) is required in that way to allow the plugin-framework to create a markup instance on start-up. In line 6 also the name (and markup keyword) is specified as parameter for the DefaultMarkup object, "HelloWorld" in this example. The DefaultMarkup object has to be passed to the super class constructor call, as shown in line 10.
In the following the above listing is extended in line 4 and line 8 to introduce an annotation. The markup example allows to specify an image file name by the image annotation.
1| public class HelloWorldMarkup extends DefaultMarkupType { 2| 3| private static final DefaultMarkup MARKUP; 4| public static final String IMAGE_KEY = "image"; 5| 6| static { 7| MARKUP = new DefaultMarkup("HelloWorld"); 8| MARKUP.addAnnotation(Image_KEY, false); 9| } 10| 11| public HelloWorldMarkup() { 12| super(MARKUP); 13| } 14| }
1| public HelloWorldMarkup() { 2| super(MARKUP); 3| this.setRenderer(new HelloWorldRenderer()); 4| }
The extension point for markups is called Type. The code to register the markup defined above on the root level, i.e., making it available as root level content element on any page, would look like this:
<extension plugin-id="KnowWEExtensionPoints" point-id="Type" id="HelloKnowWEType"> <parameter id="class" value="de.knowwe.example.HelloKnowWEType" /> <parameter id="name" value="HelloKnowWEType" /> <parameter id="description" value="KnowWEObjectType HelloKnowWEType" /> <parameter id="version" value="1.0" /> <parameter id="priority" value="5" /> <parameter id="scope" value="root" /> </extension>
To create a general markup, the class AbstractType has to be extended. In contrast to the DefaultMarkup in this case a parser-component needs to be defined in the first place. More details about parsing in KnowWE can be found here:
If the markup is an extension to an existing one and not on root level, the class name of the parent type needs to be specified within the scope parameter of the plugin.xml.