package com.oracle.determinations.interview.engine.userplugins.commentary;
import java.util.HashMap;
import com.oracle.determinations.interview.engine.InterviewSession;
import com.oracle.determinations.interview.engine.plugins.InterviewSessionPlugin;
import com.oracle.determinations.interview.engine.plugins.InterviewSessionRegisterArgs;
import com.oracle.determinations.interview.engine.plugins.commentary.CommentaryProviderPlugin;
import com.oracle.determinations.interview.util.TypedInputStream;
/**
* Tutorials and Examples - Plugins - Commentary - Sample
* Code(RedirectCommentary)
*/
public class RedirectCommentary implements CommentaryProviderPlugin {
private static HashMap<String, String> redirectMap = null;
static {
// initialise the hash map for targets that have corresponding
// URL redirections for commentary
redirectMap = new HashMap<String, String>();
redirectMap
.put("en-GB/attribute/person_name",
"http://www.google.com/dictionary?langpair=en%7Cen&q=person&hl=en&aq=f");
redirectMap
.put("en-GB/attribute/child_name",
"http://www.google.com/dictionary?langpair=en%7Cen&q=child&hl=en&aq=f");
redirectMap
.put("en-GB/attribute/eating_icecream",
"http://www.google.com/dictionary?langpair=en%7Cen&q=ice+cream&hl=en&aq=f");
redirectMap
.put("en-GB/attribute/sun_shining",
"http://www.google.com/dictionary?langpair=en%7Cen&q=shining&hl=en&aq=f");
redirectMap
.put("en-GB/relationship/personschildren",
"http://www.google.com/dictionary?langpair=en%7Cen&q=children&hl=en&aq=f");
}
/**
* Constructor - required for plugin architecture
*/
public RedirectCommentary() {
}
/**
* Constructs the full target and key to the hash map
*
* @param session the interview session
* @param target the target
* @return the full target
*/
private String buildFullTarget(InterviewSession session, String target) {
return session.getLocale() + "/" + target;
}
/***********************************/
/* Web-determinations method calls */
/***********************************/
/**
* The example redirects to URLs. This returns null for commentary content.
*/
public TypedInputStream getCommentaryContent(InterviewSession session,
String target) {
return null;
}
/**
* This returns the URL to redirect to for a particular target.
*/
public String getCommentaryURL(InterviewSession session, String target) {
String fullTarget = buildFullTarget(session, target);
if (redirectMap.containsKey(fullTarget)) {
return redirectMap.get(fullTarget);
}
return null;
}
/**
* Checks if the target has a commentary or not
*/
public boolean hasCommentary(InterviewSession session, String target) {
return redirectMap.containsKey(buildFullTarget(session, target));
}
/**
* For the example, it returns true to enable commentary in the Web
* Determinations Interview
*/
public boolean isCommentaryEnabled(InterviewSession session) {
return true;
}
/**
* For redirecting to URLs, it returns true
*/
public boolean isCommentaryRedirect(InterviewSession session, String target) {
return true;
}
/**
* Used to register the plugin
*/
public InterviewSessionPlugin getInstance(InterviewSessionRegisterArgs args) {
if (args.getSession().getRulebase().getIdentifier().equals(
"Parents and Children")) {
return new RedirectCommentary();
}
return null;
}
}