001    package railo.runtime.functions.file;
002    
003    import java.io.IOException;
004    
005    import railo.commons.io.res.Resource;
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.PageException;
008    import railo.runtime.op.Caster;
009    
010    public class FileWriteLine {
011    
012            public static String call(PageContext pc, Object obj, String text) throws PageException {
013                    FileStreamWrapper fsw=null;
014                    boolean close=false;
015                    try {
016                            try {
017                                    if(obj instanceof FileStreamWrapper) {
018                                            fsw=(FileStreamWrapper)obj;
019                                    }
020                                    else {
021                                            close=true;
022                                            Resource res = Caster.toResource(pc,obj,false);
023                                            pc.getConfig().getSecurityManager().checkFileLocation(res);
024                                            fsw=new FileStreamWrapperWrite(res,pc.getConfig().getResourceCharset(),false,false);
025                                    }
026                                    fsw.write(text+"\n");
027                            }
028                            finally {
029                                    if(close && fsw!=null)fsw.close();
030                            }
031                            
032                    } 
033                    catch (IOException e) {
034                            throw Caster.toPageException(e);
035                    }
036                    return null;
037            }
038    }