Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* ************************************************************************
 #
 #  DivConq
 #
 #  http://divconq.com/
 #
 #  Copyright:
 #    Copyright 2014 eTimeline, LLC. All rights reserved.
 #
#  License:
#    See the license.txt file in the project's top-level directory for details.
#  Authors:
#    * Andy White
************************************************************************ */
package divconq.script.inst.file;
public class File extends With {
	public void prepTarget(StackEntry stack) {
        String name = stack.stringFromSource("Name");
        
        if (StringUtil.isEmpty(name))
        	name = "Folder_" + stack.getActivity().tempVarName();
        
        String vname = name;
        
        Struct ss = stack.refFromSource("In");
        
        if ((ss == null) || (!(ss instanceof IFileStoreDriver) && !(ss instanceof IFileStoreFile))) {
        	stack.log().errorTr(536);
    		this.nextOpResume(stack);
        	return;
        }
        
        CommonPath path = null;
        
        try {
            path = new CommonPath(stack.stringFromSource("Path""/"));
        }
        catch (Exception x) {
			stack.log().errorTr(537);
			this.nextOpResume(stack);
			return;
        }
        IFileStoreDriver drv = null;
        
        if (ss instanceof IFileStoreDriver) {
            drv = (IFileStoreDriver)ss;
        }
        else {
        	drv = ((IFileStoreFile)ss).driver();
        	path = ((IFileStoreFile)ss).resolvePath(path);
        }
        
        drv.getFileDetail(pathnew FuncCallback<IFileStoreFile>() {
			public void callback() {
				stack.log().copyMessages(this);
				if (this.hasErrors()) {
					stack.log().errorTr(538);
					File.this.nextOpResume(stack);
					return;
				}
	            IFileStoreFile fh = this.getResult();			            
	            
	            if (!fh.exists() && stack.getInstruction().getXml().getName().equals("Folder"))
	            	fh.isFolder(true); 
	            stack.addVariable(vname, (Struct)fh);
	            
	            File.this.setTarget(stack, (Struct)fh);
	            
	    		File.this.nextOpResume(stack);
			}
		});
	}
New to GrepCode? Check out our FAQ X