Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

In this page you can find the example usage for java.lang NumberFormatException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.monome.pages.configuration.Configuration.java

/**
 * Reads a given configuration file and sets up the object appropriately.
 * /*from www  .jav  a 2 s .co m*/
 * @param file the configuration file to read
 */
public boolean readConfigurationFile(File file) {
    try {
        System.out.println("Reading configuration file: " + file.getAbsolutePath());
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(file);
        doc.getDocumentElement().normalize();

        // read <name> from the configuration file
        NodeList rootNL = doc.getElementsByTagName("name");
        Element rootEL = (Element) rootNL.item(0);
        NodeList rootNL2 = rootEL.getChildNodes();
        String name = ((Node) rootNL2.item(0)).getNodeValue();
        this.name = name;

        // read <hostname> from the configuration file
        rootNL = doc.getElementsByTagName("hostname");
        rootEL = (Element) rootNL.item(0);
        rootNL2 = rootEL.getChildNodes();
        String hostname = ((Node) rootNL2.item(0)).getNodeValue();
        setMonomeHostname(hostname);

        // read <zeroconfLibrary> from the configuration file
        rootNL = doc.getElementsByTagName("zeroconfLibrary");
        rootEL = (Element) rootNL.item(0);
        if (rootEL != null) {
            rootNL2 = rootEL.getChildNodes();
            String zeroconfLibrary = ((Node) rootNL2.item(0)).getNodeValue();
            try {
                Main.main.zeroconfLibrary = Integer.parseInt(zeroconfLibrary);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }

        // read <oscinport> from the configuration file
        rootNL = doc.getElementsByTagName("oscinport");
        rootEL = (Element) rootNL.item(0);
        rootNL2 = rootEL.getChildNodes();
        String oscinport = ((Node) rootNL2.item(0)).getNodeValue();

        setMonomeSerialOSCInPortNumber(Integer.valueOf(oscinport).intValue());

        // read <oscoutport> from the configuration file
        rootNL = doc.getElementsByTagName("oscoutport");
        rootEL = (Element) rootNL.item(0);
        rootNL2 = rootEL.getChildNodes();
        String oscoutport = ((Node) rootNL2.item(0)).getNodeValue();

        setMonomeSerialOSCOutPortNumber(Integer.valueOf(oscoutport).intValue());

        // read <abletonhostname> from the configuration file
        rootNL = doc.getElementsByTagName("abletonhostname");
        rootEL = (Element) rootNL.item(0);
        // old versions might not have this setting
        if (rootEL != null) {
            rootNL2 = rootEL.getChildNodes();
            String abletonhostname = ((Node) rootNL2.item(0)).getNodeValue();
            setAbletonHostname(abletonhostname);
        }

        // read <abletonoscinport> from the configuration file
        rootNL = doc.getElementsByTagName("abletonoscinport");
        rootEL = (Element) rootNL.item(0);
        // old versions might not have this setting
        if (rootEL != null) {
            rootNL2 = rootEL.getChildNodes();
            String abletonoscinport = ((Node) rootNL2.item(0)).getNodeValue();
            setAbletonOSCInPortNumber(Integer.valueOf(abletonoscinport).intValue());
        }

        // read <abletonoscoutport> from the configuration file
        rootNL = doc.getElementsByTagName("abletonoscoutport");
        rootEL = (Element) rootNL.item(0);
        // old versions might not have this setting
        if (rootEL != null) {
            rootNL2 = rootEL.getChildNodes();
            String abletonoscoutport = ((Node) rootNL2.item(0)).getNodeValue();
            setAbletonOSCOutPortNumber(Integer.valueOf(abletonoscoutport).intValue());
        }

        // read <abletonignoreviewtrack> from the configuration file
        rootNL = doc.getElementsByTagName("abletonignoreviewtrack");
        rootEL = (Element) rootNL.item(0);
        // old versions might not have this setting
        if (rootEL != null) {
            rootNL2 = rootEL.getChildNodes();
            String abletonignoreviewtrack = ((Node) rootNL2.item(0)).getNodeValue();
            if (abletonignoreviewtrack.compareTo("true") == 0) {
                this.abletonIgnoreViewTrack = true;
            } else {
                this.abletonIgnoreViewTrack = false;
            }
        }
        initAbleton();

        // read <midiinport> from the configuration file
        rootNL = doc.getElementsByTagName("midiinport");
        for (int i = 0; i < rootNL.getLength(); i++) {
            rootEL = (Element) rootNL.item(i);
            rootNL2 = rootEL.getChildNodes();
            String midiinport = ((Node) rootNL2.item(0)).getNodeValue();
            actionAddMidiInput(midiinport);
        }

        // read all <midioutport> tags from the configuration file
        rootNL = doc.getElementsByTagName("midioutport");
        for (int i = 0; i < rootNL.getLength(); i++) {
            rootEL = (Element) rootNL.item(i);
            rootNL2 = rootEL.getChildNodes();
            String midioutport = ((Node) rootNL2.item(0)).getNodeValue();
            actionAddMidiOutput(midioutport);
        }

        // read in each <monome> block
        rootNL = doc.getElementsByTagName("monome");
        for (int i = 0; i < rootNL.getLength(); i++) {
            Node node = rootNL.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element monomeElement = (Element) node;

                // set the monome prefix
                NodeList nl = monomeElement.getElementsByTagName("prefix");
                Element el = (Element) nl.item(0);
                nl = el.getChildNodes();
                String prefix = "";
                if (nl.item(0) != null) {
                    prefix = ((Node) nl.item(0)).getNodeValue();
                }

                // set the monome prefix
                nl = monomeElement.getElementsByTagName("serial");
                el = (Element) nl.item(0);
                String serial = "no serial";
                if (el != null) {
                    nl = el.getChildNodes();
                    if (nl.item(0) != null) {
                        serial = ((Node) nl.item(0)).getNodeValue();
                    }
                }

                // set the monome serialosc hostname if present
                String serialOSCHostName = null;
                nl = monomeElement.getElementsByTagName("serialOSCHostname");
                if (nl != null) {
                    el = (Element) nl.item(0);
                    if (el != null) {
                        nl = el.getChildNodes();
                        if (nl.item(0) != null) {
                            serialOSCHostName = ((Node) nl.item(0)).getNodeValue();
                        }
                    }
                }

                // set the width of the monome
                nl = monomeElement.getElementsByTagName("sizeX");
                el = (Element) nl.item(0);
                nl = el.getChildNodes();
                String sizeX = ((Node) nl.item(0)).getNodeValue();

                // set the height of the monome
                nl = monomeElement.getElementsByTagName("sizeY");
                el = (Element) nl.item(0);
                nl = el.getChildNodes();
                String sizeY = ((Node) nl.item(0)).getNodeValue();

                // set the height of the monome
                String altClear = "";
                nl = monomeElement.getElementsByTagName("altClear");
                if (nl != null) {
                    el = (Element) nl.item(0);
                    if (el != null) {
                        nl = el.getChildNodes();
                        altClear = ((Node) nl.item(0)).getNodeValue();
                    }
                }

                boolean boolUsePageChangeButton = true;
                nl = monomeElement.getElementsByTagName("usePageChangeButton");
                el = (Element) nl.item(0);
                if (el != null) {
                    nl = el.getChildNodes();
                    String usePageChangeButton = ((Node) nl.item(0)).getNodeValue();
                    if (usePageChangeButton.equals("false")) {
                        boolUsePageChangeButton = false;
                    }
                }

                boolean boolUseMIDIPageChanging = false;
                nl = monomeElement.getElementsByTagName("useMIDIPageChanging");
                el = (Element) nl.item(0);
                if (el != null) {
                    nl = el.getChildNodes();
                    String useMIDIPageChanging = ((Node) nl.item(0)).getNodeValue();
                    if (useMIDIPageChanging.equals("true")) {
                        boolUseMIDIPageChanging = true;
                    }
                }

                NodeList rootNL3 = monomeElement.getElementsByTagName("MIDIPageChangeRule");
                ArrayList<MIDIPageChangeRule> midiPageChangeRules = new ArrayList<MIDIPageChangeRule>();
                for (int i2 = 0; i2 < rootNL3.getLength(); i2++) {
                    Node node2 = rootNL3.item(i2);
                    if (node2.getNodeType() == Node.ELEMENT_NODE) {
                        Element monomeElement2 = (Element) node2;

                        NodeList nl2 = monomeElement2.getElementsByTagName("pageIndex");
                        Element el2 = (Element) nl2.item(0);
                        nl2 = el2.getChildNodes();
                        String pageIndex = ((Node) nl2.item(0)).getNodeValue();

                        nl2 = monomeElement2.getElementsByTagName("note");
                        el2 = (Element) nl2.item(0);
                        nl2 = el2.getChildNodes();
                        String note = ((Node) nl2.item(0)).getNodeValue();

                        nl2 = monomeElement2.getElementsByTagName("channel");
                        el2 = (Element) nl2.item(0);
                        nl2 = el2.getChildNodes();
                        String channel = ((Node) nl2.item(0)).getNodeValue();

                        nl2 = monomeElement2.getElementsByTagName("cc");
                        el2 = (Element) nl2.item(0);
                        nl2 = el2.getChildNodes();
                        String cc = ((Node) nl2.item(0)).getNodeValue();

                        nl2 = monomeElement2.getElementsByTagName("ccVal");
                        el2 = (Element) nl2.item(0);
                        nl2 = el2.getChildNodes();
                        String ccVal = ((Node) nl2.item(0)).getNodeValue();

                        MIDIPageChangeRule mpcr = new MIDIPageChangeRule(Integer.valueOf(note).intValue(),
                                Integer.valueOf(channel).intValue(), Integer.valueOf(cc).intValue(),
                                Integer.valueOf(ccVal).intValue(), Integer.valueOf(pageIndex).intValue());
                        midiPageChangeRules.add(mpcr);

                        nl2 = monomeElement2.getElementsByTagName("linkedSerial");
                        el2 = (Element) nl2.item(0);
                        String linkedSerial = null;
                        if (el2 != null) {
                            nl2 = el2.getChildNodes();
                            linkedSerial = ((Node) nl2.item(0)).getNodeValue();
                            if (linkedSerial != null && linkedSerial.compareTo("null") != 0)
                                mpcr.setLinkedSerial(linkedSerial);
                        }

                        if (linkedSerial != null && linkedSerial.compareTo("null") != 0) {
                            nl2 = monomeElement2.getElementsByTagName("linkedPageIndex");
                            el2 = (Element) nl2.item(0);
                            if (el2 != null) {
                                nl2 = el2.getChildNodes();
                                String linkedPageIndex = ((Node) nl2.item(0)).getNodeValue();
                                mpcr.setLinkedPageIndex(Integer.valueOf(linkedPageIndex).intValue());
                            }
                        }
                    }
                }

                // create the new monome configuration and display its window
                MonomeConfiguration monomeConfig = addMonomeConfiguration(i, prefix, serial,
                        Integer.valueOf(sizeX).intValue(), Integer.valueOf(sizeY).intValue(),
                        boolUsePageChangeButton, boolUseMIDIPageChanging, midiPageChangeRules);
                if (altClear.compareTo("on") == 0) {
                    monomeConfig.altClear = true;
                }
                monomeConfig.serialOSCHostname = serialOSCHostName;
                monomeConfig.deviceFrame.updateMidiInMenuOptions(MidiDeviceFactory.getMidiInOptions());
                monomeConfig.deviceFrame.updateMidiOutMenuOptions(MidiDeviceFactory.getMidiOutOptions());

                String s;
                float[] min = { 0, 0, 0, 0 };
                NodeList minNL = monomeElement.getElementsByTagName("min");
                for (int j = 0; j < minNL.getLength(); j++) {
                    el = (Element) minNL.item(j);
                    if (el != null) {
                        nl = el.getChildNodes();
                        s = ((Node) nl.item(0)).getNodeValue();
                        min[j] = Float.parseFloat(s.trim());
                        //monomeConfig.adcObj.setMin(min);
                    }
                }

                float[] max = { 1, 1, 1, 1 };
                NodeList maxNL = monomeElement.getElementsByTagName("max");
                for (int j = 0; j < maxNL.getLength(); j++) {
                    el = (Element) maxNL.item(j);
                    if (el != null) {
                        nl = el.getChildNodes();
                        s = ((Node) nl.item(0)).getNodeValue();
                        max[j] = Float.parseFloat(s.trim());
                        //monomeConfig.adcObj.setMax(max);
                    }
                }

                // enable tilt
                /*
                nl = monomeElement.getElementsByTagName("adcEnabled");
                el = (Element) nl.item(0);
                if (el != null) {
                   nl = el.getChildNodes();
                   String enabled = ((Node) nl.item(0)).getNodeValue();
                   monomeConfig.adcObj.setEnabled(Boolean.parseBoolean(enabled));
                }
                */

                NodeList pcmidiNL = monomeElement.getElementsByTagName("selectedpagechangemidiinport");
                for (int k = 0; k < pcmidiNL.getLength(); k++) {
                    el = (Element) pcmidiNL.item(k);
                    if (el != null) {
                        nl = el.getChildNodes();
                        String midintport = ((Node) nl.item(0)).getNodeValue();
                        monomeConfig.togglePageChangeMidiInDevice(midintport);
                    }
                }

                // read in each page of the monome
                monomeConfig.curPage = -1;
                NodeList pageNL = monomeElement.getElementsByTagName("page");
                for (int j = 0; j < pageNL.getLength(); j++) {
                    Node pageNode = pageNL.item(j);
                    if (pageNode.getNodeType() == Node.ELEMENT_NODE) {
                        Element pageElement = (Element) pageNode;
                        String pageClazz = pageElement.getAttribute("class");

                        // all pages have a name
                        nl = pageElement.getElementsByTagName("name");
                        el = (Element) nl.item(0);
                        nl = el.getChildNodes();
                        String pageName = ((Node) nl.item(0)).getNodeValue();
                        Page page;
                        page = monomeConfig.addPage(pageClazz);
                        page.setName(pageName);
                        monomeConfig.curPage++;

                        // most pages have midi outputs
                        NodeList midiNL = pageElement.getElementsByTagName("selectedmidioutport");
                        for (int k = 0; k < midiNL.getLength(); k++) {
                            el = (Element) midiNL.item(k);
                            if (el != null) {
                                nl = el.getChildNodes();
                                String midioutport = ((Node) nl.item(0)).getNodeValue();
                                monomeConfig.toggleMidiOutDevice(midioutport);
                            }
                        }

                        // most pages have midi inputs
                        midiNL = pageElement.getElementsByTagName("selectedmidiinport");
                        for (int k = 0; k < midiNL.getLength(); k++) {
                            el = (Element) midiNL.item(k);
                            if (el != null) {
                                nl = el.getChildNodes();
                                String midintport = ((Node) nl.item(0)).getNodeValue();
                                monomeConfig.toggleMidiInDevice(midintport);
                            }
                        }
                        page.configure(pageElement);

                        int pageChangeDelay = 0;
                        nl = pageElement.getElementsByTagName("pageChangeDelay");
                        el = (Element) nl.item(0);
                        if (el != null) {
                            nl = el.getChildNodes();
                            String sPageChangeDelay = ((Node) nl.item(0)).getNodeValue();
                            try {
                                pageChangeDelay = Integer.parseInt(sPageChangeDelay);
                            } catch (NumberFormatException ex) {
                                ex.printStackTrace();
                            }
                        }
                        monomeConfig.pageChangeDelays[monomeConfig.curPage] = pageChangeDelay;
                    }
                }

                NodeList lengthNL = monomeElement.getElementsByTagName("patternlength");
                for (int k = 0; k < lengthNL.getLength(); k++) {
                    el = (Element) lengthNL.item(k);
                    nl = el.getChildNodes();
                    String patternLength = ((Node) nl.item(0)).getNodeValue();
                    int length = Integer.parseInt(patternLength);
                    monomeConfig.setPatternLength(k, length);
                }
                NodeList quantifyNL = monomeElement.getElementsByTagName("quantization");
                for (int k = 0; k < quantifyNL.getLength(); k++) {
                    el = (Element) quantifyNL.item(k);
                    nl = el.getChildNodes();
                    String quantization = ((Node) nl.item(0)).getNodeValue();
                    int quantify = Integer.parseInt(quantization);
                    monomeConfig.setQuantization(k, quantify);
                }
                if (serialOSCHostName == null) {
                    startMonomeSerialOSC();
                }
            }
        }

        // read in each <arc> block
        rootNL = doc.getElementsByTagName("arc");
        for (int i = 0; i < rootNL.getLength(); i++) {
            Node node = rootNL.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element monomeElement = (Element) node;

                // set the monome prefix
                NodeList nl = monomeElement.getElementsByTagName("prefix");
                Element el = (Element) nl.item(0);
                nl = el.getChildNodes();
                String prefix = "";
                if (nl.item(0) != null) {
                    prefix = ((Node) nl.item(0)).getNodeValue();
                }

                // set the monome prefix
                nl = monomeElement.getElementsByTagName("serial");
                el = (Element) nl.item(0);
                String serial = "no serial";
                if (el != null) {
                    nl = el.getChildNodes();
                    if (nl.item(0) != null) {
                        serial = ((Node) nl.item(0)).getNodeValue();
                    }
                }

                // set the monome serialosc hostname if present
                String serialOSCHostName = null;
                nl = monomeElement.getElementsByTagName("serialOSCHostname");
                if (nl != null) {
                    el = (Element) nl.item(0);
                    if (el != null) {
                        nl = el.getChildNodes();
                        if (nl.item(0) != null) {
                            serialOSCHostName = ((Node) nl.item(0)).getNodeValue();
                        }
                    }
                }

                // set the number of knobs
                nl = monomeElement.getElementsByTagName("knobs");
                el = (Element) nl.item(0);
                nl = el.getChildNodes();
                String knobs = ((Node) nl.item(0)).getNodeValue();

                boolean boolUseMIDIPageChanging = false;
                nl = monomeElement.getElementsByTagName("useMIDIPageChanging");
                el = (Element) nl.item(0);
                if (el != null) {
                    nl = el.getChildNodes();
                    String useMIDIPageChanging = ((Node) nl.item(0)).getNodeValue();
                    if (useMIDIPageChanging.equals("true")) {
                        boolUseMIDIPageChanging = true;
                    }
                }

                NodeList rootNL3 = monomeElement.getElementsByTagName("MIDIPageChangeRule");
                ArrayList<MIDIPageChangeRule> midiPageChangeRules = new ArrayList<MIDIPageChangeRule>();
                for (int i2 = 0; i2 < rootNL3.getLength(); i2++) {
                    Node node2 = rootNL3.item(i2);
                    if (node2.getNodeType() == Node.ELEMENT_NODE) {
                        Element monomeElement2 = (Element) node2;

                        NodeList nl2 = monomeElement2.getElementsByTagName("pageIndex");
                        Element el2 = (Element) nl2.item(0);
                        nl2 = el2.getChildNodes();
                        String pageIndex = ((Node) nl2.item(0)).getNodeValue();

                        nl2 = monomeElement2.getElementsByTagName("note");
                        el2 = (Element) nl2.item(0);
                        nl2 = el2.getChildNodes();
                        String note = ((Node) nl2.item(0)).getNodeValue();

                        nl2 = monomeElement2.getElementsByTagName("channel");
                        el2 = (Element) nl2.item(0);
                        nl2 = el2.getChildNodes();
                        String channel = ((Node) nl2.item(0)).getNodeValue();

                        nl2 = monomeElement2.getElementsByTagName("cc");
                        String cc = "-1";
                        if (nl2 != null) {
                            el2 = (Element) nl2.item(0);
                            if (el2 != null) {
                                nl2 = el2.getChildNodes();
                                cc = ((Node) nl2.item(0)).getNodeValue();
                            }
                        }

                        String ccVal = "-1";
                        nl2 = monomeElement2.getElementsByTagName("ccVal");
                        if (nl2 != null) {
                            el2 = (Element) nl2.item(0);
                            if (el2 != null) {
                                nl2 = el2.getChildNodes();
                                ccVal = ((Node) nl2.item(0)).getNodeValue();
                            }
                        }

                        MIDIPageChangeRule mpcr = new MIDIPageChangeRule(Integer.valueOf(note).intValue(),
                                Integer.valueOf(channel).intValue(), Integer.valueOf(cc).intValue(),
                                Integer.valueOf(ccVal).intValue(), Integer.valueOf(pageIndex).intValue());
                        midiPageChangeRules.add(mpcr);
                    }
                }

                // create the new arc configuration and display its window
                ArcConfiguration arcConfig = addArcConfiguration(i, prefix, serial, Integer.parseInt(knobs),
                        midiPageChangeRules);
                arcConfig.serialOSCHostname = serialOSCHostName;
                arcConfig.deviceFrame.updateMidiInMenuOptions(MidiDeviceFactory.getMidiInOptions());
                arcConfig.deviceFrame.updateMidiOutMenuOptions(MidiDeviceFactory.getMidiOutOptions());

                NodeList pcmidiNL = monomeElement.getElementsByTagName("selectedpagechangemidiinport");
                for (int k = 0; k < pcmidiNL.getLength(); k++) {
                    el = (Element) pcmidiNL.item(k);
                    if (el != null) {
                        nl = el.getChildNodes();
                        String midintport = ((Node) nl.item(0)).getNodeValue();
                        arcConfig.togglePageChangeMidiInDevice(midintport);
                    }
                }

                // read in each page of the arc
                arcConfig.curPage = -1;
                NodeList pageNL = monomeElement.getElementsByTagName("page");
                for (int j = 0; j < pageNL.getLength(); j++) {
                    Node pageNode = pageNL.item(j);
                    if (pageNode.getNodeType() == Node.ELEMENT_NODE) {
                        Element pageElement = (Element) pageNode;
                        String pageClazz = pageElement.getAttribute("class");

                        // all pages have a name
                        nl = pageElement.getElementsByTagName("name");
                        el = (Element) nl.item(0);
                        nl = el.getChildNodes();
                        String pageName = ((Node) nl.item(0)).getNodeValue();
                        ArcPage page;
                        page = arcConfig.addPage(pageClazz);
                        page.setName(pageName);
                        arcConfig.curPage++;

                        // most pages have midi outputs
                        NodeList midiNL = pageElement.getElementsByTagName("selectedmidioutport");
                        for (int k = 0; k < midiNL.getLength(); k++) {
                            el = (Element) midiNL.item(k);
                            if (el != null) {
                                nl = el.getChildNodes();
                                String midioutport = ((Node) nl.item(0)).getNodeValue();
                                arcConfig.toggleMidiOutDevice(midioutport);
                            }
                        }

                        // most pages have midi inputs
                        midiNL = pageElement.getElementsByTagName("selectedmidiinport");
                        for (int k = 0; k < midiNL.getLength(); k++) {
                            el = (Element) midiNL.item(k);
                            if (el != null) {
                                nl = el.getChildNodes();
                                String midintport = ((Node) nl.item(0)).getNodeValue();
                                arcConfig.toggleMidiInDevice(midintport);
                            }
                        }
                        page.configure(pageElement);
                    }
                }
            }
        }

        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:com.amaze.filemanager.fragments.Main.java

private void addTo(BaseFile mFile) {
    File f = new File(mFile.getPath());
    String size = "";
    if (!DataUtils.hiddenfiles.contains(mFile.getPath())) {
        if (mFile.isDirectory()) {
            size = "";
            Layoutelements layoutelements = utils.newElement(folder, f.getPath(), mFile.getPermisson(),
                    mFile.getLink(), size, 0, true, false, mFile.getDate() + "");
            layoutelements.setMode(mFile.getMode());
            LIST_ELEMENTS.add(layoutelements);
            folder_count++;/* w  ww  .java2s. c om*/
        } else {
            long longSize = 0;
            try {
                if (mFile.getSize() != -1) {
                    longSize = Long.valueOf(mFile.getSize());
                    size = utils.readableFileSize(longSize);
                } else {
                    size = "";
                    longSize = 0;
                }
            } catch (NumberFormatException e) {
                //e.printStackTrace();
            }
            try {
                Layoutelements layoutelements = utils.newElement(
                        Icons.loadMimeIcon(getActivity(), f.getPath(), !IS_LIST, res), f.getPath(),
                        mFile.getPermisson(), mFile.getLink(), size, longSize, false, false,
                        mFile.getDate() + "");
                layoutelements.setMode(mFile.getMode());
                LIST_ELEMENTS.add(layoutelements);
                file_count++;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:free.chessclub.bot.Bot.java

protected boolean processPersonalTell(String username, String titles, String message) {
    super.processPersonalTell(username, titles, message);

    if (message.indexOf("status") > -1) {
        String currentStatus = getCurrentStatus();
        if (currentStatus != null) {
            sendCommand("tell " + username + " " + currentStatus);
        }/*from w w w.  j  a  v  a  2 s  .c  o m*/
        String currentGameStatus = getCurrentGameStatus();
        if (currentGameStatus != null) {
            sendCommand("tell " + username + " " + currentGameStatus);
        }
    } else if (username.equals(owner)) {
        if (message.indexOf("tellme") > -1) {
            tellOwner = !tellOwner;
            sendCommand("tell " + owner + " tellme: " + tellOwner);
        } else if (message.indexOf("tdf") == 0) {
            sendCommand("tell " + owner + " challenging testdonkeyfactor");
            sendCommand("ma testdonkeyfactor 1 0 u");
        } else if (message.indexOf("tweetGame") > -1) {
            tweetCurrentGameStatus();
        } else if (message.indexOf("dset ") == 0) {
            if (message.indexOf(" tweetMax ") > -1) {
                try {
                    TWEET_MAX = Integer.parseInt(
                            message.substring(message.indexOf(SET_TWEET_MAX) + SET_TWEET_MAX.length() + 1));
                } catch (NumberFormatException e) {
                    sendCommand("tell " + owner + " no... e.g. set " + SET_TWEET_MAX + " 8");
                }
            }
            if (message.indexOf(" " + SET_TWEET_SOFT + " ") > -1) {
                try {
                    TWEET_SOFT = Integer.parseInt(
                            message.substring(message.indexOf(SET_TWEET_SOFT) + SET_TWEET_SOFT.length() + 1));
                } catch (NumberFormatException e) {
                    sendCommand("tell " + owner + " no... e.g. set " + SET_TWEET_SOFT + " 8");
                }
            }
        } else if (message.startsWith("dset")) {
            sendCommand("tell " + owner + " " + SET_TWEET_MAX + ": " + TWEET_MAX);
            sendCommand("tell " + owner + " " + SET_TWEET_SOFT + ": " + TWEET_SOFT);
        } else if (message.indexOf("tweet ") == 0) {
            sendCommand("tell " + owner + " tweeting '" + message.substring(6) + "'");
            try {
                twitter.tweet(message.substring(6));
            } catch (TwitterException e) {
                e.printStackTrace();
            }
        } else if (message.indexOf("seek") > -1) {
            autoseek = !autoseek;
            sendCommand("tell " + owner + " autoseek: " + autoseek);
            if (autoseek) {
                seek();
            }
        } else {
            sendCommand(message);
        }
    }

    return true;
}

From source file:org.loklak.harvester.YoutubeScraper.java

public static JSONObject parseVideo(final BufferedReader br) throws IOException {
    String input;/*from   ww  w.  java  2  s  .  c  o  m*/
    JSONObject json = new JSONObject(true);
    boolean parse_span = false, parse_license = false;
    String itemprop = "", itemtype = ""; // values for span
    while ((input = br.readLine()) != null)
        try {
            input = input.trim();
            //System.out.println(input); // uncomment temporary to debug or add new fields
            int p;

            if (parse_license) {
                if ((p = input.indexOf("<li")) >= 0) {
                    String tag = parseTag(input, p);
                    if (tag == null)
                        continue;
                    if (tag.startsWith("<a ")) {
                        tag = parseTag(tag, 0);
                        addRDF(new String[] { "youtube", "category", tag }, json);
                    } else {
                        addRDF(new String[] { "youtube", "license", tag }, json);
                    }
                    parse_license = false;
                    continue;
                }
            } else if (parse_span) {
                if ((p = input.indexOf("itemprop=\"")) >= 0) {
                    String[] token = parseItemprop(input, p, new String[] { "href", "content" }, "");
                    if (token == null)
                        continue;
                    int q = itemtype.indexOf("//");
                    if (q < 0)
                        continue;
                    String subject = itemtype.substring(q + 2).replace('.', '_').replace('/', '_');
                    String predicate = itemprop + "_" + token[1];
                    String object = token[2];
                    addRDF(new String[] { subject, predicate, object }, json);
                    continue;
                }
                if (input.indexOf("</span>") >= 0) {
                    parse_span = false;
                    continue;
                }
            } else {
                tags: for (String tag : html_tags) {
                    if ((p = input.indexOf("<" + tag)) >= 0) {
                        addRDF(new String[] { "html", tag, parseTag(input, p) }, json);
                        continue tags;
                    }
                }
                vocs: for (String subject : microformat_vocabularies) {
                    if ((p = input.indexOf("property=\"" + subject + ":")) >= 0) {
                        addRDF(parseMicroformat(input, "property", p), json);
                        continue vocs;
                    }
                    if ((p = input.indexOf("name=\"" + subject + ":")) >= 0) {
                        addRDF(parseMicroformat(input, "name", p), json);
                        continue vocs;
                    }
                }
                if ((p = input.indexOf("span itemprop=\"")) >= 0) {
                    String[] token = parseItemprop(input, p, new String[] { "itemtype" }, "");
                    if (token == null)
                        continue;
                    itemprop = token[1];
                    itemtype = token[2];
                    parse_span = true;
                    continue;
                }
                if ((p = input.indexOf("itemprop=\"")) >= 0) {
                    String[] token = parseItemprop(input, p, new String[] { "content" }, "youtube");
                    if (token == null)
                        continue;
                    addRDF(token, json);
                    continue;
                }
                if ((p = input.indexOf("class=\"content watch-info-tag-list")) >= 0) {
                    parse_license = true;
                    continue;
                }
                if ((p = input.indexOf("yt-subscriber-count")) >= 0) {
                    String subscriber_string = parseProp(input, p, "title");
                    if (subscriber_string == null)
                        continue;
                    json.put("youtube_subscriber", parseNumber(subscriber_string));
                    continue;
                }
                if (input.indexOf("\"like this") > 0 && (p = input.indexOf("yt-uix-button-content")) >= 0) {
                    String likes_string = parseTag(input, p);
                    json.put("youtube_likes", parseNumber(likes_string));
                    continue;
                }
                if (input.indexOf("\"dislike this") > 0 && (p = input.indexOf("yt-uix-button-content")) >= 0) {
                    String dislikes_string = parseTag(input, p);
                    json.put("youtube_dislikes", parseNumber(dislikes_string));
                    continue;
                }
                if ((p = input.indexOf("watch-view-count")) >= 0) {
                    String viewcount_string = parseTag(input, p);
                    if (viewcount_string == null)
                        continue;
                    viewcount_string = viewcount_string.replace(" views", "");
                    if (viewcount_string.length() == 0)
                        continue;
                    long viewcount = 0;
                    // if there are no views, there may be a string saying "No". But this is done in all languages, so we just catch a NumberFormatException
                    try {
                        viewcount = parseNumber(viewcount_string);
                    } catch (NumberFormatException e) {
                    }
                    json.put("youtube_viewcount", viewcount);
                    continue;
                }
                if ((p = input.indexOf("watch?v=")) >= 0) {
                    p += 8;
                    int q = input.indexOf("\"", p);
                    if (q > 0) {
                        String videoid = input.substring(p, q);
                        int r = videoid.indexOf('&');
                        if (r > 0)
                            videoid = videoid.substring(0, r);
                        addRDF(new String[] { "youtube", "next", videoid }, json);
                        continue;
                    }
                }
                if ((p = input.indexOf("playlist-header-content")) >= 0) {
                    String playlist_title = parseProp(input, p, "data-list-title");
                    if (playlist_title == null)
                        continue;
                    addRDF(new String[] { "youtube", "playlist_title", playlist_title }, json);
                    continue;
                }
                if ((p = input.indexOf("yt-uix-scroller-scroll-unit")) >= 0) {
                    String playlist_videoid = parseProp(input, p, "data-video-id");
                    if (playlist_videoid == null)
                        continue;
                    addRDF(new String[] { "youtube", "playlist_videoid", playlist_videoid }, json);
                    continue;
                }
                if ((p = input.indexOf("watch-description-text")) >= 0) {
                    p = input.indexOf('>', p);
                    int q = input.indexOf("</div", p);
                    String text = input.substring(p + 1, q < 0 ? input.length() : q);
                    text = paragraph.matcher(brend.matcher(text).replaceAll("\n")).replaceAll("").trim();
                    Matcher m;
                    anchor_loop: while ((m = anchor_pattern.matcher(text)).find())
                        try {
                            text = m.replaceFirst(m.group(1) + " ");
                        } catch (IllegalArgumentException e) {
                            text = "";
                            break anchor_loop;
                        }
                    text = CharacterCoding.html2unicode(text);
                    json.put("youtube_description", text);
                    continue;
                }
            }
        } catch (Throwable e) {
            e.printStackTrace();
            System.err.println("error in video " + json.toString(2));
            System.err.println("current line: " + input);
            System.exit(0);
        }
    br.close();
    return json;
}

From source file:edu.umich.robot.GuiApplication.java

public void connectSuperdroidRobotDialog() {
    final int defaultPort = 3192;

    FormLayout layout = new FormLayout("right:pref, 4dlu, 35dlu, 4dlu, 35dlu",
            "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref");

    final JDialog dialog = new JDialog(frame, "Connect to Superdroid", true);
    dialog.setLayout(layout);//  ww w  .j a  v a 2 s .com
    final JTextField namefield = new JTextField("charlie");
    final JTextField hostfield = new JTextField("192.168.1.165");
    final JTextField portfield = new JTextField(Integer.toString(defaultPort));
    final JButton cancel = new JButton("Cancel");
    final JButton ok = new JButton("OK");

    CellConstraints cc = new CellConstraints();
    dialog.add(new JLabel("Name"), cc.xy(1, 1));
    dialog.add(namefield, cc.xyw(3, 1, 3));
    dialog.add(new JLabel("Host"), cc.xy(1, 3));
    dialog.add(hostfield, cc.xyw(3, 3, 3));
    dialog.add(new JLabel("Port"), cc.xy(1, 5));
    dialog.add(portfield, cc.xyw(3, 5, 3));
    dialog.add(cancel, cc.xy(3, 7));
    dialog.add(ok, cc.xy(5, 7));

    portfield.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            int p = defaultPort;
            try {
                p = Integer.parseInt(portfield.getText());
                if (p < 1)
                    p = 1;
                if (p > 65535)
                    p = 65535;
            } catch (NumberFormatException ex) {
            }
            portfield.setText(Integer.toString(p));
        }
    });

    final ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String robotName = namefield.getText().trim();
            if (robotName.isEmpty()) {
                logger.error("Connect Superdroid: robot name empty");
                return;
            }

            for (char c : robotName.toCharArray()) {
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create Superdroid: illegal robot name");
                    return;
                }
            }

            try {
                controller.createRealSuperdroid(robotName, hostfield.getText(),
                        Integer.valueOf(portfield.getText()));
            } catch (UnknownHostException ex) {
                ex.printStackTrace();
                logger.error("Connect Superdroid: " + ex);
            } catch (SocketException ex) {
                ex.printStackTrace();
                logger.error("Connect Superdroid: " + ex);
            }
            dialog.dispose();
        }
    };

    namefield.addActionListener(okListener);
    hostfield.addActionListener(okListener);
    portfield.addActionListener(okListener);
    ok.addActionListener(okListener);

    ActionListener cancelAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);

    dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    dialog.setLocationRelativeTo(frame);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:de.fau.amos.ChartRenderer.java

