// Path: src/com/govu/util/Util.java
// public class Util {
// 
//     public static boolean isDomainValid(String domain) {
//         return DOMAIN_NAME_PATTERN.matcher(domain).matches();
//     }
//     
//     public static final Pattern DOMAIN_NAME_PATTERN = Pattern.compile("^[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$");
// }
// 
// Path: src/com/govu/util/ZipHelper.java
// public class ZipHelper {
// 
//     public ZipHelper() {
//     }
// 
//     public ByteArrayOutputStream zipDir(String dir) throws IOException {
//         ByteArrayOutputStream out = new ByteArrayOutputStream();
// 
//         ZipOutputStream zip = new ZipOutputStream(out);
//         addDirectory("", zip, new File(dir));
//         zip.close();
// 
//         return out;
//     }
// 
//     private static void addDirectory(String root, ZipOutputStream zout, File fileSource) throws IOException {
//         File[] files = fileSource.listFiles();
//         for (int i = 0; i < files.length; i++) {
//             if (files[i].isDirectory()) {
//                 zout.putNextEntry(new ZipEntry(root + files[i].getName() + "/"));
//                 addDirectory(root + files[i].getName() + "/", zout, files[i]);
//                 continue;
//             }
//             byte[] buffer = new byte[1024];
//             FileInputStream fin = new FileInputStream(files[i]);
// 
//             zout.putNextEntry(new ZipEntry(root + files[i].getName()));
//             int length;
// 
//             while ((length = fin.read(buffer)) > 0) {
//                 zout.write(buffer, 0, length);
//             }
//             zout.closeEntry();
//             fin.close();
//         }
// 
//     }
// }


import com.govu.util.Util;
import com.govu.util.ZipHelper;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.govu.command;


/**
 *
 * @author Mehmet Ecevit
 */
public class DeployCommand extends Command {

    

    public DeployCommand() {
        super();
    }

    @Override
    public void process(String[] args) {
        
        if (args.length < 3) {
            System.out.println("Invalid arguments for deploy");
        }
        try {
            String path = args[1] + "/";
            String domain = args[2];
            String password = args.length > 3 ? args[3] : null;

            System.out.println("Path: " + path);
            System.out.println("Domain: " + domain);
            
            if (domain.toLowerCase().equals("codegovu.com") || !Util.isDomainValid(domain )) {
                System.out.println("Invalid domain");
                return;
            }
            
            if (password != null) {
                System.out.println("Password: " + password);
            }

            File zipDir = new File(path);
            if (!zipDir.exists()) {
                System.out.println("Path does not exist!");
                return;
            }

// Path: src/com/govu/util/Util.java
// public class Util {
// 
//     public static boolean isDomainValid(String domain) {
//         return DOMAIN_NAME_PATTERN.matcher(domain).matches();
//     }
//     
//     public static final Pattern DOMAIN_NAME_PATTERN = Pattern.compile("^[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$");
// }
// 
// Path: src/com/govu/util/ZipHelper.java
// public class ZipHelper {
// 
//     public ZipHelper() {
//     }
// 
//     public ByteArrayOutputStream zipDir(String dir) throws IOException {
//         ByteArrayOutputStream out = new ByteArrayOutputStream();
// 
//         ZipOutputStream zip = new ZipOutputStream(out);
//         addDirectory("", zip, new File(dir));
//         zip.close();
// 
//         return out;
//     }
// 
//     private static void addDirectory(String root, ZipOutputStream zout, File fileSource) throws IOException {
//         File[] files = fileSource.listFiles();
//         for (int i = 0; i < files.length; i++) {
//             if (files[i].isDirectory()) {
//                 zout.putNextEntry(new ZipEntry(root + files[i].getName() + "/"));
//                 addDirectory(root + files[i].getName() + "/", zout, files[i]);
//                 continue;
//             }
//             byte[] buffer = new byte[1024];
//             FileInputStream fin = new FileInputStream(files[i]);
// 
//             zout.putNextEntry(new ZipEntry(root + files[i].getName()));
//             int length;
// 
//             while ((length = fin.read(buffer)) > 0) {
//                 zout.write(buffer, 0, length);
//             }
//             zout.closeEntry();
//             fin.close();
//         }
// 
//     }
// }


// Path: src/com/govu/command/DeployCommand.java
import com.govu.util.Util;
import com.govu.util.ZipHelper;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.govu.command;


/**
 *
 * @author Mehmet Ecevit
 */
public class DeployCommand extends Command {

    

    public DeployCommand() {
        super();
    }

    @Override
    public void process(String[] args) {
        
        if (args.length < 3) {
            System.out.println("Invalid arguments for deploy");
        }
        try {
            String path = args[1] + "/";
            String domain = args[2];
            String password = args.length > 3 ? args[3] : null;

            System.out.println("Path: " + path);
            System.out.println("Domain: " + domain);
            
            if (domain.toLowerCase().equals("codegovu.com") || !Util.isDomainValid(domain )) {
                System.out.println("Invalid domain");
                return;
            }
            
            if (password != null) {
                System.out.println("Password: " + password);
            }

            File zipDir = new File(path);
            if (!zipDir.exists()) {
                System.out.println("Path does not exist!");
                return;
            }

            ZipHelper zipHelper = new ZipHelper();