Creating data visualization modules on the mid tier
Use the following procedure to create DVMs. See also that examples that follow.
When writing the module, generate output that is compliant with Section 508 if your users specify anything other than default in the Accessible Mode field of the User Preference form.
To create a data visualization module
- Save your code to a .java file with a name that matches the Class file name.
If you use the first example below (HelloWorld plug-in), your resulting file should be HelloWorldPlugin.java. - Compile the code using javac.
Make sure to reference the GraphPlugin.jar file from the Mid Tier's /WEB-INF/lib directory and a .jar file that contains the Oracle Java HttpServletResponse class in your -classpath parameter for javac. HttpServletResponse is in j2ee.jar if you use a OracleOne web server; it is in servlet.jar if you use ServletExec. For example:
javac -classpath /yourDirStructure/j2ee.jar:/yourDirStructure/GraphPlugin.jar HelloWorldPlugin.java - Add the compiled .class file to a .jar file. For example:
jar -cvf DataVisHelloWorld.jar HelloWorldPlugin.class
If you use a package structure, enter this:
jar -cvf DataVisHellowWorld.jartopLevelDir
If you use package structures, remember these guidelines:- If you chose to use a Java package reference, add this to the sample code, for example, package com.mycompany.plugin.
- When running javac and jar, your .java or .class file must exist in a directory structure that matches the package declaration, and you should be in the directory immediately above the top of the package structure when running javac and jar.
When running javac, java, and jar commands, remember that these Java tools look "down" a directory structure. To see files in directories above your current directory, use the ../ reference; you cannot simply use an absolute file path reference.
Example 1: HelloWorld plug-in
This example sends back HTML that displays Hello World on the client.
public class HelloWorldPlugin implements Plugin {
public void init(PluginConfig config) {
}
public void processRequest(PluginContext pc) throws IOException, NoPermissionException {
HttpServletResponse response = pc.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.println("<html><head><title>Hello World Plugin Example</title></head>");
writer.println("<body><h1>Hello World</h1></body></html>");
}
public String handleEvent(PluginContext pc, String eventType,String eventData) throws IOException, NoPermissionException {
return "alert(\"Got event data in Midtier as " + eventData + "\");";
}
public DefinitionFactory getDefinitionFactory() {
return null;
}
public void cleanup() {}
}
public void init(PluginConfig config) {
}
public void processRequest(PluginContext pc) throws IOException, NoPermissionException {
HttpServletResponse response = pc.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.println("<html><head><title>Hello World Plugin Example</title></head>");
writer.println("<body><h1>Hello World</h1></body></html>");
}
public String handleEvent(PluginContext pc, String eventType,String eventData) throws IOException, NoPermissionException {
return "alert(\"Got event data in Midtier as " + eventData + "\");";
}
public DefinitionFactory getDefinitionFactory() {
return null;
}
public void cleanup() {}
}
Example 2: Event handling code
This scenario shows event handling code added to the generated HTML in the head tag.
PageService ps = pc.getPageService();
HttpServletResponse response = pc.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.println("<html><head>");
writer.println(ps.getEventInfrastructureCode());
writer.println("<script>function sendMidTierEvent() {");
writer.println("var result = "+ps.getEventDispatcherName()+
".sendEventToMidTier(\"ClickEvent\",\"Title\");");
writer.println("eval(result);");
writer.println("};</script>");
writer.println("<html><head><title>Hello World Plugin Example</title></head>");
writer.println("<body><h1 onclick=sendMidTierEvent()>Hello World</h1></body></html>");
HttpServletResponse response = pc.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.println("<html><head>");
writer.println(ps.getEventInfrastructureCode());
writer.println("<script>function sendMidTierEvent() {");
writer.println("var result = "+ps.getEventDispatcherName()+
".sendEventToMidTier(\"ClickEvent\",\"Title\");");
writer.println("eval(result);");
writer.println("};</script>");
writer.println("<html><head><title>Hello World Plugin Example</title></head>");
writer.println("<body><h1 onclick=sendMidTierEvent()>Hello World</h1></body></html>");
Example 3: Using the definition factory
This is an scenario of using the definition factory.
public void processRequest(PluginContext pc) throws IOException, NoPermissionException {
HttpServletRequest req = pc.getRequest();
String defName = req.getParameter("name");
// get our definition object from the definition service.
MyDefObject def = (MyDefObject) pc.getDefinitionService().getDefinition(name);
..... generate the html using def ....
}
private DefinitionFactory myDefFactory;
public void init(PluginConfig config) {
// create the definition factory and stash it in a member variable for future use.
myDefFactory=new MyDefObjFactory();
}
public DefinitionFactory getDefinitionFactory() {
// return the stashed definition when the definition service asks for it.
return myDefFactory;
}
private class MyDefObjectFactory implements DefinitionFactory {
// This method is called by the AR Plugin container if the definition is stored
// in the SimpleDefinition field in the Data Visualization Definition form
public Definition createFromString(PluginContext pc, String defName, String defAsString) throws IOException {
return new MyDefObject(defName, defAsString);
}
// This method is called by the AR Plugin container if the definition is stored
// in the ComplexDefinition field in the Data Visualization Definition form
public Definition createFromStream(PluginContext pc, Strign defName, InputStream defAsStream) throws IOException {
return new MyDefObject(defName, defAsStream);
}
}
// This class implements CacheableDefinition so that the Definition Service provided by
// the AR Plugin container caches this object till it sees any modifications in the entry for
// this definition in the Data Visualization Definition form.
private class MyDefObject implements CacheableDefinition {
private MyDefObject(String defName, String defString) {
... initialize the def object with the string ...
private MyDefObject(String defName, InputStream is) {
... initialize the def object using the stream ...
HttpServletRequest req = pc.getRequest();
String defName = req.getParameter("name");
// get our definition object from the definition service.
MyDefObject def = (MyDefObject) pc.getDefinitionService().getDefinition(name);
..... generate the html using def ....
}
private DefinitionFactory myDefFactory;
public void init(PluginConfig config) {
// create the definition factory and stash it in a member variable for future use.
myDefFactory=new MyDefObjFactory();
}
public DefinitionFactory getDefinitionFactory() {
// return the stashed definition when the definition service asks for it.
return myDefFactory;
}
private class MyDefObjectFactory implements DefinitionFactory {
// This method is called by the AR Plugin container if the definition is stored
// in the SimpleDefinition field in the Data Visualization Definition form
public Definition createFromString(PluginContext pc, String defName, String defAsString) throws IOException {
return new MyDefObject(defName, defAsString);
}
// This method is called by the AR Plugin container if the definition is stored
// in the ComplexDefinition field in the Data Visualization Definition form
public Definition createFromStream(PluginContext pc, Strign defName, InputStream defAsStream) throws IOException {
return new MyDefObject(defName, defAsStream);
}
}
// This class implements CacheableDefinition so that the Definition Service provided by
// the AR Plugin container caches this object till it sees any modifications in the entry for
// this definition in the Data Visualization Definition form.
private class MyDefObject implements CacheableDefinition {
private MyDefObject(String defName, String defString) {
... initialize the def object with the string ...
private MyDefObject(String defName, InputStream is) {
... initialize the def object using the stream ...
Example 4: Using the locale service to format dates
This snippet is an scenario of using the locale service for formatting dates and also formatting the AR System com.remedy.arsys.Value objects.
LocaleService ls = pluginContext.getLocaleService();
// format current date as per current locale and user preferences
String dateValue = ls.formatDate(new Date());
ARLocaleService als = (ARLocaleService)ls;
Value val = getValueFromServer(server, form, fieldId);
String formattedStr = als.formatValue(val, server, form,view,fieldId);
// format current date as per current locale and user preferences
String dateValue = ls.formatDate(new Date());
ARLocaleService als = (ARLocaleService)ls;
Value val = getValueFromServer(server, form, fieldId);
String formattedStr = als.formatValue(val, server, form,view,fieldId);
Example 5: Using the locale service to get a localized string
This snippet is an scenario of using of the locale service to get a localized string.
LocaleService ls = pluginContext.getLocaleService();
String defName=pluginContext.getRequest().getParameter("name");
int TITLE_ID=100;
LocalizedStringID localizedTitle = new LocalizedStringID(defName, TITLE_ID);
LocalizedStringID[] retrieveIDs={localizedTitle};
String[] localizedStrings = ls.getLocalizedStrings(retrieveIDs);
String localizedTitle = localizedStrings[0];
String defName=pluginContext.getRequest().getParameter("name");
int TITLE_ID=100;
LocalizedStringID localizedTitle = new LocalizedStringID(defName, TITLE_ID);
LocalizedStringID[] retrieveIDs={localizedTitle};
String[] localizedStrings = ls.getLocalizedStrings(retrieveIDs);
String localizedTitle = localizedStrings[0];
Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*