<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: calling a ModuleRoot's function in other class in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/calling-a-moduleroot-s-function-in-other-class/m-p/313884#M885</link>
    <description>&lt;P&gt;Ok. I have solved the problem in this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;        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);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 10 Jun 2013 18:39:54 GMT</pubDate>
    <dc:creator>adam_bo_</dc:creator>
    <dc:date>2013-06-10T18:39:54Z</dc:date>
    <item>
      <title>calling a ModuleRoot's function in other class</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/calling-a-moduleroot-s-function-in-other-class/m-p/313883#M884</link>
      <description>&lt;P&gt;I have created a new class:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@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();
    }    
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;        ModuleManager moduleManager = Framework.getLocalService(WebEngine.class).getModuleManager();        	
        ModuleConfiguration moduleConfig = moduleManager.getModule("pidedit");
        Module mod =  moduleConfig.get(); 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but finally I have a trouble to create the instance of the PIDEditorModule class with a context.&lt;/P&gt;
&lt;P&gt;Any help is going to be appreciated.&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2013 16:59:36 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/calling-a-moduleroot-s-function-in-other-class/m-p/313883#M884</guid>
      <dc:creator>adam_bo_</dc:creator>
      <dc:date>2013-05-12T16:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: calling a ModuleRoot's function in other class</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/calling-a-moduleroot-s-function-in-other-class/m-p/313884#M885</link>
      <description>&lt;P&gt;Ok. I have solved the problem in this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;        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);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Jun 2013 18:39:54 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/calling-a-moduleroot-s-function-in-other-class/m-p/313884#M885</guid>
      <dc:creator>adam_bo_</dc:creator>
      <dc:date>2013-06-10T18:39:54Z</dc:date>
    </item>
  </channel>
</rss>

