001    package railo.runtime.exp;
002    
003    import railo.commons.lang.StringUtil;
004    import railo.runtime.PageSource;
005    import railo.runtime.config.Config;
006    import railo.runtime.type.Collection;
007    import railo.runtime.type.KeyImpl;
008    
009    /**
010     * Exception throwed when missing include
011     */
012    public final class MissingIncludeException extends PageExceptionImpl {
013    
014            private static final Collection.Key MISSING_FILE_NAME = KeyImpl.intern("MissingFileName");
015            private static final Collection.Key MISSING_FILE_NAME_REL = KeyImpl.intern("MissingFileName_rel");
016            private static final Collection.Key MISSING_FILE_NAME_ABS = KeyImpl.intern("MissingFileName_abs");
017            
018            private PageSource pageSource;
019    
020            /**
021             * constructor of the exception
022         * @param pageSource
023         */
024        public MissingIncludeException(PageSource pageSource) {
025            super(createMessage(pageSource),"missinginclude");
026            this.pageSource=pageSource;
027            
028        }
029        public MissingIncludeException(PageSource pageSource,String msg) {
030            super(msg,"missinginclude");
031            this.pageSource=pageSource;
032            
033        }
034    
035            /**
036             * @return the pageSource
037             */
038            public PageSource getPageSource() {
039                    return pageSource;
040            }
041    
042            private static String createMessage(PageSource pageSource) {
043                    String dsp=pageSource.getDisplayPath();
044                    if(dsp==null) return "Page "+pageSource.getRealpath()+" not found";
045                    return "Page "+pageSource.getRealpath()+" ["+dsp+"] not found";
046            }
047    
048            @Override
049            public CatchBlock getCatchBlock(Config config) {
050                    CatchBlock sct=super.getCatchBlock(config);
051                    String mapping="";
052                    if(StringUtil.startsWith(pageSource.getRealpath(),'/')){
053                            mapping = pageSource.getMapping().getVirtual();
054                            if(StringUtil.endsWith(mapping, '/'))
055                                    mapping=mapping.substring(0,mapping.length()-1);
056                    }
057                    sct.setEL(MISSING_FILE_NAME,mapping+pageSource.getRealpath());
058                    
059                    sct.setEL(MISSING_FILE_NAME_REL,mapping+pageSource.getRealpath());
060                    sct.setEL(MISSING_FILE_NAME_ABS,pageSource.getDisplayPath());
061                    return sct;
062            }
063            
064            public boolean typeEqual(String type) {
065            if(super.typeEqual(type)) return true;
066            type=type.toLowerCase().trim();
067            return type.equals("template");
068        }
069    }