Loading a regex?

Poster Content
nk4um Moderator
Posts: 599
May 29, 2010 09:16Try using the mapper overlay
Thank you for explaining. There is way to achieve what you want but not in the way you are currently doing it.

The module.xml is a static resource which is loaded by the module infrastructure and doesn''t support loading resources directly because it is actually loaded before the address space comes into life based directly on it''s contents (chicken and egg) There it would not be possible to import like functionality in it.

However using the mapper overlay is probably the way to go. This allows for a dynamic mapping definition (loaded from a resource) to define the interfaces of many endpoints. By generating the mapper definition dynamically using XRL or XSLT it would be easy load all the common grammar or regex parts from the same location to avoid replication and to ensure consistency.

Cheers, Tony
Like · Post Reply
nk4um User
Posts: 168
May 28, 2010 20:51
Hi Tony,

Thank you for your reply. I''ll try to be more explicit.

My use-case is the following : I wanted to create a web service that returns data about a town given its postal code. In France, the postal code definition is a 5-digits number, so my first idea was to use :

<grammar>res:/services/towns/
  <groupname="postalCode">
    <regex>\\d{5}</regex>
  </group>
</grammar>


Later, I realized that I have to create a few other web services that all need to be called with a postal code. That means I have many "module.xml" to write, and all of them will contain the same regular expression "\\d{5}", which is not even the best we could write because, for example "00000" and "99999" are invalid.

I am wondering if something like this is possible:

<regex>
  <identifier>res:/resources/regex/postal-code-france.xml</identifier>
</regex>


Taking into account the fact that I''m a newbie, my question is : is there any way to avoid duplication of regular expressions used in "module.xml" files?

Best regards,
Gregoire
Like · Post Reply
nk4um Moderator
Posts: 599
May 28, 2010 18:16
Hi Gregoire, can you be a bit more explicit in what you''d like to do. I''m not quite following. :-)

Cheers, Tony
Like · Post Reply
nk4um User
Posts: 168
May 28, 2010 09:45Loading a regex?
Hi,

Is it possible to dynamically load the content of <regex> in "module.xml"?

A possible use case would be to use a same regex in various web services, without duplication.

Thanks,
Gregoire
Like · Post Reply