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 /** 049 * 050 * @see railo.runtime.exp.PageExceptionImpl#getCatchBlock(railo.runtime.PageContext) 051 */ 052 public CatchBlock getCatchBlock(Config config) { 053 CatchBlock sct=super.getCatchBlock(config); 054 String mapping=""; 055 if(StringUtil.startsWith(pageSource.getRealpath(),'/')){ 056 mapping = pageSource.getMapping().getVirtual(); 057 if(StringUtil.endsWith(mapping, '/')) 058 mapping=mapping.substring(0,mapping.length()-1); 059 } 060 sct.setEL(MISSING_FILE_NAME,mapping+pageSource.getRealpath()); 061 062 sct.setEL(MISSING_FILE_NAME_REL,mapping+pageSource.getRealpath()); 063 sct.setEL(MISSING_FILE_NAME_ABS,pageSource.getDisplayPath()); 064 return sct; 065 } 066 067 public boolean typeEqual(String type) { 068 if(super.typeEqual(type)) return true; 069 type=type.toLowerCase().trim(); 070 return type.equals("template"); 071 } 072 }