get module properties from code

classic Classic list List threaded Threaded
14 messages Options
hablutzel1 hablutzel1
Reply | Threaded
Open this post in threaded view
|

get module properties from code

Hi, I want to be able to access this url from whitin my module code, and I need the module's name is there some method in the openmrs api to get the name (and other properties) for modules?

\webapps\openmrs\WEB-INF\view\module\mymodule



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

[hidden email] from OpenMRS Developers' mailing list
Wyclif Luyima Wyclif Luyima
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Hi Jaime,

 

First all J2EE containers can’t let your send requests urls like ‘\webapps\openmrs\WEB-INF\view\module\mymodule’  to the server because anything under ‘WEB-INF’ is considered private and you can only be directed there through a registered servlet in web.xml, so my suggestion would be to add a servlet url mapping to web.xml that will actually access the resource under WEB-INF directory and the openmrs module structure allows you to register module servlets.

To get the module name just call module.getModuleId(), it returns the name of the module and not a number as its name might imply.

 

Wyclif

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
Sent: Friday, May 14, 2010 09:54
To: [hidden email]
Subject: [OPENMRS-DEV] get module properties from code

 

Hi, I want to be able to access this url from whitin my module code, and I need the module's name is there some method in the openmrs api to get the name (and other properties) for modules?

\webapps\openmrs\WEB-INF\view\module\mymodule



--
Jaime Hablutzel

(tildes omitidas intencionalmente)


[hidden email] from OpenMRS Developers' mailing list


[hidden email] from OpenMRS Developers' mailing list
hablutzel1 hablutzel1
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Yes, J2EE protect WEB-INF folder, I just want to get the full system
directory path to this folder \webapps\openmrs\WEB-INF\

view\module\mymodule’ because I'm saving some xslt's inside of it (I
can't find another place to put them with an openmrs module).

I have realized that I can get this path using:

servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId

But I need to access the servlet context (statically maybe) and the module id.
As you say, I can use: module.getModuleId(), but how can I get my
module object reference to call that method.

On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima <[hidden email]> wrote:

>
> Hi Jaime,
>
>
>
> First all J2EE containers can’t let your send requests urls like ‘\webapps\openmrs\WEB-INF\view\module\mymodule’  to the server because anything under ‘WEB-INF’ is considered private and you can only be directed there through a registered servlet in web.xml, so my suggestion would be to add a servlet url mapping to web.xml that will actually access the resource under WEB-INF directory and the openmrs module structure allows you to register module servlets.
>
> To get the module name just call module.getModuleId(), it returns the name of the module and not a number as its name might imply.
>
>
>
> Wyclif
>
>
>
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
> Sent: Friday, May 14, 2010 09:54
> To: [hidden email]
> Subject: [OPENMRS-DEV] get module properties from code
>
>
>
> Hi, I want to be able to access this url from whitin my module code, and I need the module's name is there some method in the openmrs api to get the name (and other properties) for modules?
>
> \webapps\openmrs\WEB-INF\view\module\mymodule
>
>
>
> --
> Jaime Hablutzel
>
> (tildes omitidas intencionalmente)
>
> ________________________________
>
> Click here to unsubscribe from OpenMRS Developers' mailing list
>
> ________________________________
> Click here to unsubscribe from OpenMRS Developers' mailing list


--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
Wyclif Luyima Wyclif Luyima
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Well, I thought you are trying to do what you want to do within your module and inside there you have ways to get the module name or you know its name, so I don't think you need to call module.getModuleId().  A call like servletContext.getRealPath("/myResourceName.ext")  or ServletContext.getResourceAsStream("/myResourceName.ext") can return the absolute path of the resource you want without the need to create the path through concatenating strings, though am not sure if it will  return the files under 'WEB-INF'. For some servlet containers it might work for calls like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"), and i guess tomcat might be one of them where it works, just give it a try.
The class ModuleFactory has the method getStartedModuleById(moduleId) but still with this, you need to know the moduleId which comes back to the fact that you need to know the name of the module.
It seems to me like you want to create a new file or upload a file to the server through the web app to the web-inf directory, right?

Wyclif
 

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
Sent: Friday, May 14, 2010 11:04
To: [hidden email]
Subject: Re: [OPENMRS-DEV] get module properties from code

Yes, J2EE protect WEB-INF folder, I just want to get the full system
directory path to this folder \webapps\openmrs\WEB-INF\

view\module\mymodule' because I'm saving some xslt's inside of it (I
can't find another place to put them with an openmrs module).

I have realized that I can get this path using:

servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId

But I need to access the servlet context (statically maybe) and the module id.
As you say, I can use: module.getModuleId(), but how can I get my
module object reference to call that method.

On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima <[hidden email]> wrote:

>
> Hi Jaime,
>
>
>
> First all J2EE containers can't let your send requests urls like '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server because anything under 'WEB-INF' is considered private and you can only be directed there through a registered servlet in web.xml, so my suggestion would be to add a servlet url mapping to web.xml that will actually access the resource under WEB-INF directory and the openmrs module structure allows you to register module servlets.
>
> To get the module name just call module.getModuleId(), it returns the name of the module and not a number as its name might imply.
>
>
>
> Wyclif
>
>
>
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
> Sent: Friday, May 14, 2010 09:54
> To: [hidden email]
> Subject: [OPENMRS-DEV] get module properties from code
>
>
>
> Hi, I want to be able to access this url from whitin my module code, and I need the module's name is there some method in the openmrs api to get the name (and other properties) for modules?
>
> \webapps\openmrs\WEB-INF\view\module\mymodule
>
>
>
> --
> Jaime Hablutzel
>
> (tildes omitidas intencionalmente)
>
> ________________________________
>
> Click here to unsubscribe from OpenMRS Developers' mailing list
>
> ________________________________
> Click here to unsubscribe from OpenMRS Developers' mailing list


--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
hablutzel1 hablutzel1
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

I'm integrating chiba xforms engine with a openmrs module, and they
use xslt to process xforms in the server side, I just wanted the full
path to these files, and I thought in getting the module id to avoid
typing is somewhere else (like in a  MyModuleUtil constant variable)
because it already exist in config.xml, thus if I change the module id
I just have to do it in one place.

servletContext.getRealPath("") returns correctly
C:\..\apache-tomcat\openmrs, my another question is how to get a
reference to servletContext from api code, (I think it is available in
web controllers).


On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima <[hidden email]> wrote:

> Well, I thought you are trying to do what you want to do within your module and inside there you have ways to get the module name or you know its name, so I don't think you need to call module.getModuleId().  A call like servletContext.getRealPath("/myResourceName.ext")  or ServletContext.getResourceAsStream("/myResourceName.ext") can return the absolute path of the resource you want without the need to create the path through concatenating strings, though am not sure if it will  return the files under 'WEB-INF'. For some servlet containers it might work for calls like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"), and i guess tomcat might be one of them where it works, just give it a try.
> The class ModuleFactory has the method getStartedModuleById(moduleId) but still with this, you need to know the moduleId which comes back to the fact that you need to know the name of the module.
> It seems to me like you want to create a new file or upload a file to the server through the web app to the web-inf directory, right?
>
> Wyclif
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
> Sent: Friday, May 14, 2010 11:04
> To: [hidden email]
> Subject: Re: [OPENMRS-DEV] get module properties from code
>
> Yes, J2EE protect WEB-INF folder, I just want to get the full system
> directory path to this folder \webapps\openmrs\WEB-INF\
>
> view\module\mymodule' because I'm saving some xslt's inside of it (I
> can't find another place to put them with an openmrs module).
>
> I have realized that I can get this path using:
>
> servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId
>
> But I need to access the servlet context (statically maybe) and the module id.
> As you say, I can use: module.getModuleId(), but how can I get my
> module object reference to call that method.
>
> On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima <[hidden email]> wrote:
>>
>> Hi Jaime,
>>
>>
>>
>> First all J2EE containers can't let your send requests urls like '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server because anything under 'WEB-INF' is considered private and you can only be directed there through a registered servlet in web.xml, so my suggestion would be to add a servlet url mapping to web.xml that will actually access the resource under WEB-INF directory and the openmrs module structure allows you to register module servlets.
>>
>> To get the module name just call module.getModuleId(), it returns the name of the module and not a number as its name might imply.
>>
>>
>>
>> Wyclif
>>
>>
>>
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
>> Sent: Friday, May 14, 2010 09:54
>> To: [hidden email]
>> Subject: [OPENMRS-DEV] get module properties from code
>>
>>
>>
>> Hi, I want to be able to access this url from whitin my module code, and I need the module's name is there some method in the openmrs api to get the name (and other properties) for modules?
>>
>> \webapps\openmrs\WEB-INF\view\module\mymodule
>>
>>
>>
>> --
>> Jaime Hablutzel
>>
>> (tildes omitidas intencionalmente)
>>
>> ________________________________
>>
>> Click here to unsubscribe from OpenMRS Developers' mailing list
>>
>> ________________________________
>> Click here to unsubscribe from OpenMRS Developers' mailing list
>
>
> --
> Jaime Hablutzel
>
> (tildes omitidas intencionalmente)
>
> _________________________________________
>
> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.
>
> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>
> _________________________________________
>
> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.
>
> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
Wyclif Luyima Wyclif Luyima
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Inside the controller or anywhere you have access to the request or servletContext, Just call getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml") or getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")  and that will be enough to return the absolute file or input/ouputStream respectively, tomcats will return it.
I still wonder why a module developer should find a hard time getting the name of their own module.

