Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
micstriit committed Dec 3, 2012
1 parent adfa9ac commit 210157b
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 16 deletions.
Expand Up @@ -46,6 +46,7 @@ public UDFGSProperty(ComponentImpl component,String name,FunctionArgument[] argu
Boolean.FALSE,
Boolean.FALSE,
0L,
null,
new StructImpl()

));
Expand All @@ -70,6 +71,7 @@ private static UDFPropertiesImpl UDFProperties(PageSource pageSource,
Boolean secureJson,
Boolean verifyClient,
long cachedWithin,
Integer localMode,
StructImpl meta) {
try {
return new UDFPropertiesImpl( pageSource,
Expand All @@ -87,6 +89,7 @@ private static UDFPropertiesImpl UDFProperties(PageSource pageSource,
secureJson,
verifyClient,
cachedWithin,
localMode,
meta);
} catch (ExpressionException e) {
return new UDFPropertiesImpl();
Expand Down
5 changes: 2 additions & 3 deletions railo-java/railo-core/src/railo/runtime/type/UDFImpl.java
Expand Up @@ -31,7 +31,6 @@
import railo.runtime.exp.PageException;
import railo.runtime.exp.UDFCasterException;
import railo.runtime.functions.cache.Util;
import railo.runtime.listener.ApplicationContext;
import railo.runtime.listener.ApplicationContextSupport;
import railo.runtime.op.Caster;
import railo.runtime.op.Decision;
Expand All @@ -46,7 +45,6 @@
import railo.runtime.type.util.ComponentUtil;
import railo.runtime.type.util.KeyConstants;
import railo.runtime.type.util.UDFUtil;
import railo.runtime.writer.BodyContentImpl;
import railo.runtime.writer.BodyContentUtil;

/**
Expand Down Expand Up @@ -332,7 +330,8 @@ private Object _call(PageContext pc, Object[] args, Struct values,boolean doIncl
Local oldLocal=pc.localScope();

pc.setFunctionScopes(newLocal,newArgs);
int oldCheckArgs=undefined.setMode(pc.getApplicationContext().getLocalMode());

int oldCheckArgs=undefined.setMode(properties.localMode==null?pc.getApplicationContext().getLocalMode():properties.localMode.intValue());
PageSource psInc=null;
try {
PageSource ps = getPageSource();
Expand Down
Expand Up @@ -39,6 +39,7 @@ public final class UDFPropertiesImpl implements UDFProperties {
public Set<Collection.Key> argumentsSet;
public int access;
public long cachedWithin;
public Integer localMode;

/**
* NEVER USE THIS CONSTRUCTOR, this constructor is only for deserialize this object from stream
Expand All @@ -64,6 +65,7 @@ public UDFPropertiesImpl(
Boolean secureJson,
Boolean verifyClient,
long cachedWithin,
Integer localMode,
StructImpl meta) throws ExpressionException {

// this happens when a arcive is based on older source code
Expand Down Expand Up @@ -101,6 +103,7 @@ public UDFPropertiesImpl(
this.verifyClient = verifyClient;
this.access = access;
this.cachedWithin=cachedWithin;
this.localMode=localMode;
}

public UDFPropertiesImpl(
Expand All @@ -119,6 +122,7 @@ public UDFPropertiesImpl(
Boolean secureJson,
Boolean verifyClient,
long cachedWithin,
Integer localMode,
StructImpl meta) throws ExpressionException {

// this happens when a arcive is based on older source code
Expand Down Expand Up @@ -155,6 +159,7 @@ public UDFPropertiesImpl(
this.verifyClient = verifyClient;
this.access = access;
this.cachedWithin=cachedWithin;
this.localMode=localMode;
}

/**
Expand All @@ -177,7 +182,7 @@ public UDFPropertiesImpl(
long cachedWithin,
StructImpl meta) throws ExpressionException {
this(pageSource, arguments, index, functionName, strReturnType, strReturnFormat,
output, access, null,displayName, description, hint, secureJson, verifyClient, cachedWithin, meta);
output, access, null,displayName, description, hint, secureJson, verifyClient, cachedWithin,null, meta);
}

/**
Expand All @@ -200,7 +205,7 @@ public UDFPropertiesImpl(
long cachedWithin,
StructImpl meta) throws ExpressionException {
this(pageSource, arguments, index, functionName, returnType, strReturnFormat,
output, access,null, displayName, description, hint, secureJson, verifyClient, cachedWithin, meta);
output, access,null, displayName, description, hint, secureJson, verifyClient, cachedWithin, null, meta);
}

/**
Expand All @@ -216,7 +221,7 @@ public UDFPropertiesImpl(
boolean output,
int access) throws ExpressionException {
this(pageSource, arguments, index, functionName, returnType,strReturnFormat, output, access, null,
"","", "", null, null, 0L, null);
"","", "", null, null, 0L, null, null);
}

/**
Expand Down
Expand Up @@ -20,10 +20,10 @@ public final class LitInteger extends ExpressionBase implements Literal,ExprInt

private int i;

public static Expression toExpr(int i, Position start,Position end) {
public static ExprInt toExpr(int i, Position start,Position end) {
return new LitInteger(i,start,end);
}
public static Expression toExpr(int i) {
public static ExprInt toExpr(int i) {
return new LitInteger(i,null,null);
}

Expand Down
Expand Up @@ -25,6 +25,7 @@
import railo.transformer.bytecode.statement.PrintOut;
import railo.transformer.bytecode.statement.udf.Function;
import railo.transformer.bytecode.statement.udf.FunctionImpl;
import railo.transformer.bytecode.util.ASMUtil;

public final class TagFunction extends TagBase implements IFunction {

Expand Down Expand Up @@ -241,6 +242,12 @@ private Function createFunction(Page page, Body body) throws BytecodeException {
attr = removeAttribute("verifyclient");
Expression verifyClient = (attr == null) ? null : attr.getValue();

// localMode
attr = removeAttribute("localmode");
Expression localMode = (attr == null) ? null : attr.getValue();



// cachedWithin
long cachedWithin=0;
attr = removeAttribute("cachedwithin");
Expand All @@ -256,7 +263,7 @@ private Function createFunction(Page page, Body body) throws BytecodeException {
throw new BytecodeException("invalid access type ["+strAccess+"], access types are remote, public, package, private",getStart());

Function func = new FunctionImpl(page,name, returnType,returnFormat, output, bufferOutput, acc, displayname,description,
hint,secureJson,verifyClient,cachedWithin,_abstract,_final, body, getStart(),getEnd());
hint,secureJson,verifyClient,localMode,cachedWithin,_abstract,_final, body, getStart(),getEnd());



Expand Down
Expand Up @@ -11,10 +11,11 @@ public final class Closure extends Function {

public Closure(Page page,Expression name, Expression returnType, Expression returnFormat, Expression output,Expression bufferOutput,
int access, Expression displayName, Expression description,Expression hint, Expression secureJson, Expression verifyClient,
Expression localMode,
long cachedWithin, boolean _abstract, boolean _final,
Body body, Position start,Position end) {
super(page,name, returnType, returnFormat, output,bufferOutput, access, displayName,description, hint, secureJson, verifyClient,
cachedWithin,_abstract,_final,body, start, end);
localMode,cachedWithin,_abstract,_final,body, start, end);

}

Expand Down
Expand Up @@ -14,6 +14,7 @@
import railo.commons.lang.StringUtil;
import railo.runtime.Component;
import railo.runtime.exp.TemplateException;
import railo.runtime.listener.AppListenerUtil;
import railo.runtime.type.FunctionArgument;
import railo.runtime.type.FunctionArgumentImpl;
import railo.runtime.type.FunctionArgumentLight;
Expand All @@ -25,8 +26,10 @@
import railo.transformer.bytecode.Page;
import railo.transformer.bytecode.Position;
import railo.transformer.bytecode.cast.CastBoolean;
import railo.transformer.bytecode.cast.CastInt;
import railo.transformer.bytecode.cast.CastString;
import railo.transformer.bytecode.expression.ExprBoolean;
import railo.transformer.bytecode.expression.ExprInt;
import railo.transformer.bytecode.expression.ExprString;
import railo.transformer.bytecode.expression.Expression;
import railo.transformer.bytecode.expression.var.Variable;
Expand Down Expand Up @@ -126,6 +129,7 @@ public abstract class Function extends StatementBaseNoFinal implements Opcodes,
Types.BOOLEAN,
Types.BOOLEAN,
Types.LONG_VALUE,
Types.INTEGER,
Page.STRUCT_IMPL
}
);
Expand All @@ -148,6 +152,7 @@ public abstract class Function extends StatementBaseNoFinal implements Opcodes,
Types.BOOLEAN,
Types.BOOLEAN,
Types.LONG_VALUE,
Types.INTEGER,
Page.STRUCT_IMPL
}
);
Expand Down Expand Up @@ -279,6 +284,7 @@ public abstract class Function extends StatementBaseNoFinal implements Opcodes,
ExprString description;
ExprBoolean secureJson;
ExprBoolean verifyClient;
ExprInt localMode;
protected int valueIndex;
protected int arrayIndex;
private long cachedWithin;
Expand All @@ -300,7 +306,7 @@ public Function(Page page,String name,int access,String returnType,Body body,Pos

public Function(Page page,Expression name,Expression returnType,Expression returnFormat,Expression output,Expression bufferOutput,
int access,Expression displayName,Expression description,Expression hint,Expression secureJson,
Expression verifyClient,long cachedWithin, boolean _abstract, boolean _final,Body body,Position start, Position end) {
Expression verifyClient,Expression localMode,long cachedWithin, boolean _abstract, boolean _final,Body body,Position start, Position end) {
super(start,end);

this.name=CastString.toExprString(name);
Expand All @@ -317,6 +323,7 @@ public Function(Page page,Expression name,Expression returnType,Expression retur
this.cachedWithin=cachedWithin;
this._abstract=_abstract;
this._final=_final;
this.localMode=toLocalMode(localMode, null);

this.body=body;
body.setParent(this);
Expand All @@ -327,6 +334,19 @@ public Function(Page page,Expression name,Expression returnType,Expression retur
}


public static ExprInt toLocalMode(Expression expr, ExprInt defaultValue) {
int mode=-1;
if(expr instanceof Literal) {
String str = ((Literal)expr).getString();
str=str.trim().toLowerCase();
mode = AppListenerUtil.toLocalMode(str,-1);
}
if(mode==-1) return defaultValue;
return LitInteger.toExpr(mode);
}



/*private static void checkNameConflict(ExprString expr) {
if(expr instanceof LitString){
String name=((LitString)expr).getString();
Expand Down Expand Up @@ -418,6 +438,7 @@ public final void createUDFProperties(BytecodeContext bc, int index, boolean clo
if(light && verifyClient!=null)light=false;
if(light && cachedWithin>0)light=false;
if(light && bufferOutput!=null)light=false;
if(light && localMode!=null)light=false;
if(light && Page.hasMetaDataStruct(metadata, null))light=false;

if(light){
Expand Down Expand Up @@ -451,6 +472,10 @@ public final void createUDFProperties(BytecodeContext bc, int index, boolean clo
// cachedwithin
adapter.push(cachedWithin<0?0:cachedWithin);

// localMode
if(localMode!=null)ExpressionUtil.writeOutSilent(localMode,bc, Expression.MODE_REF);
else ASMConstants.NULL(adapter);

// meta
Page.createMetaDataStruct(bc,metadata,null);

Expand Down Expand Up @@ -685,6 +710,17 @@ else if("access".equals(name)) {
else if("returnformat".equals(name))this.returnFormat=toLitString(name,attr.getValue());
else if("securejson".equals(name)) this.secureJson=toLitBoolean(name,attr.getValue());
else if("verifyclient".equals(name)) this.verifyClient=toLitBoolean(name,attr.getValue());
else if("localmode".equals(name)) {
Expression v = attr.getValue();
if(v!=null) {
String str = ASMUtil.toString(v,null);
if(!StringUtil.isEmpty(str)){
int mode = AppListenerUtil.toLocalMode(str, -1);
if(mode!=-1) this.localMode=LitInteger.toExpr(mode);
else throw new BytecodeException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)",getStart());
}
}
}
else if("cachedwithin".equals(name)) {
try {
this.cachedWithin=ASMUtil.timeSpanToLong(attr.getValue());
Expand Down Expand Up @@ -724,5 +760,12 @@ private final LitBoolean toLitBoolean(String name, Expression value) throws Byte
throw new BytecodeException("value of attribute ["+name+"] must have a literal/constant value",getStart());
return (LitBoolean) eb;
}

private final ExprInt toLitInt(String name, Expression value) throws BytecodeException {
ExprInt eb = CastInt.toExprInt(value);
if(!(eb instanceof Literal))
throw new BytecodeException("value of attribute ["+name+"] must have a literal/constant value",getStart());
return eb;
}

}
Expand Up @@ -14,10 +14,10 @@
public final class FunctionImpl extends Function {

public FunctionImpl(Page page, Expression name, Expression returnType, Expression returnFormat, Expression output, Expression bufferOutput,
int access, Expression displayName, Expression description,Expression hint, Expression secureJson, Expression verifyClient,
int access, Expression displayName, Expression description,Expression hint, Expression secureJson, Expression verifyClient, Expression localMode,
long cachedWithin, boolean _abstract, boolean _final,
Body body, Position start,Position end) {
super(page,name, returnType, returnFormat, output, bufferOutput, access, displayName,description, hint, secureJson, verifyClient,cachedWithin,_abstract,_final, body, start, end);
super(page,name, returnType, returnFormat, output, bufferOutput, access, displayName,description, hint, secureJson, verifyClient,localMode,cachedWithin,_abstract,_final, body, start, end);
}


Expand Down
Expand Up @@ -7,6 +7,7 @@

import railo.commons.lang.StringUtil;
import railo.runtime.functions.system.CFFunction;
import railo.runtime.listener.AppListenerUtil;
import railo.transformer.bytecode.Body;
import railo.transformer.bytecode.BytecodeException;
import railo.transformer.bytecode.Literal;
Expand Down Expand Up @@ -78,6 +79,17 @@ public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws Eval
tag.addAttribute(new Attribute(attrCachedWithin.isDynamicType(), attrCachedWithin.getName(), LitLong.toExpr(ASMUtil.timeSpanToLong(val), null, null), "numeric"));
}

// Attribute localMode
Attribute attrLocalMode = tag.getAttribute("localmode");
if(attrLocalMode!=null) {
Expression expr = attrLocalMode.getValue();
String str = ASMUtil.toString(expr,null);
if(!StringUtil.isEmpty(str) && AppListenerUtil.toLocalMode(str, -1)==-1)
throw new EvaluatorException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)");
//boolean output = ((LitBoolean)expr).getBooleanValue();
//if(!output) ASMUtil.removeLiterlChildren(tag, true);
}


// Attribute Output
// "output=true" wird in "railo.transformer.cfml.attributes.impl.Function" gehŠndelt
Expand Down Expand Up @@ -111,8 +123,7 @@ public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws Eval
//}

}



public static void checkFunctionName(String name, FunctionLib[] flibs) throws EvaluatorException {
FunctionLibFunction flf;
for (int i = 0; i < flibs.length; i++) {
Expand All @@ -123,7 +134,6 @@ public static void checkFunctionName(String name, FunctionLib[] flibs) throws Ev
}
}


public static void throwIfNotEmpty(Tag tag) throws EvaluatorException {
Body body = tag.getBody();
List statments = body.getStatements();
Expand Down

0 comments on commit 210157b

Please sign in to comment.