Example

Step1:

The first thing you have to do, if you want to use the LOM-API is to create an instance of a KOMLOMEngine object. The Constructor of the KOMLOMEngine class is using a java.util.Dictionary object as a parameter. This dictionary object has to contain the following ( key,value) pairs (default values if no value is specified are shown in brackets in the following:

key
value
default
VocabularyFile
<location of the vocabulary file>
./conf/lom-vocbulary.txt
DTDLocation
<location of the dtd>
http://www.multibook.de/xml/lom1.dtd
Validation
true/false
true
JaxpProperty
<class name of the class implementing the apropriate jaxp-Interface>


org.apache.crimson.jaxp.DocumentBuilderFactoryImpl



Code:
import kom.lom.model.*;
import kom.lom.editor.*;

import kom.lom.exceptions.*;


//use default values
KOMLOMEngine engine = new KOMLOMEngine(null);

Step2:

Create an instance of KOMLOMDataModel. A KOMLOMEngine offers different methods for creating a KOMLOMDataModel object.

method
description
createLOM()
creates an empty KOMLOMDataModel object
createLOM(KOMLOMDataModel lommod)
returns a deep copy of the KOMLOMDataModel object passed as parameter
createLOM(InputStream is)
Create a LOM data model by parsing the input stream.
Note: The InputStream must contain a xmlL description acording to the LOM DTD found at
http://www.multibook.de/xml/lom1.dtd

Note2: The location for the DTD is taken from the KOMLOMEnvironemnt passed during creation of this object.

Code:

KOMLOMDataModel emptyModel = engine.createLOM();

//create a File Handle for a xml file containing a LOM description;
//create an InputStream object for this handle

//and pass it as an agurment to the createLOM(InputStream is) method

String fileName = "./examples/ethernet.lom";
InputStream fi = new FileInputStream(fileName);
KOMLOMDataModel xmlModel = engine.createLOM(is);


Step3:

Read, add and change values from the KOMLOMDataModel objects.
All LOM fields are mapped to instances of KOMLOMDataElement or KOMLOMDataValue objects. Every LOM description represented by an instance of a KOMLOMDataModel object contains a root element which can be accessed with calling the method getRootElement(). This method returns an instance of the top level KOMLOMDataElement object containing all 9 LOM categories.
There are two methods to create a KOMLOMDataElement instance or a KOMLOMDataValue instance:

Code:

KOMLOMDataElement root = emptyModel.getRootElement();

//generate a KOMLOMDataElement representing the general category
KOMLOMDataElement gen = root.getElement("general",true,null);

//generate a KOMLOMDataElement representing the technical category
//we could use the same method as with generating the general category, but we use the other way now
KOMLOMDataElement tech = engine.createDataElement("technical",null);
engine.addElement(tech);


//let's add a title element and a structure element to the general obejct
KOMLOMDataElement title = gen.getElement("title",true,null);
KOMLOMDataElement stru = gen.getElement("structure",true,null);

//the title element contains Langstring elements and the getElement method even works with arrays
KOMLOMDataElement titlelang = title.getElement("langstring",true,null);

//an instance of a langstring object contains two KOMLOMDataValue objects representing the language identifier and the value
//we will generate and set them now
KOMLOMDataValue val1 = titlelang.getValue("lang",true);
KOMLOMDataValue val2 = titlelang.getValue("data",true);
val1.setData("en");
val2.setData("this is an english test title");


//the structure element contains a vocabulary element, so we need to create parameters first
Object[] params = new Object[] { "GENERAL.STRUCTURE" };
KOMLOMDataElement struvoc = stru.getElement("structure",true,params);

//for setting and getting the values for the Structure element, we can use methods offered by an instance of a Vocbaulary element
((Vocabulary) struvoc).setEntryWithStringVocabulary("Sammlung","de");

//this will result in the following xml representation
//<structure><vocabulary><vocentry>0</vocentry></vocabulary></structure>
// calling ((Vocabulary) struvoc).setEntryWithStringVocabulary("Collection","en");  would do the same

String v = ((Vocabulary)struvoc).getEntryAsString("en");
//v contains the value "Collection"


Step4:

create a panel for displaying the LOM description.
Note: Changes for all KOMLOMDataElement and KOMLOMDataValue objects made by the user, while working with the panel, are immediately reflected in the apropriate object (even without depending on pressing the retrun key in TextFields).
Note2: While it is possible to make changes to KOMLOMDataElement and KOMLOMDataValue objects while their values are displayed inside the Panel, the methods to change the values are not synchronized.

An instance of a KOMLOMEngine object offers a method to create a KOMLOMPanel . The method needs a Dictionary to configure the panel. This dictionary object has to contain the following (key,value) pairs (default values if no value is specified are shown in brackets in the following:

key
value
default
Language
<language for the labels and text fields> (String)
none
ClassificationFolder
<location of the classification files>
"./classifications"
Categories
<enumeration of the categories to display> (java.util.Hashset)
{ general, technical, educational, metametadata, annotation, relation, lifecycle, classification }



Code:

// We need some parameters to initalize the Panel
Hashtable h= new Hashtable().put("Language","en);
KOMLOMPanel editorPanel = engine.getEditorPanel(root,h);