Wyclif

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
Sent: Friday, May 14, 2010 11:50
To: [hidden email]
Subject: Re: [OPENMRS-DEV] get module properties from code

I'm integrating chiba xforms engine with a openmrs module, and they
use xslt to process xforms in the server side, I just wanted the full
path to these files, and I thought in getting the module id to avoid
typing is somewhere else (like in a  MyModuleUtil constant variable)
because it already exist in config.xml, thus if I change the module id
I just have to do it in one place.

servletContext.getRealPath("") returns correctly
C:\..\apache-tomcat\openmrs, my another question is how to get a
reference to servletContext from api code, (I think it is available in
web controllers).


On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima <[hidden email]> wrote:

> Well, I thought you are trying to do what you want to do within your module and inside there you have ways to get the module name or you know its name, so I don't think you need to call module.getModuleId().  A call like servletContext.getRealPath("/myResourceName.ext")  or ServletContext.getResourceAsStream("/myResourceName.ext") can return the absolute path of the resource you want without the need to create the path through concatenating strings, though am not sure if it will  return the files under 'WEB-INF'. For some servlet containers it might work for calls like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"), and i guess tomcat might be one of them where it works, just give it a try.
> The class ModuleFactory has the method getStartedModuleById(moduleId) but still with this, you need to know the moduleId which comes back to the fact that you need to know the name of the module.
> It seems to me like you want to create a new file or upload a file to the server through the web app to the web-inf directory, right?
>
> Wyclif
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
> Sent: Friday, May 14, 2010 11:04
> To: [hidden email]
> Subject: Re: [OPENMRS-DEV] get module properties from code
>
> Yes, J2EE protect WEB-INF folder, I just want to get the full system
> directory path to this folder \webapps\openmrs\WEB-INF\
>
> view\module\mymodule' because I'm saving some xslt's inside of it (I
> can't find another place to put them with an openmrs module).
>
> I have realized that I can get this path using:
>
> servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId
>
> But I need to access the servlet context (statically maybe) and the module id.
> As you say, I can use: module.getModuleId(), but how can I get my
> module object reference to call that method.
>
> On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima <[hidden email]> wrote:
>>
>> Hi Jaime,
>>
>>
>>
>> First all J2EE containers can't let your send requests urls like '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server because anything under 'WEB-INF' is considered private and you can only be directed there through a registered servlet in web.xml, so my suggestion would be to add a servlet url mapping to web.xml that will actually access the resource under WEB-INF directory and the openmrs module structure allows you to register module servlets.
>>
>> To get the module name just call module.getModuleId(), it returns the name of the module and not a number as its name might imply.
>>
>>
>>
>> Wyclif
>>
>>
>>
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
>> Sent: Friday, May 14, 2010 09:54
>> To: [hidden email]
>> Subject: [OPENMRS-DEV] get module properties from code
>>
>>
>>
>> Hi, I want to be able to access this url from whitin my module code, and I need the module's name is there some method in the openmrs api to get the name (and other properties) for modules?
>>
>> \webapps\openmrs\WEB-INF\view\module\mymodule
>>
>>
>>
>> --
>> Jaime Hablutzel
>>
>> (tildes omitidas intencionalmente)
>>
>> ________________________________
>>
>> Click here to unsubscribe from OpenMRS Developers' mailing list
>>
>> ________________________________
>> Click here to unsubscribe from OpenMRS Developers' mailing list
>
>
> --
> Jaime Hablutzel
>
> (tildes omitidas intencionalmente)
>
> _________________________________________
>
> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.
>
> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>
> _________________________________________
>
> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.
>
> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
Darius Jazayeri-3 Darius Jazayeri-3
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Hi Jaime,

It seems like the 'moduleResources' folder would be the right place to put these. But I am guessing there's no way to programatically get these files--we should try to add it. If that function doesn't exist, then go ahead and create a ticket and cc me.

-Darius

On Fri, May 14, 2010 at 9:00 AM, Wyclif Luyima <[hidden email]> wrote:
Inside the controller or anywhere you have access to the request or servletContext, Just call getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml") or getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")  and that will be enough to return the absolute file or input/ouputStream respectively, tomcats will return it.
I still wonder why a module developer should find a hard time getting the name of their own module.

Wyclif

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
Sent: Friday, May 14, 2010 11:50
To: [hidden email]
Subject: Re: [OPENMRS-DEV] get module properties from code

I'm integrating chiba xforms engine with a openmrs module, and they
use xslt to process xforms in the server side, I just wanted the full
path to these files, and I thought in getting the module id to avoid
typing is somewhere else (like in a  MyModuleUtil constant variable)
because it already exist in config.xml, thus if I change the module id
I just have to do it in one place.

servletContext.getRealPath("") returns correctly
C:\..\apache-tomcat\openmrs, my another question is how to get a
reference to servletContext from api code, (I think it is available in
web controllers).


On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima <[hidden email]> wrote:
> Well, I thought you are trying to do what you want to do within your module and inside there you have ways to get the module name or you know its name, so I don't think you need to call module.getModuleId().  A call like servletContext.getRealPath("/myResourceName.ext")  or ServletContext.getResourceAsStream("/myResourceName.ext") can return the absolute path of the resource you want without the need to create the path through concatenating strings, though am not sure if it will  return the files under 'WEB-INF'. For some servlet containers it might work for calls like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"), and i guess tomcat might be one of them where it works, just give it a try.
> The class ModuleFactory has the method getStartedModuleById(moduleId) but still with this, you need to know the moduleId which comes back to the fact that you need to know the name of the module.
> It seems to me like you want to create a new file or upload a file to the server through the web app to the web-inf directory, right?
>
> Wyclif
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
> Sent: Friday, May 14, 2010 11:04
> To: [hidden email]
> Subject: Re: [OPENMRS-DEV] get module properties from code
>
> Yes, J2EE protect WEB-INF folder, I just want to get the full system
> directory path to this folder \webapps\openmrs\WEB-INF\
>
> view\module\mymodule' because I'm saving some xslt's inside of it (I
> can't find another place to put them with an openmrs module).
>
> I have realized that I can get this path using:
>
> servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId
>
> But I need to access the servlet context (statically maybe) and the module id.
> As you say, I can use: module.getModuleId(), but how can I get my
> module object reference to call that method.
>
> On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima <[hidden email]> wrote:
>>
>> Hi Jaime,
>>
>>
>>
>> First all J2EE containers can't let your send requests urls like '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server because anything under 'WEB-INF' is considered private and you can only be directed there through a registered servlet in web.xml, so my suggestion would be to add a servlet url mapping to web.xml that will actually access the resource under WEB-INF directory and the openmrs module structure allows you to register module servlets.
>>
>> To get the module name just call module.getModuleId(), it returns the name of the module and not a number as its name might imply.
>>
>>
>>
>> Wyclif
>>
>>
>>
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
>> Sent: Friday, May 14, 2010 09:54
>> To: [hidden email]
>> Subject: [OPENMRS-DEV] get module properties from code
>>
>>
>>
>> Hi, I want to be able to access this url from whitin my module code, and I need the module's name is there some method in the openmrs api to get the name (and other properties) for modules?
>>
>> \webapps\openmrs\WEB-INF\view\module\mymodule
>>
>>
>>
>> --
>> Jaime Hablutzel
>>
>> (tildes omitidas intencionalmente)
>>
>> ________________________________
>>
>> Click here to unsubscribe from OpenMRS Developers' mailing list
>>
>> ________________________________
>> Click here to unsubscribe from OpenMRS Developers' mailing list
>
>
> --
> Jaime Hablutzel
>
> (tildes omitidas intencionalmente)
>
> _________________________________________
>
> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.
>
> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>
> _________________________________________
>
> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.
>
> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]


[hidden email] from OpenMRS Developers' mailing list
hablutzel1 hablutzel1
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Wyclif, you are right, with
getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
 I can get the files I want, but from a controller, or a servlet, or a
filter, not from anywhere else, maybe I'm looking for some static
method in openmrs to get a reference to the servletContext.

Regard the module id, well I think it would be easier to reuse the
code in several modules, if I could just use something like:

SomeOpenMRSUtil.getMyModule().getModuleId();

But i'm not pretty sure if it is possible, for the getMyModule method
to detect the calling code, and use it to determine the module.

