[opencms-dev] Load templates randomly from a folder

spring2007 vivekmisra2004 at gmail.com
Tue Nov 27 03:48:23 CET 2007


Hey Experts!,
I want to load jsps/templates randomly from a folder.Let us say under for
project offline or online we have "/sites/default/demopages"
and there are several tempaltes like indext.html,element.html,indext.html
and there are and subfolders.


I want that when user requests resource "/sites/default/demopages" , he
should see these templates randomly.
If this succeeds, I will probably want to do same for subfolders.


I dont know if I was naive but I tried to achieve this unsuccessfully by
subclassing org.opencms.i18n.CmsDefaultLocaleHandler since this is
configurable in opencms-system.xml.
So I just have one method in my subclassed CmsDefaultLocaleHandler where I
override getI18nInfo as:

 @Override
    public CmsI18nInfo getI18nInfo(HttpServletRequest req, CmsUser user,
CmsProject project, String resourceName) {
        System.out.println("getI18nInfo resourceName=" + resourceName);
        List fileList = null;
        CmsObject cmso = null;
        String fname = null;
        try {
            
                if(resourceName.equals("/sites/default/demopages/")){
                    cmso = OpenCms.initCmsObject(user.getName()); 
                   fileList = cmso.getFilesInFolder(resourceName);
                   int fileListSize = fileList.size();
                   if (fileListSize == 0) {
                       System.out.println("No files found in " +
resourceName + ".");
                   } else {
                       int rand = (int) (Math.random() * 10);
                       System.out.println(" rand =" + rand);
                       CmsFile f = (CmsFile) fileList.get(rand %
fileListSize);
                       fname = f.getName();
                       System.out.println("fname=" + fname);
                       resourceName = resourceName + fname;
                       System.out.println(" new random resourceName =" +
resourceName );
                   }
                }
        
            
        } catch (CmsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
              

        return super.getI18nInfo(req, user, project, resourceName);
    }



I know there is something worng. So I need some expert help with code
snippet if possible as to waht should I do. Please help.<smiley
image='anim_confused.gif' text=':confused:' /
-- 
View this message in context: http://www.nabble.com/Load-templates-randomly-from-a-folder-tf4879446.html#a13963693
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.




More information about the opencms-dev mailing list