}
@Override
public void createContent() throws Exception {
final OutputStream out;
final IContentItem contentItem;
final IParameterProvider pathParams;
final String method;
final String payload;
logger.info("CDF content generator took over: " + Long.toString((new Date()).getTime()));
try {
if (parameterProviders.get("path") != null
&& parameterProviders.get("path").getParameter("httprequest") != null
&& ((HttpServletRequest) parameterProviders.get("path").getParameter("httprequest")).getContextPath() != null) {
RELATIVE_URL = ((HttpServletRequest) parameterProviders.get("path").getParameter("httprequest")).getContextPath();
} else {
RELATIVE_URL = getBaseUrl();
/* If we detect an empty string, things will break.
* If we detect an absolute url, things will *probably* break.
* In either of these cases, we'll resort to Catalina's context,
* and its getContextPath() method for better results.
*/
if ("".equals(RELATIVE_URL) || RELATIVE_URL.matches("^http://.*")) {
Object context = PentahoSystem.getApplicationContext().getContext();
Method getContextPath = context.getClass().getMethod("getContextPath", null);
if (getContextPath != null) {
RELATIVE_URL = getContextPath.invoke(context, null).toString();
}
}
}
if (RELATIVE_URL.endsWith("/")) {
RELATIVE_URL = RELATIVE_URL.substring(0, RELATIVE_URL.length() - 1);
}
// If callbacks is properly setup, we assume we're being called from another plugin
if (this.callbacks != null && callbacks.size() > 0 && HashMap.class.isInstance(callbacks.get(0))) {
HashMap<String, Object> iface = (HashMap<String, Object>) callbacks.get(0);
pathParams = parameterProviders.get("path");
contentItem = outputHandler.getOutputContentItem("response", "content", "", instanceId, MIME_HTML);
out = (OutputStream) iface.get("output");
method = "/" + (String) iface.get("method");
payload = (String) iface.get("payload");
this.userSession = this.userSession != null ? this.userSession : (IPentahoSession) iface.get("usersession");
} else { // if not, we handle the request normally
pathParams = parameterProviders.get("path");
contentItem = outputHandler.getOutputContentItem("response", "content", "", instanceId, MIME_HTML);
out = contentItem.getOutputStream(null);
method = pathParams.getStringParameter("path", null);
payload = "";
}
// make sure we have a workable state