public static String[] split(String s, String delimiter) {
        if (s == null || delimiter == null) {
            return new String[0];
        }

        if (!s.endsWith(delimiter)) {
            s += delimiter;
        }

        s = s.trim();

        if (s.equals(delimiter)) {
            return new String[0];
        }

        List nodeValues = new ArrayList();

        if (delimiter.equals("\n") || delimiter.equals("\r")) {
            try {
                BufferedReader br = new BufferedReader(new StringReader(s));

                String line = null;

                while ((line = br.readLine()) != null) {
                    nodeValues.add(line);
                }

                br.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        } else {
            int offset = 0;
            int pos = s.indexOf(delimiter, offset);

            while (pos != -1) {
                nodeValues.add(s.substring(offset, pos));

                offset = pos + delimiter.length();
                pos = s.indexOf(delimiter, offset);
            }
        }

        return (String[])nodeValues.toArray(new String[0]);
    }