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