/**
 * //from  w ww . j  a  va2s. c  o  m
 * Creates TimeSeriesCollection that provides the basis for a Chart. Is used for forecast.
 * 
 * @param sYear Selected year.
 * @param plantId Selected plant.
 * @param method Is not used.
 * @param units Is not used.
 * @return Returns TimeSeriesCollection that provides the basis for a Chart.
 */
private TimeSeriesCollection createForecastCollection(String sYear, String plantId, String method,
        String units) {

    int year = 0;
    try {
        year = Integer.parseInt(sYear);
    } catch (NumberFormatException e) {
        return new TimeSeriesCollection();
    }

    TimeSeriesCollection collection = new TimeSeriesCollection();

    /*
     * get planned tnf
     */
    TimeSeries planned = new TimeSeries("Planned");

    double lastYearKwhPerTnf = 0;
    ResultSet rs = SQL.queryToResultSet(
            "select round((select sum(value)from measures where date_trunc('year',measure_time)='" + (year - 1)
                    + "-1-1')/(select sum(amount)from productiondata "
                    + "inner join controlpoints on productiondata.controlpoint_id=controlpoints.controlpoints_id "
                    + "where date_trunc('year',measure_time)='" + (year - 1) + "-1-1' AND plant_id='" + plantId
                    + "'),4);");

    if (rs != null) {
        try {
            if (rs.next()) {
                lastYearKwhPerTnf = rs.getDouble(1);
            }
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    String months = "";
    for (int i = 1; i <= 12; i++) {
        months += "sum(m_" + i + ")";
        if (i != 12) {
            months += ", ";
        }
    }

    rs = SQL.queryToResultSet(

            "select " + months + " from planning_values where planning_year='" + year + "' AND plant_id='"
                    + plantId + "';");

    if (rs != null) {
        try {
            while (rs.next()) {
                for (int i = 1; i <= 12; i++) {
                    planned.add(new Month((i), year),
                            rs.getDouble(i) / (lastYearKwhPerTnf != 0 ? lastYearKwhPerTnf : 1));
                }

            }
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    collection.addSeries(planned);

    TimeSeries is = new TimeSeries("Is");
    int passedMonths = 0;
    double lastVal = 0;
    rs = SQL.queryToResultSet(

            "select * from (select round((select sum(am) from(select sum(amount)as am,date_trunc('month',measure_time)as zeit "
                    + "from productiondata inner join controlpoints on productiondata.controlpoint_id=controlpoints.controlpoints_id "
                    + "where productiondata.measure_time >= '" + year
                    + "-01-01 00:00:00' AND productiondata.measure_time < '" + (year + 1) + "-01-01 00:00:00' "
                    + "AND reference_point='t' AND plant_id='" + plantId
                    + "' group by measure_time)as wat where zeit=gruppenZeit group by zeit order by zeit),4), "
                    + "gruppenZeit from(select sum(wert) as gruppenWert,control_point_name, zeit1 as gruppenZeit from("
                    + "select sum(value)as wert,control_point_name,date_trunc('month',measure_time)as zeit1 from measures inner join controlpoints "
                    + "on measures.controlpoint_id=controlpoints.controlpoints_id where measure_time >= '"
                    + year + "-01-01 00:00:00' AND measure_time < '" + (year + 1)
                    + "-01-01 00:00:00' AND plant_id='" + plantId
                    + "' group by measure_time,control_point_name)as data group by zeit1,control_point_name) "
                    + "as groupedByTime group by gruppenZeit)as result order by gruppenZeit;");
    if (rs != null) {
        try {
            while (rs.next()) {
                passedMonths++;
                lastVal = rs.getDouble(1) / (lastYearKwhPerTnf != 0 ? lastYearKwhPerTnf : 1);
                is.add(new Month((passedMonths), year), lastVal);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    collection.addSeries(is);

    TimeSeries forecast = new TimeSeries("Forecast");

    if (passedMonths != 0) {

        forecast.add(new Month(passedMonths, year), lastVal);
    }
    passedMonths++;

    double factor = calculateDifferenz(planned, is);

    for (int i = passedMonths; i <= 12; i++) {
        forecast.add(new Month((i), year), planned.getValue(i - 1).doubleValue() * factor);
    }
    collection.addSeries(forecast);
    return collection;
}

From source file:com.sonymobile.backlogtool.JSONController.java

@PreAuthorize("hasPermission(#areaName, 'isEditor')")
@RequestMapping(value = "/updatetask/{areaName}", method = RequestMethod.POST)
@Transactional/*from w w w.j a  v a 2 s.c o m*/
public @ResponseBody boolean updateTask(@PathVariable String areaName,
        @RequestBody NewTaskContainer updatedTask, @RequestParam boolean pushUpdate) {
    Session session = sessionFactory.openSession();
    Transaction tx = null;
    try {
        tx = session.beginTransaction();

        Task task = (Task) session.get(Task.class, updatedTask.getId());
        if (!task.getStory().getArea().getName().equals(areaName)) {
            throw new Error("Trying to modify unauthorized object");
        }

        AttributeOption attr1 = null;
        try {
            attr1 = (AttributeOption) session.get(AttributeOption.class,
                    Integer.parseInt(updatedTask.getTaskAttr1Id()));
        } catch (NumberFormatException e) {
        } //AttrId can be empty, in that case we want null as attr1.

        task.setTitle(updatedTask.getTitle());
        task.setOwner(updatedTask.getOwner());
        task.setCalculatedTime(updatedTask.getCalculatedTime());
        task.setTaskAttr1(attr1);

        tx.commit();
    } catch (Exception e) {
        e.printStackTrace();
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    if (pushUpdate) {
        PushContext pushContext = PushContext.getInstance(context);
        pushContext.push(areaName);
    }
    return true;
}

From source file:eu.prestoprime.plugin.p4.MetadataTasks.java

@WfService(name = "ffprobe", version = "2.1.0")
public void ffprobe(Map<String, String> sParams, Map<String, String> dParamsString,
        Map<String, File> dParamFile) throws TaskExecutionFailedException {

    // get sipID//  ww w .  j a  v a2s.co m
    String sipID = dParamsString.get("sipID");

    SIP sip = null;
    try {
        // get sip
        sip = P4DataManager.getInstance().getSIPByID(sipID);

        // get MQ file
        String videoFile = null;
        String[] MQformats = sParams.get("MQformats").split(",");
        logger.debug("Checking for MQ formats: " + Arrays.toString(MQformats));
        for (String format : MQformats) {
            List<String> videoFileList = sip.getAVMaterial(format, "FILE");
            if (videoFileList.size() > 0) {
                videoFile = videoFileList.get(0);
                break;
            }
        }
        if (videoFile == null) {
            throw new TaskExecutionFailedException("Unable to find supported MQ format...");
        }

        // run FFprobe
        FFprobe ffprobe = new FFprobe();

        ToolOutput<FFprobe.AttributeType> output = ffprobe.extract(videoFile);
        String ffprobeOutput = output.getAttribute(FFprobe.AttributeType.json);

        Section section = new Section();
        section.setId("ffprobe");

        // get JSON Object
        JSONObject jsonOutput = new JSONObject(ffprobeOutput);

        // FFprobe show format
        JSONObject jsonFormat = jsonOutput.getJSONObject("format");

        Iterator<String> itFormat = jsonFormat.keys();

        while (itFormat.hasNext()) {

            String key = itFormat.next();
            String value = jsonFormat.getString(key);

            Record record = new Record();
            Key keyType = new Key();
            keyType.setId("significantPropertiesType");
            keyType.setValue("ffprobe:" + key);
            record.getKey().add(keyType);
            Key keyValue = new Key();
            keyValue.setId("significantPropertiesValue");
            keyValue.setValue(value);
            record.getKey().add(keyValue);
            section.getRecord().add(record);
        }

        // set format
        String formatN = jsonFormat.getString("format_name");
        String formatLN = jsonFormat.getString("format_long_name");

        // size
        String size = jsonFormat.getString("size");

        dParamsString.put("isMXF", "false");
        if (formatN != null) {
            synchronized (sip) {
                List<String> formats = sip.getDCField(DCField.format);
                formats.add(formatLN + "(" + formatN.toUpperCase() + ")");
                sip.setDCField(DCField.format, formats);
            }

            if (formatN.equalsIgnoreCase("MXF")) {
                dParamsString.put("isMXF", "true");
            }
        }

        // FFprobe show streams
        JSONArray jsonStreams = jsonOutput.getJSONArray("streams");

        String secDuration = null;
        String frameRate = null;
        int numOfStreams = jsonStreams.length();

        for (int i = 0; i < numOfStreams; i++) {

            JSONObject jsonStream = jsonStreams.getJSONObject(i);
            String index = jsonStream.getString("index");

            Iterator<String> itStream = jsonStream.keys();

            while (itStream.hasNext()) {
                String key = itStream.next();
                String value = jsonStream.getString(key);

                Record record = new Record();
                Key keyType = new Key();
                keyType.setId("significantPropertiesType");
                keyType.setValue("ffprobe:" + key + "_" + index);
                record.getKey().add(keyType);
                Key keyValue = new Key();
                keyValue.setId("significantPropertiesValue");
                keyValue.setValue(value);
                record.getKey().add(keyValue);
                section.getRecord().add(record);
            }

            if (jsonStream.getString("codec_type").equals("video")) {

                secDuration = jsonStream.getString("duration");
                frameRate = jsonStream.getString("r_frame_rate");
            }

        }

        try {
            dParamsString.put("duration", "" + (int) Double.parseDouble(secDuration));

        } catch (NumberFormatException e) {
            dParamsString.put("duration", "0");
        }

        if (frameRate != null) {

            String fpsString = frameRate.split("/")[0];

            try {
                dParamsString.put("fps", "" + Integer.parseInt(fpsString));
            } catch (NumberFormatException e) {
                dParamsString.put("fps", "25");
            }
        }

        // set new DNX section
        Dnx dnx = new Dnx();
        dnx.getSection().add(section);
        sip.addDNX(dnx, "ffprobe", true);

        // add DNX section with video information
        Record videoRecord = new Record();

        Key key1 = new Key();
        key1.setId("duration");
        key1.setValue(secDuration);
        videoRecord.getKey().add(key1);

        Key key2 = new Key();
        key2.setId("nb_streams");
        key2.setValue(String.valueOf(numOfStreams));
        videoRecord.getKey().add(key2);

        Key key3 = new Key();
        key3.setId("format_long_name");
        key3.setValue(formatLN);
        videoRecord.getKey().add(key3);

        Key key4 = new Key();
        key4.setId("size");
        key4.setValue(size);
        videoRecord.getKey().add(key4);

        Section videoSec = new Section();
        videoSec.setId("videoMD");
        videoSec.getRecord().add(videoRecord);

        Dnx videoDnx = new Dnx();
        videoDnx.getSection().add(videoSec);

        sip.addDNX(videoDnx, "videoMD", false);

    } catch (JSONException e) {
        e.printStackTrace();
        throw new TaskExecutionFailedException("Unable to parse JSON output from ffprobe...");
    } catch (DataException e) {
        e.printStackTrace();
        throw new TaskExecutionFailedException("Unable to retrieve the SIP...");
    } catch (IPException e) {
        e.printStackTrace();
        throw new TaskExecutionFailedException("Unable to work with SIP...");
    } catch (ToolException e) {
        e.printStackTrace();
        throw new TaskExecutionFailedException("Unable to run FFProbe...");
    } finally {
        // release SIP
        P4DataManager.getInstance().releaseIP(sip);
    }
}

From source file:edu.harvard.mcz.imagecapture.VerbatimClassifyDialog.java

protected void saveChanges() {
    if (jTableCollectors.isEditing()) {
        jTableCollectors.getCellEditor().stopCellEditing();
    }//from   w  w w.java  2  s  . c o m
    if (jTableNumbers.isEditing()) {
        jTableNumbers.getCellEditor().stopCellEditing();
    }

    log.debug("Saving verbatim data changes to all records with shared verbatim data.");
    log.debug("Should affect " + this.verbatimData.getCount() + " Specimen records.");
    SpecimenLifeCycle sls = new SpecimenLifeCycle();
    List<Specimen> specimens = sls.findSpecimensFromVerbatim(verbatimData);
    Iterator<Specimen> i = specimens.iterator();
    while (i.hasNext()) {
        Specimen specimen = i.next();

        // populate fields from parsed (10 fields, 2 lists)

        if (comboBoxHigherGeog.getSelectedIndex() == -1 && comboBoxHigherGeog.getSelectedItem() == null) {
            specimen.setHigherGeography("");
        } else {
            // combo box contains a geography object, obtain the higher geography string.
            specimen.setHigherGeography(((HigherGeographyComboBoxModel) comboBoxHigherGeog.getModel())
                    .getSelectedItemHigherGeography());
        }

        specimen.setSpecificLocality(textFieldSpecificLocality.getText());

        if (jTableCollectors.getModel().getRowCount() > 0) {
            // add collectors
            int rows = jTableCollectors.getModel().getRowCount();
            for (int row = 0; row < rows; row++) {
                String collector = (String) jTableCollectors.getModel().getValueAt(row, 1);
                specimen.getCollectors().add(new Collector(specimen, collector));
            }
        }

        if (jComboBoxCollection.getSelectedIndex() == -1 && jComboBoxCollection.getSelectedItem() == null) {
            specimen.setCollection("");
        } else {
            specimen.setCollection(jComboBoxCollection.getSelectedItem().toString());
        }

        // Elevations
        Long min_elev;
        if (textFieldMinElevation.getText().trim().length() == 0) {
            min_elev = null;
        } else {
            try {
                min_elev = Long.parseLong(textFieldMinElevation.getText());
            } catch (NumberFormatException e) {
                min_elev = null;
            }
        }
        specimen.setMinimum_elevation(min_elev);
        Long max_elev;
        if (textFieldMaxElevation.getText().trim().length() == 0) {
            max_elev = null;
        } else {
            try {
                max_elev = Long.parseLong(textFieldMaxElevation.getText());
            } catch (NumberFormatException e) {
                max_elev = null;
            }
        }
        specimen.setMaximum_elevation(max_elev);
        if (this.comboBoxElevUnits.getSelectedIndex() == -1 && comboBoxElevUnits.getSelectedItem() == null) {
            specimen.setElev_units("");
        } else {
            specimen.setElev_units(comboBoxElevUnits.getSelectedItem().toString());
        }

        specimen.setIsoDate(textFieldISODate.getText().trim());

        specimen.setHabitat(textFieldHabitat.getText());
        specimen.setMicrohabitat(textFieldMicrohabitat.getText());

        specimen.setWorkFlowStatus((String) comboBoxWorkflowStatus.getSelectedItem());

        // store values for reuse 
        storeLastEditedValues(specimen);

        try {
            sls.attachDirty(specimen);
        } catch (SaveFailedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

From source file:com.amaze.filemanager.fragments.MainFragment.java

private LayoutElementParcelable addTo(HybridFileParcelable mFile) {
    File f = new File(mFile.getPath());
    String size = "";
    if (!dataUtils.isFileHidden(mFile.getPath())) {
        if (mFile.isDirectory()) {
            size = "";
            LayoutElementParcelable layoutElement = new LayoutElementParcelable(f.getPath(),
                    mFile.getPermission(), mFile.getLink(), size, 0, true, mFile.getDate() + "", false,
                    getBoolean(PREFERENCE_SHOW_THUMB), mFile.getMode());

            LIST_ELEMENTS.add(layoutElement);
            folder_count++;//www.  jav  a 2s  .  c o m
            return layoutElement;
        } else {
            long longSize = 0;
            try {
                if (mFile.getSize() != -1) {
                    longSize = mFile.getSize();
                    size = Formatter.formatFileSize(getContext(), longSize);
                } else {
                    size = "";
                    longSize = 0;
                }
            } catch (NumberFormatException e) {
                //e.printStackTrace();
            }
            try {
                LayoutElementParcelable layoutElement = new LayoutElementParcelable(f.getPath(),
                        mFile.getPermission(), mFile.getLink(), size, longSize, false, mFile.getDate() + "",
                        false, getBoolean(PREFERENCE_SHOW_THUMB), mFile.getMode());
                LIST_ELEMENTS.add(layoutElement);
                file_count++;
                return layoutElement;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return null;
}