Darius, I thought about putting these files in moduleResources
(resources folder)  but they would become publicy available, and I
just want to use them from code, in web/module they are safer (or
not?)

On Fri, May 14, 2010 at 11:05 AM, Darius Jazayeri
<[hidden email]> wrote:

> Hi Jaime,
> It seems like the 'moduleResources' folder would be the right place to put
> these. But I am guessing there's no way to programatically get these
> files--we should try to add it. If that function doesn't exist, then go
> ahead and create a ticket and cc me.
> -Darius
>
> On Fri, May 14, 2010 at 9:00 AM, Wyclif Luyima <[hidden email]>
> wrote:
>>
>> Inside the controller or anywhere you have access to the request or
>> servletContext, Just call
>> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml") or
>> getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")
>>  and that will be enough to return the absolute file or input/ouputStream
>> respectively, tomcats will return it.
>> I still wonder why a module developer should find a hard time getting the
>> name of their own module.
>>
>> Wyclif
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> Hablutzel Egoavil
>> Sent: Friday, May 14, 2010 11:50
>> To: [hidden email]
>> Subject: Re: [OPENMRS-DEV] get module properties from code
>>
>> I'm integrating chiba xforms engine with a openmrs module, and they
>> use xslt to process xforms in the server side, I just wanted the full
>> path to these files, and I thought in getting the module id to avoid
>> typing is somewhere else (like in a  MyModuleUtil constant variable)
>> because it already exist in config.xml, thus if I change the module id
>> I just have to do it in one place.
>>
>> servletContext.getRealPath("") returns correctly
>> C:\..\apache-tomcat\openmrs, my another question is how to get a
>> reference to servletContext from api code, (I think it is available in
>> web controllers).
>>
>>
>> On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima <[hidden email]>
>> wrote:
>> > Well, I thought you are trying to do what you want to do within your
>> > module and inside there you have ways to get the module name or you know its
>> > name, so I don't think you need to call module.getModuleId().  A call like
>> > servletContext.getRealPath("/myResourceName.ext")  or
>> > ServletContext.getResourceAsStream("/myResourceName.ext") can return the
>> > absolute path of the resource you want without the need to create the path
>> > through concatenating strings, though am not sure if it will  return the
>> > files under 'WEB-INF'. For some servlet containers it might work for calls
>> > like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or
>> > ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"), and i
>> > guess tomcat might be one of them where it works, just give it a try.
>> > The class ModuleFactory has the method getStartedModuleById(moduleId)
>> > but still with this, you need to know the moduleId which comes back to the
>> > fact that you need to know the name of the module.
>> > It seems to me like you want to create a new file or upload a file to
>> > the server through the web app to the web-inf directory, right?
>> >
>> > Wyclif
>> >
>> >
>> > -----Original Message-----
>> > From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> > Hablutzel Egoavil
>> > Sent: Friday, May 14, 2010 11:04
>> > To: [hidden email]
>> > Subject: Re: [OPENMRS-DEV] get module properties from code
>> >
>> > Yes, J2EE protect WEB-INF folder, I just want to get the full system
>> > directory path to this folder \webapps\openmrs\WEB-INF\
>> >
>> > view\module\mymodule' because I'm saving some xslt's inside of it (I
>> > can't find another place to put them with an openmrs module).
>> >
>> > I have realized that I can get this path using:
>> >
>> > servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId
>> >
>> > But I need to access the servlet context (statically maybe) and the
>> > module id.
>> > As you say, I can use: module.getModuleId(), but how can I get my
>> > module object reference to call that method.
>> >
>> > On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima <[hidden email]>
>> > wrote:
>> >>
>> >> Hi Jaime,
>> >>
>> >>
>> >>
>> >> First all J2EE containers can't let your send requests urls like
>> >> '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server because
>> >> anything under 'WEB-INF' is considered private and you can only be directed
>> >> there through a registered servlet in web.xml, so my suggestion would be to
>> >> add a servlet url mapping to web.xml that will actually access the resource
>> >> under WEB-INF directory and the openmrs module structure allows you to
>> >> register module servlets.
>> >>
>> >> To get the module name just call module.getModuleId(), it returns the
>> >> name of the module and not a number as its name might imply.
>> >>
>> >>
>> >>
>> >> Wyclif
>> >>
>> >>
>> >>
>> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> >> Hablutzel Egoavil
>> >> Sent: Friday, May 14, 2010 09:54
>> >> To: [hidden email]
>> >> Subject: [OPENMRS-DEV] get module properties from code
>> >>
>> >>
>> >>
>> >> Hi, I want to be able to access this url from whitin my module code,
>> >> and I need the module's name is there some method in the openmrs api to get
>> >> the name (and other properties) for modules?
>> >>
>> >> \webapps\openmrs\WEB-INF\view\module\mymodule
>> >>
>> >>
>> >>
>> >> --
>> >> Jaime Hablutzel
>> >>
>> >> (tildes omitidas intencionalmente)
>> >>
>> >> ________________________________
>> >>
>> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>> >>
>> >> ________________________________
>> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>> >
>> >
>> > --
>> > Jaime Hablutzel
>> >
>> > (tildes omitidas intencionalmente)
>> >
>> > _________________________________________
>> >
>> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> > [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> > the subject) of your e-mail.
>> >
>> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >
>> > _________________________________________
>> >
>> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> > [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> > the subject) of your e-mail.
>> >
>> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >
>>
>>
>>
>> --
>> Jaime Hablutzel
>>
>> (tildes omitidas intencionalmente)
>>
>> _________________________________________
>>
>> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> the subject) of your e-mail.
>>
>> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>>
>> _________________________________________
>>
>> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> the subject) of your e-mail.
>>
>> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>
> ________________________________
> Click here to unsubscribe from OpenMRS Developers' mailing list



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
Darius Jazayeri-3 Darius Jazayeri-3
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Hi Jaime,

You're right, if they're in moduleResources they'd be publicly available. I suppose we could create a privateResources folder, but that seems to have pretty limited utility.

-Darius

On Fri, May 14, 2010 at 9:23 AM, Jaime Hablutzel Egoavil <[hidden email]> wrote:
Wyclif, you are right, with
getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
 I can get the files I want, but from a controller, or a servlet, or a
filter, not from anywhere else, maybe I'm looking for some static
method in openmrs to get a reference to the servletContext.

Regard the module id, well I think it would be easier to reuse the
code in several modules, if I could just use something like:

SomeOpenMRSUtil.getMyModule().getModuleId();

But i'm not pretty sure if it is possible, for the getMyModule method
to detect the calling code, and use it to determine the module.

Darius, I thought about putting these files in moduleResources
(resources folder)  but they would become publicy available, and I
just want to use them from code, in web/module they are safer (or
not?)

