001    package railo.runtime.tag;
002    
003    import java.io.File;
004    
005    import railo.commons.lang.StringUtil;
006    import railo.runtime.PageContextImpl;
007    import railo.runtime.PageSource;
008    import railo.runtime.config.ConfigWeb;
009    import railo.runtime.customtag.CustomTagUtil;
010    import railo.runtime.customtag.InitFile;
011    import railo.runtime.exp.ExpressionException;
012    import railo.runtime.exp.PageException;
013    import railo.runtime.type.util.ListUtil;
014    
015    /**
016     * To create cfimport custom tags
017     */
018    public final class CFImportTag extends CFTag {
019    
020        
021            @Override
022            public void initFile() throws PageException {
023                    ConfigWeb config = pageContext.getConfig();
024            
025                    String[] filenames=CustomTagUtil.getFileNames(config, getAppendix());// = appendix+'.'+config.getCFMLExtension();
026            
027                    
028                    String strRealPathes=attributesScope.remove("__custom_tag_path").toString();
029                    String[] realPathes=ListUtil.listToStringArray(strRealPathes, File.pathSeparatorChar);
030                for(int i=0;i<realPathes.length;i++){
031                    if(!StringUtil.endsWith(realPathes[i],'/'))realPathes[i]=realPathes[i]+"/";
032                }
033                
034                // MUSTMUST use cache like regular ct
035                    // page source
036                PageSource ps;
037                for(int rp=0;rp<realPathes.length;rp++){
038                        for(int fn=0;fn<filenames.length;fn++){
039                        ps=((PageContextImpl)pageContext).getRelativePageSourceExisting(realPathes[rp]+filenames[fn]);
040                        if(ps!=null){
041                            source=new InitFile(ps,filenames[fn],filenames[fn].endsWith('.'+config.getCFCExtension()));
042                            return;
043                        }
044                            } 
045                }
046                
047            // EXCEPTION
048                // message
049                
050            StringBuffer msg=new StringBuffer("could not find template [");
051            msg.append(CustomTagUtil.getDisplayName(config, getAppendix()));
052            msg.append("] in the following directories [");
053            msg.append(strRealPathes.replace(File.pathSeparatorChar, ','));
054            msg.append(']');
055            
056                
057                    throw new ExpressionException(msg.toString(),CustomTagUtil.getDetail(config));
058                
059            }
060    
061    }