001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.session;
025:
026: import jacareto.cleverphl.CleverPHL;
027:
028: import java.io.File;
029: import java.io.FileFilter;
030:
031: import java.util.Arrays;
032: import java.util.Vector;
033:
034: /**
035: * A toolkit for sessions.
036: *
037: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
038: * @version 1.00
039: */
040: public class SessionUtilities {
041: /**
042: * Returns a default record name for a given session.
043: *
044: * @param cleverPHL the cleverphl instance
045: * @param session the session
046: *
047: * @return DOCUMENT ME!
048: */
049: public static String getDefaultRecordName(CleverPHL cleverPHL,
050: Session session) {
051: String recordString = cleverPHL.getLanguage().getString(
052: "General.Record");
053:
054: return session.getName() + " " + recordString;
055: }
056:
057: /**
058: * Returns an array containing the names of all stored sessions.
059: *
060: * @param cleverPHL the CleverPHL instance
061: *
062: * @return an array with the names of stored sessions.
063: */
064: public static String[] getStoredSessionNames(CleverPHL cleverPHL) {
065: String[] result;
066: File sessionDir = cleverPHL.getFiles().getDir(
067: "CLEVERPHL_SESSIONS_DIR");
068: File[] dirs = sessionDir.listFiles(new FileFilter() {
069: public boolean accept(File file) {
070: return file.isDirectory();
071: }
072: });
073:
074: result = new String[dirs.length];
075:
076: for (int i = 0; i < dirs.length; i++) {
077: result[i] = dirs[i].getName();
078: }
079:
080: return result;
081: }
082:
083: /**
084: * Returns an array containing the names of all open sessions
085: *
086: * @param cleverPHL the CleverPHL instance
087: *
088: * @return an array with all open session names.
089: */
090: public static String[] getOpenSessionNames(CleverPHL cleverPHL) {
091: SessionList sessionList = cleverPHL.getSessionList();
092: String[] result = new String[sessionList.size()];
093:
094: for (int i = 0; i < result.length; i++) {
095: result[i] = sessionList.get(i).getName();
096: }
097:
098: return result;
099: }
100:
101: /**
102: * Returns an array containing the names of all sessions (stored and not stored ones)
103: *
104: * @param cleverPHL the CleverPHL instance
105: *
106: * @return an array with all session names.
107: */
108: public static String[] getAllSessionNames(CleverPHL cleverPHL) {
109: Vector sessions = new Vector(Arrays
110: .asList(getStoredSessionNames(cleverPHL)));
111:
112: String[] openSessions = getOpenSessionNames(cleverPHL);
113:
114: for (int i = 0; i < openSessions.length; i++) {
115: if (!sessions.contains(openSessions[i])) {
116: sessions.add(openSessions[i]);
117: }
118: }
119:
120: String[] result = new String[sessions.size()];
121:
122: for (int i = 0; i < result.length; i++) {
123: result[i] = (String) sessions.get(i);
124: }
125:
126: Arrays.sort(result);
127:
128: return (result);
129: }
130: }
|