Source code: medi/db/util/FileManager.java
1 /*
2 * FileManager.java
3 *
4 * Created on 17 giugno 2002, 9.24
5 Medi - A media archiver. Archives media files for easy management.
6 Copyright (C) 2002-2003 Antonio Petrelli
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Contact me at: brenmcguire@users.sourceforge.net
23 */
24
25 package medi.db.util;
26
27 import medi.db.AbstractProvider;
28 import medi.db.util.*;
29 import medi.swing.dialog.MountManagement;
30 import javatools.db.*;
31 import java.io.*;
32
33 /**
34 * A class that contains a set of static functions to manage files mapped in the
35 * database.
36 * @author Antonio Petrelli
37 * @version 0.2.0
38 */
39 public class FileManager {
40
41 /** Creates new FileManager */
42 public FileManager() {
43 }
44
45 /** Execute a file whose data ID is specified.
46 * @param prv The provider to use.
47 * @param vmount The volume mounter to use.
48 * @param dataID The data ID to open.
49 * @throws DbException If something goes wrong.
50 * @throws IOException If the file is invalid.
51 */
52 public static void execute(AbstractProvider prv, VolumeMounter vmount, Long dataID)
53 throws DbException, IOException {
54 int result;
55 DbIterator rowIt;
56 DbRow tempRow;
57 Integer firstVolumeID, tempVolumeID, volumeID,
58 firstSessionID, tempSessionID, sessionID;
59 String mountPoint, completePath, command, tempPath, tempOptions;
60 String containerType, containerLocation, volumeName;
61 Runtime rt;
62 String[] cmdArray;
63 boolean noOptions;
64
65 rowIt = prv.getSessionsByData(dataID).iterator();
66 mountPoint = null;
67 firstVolumeID = null;
68 volumeID = null;
69 firstSessionID = null;
70 sessionID = null;
71 if (rowIt.hasNextRow()) {
72 tempRow = rowIt.nextRow();
73 firstVolumeID = (Integer) tempRow.getValue(0);
74 firstSessionID = (Integer) tempRow.getValue(1);
75 mountPoint = vmount.getMountPoint(firstVolumeID);
76 if (mountPoint != null) {
77 volumeID = firstVolumeID;
78 sessionID = firstSessionID;
79 }
80 }
81 while (rowIt.hasNextRow() && mountPoint == null) {
82 tempRow = rowIt.nextRow();
83 tempVolumeID = (Integer) tempRow.getValue(0);
84 tempSessionID = (Integer) tempRow.getValue(1);
85 mountPoint = vmount.getMountPoint(tempVolumeID);
86 if (mountPoint != null) {
87 volumeID = tempVolumeID;
88 sessionID = tempSessionID;
89 }
90 }
91 if (volumeID == null) {
92 volumeID = firstVolumeID;
93 sessionID = firstSessionID;
94 }
95 if (volumeID != null) {
96 if (mountPoint == null) {
97 rowIt = prv.getVolumeLocation(volumeID).iterator();
98 if (rowIt.hasNext()) {
99 tempRow = rowIt.nextRow();
100 containerType = (String) tempRow.getValue(0);
101 containerLocation = (String) tempRow.getValue(1);
102 volumeName = (String) tempRow.getValue(2);
103 }
104 else {
105 rowIt = prv.getVolumes(null, volumeID).iterator();
106 if (rowIt.hasNextRow()) {
107 tempRow = rowIt.nextRow();
108 containerType = null;
109 containerLocation = null;
110 volumeName = (String) tempRow.getValue(2);
111 }
112 else {
113 containerType = null;
114 containerLocation = null;
115 volumeName = null;
116 }
117 }
118 result = MountManagement.showSelectDialog(prv, containerType,
119 containerLocation, volumeName);
120 if (result == 1)
121 mountPoint = MountManagement.getSelectedMountPoint();
122 }
123 if (mountPoint != null) {
124 vmount.mount(mountPoint, volumeID);
125 tempPath = prv.buildPath("", volumeID, sessionID);
126 if (tempPath.equals(""))
127 completePath = mountPoint + "/";
128 else
129 completePath = mountPoint + "/" + tempPath + "/";
130 rowIt = prv.getData(dataID).iterator();
131 if (rowIt.hasNextRow()) {
132 completePath += (String) rowIt.nextRow().getValue(3);
133 tempRow = null;
134 rowIt = prv.getDefaultProgramByData(dataID).iterator();
135 if (rowIt.hasNextRow())
136 tempRow = rowIt.nextRow();
137 else {
138 rowIt = prv.getProgramsByData(dataID).iterator();
139 if (rowIt.hasNextRow())
140 tempRow = rowIt.nextRow();
141 }
142 if (tempRow != null) {
143 noOptions = false;
144 tempOptions = (String) tempRow.getValue(3);
145 if (tempOptions != null) {
146 if (tempOptions.trim().equals(""))
147 noOptions = true;
148 }
149 else
150 noOptions = true;
151 if (noOptions)
152 cmdArray = new String[2];
153 else
154 cmdArray = new String[3];
155 cmdArray[0] = (String) tempRow.getValue(2);
156 cmdArray[1] = completePath;
157 if (!noOptions)
158 cmdArray[2]= (String) tempRow.getValue(3);
159 rt = Runtime.getRuntime();
160 rt.exec(cmdArray);
161 }
162 }
163 }
164 }
165 }
166
167 }