please suggest!
Why do you need to do that?
You tell the user to do it or you use FormAPI to set the name with the proper extension. Most people do the latter. You can also use FormAPI to check the name before saving.
In templating.cfg we can add type=iwov/xml,but while saving I need to save my dcr with .xml extension into data folder automatically.
The style of DCT ("iwov" vs. "xml") has nothing to do with file naming or extensions (both result in XML files being created).
Your options are:
I'd strongly recommend the FormAPI approach (there are several variations that can be implemented) - it really isn't that difficult, but you'll get a lot more out of it if you try it yourself rather than asking for / waiting for someone here to spoon-feed you code.
If you get most of the way there but have trouble finishing - then post your code and someone here will more than likely be willing to help you through the last part(s).
TeamSite/httpd/iw/formapi/shared.js:
function enforceXMLExtension(path) { function endsWith(string, suffix) { return string.indexOf(suffix, string.length - suffix.length) !== -1; } var isPathOk = endsWith(path, '.xml'); if (!isPathOk) alert('The DCR file name has to end with .xml extension.'); return isPathOk;}function installDCRNameValidator() { IWEventRegistry.addFormHandler("onSaveNameSpecified", enforceXMLExtension);}
Then in each DCT, before </ruleset>:
<script language="javascript" location="webserver" src="/iw/formapi/shared.js"></script><script language="javascript"> <![CDATA[ installDCRNameValidator(); ]]></script>
Ofcourse you could add it to each DCT inline but that's not too DRY .
@Zambergive a man a fish...
@rpoulin, give a man a bonfire and he'll be warm for one hour. Lit a man on fire and he'll be warm for the rest of his life .
Your code certainly works, and I always appreciate someone who quotes Harry Dresdan, but Rick's main point is that you should do more than just check if the extension is there. What about white space ? Special characters ? I never allow that in a DCR. Typically I do not even allow users to name DCRs, instead I calculate the name, from the title, or other content, for them.
And you gave a man a questionably cooked fish in a questionably constructed bonfire - so what does that say about you?
@nipper, that solution works for us because the users manage the DCRs themselves and went through training. Indeed, whitespace could be an issue but it didn't pop up (yet).
Generating the DCR name from the contents is a great idea but then you have to add custom code to handle that.
The quality of the question is, well, questionable and my answer covered it completely. Therefore, a questionable fish over a questionable bonfire is better than pointing to a river and some wood logs.
In fact it moved the topic forward because otherwise probably nobody would mention whitespace and special characters.
The problem comes if the OP takes your code and uses it as-is without bothering to become grounded in the underlying code concepts and functionality.
If they have the initiative, they'll still take the time to actually read the manuals and experiement with the code.
If they don't have that initiative, they may get something that works for them right now - but they won't have a clue about how to enhance and/or maintain it - thus the rationale for not supplying code until the OP shows that they've actually attempted to do something first.
However - it's somewhat academic at this point, since the code was provided; the additional ideas have been discussed a bit too. What remains to be seen is the OP's response.