author | Eugene Ostroukhov <eostroukhov@symbian.org> |
Tue, 12 Jan 2010 13:50:32 -0800 | |
changeset 30 | 50ffca984095 |
parent 22 | 6297dfe3bd9d |
child 38 | 954dbf7baac6 |
permissions | -rw-r--r-- |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
1 |
/** |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
3 |
* All rights reserved. |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
8 |
* |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
9 |
* Initial Contributors: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
11 |
* Contributors: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
12 |
* Description: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
13 |
* Overview: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
14 |
* Details: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
15 |
* Platforms/Drives/Compatibility: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
16 |
* Assumptions/Requirement/Pre-requisites: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
17 |
* Failures and causes: |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
18 |
*/ |
11 | 19 |
package org.symbian.tools.wrttools.util; |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
20 |
|
11 | 21 |
import java.io.BufferedInputStream; |
22 |
import java.io.File; |
|
23 |
import java.io.FileInputStream; |
|
24 |
import java.io.FileNotFoundException; |
|
25 |
import java.io.FileOutputStream; |
|
26 |
import java.io.IOException; |
|
27 |
import java.io.InputStream; |
|
28 |
import java.io.OutputStream; |
|
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
29 |
import java.net.URI; |
11 | 30 |
import java.util.zip.ZipEntry; |
31 |
import java.util.zip.ZipInputStream; |
|
32 |
import java.util.zip.ZipOutputStream; |
|
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
33 |
|
11 | 34 |
import javax.swing.filechooser.FileSystemView; |
35 |
||
36 |
import org.eclipse.core.resources.IFile; |
|
37 |
import org.eclipse.core.resources.IFolder; |
|
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
38 |
import org.eclipse.core.resources.IProject; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
39 |
import org.eclipse.core.resources.IWorkspace; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
40 |
import org.eclipse.core.resources.ResourcesPlugin; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
41 |
import org.eclipse.core.runtime.CoreException; |
11 | 42 |
import org.eclipse.core.runtime.IPath; |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
43 |
import org.eclipse.core.runtime.IProgressMonitor; |
11 | 44 |
import org.eclipse.core.runtime.IStatus; |
45 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
46 |
import org.eclipse.core.runtime.Status; |
|
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
47 |
import org.eclipse.core.runtime.SubProgressMonitor; |
11 | 48 |
import org.eclipse.jface.window.Window; |
49 |
import org.eclipse.swt.widgets.Display; |
|
50 |
import org.eclipse.ui.PlatformUI; |
|
51 |
import org.eclipse.ui.statushandlers.StatusManager; |
|
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
52 |
import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.BuildPathsBlock; |
30
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
53 |
import org.eclipse.wst.sse.core.StructuredModelManager; |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
54 |
import org.eclipse.wst.sse.core.internal.provisional.IModelManager; |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
55 |
import org.eclipse.wst.validation.ValidationFramework; |
30
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
56 |
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
57 |
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; |
11 | 58 |
import org.symbian.tools.wrttools.Activator; |
59 |
import org.symbian.tools.wrttools.dialogs.AptanaProjectSelectionDialog; |
|
30
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
60 |
import org.w3c.dom.Element; |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
61 |
import org.w3c.dom.NodeList; |
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
62 |
|
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
63 |
public class ProjectUtils { |
30
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
64 |
private static final String WRT_PREVIEW_MAIN_HTML = "wrt_preview_main.html"; |
14 | 65 |
public static final String PREVIEW_FOLDER = "preview"; |
66 |
public static final String PREVIEW_FRAME_FILE = "wrt_preview_frame.html"; |
|
67 |
||
30
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
68 |
@SuppressWarnings("restriction") |
11 | 69 |
public static IProject createWrtProject(String name, URI uri, |
70 |
IProgressMonitor monitor) throws CoreException { |
|
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
71 |
monitor.beginTask("Create project resources", 20); |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
72 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
11 | 73 |
IProject project = workspace.getRoot().getProject(name); |
22
6297dfe3bd9d
Several bugfixes
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
14
diff
changeset
|
74 |
ValidationFramework.getDefault().addValidationBuilder(project); |
11 | 75 |
BuildPathsBlock.createProject(project, uri, new SubProgressMonitor( |
76 |
monitor, 10)); |
|
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
77 |
|
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
78 |
BuildPathsBlock.addJavaNature(project, new SubProgressMonitor(monitor, |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
79 |
10)); |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
80 |
|
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
81 |
// TODO: Build path, super type, etc. |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
82 |
// BuildPathsBlock.flush(classPathEntries, javaScriptProject, superType, |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
83 |
// monitor) |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
84 |
|
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
85 |
|
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
86 |
monitor.done(); |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
87 |
return project; |
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
88 |
} |
11 | 89 |
|
90 |
public static void addPreviewer(IProject project, IPath mainHtml) { |
|
91 |
URI archive = getPreviewerArchive(); |
|
92 |
try { |
|
93 |
if (archive != null) { |
|
94 |
ZipInputStream stream = new ZipInputStream(archive.toURL().openStream()); |
|
95 |
ZipEntry entry; |
|
96 |
while ((entry = stream.getNextEntry()) != null) { |
|
97 |
if (!entry.isDirectory()) { |
|
98 |
copyFile(project, entry.getName(), stream, entry.getSize(), new NullProgressMonitor()); |
|
99 |
} else { |
|
100 |
IFolder folder = project.getFolder(entry.getName()); |
|
101 |
if (!folder.exists()) { |
|
102 |
folder.create(false, true, new NullProgressMonitor()); |
|
103 |
} |
|
104 |
} |
|
105 |
stream.closeEntry(); |
|
106 |
} |
|
107 |
} |
|
30
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
108 |
createPreviewerHomePage(project, mainHtml); |
11 | 109 |
} catch (IOException e) { |
110 |
StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to add previewer to project")); |
|
111 |
} catch (CoreException e) { |
|
112 |
StatusManager.getManager().handle(e, Activator.PLUGIN_ID); |
|
113 |
} |
|
114 |
} |
|
115 |
||
30
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
116 |
@SuppressWarnings("restriction") |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
117 |
private static void createPreviewerHomePage(IProject project, IPath mainHtml) |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
118 |
throws CoreException, IOException { |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
119 |
IFile file = project.getFile(mainHtml + ".html"); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
120 |
if (file.exists()) { |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
121 |
IFile newFile = project.getFile(WRT_PREVIEW_MAIN_HTML); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
122 |
file.copy(newFile.getFullPath(), false, new NullProgressMonitor()); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
123 |
IModelManager modelManager = StructuredModelManager |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
124 |
.getModelManager(); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
125 |
IDOMModel model = (IDOMModel) modelManager |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
126 |
.getModelForEdit(newFile); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
127 |
if (model != null) { |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
128 |
try { |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
129 |
addJS(model); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
130 |
} finally { |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
131 |
model.releaseFromEdit(); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
132 |
} |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
133 |
} |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
134 |
} |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
135 |
} |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
136 |
|
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
137 |
@SuppressWarnings("restriction") |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
138 |
private static void addJS(IDOMModel model) throws IOException, CoreException { |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
139 |
IDOMDocument document = model.getDocument(); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
140 |
Element documentElement = document.getDocumentElement(); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
141 |
if (documentElement != null) { |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
142 |
NodeList elementsByTagName = documentElement.getElementsByTagName("head"); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
143 |
if (elementsByTagName.getLength() == 1) { // We do not want to handle malformed HTMLs |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
144 |
Element head = (Element) elementsByTagName.item(0); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
145 |
Element script = document.createElement("script"); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
146 |
script.setAttribute("language", "JavaScript"); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
147 |
script.setAttribute("type", "text/javascript"); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
148 |
script.setAttribute("src", "preview/script/lib/loader.js"); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
149 |
head.insertBefore(script, head.getFirstChild()); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
150 |
model.save(); |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
151 |
} |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
152 |
} |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
153 |
} |
50ffca984095
Home button now works, launch configuration was renamed
Eugene Ostroukhov <eostroukhov@symbian.org>
parents:
22
diff
changeset
|
154 |
|
11 | 155 |
private static URI getPreviewerArchive() { |
156 |
File file = getPreviewerZip(); |
|
157 |
if (file.isFile()) { |
|
158 |
return file.toURI(); |
|
159 |
} |
|
160 |
Display display = Display.getDefault(); |
|
161 |
display.syncExec(new Runnable() { |
|
162 |
@Override |
|
163 |
public void run() { |
|
164 |
importPreviewer(); |
|
165 |
} |
|
166 |
}); |
|
167 |
if (file.isFile()) { |
|
168 |
return file.toURI(); |
|
169 |
} |
|
170 |
return null; |
|
171 |
} |
|
172 |
||
173 |
private static File getPreviewerZip() { |
|
174 |
return Activator.getDefault().getStateLocation() |
|
175 |
.append("previewer.zip").toFile(); |
|
176 |
} |
|
177 |
||
14 | 178 |
private static void importPreviewer() { |
11 | 179 |
AptanaProjectSelectionDialog dialog = new AptanaProjectSelectionDialog( |
180 |
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
|
181 |
int open = dialog.open(); |
|
182 |
if (open == Window.OK) { |
|
183 |
File project = dialog.getProject(); |
|
184 |
try { |
|
185 |
zipPreviewer(project); |
|
186 |
} catch (IOException e) { |
|
187 |
StatusManager |
|
188 |
.getManager() |
|
189 |
.handle( |
|
190 |
new Status( |
|
191 |
IStatus.ERROR, |
|
192 |
Activator.PLUGIN_ID, |
|
193 |
"Failed to create Web Runtime previewer archive.", |
|
194 |
e), StatusManager.SHOW); |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
private static void zipPreviewer(File project) throws IOException { |
|
200 |
ZipOutputStream stream = new ZipOutputStream(new FileOutputStream( |
|
201 |
getPreviewerZip())); |
|
202 |
try { |
|
14 | 203 |
zip(new File(project, PREVIEW_FOLDER), stream, PREVIEW_FOLDER + "/"); |
204 |
zipFile(new File(project, PREVIEW_FRAME_FILE), |
|
205 |
PREVIEW_FRAME_FILE, stream); |
|
11 | 206 |
} finally { |
207 |
stream.close(); |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
private static void zip(File folder, ZipOutputStream stream, String path) |
|
212 |
throws IOException { |
|
213 |
ZipEntry entry = new ZipEntry(path); |
|
214 |
stream.putNextEntry(entry); |
|
215 |
stream.closeEntry(); |
|
216 |
File[] files = folder.listFiles(); |
|
217 |
for (File file : files) { |
|
218 |
if (file.isFile()) { |
|
219 |
zipFile(file, path + file.getName(), stream); |
|
220 |
} else { |
|
221 |
zip(file, stream, path + file.getName() + "/"); |
|
222 |
} |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
private static void zipFile(File file, String zipEntry, |
|
227 |
ZipOutputStream stream) throws IOException, FileNotFoundException { |
|
228 |
ZipEntry entry = new ZipEntry(zipEntry); |
|
229 |
stream.putNextEntry(entry); |
|
230 |
BufferedInputStream inputStream = new BufferedInputStream( |
|
231 |
new FileInputStream(file)); |
|
232 |
try { |
|
233 |
copy(inputStream, stream); |
|
234 |
} finally { |
|
235 |
inputStream.close(); |
|
236 |
} |
|
237 |
stream.closeEntry(); |
|
238 |
} |
|
239 |
||
240 |
private static void copy(InputStream in, OutputStream out) |
|
241 |
throws IOException { |
|
242 |
byte[] buffer = new byte[131072]; // 128k - should be enough for most |
|
243 |
// JS/CSS files |
|
244 |
int count; |
|
245 |
while ((count = in.read(buffer)) > 0) { |
|
246 |
out.write(buffer, 0, count); |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
public static String getDefaultAptanaLocation() { |
|
251 |
File myDocuments = FileSystemView.getFileSystemView() |
|
252 |
.getDefaultDirectory(); |
|
253 |
File file = new File(myDocuments, "Aptana Studio Workspace"); |
|
254 |
return file.exists() ? file.getAbsolutePath() : ""; |
|
255 |
} |
|
256 |
||
257 |
public static boolean isAptanaProject(File f) { |
|
14 | 258 |
return new File(f, PREVIEW_FOLDER).isDirectory() |
259 |
&& new File(f, PREVIEW_FRAME_FILE).isFile(); |
|
11 | 260 |
} |
261 |
||
262 |
public static void copyFile(IProject project, String name, ZipInputStream stream, |
|
263 |
long size, IProgressMonitor monitor) throws CoreException, |
|
264 |
IOException { |
|
265 |
IFile file = project.getFile(name); |
|
266 |
file.create(new NonClosingStream(stream), true, |
|
267 |
new SubProgressMonitor(monitor, 1)); |
|
268 |
} |
|
14 | 269 |
|
270 |
public static void importPreviewer(URI locationURI) { |
|
271 |
if (!getPreviewerZip().exists()) { |
|
272 |
File file = new File(locationURI); |
|
273 |
try { |
|
274 |
zipPreviewer(file); |
|
275 |
} catch (IOException e) { |
|
276 |
Activator.log(e); |
|
277 |
} |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
public static boolean isAptanaProject(URI locationURI) { |
|
282 |
return isAptanaProject(new File(locationURI)); |
|
283 |
} |
|
3
d3477de62514
Added new wizards for importing WRT projects. Added CSS Validator.
TasneemS@US-TASNEEMS
parents:
diff
changeset
|
284 |
} |