/** * @param order the order to set * @throws ApplicationException */ public void setOrder(String strOrder) throws ApplicationException { strOrder = StringUtil.toLowerCase(strOrder.trim()); if ("name".equals(strOrder)) order = ORDER_NAME; else if ("time".equals(strOrder)) order = ORDER_TIME; else throw new ApplicationException( "invalid order definition [" + strOrder + "], valid order definitions are " + "[name,time]"); }
/** * @param resolution the resolution to set * @throws ApplicationException */ public void setResolution(String strResolution) throws ApplicationException { strResolution = StringUtil.toLowerCase(strResolution.trim()); if ("low".equals(strResolution)) resolution = RESOLUTION_LOW; else if ("high".equals(strResolution)) resolution = RESOLUTION_HIGH; else throw new ApplicationException( "invalid resolution definition [" + strResolution + "], valid resolution definitions are " + "[low,high]"); }
/** * @param saveOption the saveOption to set * @throws ApplicationException */ public void setSaveoption(String strSaveOption) throws ApplicationException { strSaveOption = StringUtil.toLowerCase(strSaveOption.trim()); if ("full".equals(strSaveOption)) saveOption = SAVE_OPTION_FULL; else if ("incremental".equals(strSaveOption)) saveOption = SAVE_OPTION_INCREMENTAL; else if ("linear".equals(strSaveOption)) saveOption = SAVE_OPTION_LINEAR; else throw new ApplicationException( "invalid saveOption definition [" + strSaveOption + "], valid saveOption definitions are " + "[full,linear,incremental]"); }
/** * @param format the format to set * @throws ApplicationException */ public void setFormat(String strFormat) throws ApplicationException { strFormat = StringUtil.toLowerCase(strFormat.trim()); if ("jpg".equals(strFormat)) format = FORMAT_JPG; else if ("jpeg".equals(strFormat)) format = FORMAT_JPG; else if ("jpe".equals(strFormat)) format = FORMAT_JPG; else if ("tiff".equals(strFormat)) format = FORMAT_TIFF; else if ("tif".equals(strFormat)) format = FORMAT_TIFF; else if ("png".equals(strFormat)) format = FORMAT_PNG; else throw new ApplicationException( "invalid format definition [" + strFormat + "], valid format definitions are " + "[jpg,tiff,png]"); }
/** * @param encrypt the encrypt to set * @throws ApplicationException */ public void setEncrypt(String strEncrypt) throws ApplicationException { strEncrypt = StringUtil.toLowerCase(strEncrypt.trim()); if ("aes128".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_AES_128; else if ("aes-128".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_AES_128; else if ("aes_128".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_AES_128; else if ("none".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_NONE; else if ("".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_NONE; else if ("rc4128".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_128; else if ("rc4-128".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_128; else if ("rc4_128".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_128; else if ("rc4128m".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_128M; else if ("rc4-128m".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_128M; else if ("rc4_128m".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_128M; else if ("rc440".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_40; else if ("rc4-40".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_40; else if ("rc4_40".equals(strEncrypt)) encrypt = PDFUtil.ENCRYPT_RC4_40; else throw new ApplicationException( "invalid encrypt definition [" + strEncrypt + "], valid encrypt definitions are " + "[aes_128,none,rc4_128,rc4_128m,rc4_40]"); }
/** * @param action the action to set * @throws ApplicationException */ public void setAction(String strAction) throws ApplicationException { strAction = StringUtil.toLowerCase(strAction.trim()); if ("addwatermark".equals(strAction)) action = ACTION_ADD_WATERMARK; else if ("add-watermark".equals(strAction)) action = ACTION_ADD_WATERMARK; else if ("add_watermark".equals(strAction)) action = ACTION_ADD_WATERMARK; else if ("deletepages".equals(strAction)) action = ACTION_DELETE_PAGES; else if ("delete-pages".equals(strAction)) action = ACTION_DELETE_PAGES; else if ("delete_pages".equals(strAction)) action = ACTION_DELETE_PAGES; else if ("deletepage".equals(strAction)) action = ACTION_DELETE_PAGES; else if ("delete-page".equals(strAction)) action = ACTION_DELETE_PAGES; else if ("delete_page".equals(strAction)) action = ACTION_DELETE_PAGES; else if ("getinfo".equals(strAction)) action = ACTION_GET_INFO; else if ("get-info".equals(strAction)) action = ACTION_GET_INFO; else if ("get_info".equals(strAction)) action = ACTION_GET_INFO; else if ("merge".equals(strAction)) action = ACTION_MERGE; // else if("processddx".equals(strAction)) action=ACTION_PROCESSDDX; // else if("process-ddx".equals(strAction)) action=ACTION_PROCESSDDX; // else if("process_ddx".equals(strAction)) action=ACTION_PROCESSDDX; else if ("protect".equals(strAction)) action = ACTION_PROTECT; else if ("read".equals(strAction)) action = ACTION_READ; else if ("removewatermark".equals(strAction)) action = ACTION_REMOVE_WATERMARK; else if ("removewater-mark".equals(strAction)) action = ACTION_REMOVE_WATERMARK; else if ("removewater_mark".equals(strAction)) action = ACTION_REMOVE_WATERMARK; else if ("setinfo".equals(strAction)) action = ACTION_SET_INFO; else if ("set-info".equals(strAction)) action = ACTION_SET_INFO; else if ("set_info".equals(strAction)) action = ACTION_SET_INFO; else if ("thumbnail".equals(strAction)) action = ACTION_THUMBNAIL; else if ("write".equals(strAction)) action = ACTION_WRITE; else throw new ApplicationException( "invalid action definition [" + strAction + "], valid actions definitions are " + "[addWatermark,deletePages,getInfo,merge,protect,read,removeWatermark,setInfo,thumbnail,write]"); }
/** * returns if a value of the list contains given value, ignore case, ignore empty values * * @param list list to search in * @param value value to serach * @param delimeter delimeter of the list * @return position in list or 0 */ public static int listContainsIgnoreEmptyNoCase(String list, String value, String delimeter) { return listContainsIgnoreEmpty( list.toLowerCase(), value.toLowerCase(), StringUtil.toLowerCase(delimeter)); }
/** * Executes a Expression * * @param sql * @param qr * @param expression * @param row * @return result * @throws PageException */ private Object executeExpression( PageContext pc, SQL sql, Query qr, ZExpression expression, int row) throws PageException { String op = StringUtil.toLowerCase(expression.getOperator()); int count = expression.nbOperands(); if (op.equals("and")) return executeAnd(pc, sql, qr, expression, row); else if (op.equals("or")) return executeOr(pc, sql, qr, expression, row); if (count == 0 && op.equals("?")) { int pos = sql.getPosition(); if (sql.getItems().length <= pos) throw new DatabaseException("invalid syntax for SQL Statment", null, sql, null); sql.setPosition(pos + 1); return sql.getItems()[pos].getValueForCF(); } // 11111111111111111111111111111111111111111111111111111 else if (count == 1) { Object value = executeExp(pc, sql, qr, expression.getOperand(0), row); // Functions switch (op.charAt(0)) { case 'a': if (op.equals("abs")) return new Double(MathUtil.abs(Caster.toDoubleValue(value))); if (op.equals("acos")) return new Double(Math.acos(Caster.toDoubleValue(value))); if (op.equals("asin")) return new Double(Math.asin(Caster.toDoubleValue(value))); if (op.equals("atan")) return new Double(Math.atan(Caster.toDoubleValue(value))); break; case 'c': if (op.equals("ceiling")) return new Double(Math.ceil(Caster.toDoubleValue(value))); if (op.equals("cos")) return new Double(Math.cos(Caster.toDoubleValue(value))); break; case 'e': if (op.equals("exp")) return new Double(Math.exp(Caster.toDoubleValue(value))); break; case 'f': if (op.equals("floor")) return new Double(Math.floor(Caster.toDoubleValue(value))); break; case 'i': if (op.equals("is not null")) return Boolean.valueOf(value != null); if (op.equals("is null")) return Boolean.valueOf(value == null); break; case 'u': if (op.equals("upper") || op.equals("ucase")) return Caster.toString(value).toUpperCase(); break; case 'l': if (op.equals("lower") || op.equals("lcase")) return Caster.toString(value).toLowerCase(); if (op.equals("ltrim")) return StringUtil.ltrim(Caster.toString(value), null); if (op.equals("length")) return new Double(Caster.toString(value).length()); break; case 'r': if (op.equals("rtrim")) return StringUtil.rtrim(Caster.toString(value), null); break; case 's': if (op.equals("sign")) return new Double(MathUtil.sgn(Caster.toDoubleValue(value))); if (op.equals("sin")) return new Double(Math.sin(Caster.toDoubleValue(value))); if (op.equals("soundex")) return StringUtil.soundex(Caster.toString(value)); if (op.equals("sin")) return new Double(Math.sqrt(Caster.toDoubleValue(value))); break; case 't': if (op.equals("tan")) return new Double(Math.tan(Caster.toDoubleValue(value))); if (op.equals("trim")) return Caster.toString(value).trim(); break; } } // 22222222222222222222222222222222222222222222222222222 else if (count == 2) { if (op.equals("=") || op.equals("in")) return executeEQ(pc, sql, qr, expression, row); else if (op.equals("!=") || op.equals("<>")) return executeNEQ(pc, sql, qr, expression, row); else if (op.equals("<")) return executeLT(pc, sql, qr, expression, row); else if (op.equals("<=")) return executeLTE(pc, sql, qr, expression, row); else if (op.equals(">")) return executeGT(pc, sql, qr, expression, row); else if (op.equals(">=")) return executeGTE(pc, sql, qr, expression, row); else if (op.equals("-")) return executeMinus(pc, sql, qr, expression, row); else if (op.equals("+")) return executePlus(pc, sql, qr, expression, row); else if (op.equals("/")) return executeDivide(pc, sql, qr, expression, row); else if (op.equals("*")) return executeMultiply(pc, sql, qr, expression, row); else if (op.equals("^")) return executeExponent(pc, sql, qr, expression, row); Object left = executeExp(pc, sql, qr, expression.getOperand(0), row); Object right = executeExp(pc, sql, qr, expression.getOperand(1), row); // Functions switch (op.charAt(0)) { case 'a': if (op.equals("atan2")) return new Double(Math.atan2(Caster.toDoubleValue(left), Caster.toDoubleValue(right))); break; case 'b': if (op.equals("bitand")) return new Double( Operator.bitand(Caster.toDoubleValue(left), Caster.toDoubleValue(right))); if (op.equals("bitor")) return new Double( Operator.bitor(Caster.toDoubleValue(left), Caster.toDoubleValue(right))); break; case 'c': if (op.equals("concat")) return Caster.toString(left).concat(Caster.toString(right)); break; case 'l': if (op.equals("like")) return executeLike(pc, sql, qr, expression, row); break; case 'm': if (op.equals("mod")) return new Double( Operator.modulus(Caster.toDoubleValue(left), Caster.toDoubleValue(right))); break; } throw new DatabaseException("unsopprted sql statement [" + op + "]", null, sql, null); } // 3333333333333333333333333333333333333333333333333333333333333333333 else if (count == 3) { if (op.equals("between")) return executeBetween(pc, sql, qr, expression, row); } if (op.equals("in")) return executeIn(pc, sql, qr, expression, row); /* addCustomFunction("cot",1); addCustomFunction("degrees",1); addCustomFunction("log",1); addCustomFunction("log10",1); addCustomFunction("pi",0); addCustomFunction("power",2); addCustomFunction("radians",1); addCustomFunction("rand",0); addCustomFunction("round",2); addCustomFunction("roundmagic",1); addCustomFunction("truncate",2); addCustomFunction("ascii",1); addCustomFunction("bit_length",1); addCustomFunction("char",1); addCustomFunction("char_length",1); addCustomFunction("difference",2); addCustomFunction("hextoraw",1); addCustomFunction("insert",4); addCustomFunction("left",2); addCustomFunction("locate",3); addCustomFunction("octet_length",1); addCustomFunction("rawtohex",1); addCustomFunction("repeat",2); addCustomFunction("replace",3); addCustomFunction("right",2); addCustomFunction("space",1); addCustomFunction("substr",3); addCustomFunction("substring",3); addCustomFunction("curdate",0); addCustomFunction("curtime",0); addCustomFunction("datediff",3); addCustomFunction("dayname",1); addCustomFunction("dayofmonth",1); addCustomFunction("dayofweek",1); addCustomFunction("dayofyear",1); addCustomFunction("hour",1); addCustomFunction("minute",1); addCustomFunction("month",1); addCustomFunction("monthname",1); addCustomFunction("now",0); addCustomFunction("quarter",1); addCustomFunction("second",1); addCustomFunction("week",1); addCustomFunction("year",1); addCustomFunction("current_date",1); addCustomFunction("current_time",1); addCustomFunction("current_timestamp",1); addCustomFunction("database",0); addCustomFunction("user",0); addCustomFunction("current_user",0); addCustomFunction("identity",0); addCustomFunction("ifnull",2); addCustomFunction("casewhen",3); addCustomFunction("convert",2); //addCustomFunction("cast",1); addCustomFunction("coalesce",1000); addCustomFunction("nullif",2); addCustomFunction("extract",1); addCustomFunction("position",1); */ // print(expression); throw new DatabaseException( "unsopprted sql statement (op-count:" + expression.nbOperands() + ";operator:" + op + ") ", null, sql, null); }
public static boolean isCastableTo(String type, Object o, boolean alsoPattern) { type = StringUtil.toLowerCase(type).trim(); if (type.length() > 2) { char first = type.charAt(0); switch (first) { case 'a': if (type.equals("any")) { return true; } else if (type.equals("array")) { return isCastableToArray(o); } break; case 'b': if (type.equals("boolean") || type.equals("bool")) { return isCastableToBoolean(o); } else if (type.equals("binary")) { return isCastableToBinary(o, true); } else if (type.equals("base64")) { return Caster.toBase64(o, null) != null; } break; case 'c': if (alsoPattern && type.equals("creditcard")) { return Caster.toCreditCard(o, null) != null; } break; case 'd': if (type.equals("date")) { return isDateAdvanced(o, true); } else if (type.equals("datetime")) { return isDateAdvanced(o, true); } else if (type.equals("double")) { return isCastableToNumeric(o); } else if (type.equals("decimal")) { return Caster.toDecimal(o, null) != null; } break; case 'e': if (type.equals("eurodate")) { return isDateAdvanced(o, true); } else if (alsoPattern && type.equals("email")) { return Caster.toEmail(o, null) != null; } break; case 'f': if (type.equals("float")) { return isCastableToNumeric(o); } break; case 'g': if (type.equals("guid")) { return isGUId(o); } break; case 'i': if (type.equals("integer") || type.equals("int")) { return isCastableToNumeric(o); } break; case 'l': if (type.equals("long")) { return isCastableToNumeric(o); } break; case 'n': if (type.equals("numeric")) { return isCastableToNumeric(o); } else if (type.equals("number")) { return isCastableToNumeric(o); } break; case 'o': if (type.equals("object")) { return true; } else if (type.equals("other")) { return true; } break; case 'p': if (alsoPattern && type.equals("phone")) { return Caster.toPhone(o, null) != null; } break; case 'q': if (type.equals("query")) { return isQuery(o); } break; case 's': if (type.equals("string")) { return isCastableToString(o); } else if (type.equals("struct")) { return isCastableToStruct(o); } else if (type.equals("short")) { return isCastableToNumeric(o); } else if (alsoPattern && (type.equals("ssn") || type.equals("social_security_number"))) { return Caster.toSSN(o, null) != null; } break; case 't': if (type.equals("timespan")) { return Caster.toTimespan(o, null) != null; } if (type.equals("time")) { return isDateAdvanced(o, true); } if (alsoPattern && type.equals("telephone")) { return Caster.toPhone(o, null) != null; } case 'u': if (type.equals("uuid")) { return isUUId(o); } if (type.equals("usdate")) { return isDateAdvanced(o, true); // return DateCaster.toDate(o,pc.getTimeZone()); } if (alsoPattern && type.equals("url")) { return Caster.toURL(o, null) != null; } break; case 'v': if (type.equals("variablename")) { return isVariableName(o); } else if (type.equals("void")) { return isVoid(o); // Caster.toVoid(o,Boolean.TRUE)!=Boolean.TRUE; } else if (type.equals("variable_name")) { return isVariableName(o); } else if (type.equals("variable-name")) { return isVariableName(o); } break; case 'x': if (type.equals("xml")) { return isXML(o); } break; case 'z': if (alsoPattern && (type.equals("zip") || type.equals("zipcode"))) { return Caster.toZip(o, null) != null; } break; } } if (o instanceof Component) { Component comp = ((Component) o); return comp.instanceOf(type); } if (isArrayType(type) && isArray(o)) { String t = type.substring(0, type.length() - 2); Array arr = Caster.toArray(o, null); if (arr != null) { Iterator it = arr.valueIterator(); while (it.hasNext()) { if (!isCastableTo(t, it.next(), alsoPattern)) return false; } return true; } } return false; }
public static boolean isValid(String type, Object value) throws ExpressionException { type = StringUtil.toLowerCase(type.trim()); char first = type.charAt(0); switch (first) { case 'a': if ("any".equals(type)) return true; // isSimpleValue(value); if ("array".equals(type)) return isArray(value); break; case 'b': if ("binary".equals(type)) return isBinary(value); if ("boolean".equals(type)) return isBoolean(value, true); break; case 'c': if ("creditcard".equals(type)) return isCreditCard(value); if ("component".equals(type)) return isComponent(value); if ("cfc".equals(type)) return isComponent(value); break; case 'd': if ("date".equals(type)) return isDateAdvanced(value, true); // ist zwar nicht logisch aber ident. zu Neo if ("double".equals(type)) return isCastableToNumeric(value); break; case 'e': if ("eurodate".equals(type)) return isEuroDate(value); if ("email".equals(type)) return isEmail(value); break; case 'f': if ("float".equals(type)) return isNumeric(value, true); break; case 'g': if ("guid".equals(type)) return isGUId(value); break; case 'i': if ("integer".equals(type)) return isInteger(value, false); break; case 'n': if ("numeric".equals(type)) return isCastableToNumeric(value); if ("number".equals(type)) return isCastableToNumeric(value); if ("node".equals(type)) return isXML(value); break; case 'p': if ("phone".equals(type)) return isPhone(value); break; case 'q': if ("query".equals(type)) return isQuery(value); break; case 's': if ("simple".equals(type)) return isSimpleValue(value); if ("struct".equals(type)) return isStruct(value); if ("ssn".equals(type)) return isSSN(value); if ("social_security_number".equals(type)) return isSSN(value); if ("string".equals(type)) return isString(value); break; case 't': if ("telephone".equals(type)) return isPhone(value); if ("time".equals(type)) return isDateAdvanced(value, false); break; case 'u': if ("usdate".equals(type)) return isUSDate(value); if ("uuid".equals(type)) return isUUId(value); if ("url".equals(type)) return isURL(value); break; case 'v': if ("variablename".equals(type)) return isVariableName(Caster.toString(value, "")); break; case 'x': if ("xml".equals(type)) return isXML(value); // DIFF 23 break; case 'z': if ("zip".equals(type)) return isZipCode(value); if ("zipcode".equals(type)) return isZipCode(value); break; } throw new ExpressionException( "invalid type [" + type + "], valid types are [any,array,binary,boolean,component,creditcard,date,time,email,eurodate,float,numeric,guid,integer,query,simple,ssn,string,struct,telephone,URL,UUID,USdate,variableName,zipcode]"); }