On Fri, May 14, 2010 at 11:05 AM, Darius Jazayeri
<[hidden email]> wrote:
> Hi Jaime,
> It seems like the 'moduleResources' folder would be the right place to put
> these. But I am guessing there's no way to programatically get these
> files--we should try to add it. If that function doesn't exist, then go
> ahead and create a ticket and cc me.
> -Darius
>
> On Fri, May 14, 2010 at 9:00 AM, Wyclif Luyima <[hidden email]>
> wrote:
>>
>> Inside the controller or anywhere you have access to the request or
>> servletContext, Just call
>> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml") or
>> getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")
>>  and that will be enough to return the absolute file or input/ouputStream
>> respectively, tomcats will return it.
>> I still wonder why a module developer should find a hard time getting the
>> name of their own module.
>>
>> Wyclif
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> Hablutzel Egoavil
>> Sent: Friday, May 14, 2010 11:50
>> To: [hidden email]
>> Subject: Re: [OPENMRS-DEV] get module properties from code
>>
>> I'm integrating chiba xforms engine with a openmrs module, and they
>> use xslt to process xforms in the server side, I just wanted the full
>> path to these files, and I thought in getting the module id to avoid
>> typing is somewhere else (like in a  MyModuleUtil constant variable)
>> because it already exist in config.xml, thus if I change the module id
>> I just have to do it in one place.
>>
>> servletContext.getRealPath("") returns correctly
>> C:\..\apache-tomcat\openmrs, my another question is how to get a
>> reference to servletContext from api code, (I think it is available in
>> web controllers).
>>
>>
>> On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima <[hidden email]>
>> wrote:
>> > Well, I thought you are trying to do what you want to do within your
>> > module and inside there you have ways to get the module name or you know its
>> > name, so I don't think you need to call module.getModuleId().  A call like
>> > servletContext.getRealPath("/myResourceName.ext")  or
>> > ServletContext.getResourceAsStream("/myResourceName.ext") can return the
>> > absolute path of the resource you want without the need to create the path
>> > through concatenating strings, though am not sure if it will  return the
>> > files under 'WEB-INF'. For some servlet containers it might work for calls
>> > like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or
>> > ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"), and i
>> > guess tomcat might be one of them where it works, just give it a try.
>> > The class ModuleFactory has the method getStartedModuleById(moduleId)
>> > but still with this, you need to know the moduleId which comes back to the
>> > fact that you need to know the name of the module.
>> > It seems to me like you want to create a new file or upload a file to
>> > the server through the web app to the web-inf directory, right?
>> >
>> > Wyclif
>> >
>> >
>> > -----Original Message-----
>> > From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> > Hablutzel Egoavil
>> > Sent: Friday, May 14, 2010 11:04
>> > To: [hidden email]
>> > Subject: Re: [OPENMRS-DEV] get module properties from code
>> >
>> > Yes, J2EE protect WEB-INF folder, I just want to get the full system
>> > directory path to this folder \webapps\openmrs\WEB-INF\
>> >
>> > view\module\mymodule' because I'm saving some xslt's inside of it (I
>> > can't find another place to put them with an openmrs module).
>> >
>> > I have realized that I can get this path using:
>> >
>> > servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId
>> >
>> > But I need to access the servlet context (statically maybe) and the
>> > module id.
>> > As you say, I can use: module.getModuleId(), but how can I get my
>> > module object reference to call that method.
>> >
>> > On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima <[hidden email]>
>> > wrote:
>> >>
>> >> Hi Jaime,
>> >>
>> >>
>> >>
>> >> First all J2EE containers can't let your send requests urls like
>> >> '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server because
>> >> anything under 'WEB-INF' is considered private and you can only be directed
>> >> there through a registered servlet in web.xml, so my suggestion would be to
>> >> add a servlet url mapping to web.xml that will actually access the resource
>> >> under WEB-INF directory and the openmrs module structure allows you to
>> >> register module servlets.
>> >>
>> >> To get the module name just call module.getModuleId(), it returns the
>> >> name of the module and not a number as its name might imply.
>> >>
>> >>
>> >>
>> >> Wyclif
>> >>
>> >>
>> >>
>> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> >> Hablutzel Egoavil
>> >> Sent: Friday, May 14, 2010 09:54
>> >> To: [hidden email]
>> >> Subject: [OPENMRS-DEV] get module properties from code
>> >>
>> >>
>> >>
>> >> Hi, I want to be able to access this url from whitin my module code,
>> >> and I need the module's name is there some method in the openmrs api to get
>> >> the name (and other properties) for modules?
>> >>
>> >> \webapps\openmrs\WEB-INF\view\module\mymodule
>> >>
>> >>
>> >>
>> >> --
>> >> Jaime Hablutzel
>> >>
>> >> (tildes omitidas intencionalmente)
>> >>
>> >> ________________________________
>> >>
>> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>> >>
>> >> ________________________________
>> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>> >
>> >
>> > --
>> > Jaime Hablutzel
>> >
>> > (tildes omitidas intencionalmente)
>> >
>> > _________________________________________
>> >
>> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> > [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> > the subject) of your e-mail.
>> >
>> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >
>> > _________________________________________
>> >
>> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> > [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> > the subject) of your e-mail.
>> >
>> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >
>>
>>
>>
>> --
>> Jaime Hablutzel
>>
>> (tildes omitidas intencionalmente)
>>
>> _________________________________________
>>
>> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> the subject) of your e-mail.
>>
>> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>>
>> _________________________________________
>>
>> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> the subject) of your e-mail.
>>
>> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>
> ________________________________
> Click here to unsubscribe from OpenMRS Developers' mailing list



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]


[hidden email] from OpenMRS Developers' mailing list
hablutzel1 hablutzel1
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

I submitted a ticket:

http://dev.openmrs.org/ticket/2329

Yes, the utility would be really limited, but I was thinking in
external configuration files, (like xslt files) that shouldn't be in
classpath unnecesarily.


On Fri, May 14, 2010 at 11:30 AM, Darius Jazayeri
<[hidden email]> wrote:

> Hi Jaime,
> You're right, if they're in moduleResources they'd be publicly available. I
> suppose we could create a privateResources folder, but that seems to have
> pretty limited utility.
> -Darius
>
> On Fri, May 14, 2010 at 9:23 AM, Jaime Hablutzel Egoavil
> <[hidden email]> wrote:
>>
>> Wyclif, you are right, with
>> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>>  I can get the files I want, but from a controller, or a servlet, or a
>> filter, not from anywhere else, maybe I'm looking for some static
>> method in openmrs to get a reference to the servletContext.
>>
>> Regard the module id, well I think it would be easier to reuse the
>> code in several modules, if I could just use something like:
>>
>> SomeOpenMRSUtil.getMyModule().getModuleId();
>>
>> But i'm not pretty sure if it is possible, for the getMyModule method
>> to detect the calling code, and use it to determine the module.
>>
>> Darius, I thought about putting these files in moduleResources
>> (resources folder)  but they would become publicy available, and I
>> just want to use them from code, in web/module they are safer (or
>> not?)
>>
>> On Fri, May 14, 2010 at 11:05 AM, Darius Jazayeri
>> <[hidden email]> wrote:
>> > Hi Jaime,
>> > It seems like the 'moduleResources' folder would be the right place to
>> > put
>> > these. But I am guessing there's no way to programatically get these
>> > files--we should try to add it. If that function doesn't exist, then go
>> > ahead and create a ticket and cc me.
>> > -Darius
>> >
>> > On Fri, May 14, 2010 at 9:00 AM, Wyclif Luyima <[hidden email]>
>> > wrote:
>> >>
>> >> Inside the controller or anywhere you have access to the request or
>> >> servletContext, Just call
>> >> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>> >> or
>> >>
>> >> getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")
>> >>  and that will be enough to return the absolute file or
>> >> input/ouputStream
>> >> respectively, tomcats will return it.
>> >> I still wonder why a module developer should find a hard time getting
>> >> the
>> >> name of their own module.
>> >>
>> >> Wyclif
>> >>
>> >> -----Original Message-----
>> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> >> Hablutzel Egoavil
>> >> Sent: Friday, May 14, 2010 11:50
>> >> To: [hidden email]
>> >> Subject: Re: [OPENMRS-DEV] get module properties from code
>> >>
>> >> I'm integrating chiba xforms engine with a openmrs module, and they
>> >> use xslt to process xforms in the server side, I just wanted the full
>> >> path to these files, and I thought in getting the module id to avoid
>> >> typing is somewhere else (like in a  MyModuleUtil constant variable)
>> >> because it already exist in config.xml, thus if I change the module id
>> >> I just have to do it in one place.
>> >>
>> >> servletContext.getRealPath("") returns correctly
>> >> C:\..\apache-tomcat\openmrs, my another question is how to get a
>> >> reference to servletContext from api code, (I think it is available in
>> >> web controllers).
>> >>
>> >>
>> >> On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima
>> >> <[hidden email]>
>> >> wrote:
>> >> > Well, I thought you are trying to do what you want to do within your
>> >> > module and inside there you have ways to get the module name or you
>> >> > know its
>> >> > name, so I don't think you need to call module.getModuleId().  A call
>> >> > like
>> >> > servletContext.getRealPath("/myResourceName.ext")  or
>> >> > ServletContext.getResourceAsStream("/myResourceName.ext") can return
>> >> > the
>> >> > absolute path of the resource you want without the need to create the
>> >> > path
>> >> > through concatenating strings, though am not sure if it will  return
>> >> > the
>> >> > files under 'WEB-INF'. For some servlet containers it might work for
>> >> > calls
>> >> > like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or
>> >> > ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"),
>> >> > and i
>> >> > guess tomcat might be one of them where it works, just give it a try.
>> >> > The class ModuleFactory has the method getStartedModuleById(moduleId)
>> >> > but still with this, you need to know the moduleId which comes back
>> >> > to the
>> >> > fact that you need to know the name of the module.
>> >> > It seems to me like you want to create a new file or upload a file to
>> >> > the server through the web app to the web-inf directory, right?
>> >> >
>> >> > Wyclif
>> >> >
>> >> >
>> >> > -----Original Message-----
>> >> > From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> >> > Hablutzel Egoavil
>> >> > Sent: Friday, May 14, 2010 11:04
>> >> > To: [hidden email]
>> >> > Subject: Re: [OPENMRS-DEV] get module properties from code
>> >> >
>> >> > Yes, J2EE protect WEB-INF folder, I just want to get the full system
>> >> > directory path to this folder \webapps\openmrs\WEB-INF\
>> >> >
>> >> > view\module\mymodule' because I'm saving some xslt's inside of it (I
>> >> > can't find another place to put them with an openmrs module).
>> >> >
>> >> > I have realized that I can get this path using:
>> >> >
>> >> > servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId
>> >> >
>> >> > But I need to access the servlet context (statically maybe) and the
>> >> > module id.
>> >> > As you say, I can use: module.getModuleId(), but how can I get my
>> >> > module object reference to call that method.
>> >> >
>> >> > On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima
>> >> > <[hidden email]>
>> >> > wrote:
>> >> >>
>> >> >> Hi Jaime,
>> >> >>
>> >> >>
>> >> >>
>> >> >> First all J2EE containers can't let your send requests urls like
>> >> >> '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server
>> >> >> because
>> >> >> anything under 'WEB-INF' is considered private and you can only be
>> >> >> directed
>> >> >> there through a registered servlet in web.xml, so my suggestion
>> >> >> would be to
>> >> >> add a servlet url mapping to web.xml that will actually access the
>> >> >> resource
>> >> >> under WEB-INF directory and the openmrs module structure allows you
>> >> >> to
>> >> >> register module servlets.
>> >> >>
>> >> >> To get the module name just call module.getModuleId(), it returns
>> >> >> the
>> >> >> name of the module and not a number as its name might imply.
>> >> >>
>> >> >>
>> >> >>
>> >> >> Wyclif
>> >> >>
>> >> >>
>> >> >>
>> >> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> >> >> Hablutzel Egoavil
>> >> >> Sent: Friday, May 14, 2010 09:54
>> >> >> To: [hidden email]
>> >> >> Subject: [OPENMRS-DEV] get module properties from code
>> >> >>
>> >> >>
>> >> >>
>> >> >> Hi, I want to be able to access this url from whitin my module code,
>> >> >> and I need the module's name is there some method in the openmrs api
>> >> >> to get
>> >> >> the name (and other properties) for modules?
>> >> >>
>> >> >> \webapps\openmrs\WEB-INF\view\module\mymodule
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Jaime Hablutzel
>> >> >>
>> >> >> (tildes omitidas intencionalmente)
>> >> >>
>> >> >> ________________________________
>> >> >>
>> >> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>> >> >>
>> >> >> ________________________________
>> >> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>> >> >
>> >> >
>> >> > --
>> >> > Jaime Hablutzel
>> >> >
>> >> > (tildes omitidas intencionalmente)
>> >> >
>> >> > _________________________________________
>> >> >
>> >> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail
>> >> > to
>> >> > [hidden email] with "SIGNOFF openmrs-devel-l" in the
>> >> >  body (not
>> >> > the subject) of your e-mail.
>> >> >
>> >> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >> >
>> >> > _________________________________________
>> >> >
>> >> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail
>> >> > to
>> >> > [hidden email] with "SIGNOFF openmrs-devel-l" in the
>> >> >  body (not
>> >> > the subject) of your e-mail.
>> >> >
>> >> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Jaime Hablutzel
>> >>
>> >> (tildes omitidas intencionalmente)
>> >>
>> >> _________________________________________
>> >>
>> >> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> >> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body
>> >> (not
>> >> the subject) of your e-mail.
>> >>
>> >> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >>
>> >> _________________________________________
>> >>
>> >> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> >> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body
>> >> (not
>> >> the subject) of your e-mail.
>> >>
>> >> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >
>> > ________________________________
>> > Click here to unsubscribe from OpenMRS Developers' mailing list
>>
>>
>>
>> --
>> Jaime Hablutzel
>>
>> (tildes omitidas intencionalmente)
>>
>> _________________________________________
>>
>> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> the subject) of your e-mail.
>>
>> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>
> ________________________________
> Click here to unsubscribe from OpenMRS Developers' mailing list



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
Wyclif Luyima Wyclif Luyima
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Hi Jaime, the most straight forward solution would be to parse the config.xml file of your module and read the moduleId from there, because I think having a utility method in openmrs would be the best option since it would need to know about the caller which comes down to knowing the module name or className and do it through java reflection or something in that line.

