001    package railo.runtime.exp;
002    
003    import railo.runtime.PageContext;
004    import railo.runtime.config.Config;
005    import railo.runtime.err.ErrorPage;
006    import railo.runtime.type.Struct;
007    
008    
009    /**
010     * Exception throwed by Cold Fusion Code
011     */
012    public final class CustomTypeException extends PageExceptionImpl {
013            
014            /**
015             * constructor of the Exception 
016             * @param message Exception Message
017             * @param detail Detailed Exception Message
018             * @param errorCode Error Code
019             * @param customType Type of the Exception
020             */
021            public CustomTypeException(String message, String detail, String errorCode, String customType,String extendedinfo) {
022                    super(message,"custom_type",customType);
023                    setDetail(detail);
024                    setErrorCode(errorCode);
025                    if(extendedinfo!=null)setExtendedInfo(extendedinfo);
026            }
027    
028            public CatchBlock getCatchBlock(Config config) {
029                    CatchBlock cb=super.getCatchBlock(config);
030                    cb.setEL("code",cb.get("errorcode",null));
031                    cb.setEL("type",getCustomTypeAsString());
032                    String ei=getExtendedInfo();
033                    if(ei!=null)cb.setEL("extended_info",ei);
034                    //cb.setEL("ErrorCode","");
035                    return cb;
036            }
037    
038            /**
039             * @see railo.runtime.exp.IPageException#getErrorBlock(railo.runtime.PageContext, railo.runtime.err.ErrorPage)
040             */
041            public Struct getErrorBlock(PageContext pc, ErrorPage ep) {
042                    Struct eb = super.getErrorBlock(pc, ep);
043                    eb.setEL("type",getCustomTypeAsString());
044                    return eb;
045            }
046    
047        /**
048         * @see railo.runtime.exp.IPageException#typeEqual(java.lang.String)
049         */
050        public boolean typeEqual(String type) {
051            if(type==null) return true;
052            type=type.toLowerCase().trim();
053            if(type.equals("any")) return true;
054            
055            // Custom Type
056            if(getTypeAsString().equals("custom_type") || getTypeAsString().equals("customtype")) {
057                return compareCustomType(type,getCustomTypeAsString().toLowerCase().trim());
058            }
059            return super.typeEqual(type);
060        }
061        
062        /**
063         * @param leftType
064         * @param rightType
065         * @return is same custom type
066         */
067        private boolean compareCustomType(String leftType, String rightType) {
068            int left=leftType.length();
069            int right=rightType.length();
070            if(left>right) return false;
071            if(left==right) return leftType.equals(rightType);
072            
073            for(int i=0;i<left;i++) {
074                if(leftType.charAt(i)!=rightType.charAt(i)) return false;
075            }
076            return rightType.charAt(left)=='.';
077        }
078    }