MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / openLibraryResource

Method openLibraryResource

src/test/LoaderTest.java:241–292  ·  view source on GitHub ↗
(LibraryResource record)

Source from the content-addressed store, hash-verified

239 }
240
241 private void openLibraryResource(LibraryResource record) {
242 boolean loadFailed = false;
243 try {
244 libraryBrowser.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
245 String target = record.getAbsoluteTarget();
246 if (!ResourceLoader.isHTTP(target)) {
247 target = ResourceLoader.getURIPath(XML.getResolvedPath(record.getTarget(), record.getBasePath()));
248 }
249 // download comPADRE targets to osp cache
250 if (target.indexOf("document/ServeFile.cfm?") >= 0) {
251 String fileName = record.getProperty("download_filename");
252 try {
253 target = ResourceLoader.downloadToOSPCache(target, fileName, false).toURI().toString();
254 } catch (Exception ex) {
255 loadFailed = true;
256 }
257 }
258 if (target == null) {
259 loadFailed = true;
260 }
261 if (loadFailed) {
262 String name = record.getName();
263 if (name == null || "".equals(name))
264 name = "Unknown";
265 String s = "No resource could be downloaded for node " + name;
266 JOptionPane.showMessageDialog(libraryBrowser, s, "Error",
267 JOptionPane.WARNING_MESSAGE);
268 return;
269 }
270 if (!isZip(target)) {
271 String msg = XML.getName(target)+ " is not a zip file.";
272 JOptionPane.showMessageDialog(frame, msg, "Wrong File Type",
273 JOptionPane.WARNING_MESSAGE);
274 return;
275 }
276 else {
277 // check target to make sure it is a readable zip file
278 Map<String, ZipEntry> contents = ResourceLoader.getZipContents(target, true);
279 if (contents.isEmpty()) {
280 String msg = XML.getName(target)+ " is empty.";
281 JOptionPane.showMessageDialog(frame, msg, "Empty File",
282 JOptionPane.WARNING_MESSAGE);
283 return;
284 }
285// loadIntoEditor(target);
286 new AsyncLoader(target).executeAsync();
287 return;
288 }
289 } finally {
290 libraryBrowser.setCursor(Cursor.getDefaultCursor());
291 }
292 }
293
294 private boolean loadIntoEditor(String path) {
295 Map<String, ZipEntry> contents = ResourceLoader.getZipContents(path, true);

Callers 1

propertyChangeMethod · 0.95

Calls 15

isHTTPMethod · 0.95
getURIPathMethod · 0.95
getResolvedPathMethod · 0.95
downloadToOSPCacheMethod · 0.95
isZipMethod · 0.95
getNameMethod · 0.95
getZipContentsMethod · 0.95
showMessageDialogMethod · 0.80
executeAsyncMethod · 0.80
setCursorMethod · 0.65
getPropertyMethod · 0.65
getNameMethod · 0.65

Tested by

no test coverage detected