Wyclif


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
Sent: Friday, May 14, 2010 12:39
To: [hidden email]
Subject: Re: [OPENMRS-DEV] get module properties from code

I submitted a ticket:

http://dev.openmrs.org/ticket/2329

Yes, the utility would be really limited, but I was thinking in
external configuration files, (like xslt files) that shouldn't be in
classpath unnecesarily.


On Fri, May 14, 2010 at 11:30 AM, Darius Jazayeri
<[hidden email]> wrote:

> Hi Jaime,
> You're right, if they're in moduleResources they'd be publicly available. I
> suppose we could create a privateResources folder, but that seems to have
> pretty limited utility.
> -Darius
>
> On Fri, May 14, 2010 at 9:23 AM, Jaime Hablutzel Egoavil
> <[hidden email]> wrote:
>>
>> Wyclif, you are right, with
>> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>>  I can get the files I want, but from a controller, or a servlet, or a
>> filter, not from anywhere else, maybe I'm looking for some static
>> method in openmrs to get a reference to the servletContext.
>>
>> Regard the module id, well I think it would be easier to reuse the
>> code in several modules, if I could just use something like:
>>
>> SomeOpenMRSUtil.getMyModule().getModuleId();
>>
>> But i'm not pretty sure if it is possible, for the getMyModule method
>> to detect the calling code, and use it to determine the module.
>>
>> Darius, I thought about putting these files in moduleResources
>> (resources folder)  but they would become publicy available, and I
>> just want to use them from code, in web/module they are safer (or
>> not?)
>>
>> On Fri, May 14, 2010 at 11:05 AM, Darius Jazayeri
>> <[hidden email]> wrote:
>> > Hi Jaime,
>> > It seems like the 'moduleResources' folder would be the right place to
>> > put
>> > these. But I am guessing there's no way to programatically get these
>> > files--we should try to add it. If that function doesn't exist, then go
>> > ahead and create a ticket and cc me.
>> > -Darius
>> >
>> > On Fri, May 14, 2010 at 9:00 AM, Wyclif Luyima <[hidden email]>
>> > wrote:
>> >>
>> >> Inside the controller or anywhere you have access to the request or
>> >> servletContext, Just call
>> >> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>> >> or
>> >>
>> >> getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")
>> >>  and that will be enough to return the absolute file or
>> >> input/ouputStream
>> >> respectively, tomcats will return it.
>> >> I still wonder why a module developer should find a hard time getting
>> >> the
>> >> name of their own module.
>> >>
>> >> Wyclif
>> >>
>> >> -----Original Message-----
>> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> >> Hablutzel Egoavil
>> >> Sent: Friday, May 14, 2010 11:50
>> >> To: [hidden email]
>> >> Subject: Re: [OPENMRS-DEV] get module properties from code
>> >>
>> >> I'm integrating chiba xforms engine with a openmrs module, and they
>> >> use xslt to process xforms in the server side, I just wanted the full
>> >> path to these files, and I thought in getting the module id to avoid
>> >> typing is somewhere else (like in a  MyModuleUtil constant variable)
>> >> because it already exist in config.xml, thus if I change the module id
>> >> I just have to do it in one place.
>> >>
>> >> servletContext.getRealPath("") returns correctly
>> >> C:\..\apache-tomcat\openmrs, my another question is how to get a
>> >> reference to servletContext from api code, (I think it is available in
>> >> web controllers).
>> >>
>> >>
>> >> On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima
>> >> <[hidden email]>
>> >> wrote:
>> >> > Well, I thought you are trying to do what you want to do within your
>> >> > module and inside there you have ways to get the module name or you
>> >> > know its
>> >> > name, so I don't think you need to call module.getModuleId().  A call
>> >> > like
>> >> > servletContext.getRealPath("/myResourceName.ext")  or
>> >> > ServletContext.getResourceAsStream("/myResourceName.ext") can return
>> >> > the
>> >> > absolute path of the resource you want without the need to create the
>> >> > path
>> >> > through concatenating strings, though am not sure if it will  return
>> >> > the
>> >> > files under 'WEB-INF'. For some servlet containers it might work for
>> >> > calls
>> >> > like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or
>> >> > ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"),
>> >> > and i
>> >> > guess tomcat might be one of them where it works, just give it a try.
>> >> > The class ModuleFactory has the method getStartedModuleById(moduleId)
>> >> > but still with this, you need to know the moduleId which comes back
>> >> > to the
>> >> > fact that you need to know the name of the module.
>> >> > It seems to me like you want to create a new file or upload a file to
>> >> > the server through the web app to the web-inf directory, right?
>> >> >
>> >> > Wyclif
>> >> >
>> >> >
>> >> > -----Original Message-----
>> >> > From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> >> > Hablutzel Egoavil
>> >> > Sent: Friday, May 14, 2010 11:04
>> >> > To: [hidden email]
>> >> > Subject: Re: [OPENMRS-DEV] get module properties from code
>> >> >
>> >> > Yes, J2EE protect WEB-INF folder, I just want to get the full system
>> >> > directory path to this folder \webapps\openmrs\WEB-INF\
>> >> >
>> >> > view\module\mymodule' because I'm saving some xslt's inside of it (I
>> >> > can't find another place to put them with an openmrs module).
>> >> >
>> >> > I have realized that I can get this path using:
>> >> >
>> >> > servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId
>> >> >
>> >> > But I need to access the servlet context (statically maybe) and the
>> >> > module id.
>> >> > As you say, I can use: module.getModuleId(), but how can I get my
>> >> > module object reference to call that method.
>> >> >
>> >> > On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima
>> >> > <[hidden email]>
>> >> > wrote:
>> >> >>
>> >> >> Hi Jaime,
>> >> >>
>> >> >>
>> >> >>
>> >> >> First all J2EE containers can't let your send requests urls like
>> >> >> '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server
>> >> >> because
>> >> >> anything under 'WEB-INF' is considered private and you can only be
>> >> >> directed
>> >> >> there through a registered servlet in web.xml, so my suggestion
>> >> >> would be to
>> >> >> add a servlet url mapping to web.xml that will actually access the
>> >> >> resource
>> >> >> under WEB-INF directory and the openmrs module structure allows you
>> >> >> to
>> >> >> register module servlets.
>> >> >>
>> >> >> To get the module name just call module.getModuleId(), it returns
>> >> >> the
>> >> >> name of the module and not a number as its name might imply.
>> >> >>
>> >> >>
>> >> >>
>> >> >> Wyclif
>> >> >>
>> >> >>
>> >> >>
>> >> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>> >> >> Hablutzel Egoavil
>> >> >> Sent: Friday, May 14, 2010 09:54
>> >> >> To: [hidden email]
>> >> >> Subject: [OPENMRS-DEV] get module properties from code
>> >> >>
>> >> >>
>> >> >>
>> >> >> Hi, I want to be able to access this url from whitin my module code,
>> >> >> and I need the module's name is there some method in the openmrs api
>> >> >> to get
>> >> >> the name (and other properties) for modules?
>> >> >>
>> >> >> \webapps\openmrs\WEB-INF\view\module\mymodule
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Jaime Hablutzel
>> >> >>
>> >> >> (tildes omitidas intencionalmente)
>> >> >>
>> >> >> ________________________________
>> >> >>
>> >> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>> >> >>
>> >> >> ________________________________
>> >> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>> >> >
>> >> >
>> >> > --
>> >> > Jaime Hablutzel
>> >> >
>> >> > (tildes omitidas intencionalmente)
>> >> >
>> >> > _________________________________________
>> >> >
>> >> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail
>> >> > to
>> >> > [hidden email] with "SIGNOFF openmrs-devel-l" in the
>> >> >  body (not
>> >> > the subject) of your e-mail.
>> >> >
>> >> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >> >
>> >> > _________________________________________
>> >> >
>> >> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail
>> >> > to
>> >> > [hidden email] with "SIGNOFF openmrs-devel-l" in the
>> >> >  body (not
>> >> > the subject) of your e-mail.
>> >> >
>> >> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Jaime Hablutzel
>> >>
>> >> (tildes omitidas intencionalmente)
>> >>
>> >> _________________________________________
>> >>
>> >> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> >> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body
>> >> (not
>> >> the subject) of your e-mail.
>> >>
>> >> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >>
>> >> _________________________________________
>> >>
>> >> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> >> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body
>> >> (not
>> >> the subject) of your e-mail.
>> >>
>> >> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>> >
>> > ________________________________
>> > Click here to unsubscribe from OpenMRS Developers' mailing list
>>
>>
>>
>> --
>> Jaime Hablutzel
>>
>> (tildes omitidas intencionalmente)
>>
>> _________________________________________
>>
>> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>> the subject) of your e-mail.
>>
>> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>
> ________________________________
> Click here to unsubscribe from OpenMRS Developers' mailing list



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
hablutzel1 hablutzel1
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

