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.ctp;
 
 
 public class CtpSession extends With {
 	@SuppressWarnings("resource")
 	public void prepTarget(StackEntry stack) {
         String name = stack.stringFromSource("Name");            
         String host = stack.stringFromSource("Host");
         String user = stack.stringFromSource("User");
         String pwd = stack.stringFromSource("Password");
         
         if (StringUtil.isEmpty(name)) {
 			stack.log().errorTr(527);
 			stack.resume();
 			return;
         }
         
         if (StringUtil.isEmpty(host)) {
 			stack.log().errorTr(528);
 			stack.resume();
 			return;
         }
         
         DomainInfo di = ..resolveDomainInfo(host);
         
         ApiSession sess = null;
         
         // if we handle the domain then use local session
         if (di != null) {
         	Session session = ..getSessions().create("hub:"host);
         	sess = new LocalSession();
     		((LocalSession)sess).init(sessionstack.getInstruction().getXml());
     		
     		// then use root user
         	if (StringUtil.isEmpty(user)) {
         		((LocalSession)sess).startSessionAsRoot();
         	}
         	else if (!sess.startSession(userpwd)) {
 				stack.log().errorTr(530);
 				stack.resume();
 				return;            		
         	}
         }
         else {
         	if (StringUtil.isEmpty(user)) {
 				stack.log().errorTr(529);
 				stack.resume();
 				return;
         	}
         	
         	// TODO enhance this some
     		sess = new WebSession();
     		((WebSession)sess).init(stack.getInstruction().getXml());
     		
             if (!sess.startSession(userpwd)) {
 				stack.log().errorTr(530);
 				stack.resume();
 				return;
             }
         }
 		
         stack.addVariable(namesess);
         this.setTarget(stacksess);
 		
 		this.nextOpResume(stack);
 	}
 
	/*
	@Override
	public void run(final StackEntry stack) {
		if (stack.getState() == ExecuteState.Ready) {
            String name = stack.stringFromSource("Name");            
            String host = stack.stringFromSource("Host");
            String user = stack.stringFromSource("User");
            String pwd = stack.stringFromSource("Password");
            
            if (StringUtil.isEmpty(name)) {
				stack.setState(ExecuteState.Exit);
				stack.log().errorTr(527);
				stack.resume();
				return;
            }
            
            if (StringUtil.isEmpty(host)) {
				stack.setState(ExecuteState.Exit);
				stack.log().errorTr(528);
				stack.resume();
				return;
            }
            
            DomainInfo di = Hub.instance.resolveDomainInfo(host);
            
            ApiSession sess = null;
            
            // if we handle the domain then use local session
            if (di != null) {
            	Session session = Hub.instance.getSessions().create("hub:", host);
            	sess = new LocalSession();
        		((LocalSession)sess).init(session, stack.getInstruction().getXml());
        		
        		// then use root user
            	if (StringUtil.isEmpty(user)) {
            		((LocalSession)sess).startSessionAsRoot();
            	}
            	else if (!sess.startSession(user, pwd)) {
    				stack.setState(ExecuteState.Exit);
    				stack.log().errorTr(530);
    				stack.resume();
    				return;            		
            	}
            }
            else {
            	if (StringUtil.isEmpty(user)) {
    				stack.setState(ExecuteState.Exit);
    				stack.log().errorTr(529);
    				stack.resume();
    				return;
            	}
            	
            	// TODO enhance this some
        		sess = new WebSession();
        		((WebSession)sess).init(stack.getInstruction().getXml());
        		
                if (!sess.startSession(user, pwd)) {
    				stack.setState(ExecuteState.Exit);
    				stack.log().errorTr(530);
    				stack.resume();
    				return;
                }
            }
    		
            stack.addVariable(name, sess);
			stack.getStore().setField("CurrNode", 0);
			stack.getStore().setField("Target", sess);
			stack.setState(ExecuteState.Resume);
			stack.resume();
		}		
		else
			super.run(stack);
	}
	*/
New to GrepCode? Check out our FAQ X