Пример #1
0
  public void setLastModified(String location, long lastModified) {
    Swc swc = (Swc) swcLRUCache.get(location);

    if (swc != null) {
      swc.setLastModified(lastModified);
    }
  }
Пример #2
0
  // changed from private to protected to support Flash Authoring - jkamerer 2007.07.30
  protected Swc getSwc(File file) {
    Swc swc;
    try {
      String location = FileUtils.canonicalPath(file);
      swc = (Swc) swcLRUCache.get(location);

      long fileLastModified = file.lastModified();

      if (swc == null || (fileLastModified != swc.getLastModified())) {
        if (Trace.swc) {
          if (swc != null) {
            Trace.trace(
                "Reloading: location = "
                    + location
                    + ", fileLastModified = "
                    + fileLastModified
                    + ", swc.getLastModified() = "
                    + swc.getLastModified()
                    + ", swc = "
                    + swc.hashCode());
          } else {
            Trace.trace("Loading " + location);
          }
        }

        SwcArchive archive =
            file.isDirectory()
                ? (SwcArchive) new SwcDirectoryArchive(location)
                : lazyRead ? new SwcLazyReadArchive(location) : new SwcDynamicArchive(location);

        swc = new Swc(archive, true);
        swc.setLastModified(fileLastModified);

        if (ThreadLocalToolkit.errorCount() > 0) {
          swc = null;
        } else if (useCache) {
          swcLRUCache.put(location, swc);
        }
      } else if (Trace.swc) {
        Trace.trace("Using cached version of " + location);
      }
    } catch (Exception e) {
      if (Trace.error) {
        e.printStackTrace();
      }
      SwcException.SwcNotLoaded ex = new SwcException.SwcNotLoaded(file.getName(), e);
      ThreadLocalToolkit.log(ex);
      throw ex;
    }
    return swc;
  }
Пример #3
0
  /** Saves the given SWC to disk and adds to the cache */
  public synchronized boolean export(Swc swc) throws FileNotFoundException, IOException {
    try {
      if (!swc.save()) {
        return false;
      }

      if (Trace.swc) {
        Trace.trace("Exported SWC " + swc.getLocation() + "(" + swc.getLastModified() + ")");
      }

      if (!(swc.getArchive() instanceof SwcWriteOnlyArchive)) {
        // add to Swc cache
        swcLRUCache.put(swc.getLocation(), swc);
      }
    } catch (Exception e) {
      if (Trace.error) {
        e.printStackTrace();
      }
      if (e instanceof SwcException) {
        throw (SwcException) e;
      } else {
        SwcException ex = new SwcException.SwcNotExported(swc.getLocation(), e);
        ThreadLocalToolkit.log(ex);
        throw ex;
      }
    }
    return true;
  }
Пример #4
0
  // changed from private to protected to support Flash Authoring - jkamerer 2007.07.30
  protected Map<String, Swc> getSwcs(String path) {
    Map<String, Swc> map = new LinkedHashMap<String, Swc>();
    File f = new File(path);
    if (!f.exists()) {
      throw new SwcException.SwcNotFound(path);
    }
    File catalog = new File(FileUtils.addPathComponents(path, Swc.CATALOG_XML, File.separatorChar));

    if (!f.isDirectory() || catalog.exists()) {
      Swc swc = getSwc(f);
      if (swc != null) {
        map.put(swc.getLocation(), swc);
      }
    } else {
      File[] files = FileUtils.listFiles(f);
      for (int i = 0; i < files.length; i++) {
        File file = files[i];

        // we don't want to snarf an entire directory tree, just a single level.
        if ((!file.isDirectory()) && file.canRead()) {
          String lowerCase = file.getName().toLowerCase();

          if (lowerCase.endsWith(GENSWC_EXTENSION)) // never automatically read genswcs
          continue;

          if (lowerCase.endsWith(SWC_EXTENSION)) {
            Swc swc = getSwc(file);
            if (swc != null) {
              map.put(swc.getLocation(), swc);
            }
          }
        }
      }
    }
    return map;
  }