Esempio n. 1
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;
  }
Esempio n. 2
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;
  }
Esempio n. 3
0
  public void addFontFaceRule(FontFaceRule rule) {
    assert rule != null;

    String family = rule.getFamily();
    boolean bold = rule.isBold();
    boolean italic = rule.isItalic();

    if (getFontFaceRule(family, bold, italic) == null) {
      fontFaceRules.add(rule);

      //    add embed for font
      String propName =
          "_embed__font_"
              + family
              + "_"
              + (bold ? "bold" : "medium")
              + "_"
              + (italic ? "italic" : "normal");
      Map embedParams = rule.getEmbedParams();
      StyleDeclaration styleDeclaration = rule.getStyle();
      String path = styleDeclaration.getPath();

      if (path.indexOf('\\') > -1) {
        embedParams.put(Transcoder.FILE, path.replace('\\', '/'));
        embedParams.put(Transcoder.PATHSEP, "true");
      } else {
        embedParams.put(Transcoder.FILE, path);
      }

      embedParams.put(Transcoder.LINE, Integer.toString(styleDeclaration.getLineNumber()));
      AtEmbed atEmbed =
          AtEmbed.create(propName, rule.getStyle().getLineNumber(), embedParams, false);
      addAtEmbed(atEmbed);
    } else if (Trace.font) {
      Trace.trace(
          "Font face already existed for " + family + " bold? " + bold + " italic? " + italic);
    }
  }