Example usage for java.util Collections enumeration

List of usage examples for java.util Collections enumeration

Introduction

In this page you can find the example usage for java.util Collections enumeration.

Prototype

public static <T> Enumeration<T> enumeration(final Collection<T> c) 

Source Link

Document

Returns an enumeration over the specified collection.

Usage

From source file:edu.ku.brc.af.ui.forms.TableViewObj.java

@SuppressWarnings("unchecked")
public void setDataObj(final Object dataObj) {
    this.dataObj = dataObj;

    if (dataObj instanceof List) {
        origDataSet = null;//from  w w w.j  av  a2s .c om
        if (dataObj instanceof Vector) {
            dataObjList = (Vector<Object>) (List<Object>) dataObj;
        } else {
            dataObjList = new Vector<Object>((List<Object>) dataObj);
        }

        newObjsList.addAll(dataObjList);

    } else {
        if (dataObjList == null) {
            dataObjList = new Vector<Object>();
        } else {
            dataObjList.clear();
        }

        if (dataObj instanceof Set) {
            origDataSet = (Set<Object>) dataObj;
            List newList = Collections.list(Collections.enumeration(origDataSet));
            if (newList.size() > 0) {
                Object firstObj = newList.get(0);
                if (firstObj instanceof Comparable<?>) {
                    Collections.sort(newList);
                }

                if (firstObj instanceof Orderable && isEditing && orderUpBtn == null) {
                    addOrderablePanel();
                }
            }
            dataObjList.addAll(newList);
            newObjsList.addAll(newList);

        } else if (dataObj instanceof RecordSetIFace) {
            //this.dataObj = dataObj;
            /*
            RecordSetIFace recordSet = (RecordSetIFace)dataObj;
                    
            DBTableIdMgr.getInstance().getInClause(recordSet);
            DBTableInfo tableInfo = DBTableIdMgr.getInstance().lookupInfoById(recordSet.getDbTableId());
                    
            DataProviderFactory.getInstance().evict(tableInfo.getClassObj());
                    
            //DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession();
                    
            String sqlStr = DBTableIdMgr.getInstance().getQueryForTable(recordSet);
            if (StringUtils.isNotBlank(sqlStr))
            {
            dataObjList =(List<Object>)session.getDataList(sqlStr);
            }
            */
        } else if (dataObj != null) {
            // single object
            dataObjList.add(dataObj);
            newObjsList.add(dataObj);
        }
    }

    setDataIntoUI();

    if (table != null) {
        table.tableChanged(new TableModelEvent(model));
    }
}

From source file:tv.phantombot.PhantomBot.java

