05-12-2013 12:59 PM
I have created a new class:
@Path("/pidedit")
@WebObject(type = "pidedit")
public class PIDEditorModule extends ModuleRoot {
public static final String PID_FIELD = "note:note";
@GET
@Path(value = "{id}/html")
@Produces("text/html;charset=UTF-8")
public Object getShow(@PathParam("id") String id)
throws ClientException {
IdRef ref = new IdRef(id);
CoreSession session = ctx.getCoreSession();
if (session.exists(ref)) {
if (session.hasPermission(ref, SecurityConstants.READ)) {
DocumentModel doc = session.getDocument(ref);
log.debug(doc.getPropertyValue(PID_FIELD));
return getTemplate("show.ftl").arg("uid", id);
}
return Response.status(Status.UNAUTHORIZED).build();
}
return Response.status(Status.NOT_FOUND).build();
}
public String getPreview(String id)
throws ClientException {
return getTemplate("show.ftl").arg("uid", id).toString();
}
}
The getShow(..) function works as it is expected, but I want to call the getPreview(..) function in a new PIDPreviewer class which extends AbstractPreviewer and I can not find a way to do it properly. I have tried something like this:
ModuleManager moduleManager = Framework.getLocalService(WebEngine.class).getModuleManager();
ModuleConfiguration moduleConfig = moduleManager.getModule("pidedit");
Module mod = moduleConfig.get();
but finally I have a trouble to create the instance of the PIDEditorModule class with a context.
Any help is going to be appreciated.
06-10-2013 02:39 PM
Ok. I have solved the problem in this way:
ModuleManager moduleManager = Framework.getLocalService(WebEngine.class).getModuleManager();
ModuleConfiguration moduleConfig = moduleManager.getModule("pidedit");
Module mod = moduleConfig.get();
WebContext ctx = mod.getEngine().getActiveContext();
HttpServletRequest request = new HttpSRW();
ctx = new DefaultContext(request);
((DefaultContext) ctx).setModule(mod);
PIDEditorModule preview = (PIDEditorModule)mod.getRootObject(ctx);
String previewStr = ((PIDEditorModule)preview).getPreview(dm.getId());
htmlPage.append(previewStr);
Attention: Blogs & Forums are in READ-ONLY mode from Oct 9-19 as we transition to our new platform. Learn more.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.