Yes, reflection sounds as a good alternative, I'll try to do it.


On Fri, May 14, 2010 at 1:16 PM, Wyclif Luyima <[hidden email]> wrote:

> Hi Jaime, the most straight forward solution would be to parse the config.xml file of your module and read the moduleId from there, because I think having a utility method in openmrs would be the best option since it would need to know about the caller which comes down to knowing the module name or className and do it through java reflection or something in that line.
>
> Wyclif
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
> Sent: Friday, May 14, 2010 12:39
> To: [hidden email]
> Subject: Re: [OPENMRS-DEV] get module properties from code
>
> I submitted a ticket:
>
> http://dev.openmrs.org/ticket/2329
>
> Yes, the utility would be really limited, but I was thinking in
> external configuration files, (like xslt files) that shouldn't be in
> classpath unnecesarily.
>
>
> On Fri, May 14, 2010 at 11:30 AM, Darius Jazayeri
> <[hidden email]> wrote:
>> Hi Jaime,
>> You're right, if they're in moduleResources they'd be publicly available. I
>> suppose we could create a privateResources folder, but that seems to have
>> pretty limited utility.
>> -Darius
>>
>> On Fri, May 14, 2010 at 9:23 AM, Jaime Hablutzel Egoavil
>> <[hidden email]> wrote:
>>>
>>> Wyclif, you are right, with
>>> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>>>  I can get the files I want, but from a controller, or a servlet, or a
>>> filter, not from anywhere else, maybe I'm looking for some static
>>> method in openmrs to get a reference to the servletContext.
>>>
>>> Regard the module id, well I think it would be easier to reuse the
>>> code in several modules, if I could just use something like:
>>>
>>> SomeOpenMRSUtil.getMyModule().getModuleId();
>>>
>>> But i'm not pretty sure if it is possible, for the getMyModule method
>>> to detect the calling code, and use it to determine the module.
>>>
>>> Darius, I thought about putting these files in moduleResources
>>> (resources folder)  but they would become publicy available, and I
>>> just want to use them from code, in web/module they are safer (or
>>> not?)
>>>
>>> On Fri, May 14, 2010 at 11:05 AM, Darius Jazayeri
>>> <[hidden email]> wrote:
>>> > Hi Jaime,
>>> > It seems like the 'moduleResources' folder would be the right place to
>>> > put
>>> > these. But I am guessing there's no way to programatically get these
>>> > files--we should try to add it. If that function doesn't exist, then go
>>> > ahead and create a ticket and cc me.
>>> > -Darius
>>> >
>>> > On Fri, May 14, 2010 at 9:00 AM, Wyclif Luyima <[hidden email]>
>>> > wrote:
>>> >>
>>> >> Inside the controller or anywhere you have access to the request or
>>> >> servletContext, Just call
>>> >> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>>> >> or
>>> >>
>>> >> getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")
>>> >>  and that will be enough to return the absolute file or
>>> >> input/ouputStream
>>> >> respectively, tomcats will return it.
>>> >> I still wonder why a module developer should find a hard time getting
>>> >> the
>>> >> name of their own module.
>>> >>
>>> >> Wyclif
>>> >>
>>> >> -----Original Message-----
>>> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>>> >> Hablutzel Egoavil
>>> >> Sent: Friday, May 14, 2010 11:50
>>> >> To: [hidden email]
>>> >> Subject: Re: [OPENMRS-DEV] get module properties from code
>>> >>
>>> >> I'm integrating chiba xforms engine with a openmrs module, and they
>>> >> use xslt to process xforms in the server side, I just wanted the full
>>> >> path to these files, and I thought in getting the module id to avoid
>>> >> typing is somewhere else (like in a  MyModuleUtil constant variable)
>>> >> because it already exist in config.xml, thus if I change the module id
>>> >> I just have to do it in one place.
>>> >>
>>> >> servletContext.getRealPath("") returns correctly
>>> >> C:\..\apache-tomcat\openmrs, my another question is how to get a
>>> >> reference to servletContext from api code, (I think it is available in
>>> >> web controllers).
>>> >>
>>> >>
>>> >> On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima
>>> >> <[hidden email]>
>>> >> wrote:
>>> >> > Well, I thought you are trying to do what you want to do within your
>>> >> > module and inside there you have ways to get the module name or you
>>> >> > know its
>>> >> > name, so I don't think you need to call module.getModuleId().  A call
>>> >> > like
>>> >> > servletContext.getRealPath("/myResourceName.ext")  or
>>> >> > ServletContext.getResourceAsStream("/myResourceName.ext") can return
>>> >> > the
>>> >> > absolute path of the resource you want without the need to create the
>>> >> > path
>>> >> > through concatenating strings, though am not sure if it will  return
>>> >> > the
>>> >> > files under 'WEB-INF'. For some servlet containers it might work for
>>> >> > calls
>>> >> > like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or
>>> >> > ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"),
>>> >> > and i
>>> >> > guess tomcat might be one of them where it works, just give it a try.
>>> >> > The class ModuleFactory has the method getStartedModuleById(moduleId)
>>> >> > but still with this, you need to know the moduleId which comes back
>>> >> > to the
>>> >> > fact that you need to know the name of the module.
>>> >> > It seems to me like you want to create a new file or upload a file to
>>> >> > the server through the web app to the web-inf directory, right?
>>> >> >
>>> >> > Wyclif
>>> >> >
>>> >> >
>>> >> > -----Original Message-----
>>> >> > From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>>> >> > Hablutzel Egoavil
>>> >> > Sent: Friday, May 14, 2010 11:04
>>> >> > To: [hidden email]
>>> >> > Subject: Re: [OPENMRS-DEV] get module properties from code
>>> >> >
>>> >> > Yes, J2EE protect WEB-INF folder, I just want to get the full system
>>> >> > directory path to this folder \webapps\openmrs\WEB-INF\
>>> >> >
>>> >> > view\module\mymodule' because I'm saving some xslt's inside of it (I
>>> >> > can't find another place to put them with an openmrs module).
>>> >> >
>>> >> > I have realized that I can get this path using:
>>> >> >
>>> >> > servletContext.getRealPath("") + WEB-INF\view\module\ + myModuleId
>>> >> >
>>> >> > But I need to access the servlet context (statically maybe) and the
>>> >> > module id.
>>> >> > As you say, I can use: module.getModuleId(), but how can I get my
>>> >> > module object reference to call that method.
>>> >> >
>>> >> > On Fri, May 14, 2010 at 9:48 AM, Wyclif Luyima
>>> >> > <[hidden email]>
>>> >> > wrote:
>>> >> >>
>>> >> >> Hi Jaime,
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> First all J2EE containers can't let your send requests urls like
>>> >> >> '\webapps\openmrs\WEB-INF\view\module\mymodule'  to the server
>>> >> >> because
>>> >> >> anything under 'WEB-INF' is considered private and you can only be
>>> >> >> directed
>>> >> >> there through a registered servlet in web.xml, so my suggestion
>>> >> >> would be to
>>> >> >> add a servlet url mapping to web.xml that will actually access the
>>> >> >> resource
>>> >> >> under WEB-INF directory and the openmrs module structure allows you
>>> >> >> to
>>> >> >> register module servlets.
>>> >> >>
>>> >> >> To get the module name just call module.getModuleId(), it returns
>>> >> >> the
>>> >> >> name of the module and not a number as its name might imply.
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> Wyclif
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>>> >> >> Hablutzel Egoavil
>>> >> >> Sent: Friday, May 14, 2010 09:54
>>> >> >> To: [hidden email]
>>> >> >> Subject: [OPENMRS-DEV] get module properties from code
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> Hi, I want to be able to access this url from whitin my module code,
>>> >> >> and I need the module's name is there some method in the openmrs api
>>> >> >> to get
>>> >> >> the name (and other properties) for modules?
>>> >> >>
>>> >> >> \webapps\openmrs\WEB-INF\view\module\mymodule
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> --
>>> >> >> Jaime Hablutzel
>>> >> >>
>>> >> >> (tildes omitidas intencionalmente)
>>> >> >>
>>> >> >> ________________________________
>>> >> >>
>>> >> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>>> >> >>
>>> >> >> ________________________________
>>> >> >> Click here to unsubscribe from OpenMRS Developers' mailing list
>>> >> >
>>> >> >
>>> >> > --
>>> >> > Jaime Hablutzel
>>> >> >
>>> >> > (tildes omitidas intencionalmente)
>>> >> >
>>> >> > _________________________________________
>>> >> >
>>> >> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail
>>> >> > to
>>> >> > [hidden email] with "SIGNOFF openmrs-devel-l" in the
>>> >> >  body (not
>>> >> > the subject) of your e-mail.
>>> >> >
>>> >> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>>> >> >
>>> >> > _________________________________________
>>> >> >
>>> >> > To unsubscribe from OpenMRS Developers' mailing list, send an e-mail
>>> >> > to
>>> >> > [hidden email] with "SIGNOFF openmrs-devel-l" in the
>>> >> >  body (not
>>> >> > the subject) of your e-mail.
>>> >> >
>>> >> > [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Jaime Hablutzel
>>> >>
>>> >> (tildes omitidas intencionalmente)
>>> >>
>>> >> _________________________________________
>>> >>
>>> >> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>>> >> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body
>>> >> (not
>>> >> the subject) of your e-mail.
>>> >>
>>> >> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>>> >>
>>> >> _________________________________________
>>> >>
>>> >> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>>> >> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body
>>> >> (not
>>> >> the subject) of your e-mail.
>>> >>
>>> >> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>>> >
>>> > ________________________________
>>> > Click here to unsubscribe from OpenMRS Developers' mailing list
>>>
>>>
>>>
>>> --
>>> Jaime Hablutzel
>>>
>>> (tildes omitidas intencionalmente)
>>>
>>> _________________________________________
>>>
>>> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to
>>> [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not
>>> the subject) of your e-mail.
>>>
>>> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>>
>> ________________________________
>> Click here to unsubscribe from OpenMRS Developers' mailing list
>
>
>
> --
> Jaime Hablutzel
>
> (tildes omitidas intencionalmente)
>
> _________________________________________
>
> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.
>
> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>
> _________________________________________
>
> To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.
>
> [mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
>



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
Ben Wolfe Ben Wolfe
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

In reply to this post by hablutzel1
You could use the current class's classloader which should be a moduleclassloader.  Getclass.getclassloader.getmodule.getmoduleid. (cassting needed)

why not put the file on the classpath again?  Put the xslt in the metadata folder and then call Openmrsclassloader.getinstance.getresource("xxx.xslt"). That gives you an inputstream.  Pass that to openmrsutil.copyfile if you really need a file pointer or there might be an openmrsutil method to turn it into a string.

Ben
-----Original Message-----
From: Jaime Hablutzel Egoavil <[hidden email]>
Date: Friday, May 14, 2010 3:10 pm
Subject: Re: get module properties from code
To: "[hidden email]" <[hidden email]>Reply-To: "[hidden email]" <[hidden email]>

Yes, reflection sounds as a good alternative, I'll try to do it.

>
>
>On Fri, May 14, 2010 at 1:16 PM, Wyclif Luyima <[hidden email]> wrote:
>> Hi Jaime, the most straight forward solution would be to parse the config.xml file of your module and read the moduleId from there, because I think having a utility method in openmrs would be the best option since it would need to know about the caller which comes down to knowing the module name or className and do it through java reflection or something in that line.
>>
>> Wyclif
>>
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
>> Sent: Friday, May 14, 2010 12:39
>> To: [hidden email]
>> Subject: Re: [OPENMRS-DEV] get module properties from code
>>
>> I submitted a ticket:
>>
>> http://dev.openmrs.org/ticket/2329
>>
>> Yes, the utility would be really limited, but I was thinking in
>> external configuration files, (like xslt files) that shouldn't be in
>> classpath unnecesarily.
>>
>>
>> On Fri, May 14, 2010 at 11:30 AM, Darius Jazayeri
>> <[hidden email]> wrote:
>>> Hi Jaime,
>>> You're right, if they're in moduleResources they'd be publicly available. I
>>> suppose we could create a privateResources folder, but that seems to have
>>> pretty limited utility.
>>> -Darius
>>>
>>> On Fri, May 14, 2010 at 9:23 AM, Jaime Hablutzel Egoavil
>>> <[hidden email]> wrote:
>>>>
>>>> Wyclif, you are right, with
>>>> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>>>>  I can get the files I want, but from a controller, or a servlet, or a
>>>> filter, not from anywhere else, maybe I'm looking for some static
>>>> method in openmrs to get a reference to the servletContext.
>>>>
>>>> Regard the module id, well I think it would be easier to reuse the
>>>> code in several modules, if I could just use something like:
>>>>
>>>> SomeOpenMRSUtil.getMyModule().getModuleId();
>>>>
>>>> But i'm not pretty sure if it is possible, for the getMyModule method
>>>> to detect the calling code, and use it to determine the module.
>>>>
>>>> Darius, I thought about putting these files in moduleResources
>>>> (resources folder)  but they would become publicy available, and I
>>>> just want to use them from code, in web/module they are safer (or
>>>> not?)
>>>>
>>>> On Fri, May 14, 2010 at 11:05 AM, Darius Jazayeri
>>>> <[hidden email]> wrote:
>>>> > Hi Jaime,
>>>> > It seems like the 'moduleResources' folder would be the right place to
>>>> > put
>>>> > these. But I am guessing there's no way to programatically get these
>>>> > files--we should try to add it. If that function doesn't exist, then go
>>>> > ahead and create a ticket and cc me.
>>>> > -Darius
>>>> >
>>>> > On Fri, May 14, 2010 at 9:00 AM, Wyclif Luyima <[hidden email]>
>>>> > wrote:
>>>> >>
>>>> >> Inside the controller or anywhere you have access to the request or
>>>> >> servletContext, Just call
>>>> >> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>>>> >> or
>>>> >>
>>>> >> getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")
>>>> >>  and that will be enough to return the absolute file or
>>>> >> input/ouputStream
>>>> >> respectively, tomcats will return it.
>>>> >> I still wonder why a module developer should find a hard time getting
>>>> >> the
>>>> >> name of their own module.
>>>> >>
>>>> >> Wyclif
>>>> >>
>>>> >> -----Original Message-----
>>>> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>>>> >> Hablutzel Egoavil
>>>> >> Sent: Friday, May 14, 2010 11:50
>>>> >> To: [hidden email]
>>>> >> Subject: Re: [OPENMRS-DEV] get module properties from code
>>>> >>
>>>> >> I'm integrating chiba xforms engine with a openmrs module, and they
>>>> >> use xslt to process xforms in the server side, I just wanted the full
>>>> >> path to these files, and I thought in getting the module id to avoid
>>>> >> typing is somewhere else (like in a  MyModuleUtil constant variable)
>>>> >> because it already exist in config.xml, thus if I change the module id
>>>> >> I just have to do it in one place.
>>>> >>
>>>> >> servletContext.getRealPath("") returns correctly
>>>> >> C:\..\apache-tomcat\openmrs, my another question is how to get a
>>>> >> reference to servletContext from api code, (I think it is available in
>>>> >> web controllers).
>>>> >>
>>>> >>
>>>> >> On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima
>>>> >> <[hidden email]>
>>>> >> wrote:
>>>> >> > Well, I thought you are trying to do what you want to do within your
>>>> >> > module and inside there you have ways to get the module name or you
>>>> >> > know its
>>>> >> > name, so I don't think you need to call module.getModuleId().  A call
>>>> >> > like
>>>> >> > servletContext.getRealPath("/myResourceName.ext")  or
>>>> >> > ServletContext.getResourceAsStream("/myResourceName.ext") can return
>>>> >> > the
>>>> >> > absolute path of the resource you want without the need to create the
>>>> >> > path
>>>> >> > through concatenating strings, though am not sure if it will  return
>>>> >> > the
>>>> >> > files under 'WEB-INF'. For some servlet containers it might work for
>>>> >> > calls
>>>> >> > like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or
>>>> >> > ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"),
>>>> >> > an

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]
hablutzel1 hablutzel1
Reply | Threaded
Open this post in threaded view
|

Re: get module properties from code

As I was working with an external library (chiba xforms) I though putting its files in the classpath would be in some way a not so clean approach, but now I have realized that it could work because there are just a small amount of xlst files.

By the way:  Getclass.getclassloader (cassting needed) from a servlet filter class defined in config.xml doesn't return the module classloader but the web application classloader (I"m using JRebel, does it affect this behaviour?)


On Fri, May 14, 2010 at 2:34 PM, Ben Wolfe <[hidden email]> wrote:
You could use the current class's classloader which should be a moduleclassloader.  Getclass.getclassloader.getmodule.getmoduleid. (cassting needed)

why not put the file on the classpath again?  Put the xslt in the metadata folder and then call Openmrsclassloader.getinstance.getresource("xxx.xslt"). That gives you an inputstream.  Pass that to openmrsutil.copyfile if you really need a file pointer or there might be an openmrsutil method to turn it into a string.

Ben
-----Original Message-----
From: Jaime Hablutzel Egoavil <[hidden email]>
Date: Friday, May 14, 2010 3:10 pm
Subject: Re: get module properties from code
To: "[hidden email]" <[hidden email]>Reply-To: "[hidden email]" <[hidden email]>

Yes, reflection sounds as a good alternative, I'll try to do it.
>
>
>On Fri, May 14, 2010 at 1:16 PM, Wyclif Luyima <[hidden email]> wrote:
>> Hi Jaime, the most straight forward solution would be to parse the config.xml file of your module and read the moduleId from there, because I think having a utility method in openmrs would be the best option since it would need to know about the caller which comes down to knowing the module name or className and do it through java reflection or something in that line.
>>
>> Wyclif
>>
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime Hablutzel Egoavil
>> Sent: Friday, May 14, 2010 12:39
>> To: [hidden email]
>> Subject: Re: [OPENMRS-DEV] get module properties from code
>>
>> I submitted a ticket:
>>
>> http://dev.openmrs.org/ticket/2329
>>
>> Yes, the utility would be really limited, but I was thinking in
>> external configuration files, (like xslt files) that shouldn't be in
>> classpath unnecesarily.
>>
>>
>> On Fri, May 14, 2010 at 11:30 AM, Darius Jazayeri
>> <[hidden email]> wrote:
>>> Hi Jaime,
>>> You're right, if they're in moduleResources they'd be publicly available. I
>>> suppose we could create a privateResources folder, but that seems to have
>>> pretty limited utility.
>>> -Darius
>>>
>>> On Fri, May 14, 2010 at 9:23 AM, Jaime Hablutzel Egoavil
>>> <[hidden email]> wrote:
>>>>
>>>> Wyclif, you are right, with
>>>> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>>>>  I can get the files I want, but from a controller, or a servlet, or a
>>>> filter, not from anywhere else, maybe I'm looking for some static
>>>> method in openmrs to get a reference to the servletContext.
>>>>
>>>> Regard the module id, well I think it would be easier to reuse the
>>>> code in several modules, if I could just use something like:
>>>>
>>>> SomeOpenMRSUtil.getMyModule().getModuleId();
>>>>
>>>> But i'm not pretty sure if it is possible, for the getMyModule method
>>>> to detect the calling code, and use it to determine the module.
>>>>
>>>> Darius, I thought about putting these files in moduleResources
>>>> (resources folder)  but they would become publicy available, and I
>>>> just want to use them from code, in web/module they are safer (or
>>>> not?)
>>>>
>>>> On Fri, May 14, 2010 at 11:05 AM, Darius Jazayeri
>>>> <[hidden email]> wrote:
>>>> > Hi Jaime,
>>>> > It seems like the 'moduleResources' folder would be the right place to
>>>> > put
>>>> > these. But I am guessing there's no way to programatically get these
>>>> > files--we should try to add it. If that function doesn't exist, then go
>>>> > ahead and create a ticket and cc me.
>>>> > -Darius
>>>> >
>>>> > On Fri, May 14, 2010 at 9:00 AM, Wyclif Luyima <[hidden email]>
>>>> > wrote:
>>>> >>
>>>> >> Inside the controller or anywhere you have access to the request or
>>>> >> servletContext, Just call
>>>> >> getServletContext().getResource("/WEB-INF/view/module/my_xsltfile.xml")
>>>> >> or
>>>> >>
>>>> >> getServletContext().getResourceAsStream("/WEB-INF/view/module/my_xsltfile.xml")
>>>> >>  and that will be enough to return the absolute file or
>>>> >> input/ouputStream
>>>> >> respectively, tomcats will return it.
>>>> >> I still wonder why a module developer should find a hard time getting
>>>> >> the
>>>> >> name of their own module.
>>>> >>
>>>> >> Wyclif
>>>> >>
>>>> >> -----Original Message-----
>>>> >> From: [hidden email] [mailto:[hidden email]] On Behalf Of Jaime
>>>> >> Hablutzel Egoavil
>>>> >> Sent: Friday, May 14, 2010 11:50
>>>> >> To: [hidden email]
>>>> >> Subject: Re: [OPENMRS-DEV] get module properties from code
>>>> >>
>>>> >> I'm integrating chiba xforms engine with a openmrs module, and they
>>>> >> use xslt to process xforms in the server side, I just wanted the full
>>>> >> path to these files, and I thought in getting the module id to avoid
>>>> >> typing is somewhere else (like in a  MyModuleUtil constant variable)
>>>> >> because it already exist in config.xml, thus if I change the module id
>>>> >> I just have to do it in one place.
>>>> >>
>>>> >> servletContext.getRealPath("") returns correctly
>>>> >> C:\..\apache-tomcat\openmrs, my another question is how to get a
>>>> >> reference to servletContext from api code, (I think it is available in
>>>> >> web controllers).
>>>> >>
>>>> >>
>>>> >> On Fri, May 14, 2010 at 10:41 AM, Wyclif Luyima
>>>> >> <[hidden email]>
>>>> >> wrote:
>>>> >> > Well, I thought you are trying to do what you want to do within your
>>>> >> > module and inside there you have ways to get the module name or you
>>>> >> > know its
>>>> >> > name, so I don't think you need to call module.getModuleId().  A call
>>>> >> > like
>>>> >> > servletContext.getRealPath("/myResourceName.ext")  or
>>>> >> > ServletContext.getResourceAsStream("/myResourceName.ext") can return
>>>> >> > the
>>>> >> > absolute path of the resource you want without the need to create the
>>>> >> > path
>>>> >> > through concatenating strings, though am not sure if it will  return
>>>> >> > the
>>>> >> > files under 'WEB-INF'. For some servlet containers it might work for
>>>> >> > calls
>>>> >> > like servletContext.getRealPath("WEB-/INF/myResourceName.ext") or
>>>> >> > ServletContext.getResourceAsStream("/WEB-INF/myResourceName.ext"),
>>>> >> > an

_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-devel-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-devel-l]



--
Jaime Hablutzel

(tildes omitidas intencionalmente)

[hidden email] from OpenMRS Developers' mailing list