public static void main(String[] args) throws IOException {
    // Move user files.
    moveUserConfig();//w w w.  j  a v  a2 s.co  m

    /* List of properties that must exist. */
    String requiredProperties[] = new String[] { "oauth", "channel", "owner", "user" };
    String requiredPropertiesErrorMessage = "";

    if (Float.valueOf(System.getProperty("java.specification.version")) < (float) 1.8
            || Float.valueOf(System.getProperty("java.specification.version")) >= (float) 1.9) {
        System.out.println("Detected Java " + System.getProperty("java.version") + ". "
                + "PhantomBot requires Java 8. Java 9 and above will NOT work.");
        System.exit(1);
    }

    /* Properties configuration */
    Properties startProperties = new Properties();

    /* Indicates that the botlogin.txt file should be overwritten/created. */
    Boolean changed = false;

    /* Print the user dir */
    com.gmt2001.Console.out.println("The working directory is: " + System.getProperty("user.dir"));

    com.gmt2001.Console.out.println("Detected Java " + System.getProperty("java.version") + " running on "
            + System.getProperty("os.name") + " " + System.getProperty("os.version") + " ("
            + System.getProperty("os.arch") + ")");

    /* If prompted, now that the version has been reported, exit. */
    if (args.length > 0) {
        if (args[0].equals("--version") || args[0].equals("-v")) {
            com.gmt2001.Console.out.println("PhantomBot Version: " + RepoVersion.getPhantomBotVersion() + " ("
                    + RepoVersion.getRepoVersion() + ")");
            System.exit(1);
        }
    }

    /* Load up the bot info from the bot login file */
    try {
        if (new File("./config/botlogin.txt").exists()) {
            FileInputStream inputStream = new FileInputStream("./config/botlogin.txt");
            startProperties.load(inputStream);
            inputStream.close();
        } else {
            /* Fill in the Properties object with some default values. Note that some values are left
             * unset to be caught in the upcoming logic to enforce settings.
             */
            startProperties.setProperty("baseport", "25000");
            startProperties.setProperty("usehttps", "false");
            startProperties.setProperty("webenable", "true");
            startProperties.setProperty("msglimit30", "19.0");
            startProperties.setProperty("musicenable", "true");
            startProperties.setProperty("whisperlimit60", "60.0");
        }
    } catch (IOException ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    } catch (Exception ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    }
    /* Load up the bot info from the environment */
    for (Entry<String, String> v : System.getenv().entrySet()) {
        String Prefix = "PHANTOMBOT_";
        String Key = v.getKey().toUpperCase();
        String Value = v.getValue();
        if (Key.startsWith(Prefix) && Prefix.length() < Key.length()) {
            Key = Key.substring(Prefix.length()).toLowerCase();
            startProperties.setProperty(Key, Value);
        }
    }
    /* Check to enable debug mode */
    if (startProperties.getProperty("debugon", "false").equals("true")) {
        com.gmt2001.Console.out.println("Debug Mode Enabled");
        PhantomBot.enableDebugging = true;
    }
    /* Check to enable debug to File */
    if (startProperties.getProperty("debuglog", "false").equals("true")) {
        com.gmt2001.Console.out.println("Debug Log Only Mode Enabled");
        PhantomBot.enableDebugging = true;
        PhantomBot.enableDebuggingLogOnly = true;
    }
    /* Check to enable Script Reloading */
    if (startProperties.getProperty("reloadscripts", "false").equals("true")) {
        com.gmt2001.Console.out.println("Enabling Script Reloading");
        PhantomBot.reloadScripts = true;
    }
    /* Check to enable Rhino Debugger */
    if (startProperties.getProperty("rhinodebugger", "false").equals("true")) {
        com.gmt2001.Console.out.println("Rhino Debugger will be launched if system supports it.");
        PhantomBot.enableRhinoDebugger = true;
    }
    /* Check to see if there's a webOauth set */
    if (startProperties.getProperty("webauth") == null) {
        startProperties.setProperty("webauth", generateWebAuth());
        com.gmt2001.Console.debug.println("New webauth key has been generated for ./config/botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a webOAuthRO set */
    if (startProperties.getProperty("webauthro") == null) {
        startProperties.setProperty("webauthro", generateWebAuth());
        com.gmt2001.Console.debug
                .println("New webauth read-only key has been generated for ./config/botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a panelUsername set */
    if (startProperties.getProperty("paneluser") == null) {
        com.gmt2001.Console.debug.println(
                "No Panel Username, using default value of 'panel' for Control Panel and YouTube Player");
        startProperties.setProperty("paneluser", "panel");
        changed = true;
    }
    /* Check to see if there's a panelPassword set */
    if (startProperties.getProperty("panelpassword") == null) {
        com.gmt2001.Console.debug.println(
                "No Panel Password, using default value of 'panel' for Control Panel and YouTube Player");
        startProperties.setProperty("panelpassword", "panel");
        changed = true;
    }
    /* Check to see if there's a youtubeOAuth set */
    if (startProperties.getProperty("ytauth") == null) {
        startProperties.setProperty("ytauth", generateWebAuth());
        com.gmt2001.Console.debug
                .println("New YouTube websocket key has been generated for ./config/botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a youtubeOAuthThro set */
    if (startProperties.getProperty("ytauthro") == null) {
        startProperties.setProperty("ytauthro", generateWebAuth());
        com.gmt2001.Console.debug
                .println("New YouTube read-only websocket key has been generated for ./config/botlogin.txt");
        changed = true;
    }

    /* Make a new botlogin with the botName, oauth or channel is not found */
    if (startProperties.getProperty("user") == null || startProperties.getProperty("oauth") == null
            || startProperties.getProperty("channel") == null) {
        try {

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("Welcome to the PhantomBot setup process!\r\n");
            com.gmt2001.Console.out.print(
                    "If you have any issues please report them on our forum, Tweet at us, or join our Discord!\r\n");
            com.gmt2001.Console.out.print("Forum: https://community.phantombot.tv/\r\n");
            com.gmt2001.Console.out.print("Documentation: https://docs.phantombot.tv/\r\n");
            com.gmt2001.Console.out.print("Twitter: https://twitter.com/PhantomBot/\r\n");
            com.gmt2001.Console.out.print("Discord: https://discord.gg/rkPqDuK/\r\n");
            com.gmt2001.Console.out.print("Support PhantomBot on Patreon: https://phantombot.tv/support/\r\n");
            com.gmt2001.Console.out.print("\r\n");

            final String os = System.getProperty("os.name").toLowerCase();

            // Detect Windows, MacOS, Linux or any other operating system.
            if (os.startsWith("win")) {
                com.gmt2001.Console.out
                        .print("PhantomBot has detected that your device is running Windows.\r\n");
                com.gmt2001.Console.out.print(
                        "Here's the setup guide for Windows: https://community.phantombot.tv/t/windows-setup-guide/");
            } else if (os.startsWith("mac")) {
                com.gmt2001.Console.out.print("PhantomBot has detected that your device is running macOS.\r\n");
                com.gmt2001.Console.out.print(
                        "Here's the setup guide for macOS: https://community.phantombot.tv/t/macos-setup-guide/");
            } else {
                com.gmt2001.Console.out.print("PhantomBot has detected that your device is running Linux.\r\n");
                com.gmt2001.Console.out.print(
                        "Here's the setup guide for Ubuntu: https://community.phantombot.tv/t/ubuntu-16-04-lts-setup-guide/\r\n");
                com.gmt2001.Console.out.print(
                        "Here's the setup guide for CentOS: https://community.phantombot.tv/t/centos-7-setup-guide/");
            }

            com.gmt2001.Console.out.print("\r\n\r\n\r\n");

            // Bot name.
            do {
                com.gmt2001.Console.out.print("1. Please enter the bot's Twitch username: ");

                startProperties.setProperty("user", System.console().readLine().trim().toLowerCase());
            } while (startProperties.getProperty("user", "").length() <= 0);

            // Twitch oauth.
            do {
                com.gmt2001.Console.out.print("\r\n");
                com.gmt2001.Console.out
                        .print("2. You will now need a OAuth token for the bot to be able to chat.\r\n");
                com.gmt2001.Console.out.print(
                        "Please note, this OAuth token needs to be generated while you're logged in into the bot's Twitch account.\r\n");
                com.gmt2001.Console.out.print(
                        "If you're not logged in as the bot, please go to https://twitch.tv/ and login as the bot.\r\n");
                com.gmt2001.Console.out
                        .print("Get the bot's OAuth token here: https://twitchapps.com/tmi/\r\n");
                com.gmt2001.Console.out.print("Please enter the bot's OAuth token: ");

                startProperties.setProperty("oauth", System.console().readLine().trim());
            } while (startProperties.getProperty("oauth", "").length() <= 0);

            // api oauth.
            do {
                com.gmt2001.Console.out.print("\r\n");
                com.gmt2001.Console.out.print(
                        "3. You will now need your channel OAuth token for the bot to be able to change your title and game.\r\n");
                com.gmt2001.Console.out.print(
                        "Please note, this OAuth token needs to be generated while you're logged in into your caster account.\r\n");
                com.gmt2001.Console.out.print(
                        "If you're not logged in as the caster, please go to https://twitch.tv/ and login as the caster.\r\n");
                com.gmt2001.Console.out
                        .print("Get the your OAuth token here: https://phantombot.tv/oauth/\r\n");
                com.gmt2001.Console.out.print("Please enter your OAuth token: ");

                startProperties.setProperty("apioauth", System.console().readLine().trim());
            } while (startProperties.getProperty("apioauth", "").length() <= 0);

            // Channel name.
            do {
                com.gmt2001.Console.out.print("\r\n");
                com.gmt2001.Console.out
                        .print("4. Please enter the name of the Twitch channel the bot should join: ");

                startProperties.setProperty("channel", System.console().readLine().trim());
            } while (startProperties.getProperty("channel", "").length() <= 0);

            // Panel username.
            do {
                com.gmt2001.Console.out.print("\r\n");
                com.gmt2001.Console.out.print("5. Please enter a custom username for the web panel: ");

                startProperties.setProperty("paneluser", System.console().readLine().trim());
            } while (startProperties.getProperty("paneluser", "").length() <= 0);

            // Panel password.
            do {
                com.gmt2001.Console.out.print("\r\n");
                com.gmt2001.Console.out.print("6. Please enter a custom password for the web panel: ");

                startProperties.setProperty("panelpassword", System.console().readLine().trim());
            } while (startProperties.getProperty("panelpassword", "").length() <= 0);

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("PhantomBot will launch in 10 seconds.\r\n");
            com.gmt2001.Console.out.print(
                    "If you're hosting the bot locally you can access the control panel here: http://localhost:25000/panel \r\n");
            com.gmt2001.Console.out.print(
                    "If you're running the bot on a server, make sure to open the following ports: \r\n");
            com.gmt2001.Console.out.print(
                    "25000, 25003, and 25004. You have to change 'localhost' to your server ip to access the panel. \r\n");

            try {
                Thread.sleep(10000);
            } catch (InterruptedException ex) {
                com.gmt2001.Console.debug.println("Failed to sleep in setup: " + ex.getMessage());
            }

            changed = true;
            newSetup = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
            com.gmt2001.Console.out.println("[ERROR] Failed to setup PhantomBot. Now exiting...");
            System.exit(0);
        }
    }

    /* Make sure the oauth has been set correctly */
    if (startProperties.getProperty("oauth") != null) {
        if (!startProperties.getProperty("oauth").startsWith("oauth")
                && !startProperties.getProperty("oauth").isEmpty()) {
            startProperties.setProperty("oauth", "oauth:" + startProperties.getProperty("oauth"));
            changed = true;
        }
    }

    /* Make sure the apiOAuth has been set correctly */
    if (startProperties.getProperty("apioauth") != null) {
        if (!startProperties.getProperty("apioauth").startsWith("oauth")
                && !startProperties.getProperty("apioauth").isEmpty()) {
            startProperties.setProperty("apioauth", "oauth:" + startProperties.getProperty("apioauth"));
            changed = true;
        }
    }

    /* Make sure the channelName does not have a # */
    if (startProperties.getProperty("channel").startsWith("#")) {
        startProperties.setProperty("channel", startProperties.getProperty("channel").substring(1));
        changed = true;
    } else if (startProperties.getProperty("channel").contains(".tv")) {
        startProperties.setProperty("channel", startProperties.getProperty("channel")
                .substring(startProperties.getProperty("channel").indexOf(".tv/") + 4).replaceAll("/", ""));
        changed = true;
    }

    /* Check for the owner after the channel check is done. */
    if (startProperties.getProperty("owner") == null) {
        if (startProperties.getProperty("channel") != null) {
            if (!startProperties.getProperty("channel").isEmpty()) {
                startProperties.setProperty("owner", startProperties.getProperty("channel"));
                changed = true;
            }
        }
    }

    /* Iterate the properties and delete entries for anything that does not have a
     * value.
     */
    for (String propertyKey : startProperties.stringPropertyNames()) {
        if (startProperties.getProperty(propertyKey).isEmpty()) {
            changed = true;
            startProperties.remove(propertyKey);
        }
    }

    /*
     * Check for required settings.
     */
    for (String requiredProperty : requiredProperties) {
        if (startProperties.getProperty(requiredProperty) == null) {
            requiredPropertiesErrorMessage += requiredProperty + " ";
        }
    }

    if (!requiredPropertiesErrorMessage.isEmpty()) {
        com.gmt2001.Console.err.println();
        com.gmt2001.Console.err.println("Missing Required Properties: " + requiredPropertiesErrorMessage);
        com.gmt2001.Console.err.println("Exiting PhantomBot");
        System.exit(0);
    }

    /* Check to see if anything changed */
    if (changed) {
        Properties outputProperties = new Properties() {
            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(new TreeSet<>(super.keySet()));
            }
        };

        try {
            try (FileOutputStream outputStream = new FileOutputStream("./config/botlogin.txt")) {
                outputProperties.putAll(startProperties);
                outputProperties.store(outputStream, "PhantomBot Configuration File");
            }
        } catch (IOException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Start PhantomBot */
    PhantomBot.instance = new PhantomBot(startProperties);
}

From source file:me.mast3rplan.phantombot.PhantomBot.java

@Subscribe
public void consoleInput(ConsoleInputEvent event) {
    String message = event.getMsg();
    Boolean changed = false;/*from ww  w  . j  a v  a 2  s .  co m*/
    Boolean reset = false;
    String arguments;
    String[] argument = null;

    /* Check to see if the message is null or has nothing in it */
    if (message == null || message.isEmpty()) {
        return;
    }

    /* Check for arguments */
    if (message.contains(" ")) {
        String messageString = message;
        message = messageString.substring(0, messageString.indexOf(" "));
        arguments = messageString.substring(messageString.indexOf(" ") + 1);
        argument = arguments.split(" ");
    }

    if (message.equalsIgnoreCase("ankhtophantombot")) {
        print("Not all of AnkhBot's data will be compatible with PhantomBot.");
        print("This process will take a long time.");
        print("Are you sure you want to convert AnkhBot's data to PhantomBot? [y/n]");
        String check = System.console().readLine().trim();
        if (check.equals("y")) {
            AnkhConverter.instance();
        } else {
            print("No changes were made.");
            return;
        }
    }

    if (message.equalsIgnoreCase("backupdb")) {
        SimpleDateFormat datefmt = new SimpleDateFormat("ddMMyyyy.hhmmss");
        datefmt.setTimeZone(TimeZone.getTimeZone(timeZone));
        String timestamp = datefmt.format(new Date());

        dataStore.backupSQLite3("phantombot.manual.backup." + timestamp + ".db");
        return;
    }

    /* Update the followed (followers) table. */
    if (message.equalsIgnoreCase("fixfollowedtable")) {
        TwitchAPIv3.instance().FixFollowedTable(channelName, dataStore, false);
        return;
    }

    /* Update the followed (followers) table - forced. */
    if (message.equalsIgnoreCase("fixfollowedtable-force")) {
        TwitchAPIv3.instance().FixFollowedTable(channelName, dataStore, true);
        return;
    }

    if (message.equalsIgnoreCase("jointest")) {
        for (int i = 0; i < 30; i++) {
            EventBus.instance()
                    .postAsync(new IrcChannelJoinEvent(this.session, this.channel, generateRandomString(8)));
        }
    }

    /* tests a follow event */
    if (message.equalsIgnoreCase("followertest")) {
        String randomUser = generateRandomString(10);
        print("[CONSOLE] Executing followertest (User: " + randomUser + ")");
        EventBus.instance()
                .postAsync(new TwitchFollowEvent(randomUser, PhantomBot.getChannel(this.channelName)));
        return;
    }

    /* tests multiple follows */
    if (message.equalsIgnoreCase("followerstest")) {
        String randomUser = generateRandomString(10);
        int followCount = 5;

        if (argument != null) {
            followCount = Integer.parseInt(argument[0]);
        }

        print("[CONSOLE] Executing followerstest (Count: " + followCount + ", User: " + randomUser + ")");
        for (int i = 0; i < followCount; i++) {
            EventBus.instance().postAsync(
                    new TwitchFollowEvent(randomUser + "_" + i, PhantomBot.getChannel(this.channelName)));
        }
        return;
    }

    /* Test a subscriber event */
    if (message.equalsIgnoreCase("subscribertest")) {
        String randomUser = generateRandomString(10);
        print("[CONSOLE] Executing subscribertest (User: " + randomUser + ")");
        EventBus.instance().postAsync(new NewSubscriberEvent(PhantomBot.getSession(this.channelName),
                PhantomBot.getChannel(this.channelName), randomUser));
        return;
    }

    /* Test a prime subscriber event */
    if (message.equalsIgnoreCase("primesubscribertest")) {
        String randomUser = generateRandomString(10);
        print("[CONSOLE] Executing primesubscribertest (User: " + randomUser + ")");
        EventBus.instance().postAsync(new NewPrimeSubscriberEvent(PhantomBot.getSession(this.channelName),
                PhantomBot.getChannel(this.channelName), randomUser));
        return;
    }

    /* Test a resubscriber event */
    if (message.equalsIgnoreCase("resubscribertest")) {
        String randomUser = generateRandomString(10);
        print("[CONSOLE] Executing resubscribertest (User: " + randomUser + ")");
        EventBus.instance().postAsync(new NewReSubscriberEvent(PhantomBot.getSession(this.channelName),
                PhantomBot.getChannel(this.channelName), randomUser, "10"));
        return;
    }

    /* Test the online event */
    if (message.equalsIgnoreCase("onlinetest")) {
        print("[CONSOLE] Executing onlinetest");
        EventBus.instance().postAsync(new TwitchOnlineEvent(PhantomBot.getChannel(this.channelName)));
        return;
    }

    /* Test the offline event */
    if (message.equalsIgnoreCase("offlinetest")) {
        print("[CONSOLE] Executing offlinetest");
        EventBus.instance().postAsync(new TwitchOfflineEvent(PhantomBot.getChannel(this.channelName)));
        return;
    }

    /* Test the host event */
    if (message.equalsIgnoreCase("hosttest")) {
        print("[CONSOLE] Executing hosttest");
        EventBus.instance()
                .postAsync(new TwitchHostedEvent(this.botName, PhantomBot.getChannel(this.channelName)));
        return;
    }

    /* test the gamewisp subscriber event */
    if (message.equalsIgnoreCase("gamewispsubscribertest")) {
        print("[CONSOLE] Executing gamewispsubscribertest");
        EventBus.instance().postAsync(new GameWispSubscribeEvent(this.botName, 1));
        return;
    }

    /* test the gamewisp resubscriber event */
    if (message.equalsIgnoreCase("gamewispresubscribertest")) {
        print("[CONSOLE] Executing gamewispresubscribertest");
        EventBus.instance().postAsync(new GameWispAnniversaryEvent(this.botName, 2));
        return;
    }

    /* test the bits event */
    if (message.equalsIgnoreCase("bitstest")) {
        print("[CONSOLE] Executing bitstest");
        EventBus.instance().postAsync(new BitsEvent(PhantomBot.getSession(this.channelName),
                PhantomBot.getChannel(this.channelName), this.botName, "100"));
        return;
    }

    /* enables debug mode */
    if (message.equalsIgnoreCase("debugon")) {
        print("[CONSOLE] Executing debugon: Enable Debug Mode");
        PhantomBot.setDebugging(true);
        return;
    }

    /* disables debug mode - note that setDebuggingLogOnly() completely disables all debugging */
    if (message.equalsIgnoreCase("debugoff")) {
        print("[CONSOLE] Executing debugoff: Disable Debug Mode");
        PhantomBot.setDebuggingLogOnly(false);
        return;
    }

    /* enables debug mode - log only */
    if (message.equalsIgnoreCase("debuglog")) {
        print("[CONSOLE] Executing debuglog: Enable Debug Mode - Log Only");
        PhantomBot.setDebuggingLogOnly(true);
        return;
    }

    /* Reset the bot login */
    if (message.equalsIgnoreCase("reset")) {
        print("Are you sure you want to reset the bot login? [y/n]");
        String check = System.console().readLine().trim();
        if (check.equals("y")) {
            reset = true;
            changed = true;
        } else {
            print("No changes were made.");
            return;
        }
    }

    /* Change the apiOAuth token */
    if (message.equalsIgnoreCase("apioauth")) {
        System.out.print(
                "Please enter you're oauth token that you generated from https://phantombot.tv/oauth while logged as the caster: ");
        apiOAuth = System.console().readLine().trim();
        pbProperties.setProperty("apioauth", apiOAuth);
        changed = true;
    }

    /* Setup for MySql */
    if (message.equalsIgnoreCase("mysqlsetup")) {
        try {
            print("");
            print("PhantomBot MySQL setup.");
            print("");

            com.gmt2001.Console.out.print("Please enter your MySQL host name: ");
            mySqlHost = System.console().readLine().trim();
            pbProperties.setProperty("mysqlhost", mySqlHost);

            com.gmt2001.Console.out.print("Please enter your MySQL port: ");
            mySqlPort = System.console().readLine().trim();
            pbProperties.setProperty("mysqlport", mySqlPort);

            com.gmt2001.Console.out.print("Please enter your MySQL db name: ");
            mySqlName = System.console().readLine().trim();
            pbProperties.setProperty("mysqlname", mySqlName);

            com.gmt2001.Console.out.print("Please enter a username for MySQL: ");
            mySqlUser = System.console().readLine().trim();
            pbProperties.setProperty("mysqluser", mySqlUser);

            com.gmt2001.Console.out.print("Please enter a password for MySQL: ");
            mySqlPass = System.console().readLine().trim();
            pbProperties.setProperty("mysqlpass", mySqlPass);

            dataStoreType = "MySQLStore";
            pbProperties.setProperty("datastore", dataStoreType);

            print("PhantomBot MySQL setup done, PhantomBot will exit.");
            changed = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Setup for GameWisp */
    if (message.equalsIgnoreCase("gamewispsetup")) {
        try {
            print("");
            print("PhantomBot GameWisp setup.");
            print("");

            com.gmt2001.Console.out.print("Please enter your GameWisp OAuth key: ");
            gameWispOAuth = System.console().readLine().trim();
            pbProperties.setProperty("gamewispauth", gameWispOAuth);

            com.gmt2001.Console.out.print("Please enter your GameWisp refresh key: ");
            gameWispRefresh = System.console().readLine().trim();
            pbProperties.setProperty("gamewisprefresh", gameWispRefresh);

            print("PhantomBot GameWisp setup done, PhantomBot will exit.");
            changed = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Setup for StreamLabs (TwitchAlerts) */
    if (message.equalsIgnoreCase("streamlabssetup")) {
        try {
            print("");
            print("PhantomBot StreamLabs setup.");
            print("");

            com.gmt2001.Console.out.print("Please enter your StreamLabs OAuth key: ");
            twitchAlertsKey = System.console().readLine().trim();
            pbProperties.setProperty("twitchalertskey", twitchAlertsKey);

            print("PhantomBot StreamLabs setup done, PhantomBot will exit.");
            changed = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Setup for StreamTip */
    if (message.equalsIgnoreCase("streamtipsetup")) {
        try {
            print("");
            print("PhantomBot StreamTip setup.");
            print("");

            com.gmt2001.Console.out.print("Please enter your StreamTip Api OAuth: ");
            streamTipOAuth = System.console().readLine().trim();
            pbProperties.setProperty("streamtipkey", streamTipOAuth);

            com.gmt2001.Console.out.print("Please enter your StreamTip Client Id: ");
            streamTipClientId = System.console().readLine().trim();
            pbProperties.setProperty("streamtipid", streamTipClientId);

            print("PhantomBot StreamTip setup done, PhantomBot will exit.");
            changed = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Setup for TipeeeStream */
    if (message.equalsIgnoreCase("tipeeestreamsetup")) {
        try {
            print("");
            print("PhantomBot TipeeeStream setup.");
            print("");

            com.gmt2001.Console.out.print("Please enter your TipeeeStream Api OAuth: ");
            tipeeeStreamOAuth = System.console().readLine().trim();
            pbProperties.setProperty("tipeeestreamkey", tipeeeStreamOAuth);

            print("PhantomBot TipeeeStream setup done, PhantomBot will exit.");
            changed = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Setup the web panel login info */
    if (message.equalsIgnoreCase("panelsetup")) {
        try {
            print("");
            print("PhantomBot Web Panel setup.");
            print("Note: Do not use any ascii characters in your username of password.");
            print("");

            com.gmt2001.Console.out.print("Please enter a username of your choice: ");
            panelUsername = System.console().readLine().trim();
            pbProperties.setProperty("paneluser", panelUsername);

            com.gmt2001.Console.out.print("Please enter a password of your choice: ");
            panelPassword = System.console().readLine().trim();
            pbProperties.setProperty("panelpassword", panelPassword);

            print("PhantomBot Web Panel setup done, PhantomBot will exit.");
            changed = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Setup for Twitter */
    if (message.equalsIgnoreCase("twittersetup")) {
        try {
            print("");
            print("PhantomBot Twitter setup.");
            print("");

            com.gmt2001.Console.out.print("Please enter your Twitter username: ");
            twitterUsername = System.console().readLine().trim();
            pbProperties.setProperty("twitterUser", twitterUsername);

            com.gmt2001.Console.out.print("Please enter your consumer key: ");
            twitterConsumerToken = System.console().readLine().trim();
            pbProperties.setProperty("twitter_consumer_key", twitterConsumerToken);

            com.gmt2001.Console.out.print("Please enter your consumer secret: ");
            twitterConsumerSecret = System.console().readLine().trim();
            pbProperties.setProperty("twitter_consumer_secret", twitterConsumerSecret);

            com.gmt2001.Console.out.print("Please enter your access token: ");
            twitterAccessToken = System.console().readLine().trim();
            pbProperties.setProperty("twitter_access_token", twitterAccessToken);

            com.gmt2001.Console.out.print("Please enter your access token secret: ");
            twitterSecretToken = System.console().readLine().trim();
            pbProperties.setProperty("twitter_secret_token", twitterSecretToken);

            /* Delete the old Twitter file if it exists */
            try {
                File f = new File("./twitter.txt");
                f.delete();
            } catch (NullPointerException ex) {
                com.gmt2001.Console.debug.println(ex);
            }

            print("PhantomBot Twitter setup done, PhantomBot will exit.");
            changed = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Check to see if any settings have been changed */
    if (changed && !reset) {
        Properties outputProperties = new Properties() {
            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(new TreeSet<>(super.keySet()));
            }
        };

        try {
            try (FileOutputStream outputStream = new FileOutputStream("botlogin.txt")) {
                outputProperties.putAll(pbProperties);
                outputProperties.store(outputStream, "PhantomBot Configuration File");
            }

            dataStore.SaveAll(true);

            print("");
            print("Changes have been saved, now exiting PhantomBot.");
            print("");
            System.exit(0);
        } catch (IOException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
        return;
    }

    /* Save everything */
    if (message.equalsIgnoreCase("save")) {
        print("[CONSOLE] Executing save");
        dataStore.SaveAll(true);
        return;
    }

    /* Exit phantombot */
    if (message.equalsIgnoreCase("exit")) {
        print("[CONSOLE] Executing exit");
        System.exit(0);
        return;
    }

    /* handle any other commands */
    handleCommand(botName, event.getMsg(), PhantomBot.getChannel(this.channelName));
    // Need to support channel here. command (channel) argument[1]

    /* Handle dev commands */
    if (event.getMsg().startsWith("!debug !dev")) {
        devDebugCommands(event.getMsg(), "no_id", botName, true);
    }
}

From source file:tv.phantombot.PhantomBot.java

public void updateGameWispTokens(String[] newTokens) {
    Properties outputProperties = new Properties() {
        @Override/* w w  w.  j a v  a  2s.  c  o  m*/
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<>(super.keySet()));
        }
    };

    gameWispOAuth = newTokens[0];
    gameWispRefresh = newTokens[1];

    pbProperties.setProperty("gamewispauth", newTokens[0]);
    pbProperties.setProperty("gamewisprefresh", newTokens[1]);

    try {
        try (FileOutputStream outputStream = new FileOutputStream("./config/botlogin.txt")) {
            outputProperties.putAll(pbProperties);
            outputProperties.store(outputStream, "PhantomBot Configuration File");
        }
        print("GameWisp Token has been refreshed.");
    } catch (IOException ex) {
        com.gmt2001.Console.err.println(
                "!!!! CRITICAL !!!! Failed to update GameWisp Refresh Tokens into ./config/botlogin.txt! Must manually add!");
        com.gmt2001.Console.err.println(
                "!!!! CRITICAL !!!! gamewispauth = " + newTokens[0] + " gamewisprefresh = " + newTokens[1]);
    }

    SingularityAPI.instance().setAccessToken(gameWispOAuth);
}

From source file:me.mast3rplan.phantombot.PhantomBot.java

public static void main(String[] args) throws IOException {
    /* List of properties that must exist. */
    String requiredProperties[] = new String[] { "oauth", "channel", "owner", "user" };
    String requiredPropertiesErrorMessage = "";

    /* Properties configuration */
    Properties startProperties = new Properties();

    /* Indicates that the botlogin.txt file should be overwritten/created. */
    Boolean changed = false;//ww  w  .ja v  a 2 s . co  m

    /* Print the user dir */
    com.gmt2001.Console.out.println("The working directory is: " + System.getProperty("user.dir"));

    /* Load up the bot info from the bot login file */
    try {
        if (new File("./botlogin.txt").exists()) {
            try {
                FileInputStream inputStream = new FileInputStream("botlogin.txt");
                startProperties.load(inputStream);
                inputStream.close();

                if (startProperties.getProperty("debugon", "false").equals("true")) {
                    com.gmt2001.Console.out.println("Debug Mode Enabled via botlogin.txt");
                    PhantomBot.enableDebugging = true;
                }

                if (startProperties.getProperty("debuglog", "false").equals("true")) {
                    com.gmt2001.Console.out.println("Debug Log Only Mode Enabled via botlogin.txt");
                    PhantomBot.enableDebugging = true;
                    PhantomBot.enableDebuggingLogOnly = true;
                }

                if (startProperties.getProperty("reloadscripts", "false").equals("true")) {
                    com.gmt2001.Console.out.println("Enabling Script Reloading");
                    PhantomBot.reloadScripts = true;
                }
                if (startProperties.getProperty("rhinodebugger", "false").equals("true")) {
                    com.gmt2001.Console.out.println("Rhino Debugger will be launched if system supports it.");
                    PhantomBot.enableRhinoDebugger = true;
                }
            } catch (IOException ex) {
                com.gmt2001.Console.err.printStackTrace(ex);
            }
        } else {

            /* Fill in the Properties object with some default values. Note that some values are left 
             * unset to be caught in the upcoming logic to enforce settings.
             */
            startProperties.setProperty("baseport", "25000");
            startProperties.setProperty("usehttps", "false");
            startProperties.setProperty("webenable", "true");
            startProperties.setProperty("msglimit30", "18.75");
            startProperties.setProperty("musicenable", "true");
            startProperties.setProperty("whisperlimit60", "60.0");
        }
    } catch (Exception ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    }

    /* Check to see if there's a webOauth set */
    if (startProperties.getProperty("webauth") == null) {
        startProperties.setProperty("webauth", generateWebAuth());
        com.gmt2001.Console.debug.println("New webauth key has been generated for botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a webOAuthRO set */
    if (startProperties.getProperty("webauthro") == null) {
        startProperties.setProperty("webauthro", generateWebAuth());
        com.gmt2001.Console.debug.println("New webauth read-only key has been generated for botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a panelUsername set */
    if (startProperties.getProperty("paneluser") == null) {
        com.gmt2001.Console.debug.println(
                "No Panel Username, using default value of 'panel' for Control Panel and YouTube Player");
        startProperties.setProperty("paneluser", "panel");
        changed = true;
    }
    /* Check to see if there's a panelPassword set */
    if (startProperties.getProperty("panelpassword") == null) {
        com.gmt2001.Console.debug.println(
                "No Panel Password, using default value of 'panel' for Control Panel and YouTube Player");
        startProperties.setProperty("panelpassword", "panel");
        changed = true;
    }
    /* Check to see if there's a youtubeOAuth set */
    if (startProperties.getProperty("ytauth") == null) {
        startProperties.setProperty("ytauth", generateWebAuth());
        com.gmt2001.Console.debug.println("New YouTube websocket key has been generated for botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a youtubeOAuthThro set */
    if (startProperties.getProperty("ytauthro") == null) {
        startProperties.setProperty("ytauthro", generateWebAuth());
        com.gmt2001.Console.debug
                .println("New YouTube read-only websocket key has been generated for botlogin.txt");
        changed = true;
    }

    /* Make a new botlogin with the botName, oauth or channel is not found */
    if (startProperties.getProperty("user") == null || startProperties.getProperty("oauth") == null
            || startProperties.getProperty("channel") == null) {
        try {
            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("Welcome to the PhantomBot setup process!\r\n");
            com.gmt2001.Console.out
                    .print("If you have any issues please report them on our forum or Tweet at us!\r\n");
            com.gmt2001.Console.out.print("Forum: https://community.phantombot.tv/\r\n");
            com.gmt2001.Console.out.print("Twitter: https://twitter.com/phantombotapp/\r\n");
            com.gmt2001.Console.out.print("PhantomBot Knowledgebase: https://docs.phantombot.tv/\r\n");
            com.gmt2001.Console.out.print("PhantomBot WebPanel: https://docs.phantombot.tv/kb/panel/\r\n");
            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("\r\n");

            com.gmt2001.Console.out.print("1. Please enter the bot's Twitch username: ");
            startProperties.setProperty("user", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out
                    .print("2. You will now need a OAuth token for the bot to be able to chat.\r\n");
            com.gmt2001.Console.out.print(
                    "Please note, this OAuth token needs to be generated while you're logged in into the bot's Twitch account.\r\n");
            com.gmt2001.Console.out.print(
                    "If you're not logged in as the bot, please go to https://twitch.tv/ and login as the bot.\r\n");
            com.gmt2001.Console.out.print("Get the bot's OAuth token here: https://twitchapps.com/tmi/\r\n");
            com.gmt2001.Console.out.print("Please enter the bot's OAuth token: ");
            startProperties.setProperty("oauth", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print(
                    "3. You will now need your channel OAuth token for the bot to be able to change your title and game.\r\n");
            com.gmt2001.Console.out.print(
                    "Please note, this OAuth token needs to be generated while you're logged in into your caster account.\r\n");
            com.gmt2001.Console.out.print(
                    "If you're not logged in as the caster, please go to https://twitch.tv/ and login as the caster.\r\n");
            com.gmt2001.Console.out.print("Get the your OAuth token here: https://phantombot.tv/oauth/\r\n");
            com.gmt2001.Console.out.print("Please enter your OAuth token: ");
            startProperties.setProperty("apioauth", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out
                    .print("4. Please enter the name of the Twitch channel the bot should join: ");
            startProperties.setProperty("channel", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("5. Please enter a custom username for the web panel: ");
            startProperties.setProperty("paneluser", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("6. Please enter a custom password for the web panel: ");
            startProperties.setProperty("panelpassword", System.console().readLine().trim());

            changed = true;
            newSetup = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
            com.gmt2001.Console.out.println("[ERROR] Failed to setup PhantomBot. Now exiting...");
            System.exit(0);
        }
    }

    /* Make sure the oauth has been set correctly */
    if (startProperties.getProperty("oauth") != null) {
        if (!startProperties.getProperty("oauth").startsWith("oauth")
                && !startProperties.getProperty("oauth").isEmpty()) {
            startProperties.setProperty("oauth", "oauth:" + startProperties.getProperty("oauth"));
            changed = true;
        }
    }

    /* Make sure the apiOAuth has been set correctly */
    if (startProperties.getProperty("apioauth") != null) {
        if (!startProperties.getProperty("apioauth").startsWith("oauth")
                && !startProperties.getProperty("apioauth").isEmpty()) {
            startProperties.setProperty("apioauth", "oauth:" + startProperties.getProperty("apioauth"));
            changed = true;
        }
    }

    /* Make sure the channelName does not have a # */
    if (startProperties.getProperty("channel").startsWith("#")) {
        startProperties.setProperty("channel", startProperties.getProperty("channel").substring(1));
        changed = true;
    } else if (startProperties.getProperty("channel").contains(".tv")) {
        startProperties.setProperty("channel", startProperties.getProperty("channel")
                .substring(startProperties.getProperty("channel").indexOf(".tv/") + 4).replaceAll("/", ""));
        changed = true;
    }

    /* Check for the owner after the channel check is done. */
    if (startProperties.getProperty("owner") == null) {
        if (startProperties.getProperty("channel") != null) {
            if (!startProperties.getProperty("channel").isEmpty()) {
                startProperties.setProperty("owner", startProperties.getProperty("channel"));
                changed = true;
            }
        }
    }

    /* Iterate the properties and delete entries for anything that does not have a 
     * value.
     */
    for (String propertyKey : startProperties.stringPropertyNames()) {
        if (startProperties.getProperty(propertyKey).isEmpty()) {
            changed = true;
            startProperties.remove(propertyKey);
        }
    }

    /* 
     * Check for required settings.
     */
    for (String requiredProperty : requiredProperties) {
        if (startProperties.getProperty(requiredProperty) == null) {
            requiredPropertiesErrorMessage += requiredProperty + " ";
        }
    }

    if (!requiredPropertiesErrorMessage.isEmpty()) {
        com.gmt2001.Console.err.println();
        com.gmt2001.Console.err.println("Missing Required Properties: " + requiredPropertiesErrorMessage);
        com.gmt2001.Console.err.println("Exiting PhantomBot");
        System.exit(0);
    }

    /* Check to see if anything changed */
    if (changed) {
        Properties outputProperties = new Properties() {
            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(new TreeSet<>(super.keySet()));
            }
        };

        try {
            try (FileOutputStream outputStream = new FileOutputStream("botlogin.txt")) {
                outputProperties.putAll(startProperties);
                outputProperties.store(outputStream, "PhantomBot Configuration File");
            }
        } catch (IOException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Start PhantomBot */
    PhantomBot.instance = new PhantomBot(startProperties);
}

From source file:org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpointTest.java

private void mockHttpRequest(final Map<String, String[]> requestParams,
        final Map<String, Object> requestAttributes, String method) {
    doAnswer(new Answer<Object>() {
        @Override//from  ww w.  j a  v a  2 s  .com
        public Object answer(InvocationOnMock invocation) {
            String key = (String) invocation.getArguments()[0];
            return requestParams.get(key) != null ? requestParams.get(key)[0] : null;
        }
    }).when(httpServletRequest).getParameter(anyString());

    doAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            String key = (String) invocation.getArguments()[0];
            return requestAttributes.get(key);
        }
    }).when(httpServletRequest).getAttribute(anyString());

    doAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            String key = (String) invocation.getArguments()[0];
            Object value = invocation.getArguments()[1];
            requestAttributes.put(key, value);
            return null;
        }
    }).when(httpServletRequest).setAttribute(anyString(), Matchers.anyObject());

    when(httpServletRequest.getParameterMap()).thenReturn(requestParams);
    when(httpServletRequest.getParameterNames())
            .thenReturn(Collections.enumeration(requestAttributes.keySet()));
    when(httpServletRequest.getSession()).thenReturn(httpSession);
    when(httpServletRequest.getMethod()).thenReturn(method);
    when(httpServletRequest.getContentType()).thenReturn(OAuth.ContentType.URL_ENCODED);

    String authHeader = "Basic Y2ExOWE1NDBmNTQ0Nzc3ODYwZTQ0ZTc1ZjYwNWQ5Mjc6ODduOWE1NDBmNTQ0Nzc3ODYwZTQ0ZTc1ZjYwNWQ0MzU=";
    when(httpServletRequest.getHeader("Authorization")).thenReturn(authHeader);
}

From source file:me.mast3rplan.phantombot.PhantomBot.java

public void updateGameWispTokens(String[] newTokens) {
    Properties outputProperties = new Properties() {
        @Override//from w w  w  . jav  a  2s . com
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<>(super.keySet()));
        }
    };

    gameWispOAuth = newTokens[0];
    gameWispRefresh = newTokens[1];

    pbProperties.setProperty("gamewispauth", newTokens[0]);
    pbProperties.setProperty("gamewisprefresh", newTokens[1]);

    try {
        try (FileOutputStream outputStream = new FileOutputStream("botlogin.txt")) {
            outputProperties.putAll(pbProperties);
            outputProperties.store(outputStream, "PhantomBot Configuration File");
        }
        print("GameWisp Token has been refreshed.");
    } catch (IOException ex) {
        com.gmt2001.Console.err.println(
                "!!!! CRITICAL !!!! Failed to update GameWisp Refresh Tokens into botlogin.txt! Must manually add!");
        com.gmt2001.Console.err.println(
                "!!!! CRITICAL !!!! gamewispauth = " + newTokens[0] + " gamewisprefresh = " + newTokens[1]);
    }

    SingularityAPI.instance().setAccessToken(gameWispOAuth);
}

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

/**
 * Set the datObj into the form but controls 
 * @param dataObj the data object/*from  www  .  j  a  v a2 s. c o  m*/
 * @param alreadyInTheList indicates whether this dataObj is already in the list of data objects we are working with
 */
@SuppressWarnings("unchecked")
protected void setDataObj(final Object dataObj, final boolean alreadyInTheList) {
    // Setting up Carry Forward Object when the object already exists
    // usually from a search
    if (dataObj instanceof FormDataObjIFace && ((FormDataObjIFace) dataObj).getId() != null) {
        carryFwdDataObj = dataObj;
    }

    //log.debug("Setting DataObj["+dataObj+"]");

    // rods - Added 3/21/08 because switching from the Grid View
    // back to the Form View causes the "+" button to be disabled and this
    // is because it thinks it is a newly created object for some reason
    isNewlyCreatedDataObj = false;

    // Convert the Set over to a List so the RecordController can be used
    Object data = dataObj;
    if (!alreadyInTheList) {
        if (data instanceof java.util.Set) {
            origDataSet = (Set) dataObj;
            List newList = Collections.list(Collections.enumeration(origDataSet));
            data = newList;

            if (newList.size() > 0) {
                if (newList.get(0) instanceof Comparable<?>) {
                    Collections.sort(newList);
                }
            }
        }
    }

    // If there is a formValidator then we set the current object into the formValidator's scripting context
    // then turn off change notification while the form is filled
    if (formValidator != null && dataObj != null) {
        formValidator.addRuleObjectMapping("dataObj", dataObj);
    }

    if (selectorCBX != null) {
        selectorCBX.setEnabled(true);
    }

    boolean isList;
    boolean isVector;
    // if we do have a list then get the first object or null
    if (data instanceof Vector) {
        isList = true;
        isVector = true;

    } else if (data instanceof List) {
        isList = true;
        isVector = false;
    } else {
        isList = false;
        isVector = false;
    }

    for (FVOFieldInfo fieldInfo : controlsById.values()) {
        if (fieldInfo.isOfType(FormCellIFace.CellType.subview)
                || fieldInfo.isOfType(FormCellIFace.CellType.iconview)) {
            MultiView mv = fieldInfo.getSubView();
            if (mv != null) {
                mv.setParentDataObj(null);

            } else {
                ((SubViewBtn) fieldInfo.getComp()).setParentDataObj(null);
            }
        }

        /*if (isEditing &&  fieldInfo.getComp() instanceof EditViewCompSwitcherPanel)
        {
        if (isDataValueNew)
        {
            ((EditViewCompSwitcherPanel)fieldInfo.getComp()).putIntoEditMode();
        } else
        {
            ((EditViewCompSwitcherPanel)fieldInfo.getComp()).putIntoViewMode();
        }
        }*/
    }

    // if we do have a list then get the first object or null
    if (isList) {
        if (isVector) {
            list = (Vector) data;
        } else {
            list = new Vector<Object>((List<?>) data);
        }

        if (list.size() > 0) {
            this.dataObj = list.get(0);
            carryFwdDataObj = this.dataObj;
            //log.debug("Getting DO from list "+this.dataObj.getClass().getSimpleName()+" "+this.dataObj.hashCode());

        } else {
            this.dataObj = null;
        }

        // Now tell the RecordController how many Object we have
        if (rsController != null) {
            int len = list.size();
            if (AppContextMgr.isSecurityOn()) {
                ensurePermissions();
                if (perm.hasNoPerm()) {
                    len = 0;
                }
            }
            rsController.setLength(len);
            //updateControllerUI();
        }

        // Set the data from the into the form
        setDataIntoUI();

    } else {
        // OK, it is a single data object
        this.dataObj = dataObj;

        if (!alreadyInTheList && (this.list != null && this.dataObj != dataObj)) {
            this.list = null;
        }

        setDataIntoUI();

        // Don't remove the rsController if the data is NULL because the next non-null one may be a list
        // mostly likely it will be
        if (rsController != null) {
            if (this.dataObj != null) {
                // I added this 'if' and I have no idea why the call was here in the first place. - rods
                // was it here for PaleoContext ?????
                if (!alreadyInTheList) {
                    //controlPanel.setRSCVisibility(!isEditting);
                    rsController.reset(); // rods - 07/07/08 just moved this into the this 'if' statement
                    // it has already caused problems not being n there.
                }

            } else {
                rsController.clear();
            }
            updateControllerUI();
        }
    }
}