1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: ParcelSupport.java,v $
*
* $Revision: 1.5 $
*
* last change: $Author: rt $ $Date: 2005-09-09 02:13:17 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
package org.openoffice.netbeans.modules.office.actions;
import java.io.File;
import java.io.IOException;
import java.beans.PropertyVetoException;
import java.util.Enumeration;
import java.util.Calendar;
import org.openide.TopManager;
import org.openide.NotifyDescriptor;
import org.openide.windows.OutputWriter;
import org.openide.windows.InputOutput;
import org.openide.ErrorManager;
import org.openide.nodes.Node;
import org.openide.filesystems.Repository;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.FileEvent;
import org.openoffice.idesupport.zip.ParcelZipper;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
import org.openoffice.netbeans.modules.office.utils.NagDialog;
import org.openoffice.netbeans.modules.office.utils.ZipMounter;
import org.openoffice.netbeans.modules.office.utils.ManifestParser;
public class ParcelSupport implements ParcelCookie
{
private FileObject fo;
private ParcelZipper zipper = ParcelZipper.getParcelZipper();
private String language = null;
public ParcelSupport(FileObject fo) {
this.fo = fo;
}
public File getFile() {
return FileUtil.toFile(fo);
}
public String getLanguage() {
if (language == null) {
try {
language = zipper.getParcelLanguage(getFile());
}
catch (IOException ioe) {
return null;
}
}
return language;
}
public void mount()
{
File parcel = FileUtil.toFile(fo);
if (parcel != null) {
try {
ZipMounter.getZipMounter().mountZipFile(parcel);
}
catch (IOException ioe) {
ErrorManager.getDefault().notify(ioe);
}
catch (PropertyVetoException pve) {
ErrorManager.getDefault().notify(pve);
}
}
}
public boolean deploy(File target) {
File source = FileUtil.toFile(fo);
if (!target.isDirectory()) {
OfficeSettings settings = OfficeSettings.getDefault();
String message = "If you already have this document open in " +
"Office, please close it before continuing. Click OK to " +
"continue deployment.";
if (settings.getWarnBeforeDocDeploy() == true) {
NagDialog warning = NagDialog.createConfirmationDialog(
message, "Show this message in future", true);
boolean result = warning.show();
if (warning.getState() == false)
settings.setWarnBeforeDocDeploy(false);
if (result == false)
return false;
}
}
OutputWriter out =
getOutputWindowWriter(fo.getName() + " (deploying)");
try {
if (zipper.isOverwriteNeeded(source, target) == true)
if (promptForOverwrite(source, target) == false)
return false;
}
catch (IOException ioe) {
out.println("DEPLOYMENT FAILED: reason: " +
ioe.getClass().getName() + ": "+ ioe.getMessage());
return false;
}
try {
out.println("Deploying: " + fo.getName() +
"\nTo: " + target.getAbsolutePath(), null);
zipper.deployParcel(source, target);
out.println("\nDEPLOYMENT SUCCESSFUL.");
FileObject[] fileobjs = FileUtil.fromFile(target);
if (fileobjs != null) {
for (int i = 0; i < fileobjs.length; i++)
fileobjs[i].refresh(true);
}
}
catch (IOException ioe) {
out.println("DEPLOYMENT FAILED: reason: " +
ioe.getClass().getName() + ": "+ ioe.getMessage());
return false;
}
finally {
if( out != null)
out.close();
}
return true;
}
public static OutputWriter getOutputWindowWriter(String title) {
InputOutput io = TopManager.getDefault().getIO(title, false);
io.setFocusTaken(true);
io.setOutputVisible(true);
OutputWriter out = io.getOut();
try {
out.reset();
}
catch( IOException e) {
e.printStackTrace(System.err);
}
out.println(Calendar.getInstance().getTime() + ":\n");
return out;
}
private boolean promptForOverwrite(File source, File target) {
String message = source.getName() + " has already been deployed " +
"to this target. Do you wish to overwrite it?";
NotifyDescriptor d = new NotifyDescriptor.Confirmation(
message, NotifyDescriptor.OK_CANCEL_OPTION);
TopManager.getDefault().notify(d);
if (d.getValue() == NotifyDescriptor.CANCEL_OPTION)
return false;
else
return true;
}
}
|