001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.exp; 020 021import lucee.commons.lang.StringUtil; 022import lucee.runtime.PageSource; 023import lucee.runtime.config.Config; 024import lucee.runtime.type.Collection; 025import lucee.runtime.type.KeyImpl; 026 027/** 028 * Exception throwed when missing include 029 */ 030public final class MissingIncludeException extends PageExceptionImpl { 031 032 private static final Collection.Key MISSING_FILE_NAME = KeyImpl.intern("MissingFileName"); 033 private static final Collection.Key MISSING_FILE_NAME_REL = KeyImpl.intern("MissingFileName_rel"); 034 private static final Collection.Key MISSING_FILE_NAME_ABS = KeyImpl.intern("MissingFileName_abs"); 035 036 private PageSource pageSource; 037 038 /** 039 * constructor of the exception 040 * @param pageSource 041 */ 042 public MissingIncludeException(PageSource pageSource) { 043 super(createMessage(pageSource),"missinginclude"); 044 this.pageSource=pageSource; 045 046 } 047 public MissingIncludeException(PageSource pageSource,String msg) { 048 super(msg,"missinginclude"); 049 this.pageSource=pageSource; 050 051 } 052 053 /** 054 * @return the pageSource 055 */ 056 public PageSource getPageSource() { 057 return pageSource; 058 } 059 060 private static String createMessage(PageSource pageSource) { 061 String dsp=pageSource.getDisplayPath(); 062 if(dsp==null) return "Page "+pageSource.getRealpath()+" not found"; 063 return "Page "+pageSource.getRealpath()+" ["+dsp+"] not found"; 064 } 065 066 @Override 067 public CatchBlock getCatchBlock(Config config) { 068 CatchBlock sct=super.getCatchBlock(config); 069 String mapping=""; 070 if(StringUtil.startsWith(pageSource.getRealpath(),'/')){ 071 mapping = pageSource.getMapping().getVirtual(); 072 if(StringUtil.endsWith(mapping, '/')) 073 mapping=mapping.substring(0,mapping.length()-1); 074 } 075 sct.setEL(MISSING_FILE_NAME,mapping+pageSource.getRealpath()); 076 077 sct.setEL(MISSING_FILE_NAME_REL,mapping+pageSource.getRealpath()); 078 sct.setEL(MISSING_FILE_NAME_ABS,pageSource.getDisplayPath()); 079 return sct; 080 } 081 082 public boolean typeEqual(String type) { 083 if(super.typeEqual(type)) return true; 084 type=type.toLowerCase().trim(); 085 return type.equals("template"); 086 } 087}