代码之家  ›  专栏  ›  技术社区  ›  Julio Faerman

HTML5离线GWT应用程序

gwt
  •  4
  • Julio Faerman  · 技术社区  · 14 年前

    本地存储,但要做到这一点,我需要构建清单文件 列出所有GWT生成的文件,对吗? 我可以在编译过程中这样做,还是在编译过程中这样做更好

    3 回复  |  直到 14 年前
        1
  •  5
  •   Jason Hall    14 年前

    最接近的选择(可能是编写HTML5链接器的一个好的起点)是 the Gears offline linker

    还有一个关于 using GWT linkers to have your app take advantage of HTML5 Web Workers .

        2
  •  2
  •   Pete Aykroyd    13 年前

    我前几天在工作的时候不得不这么做。正如前面的答案所说,您只需要添加一个链接器。下面是一个基于模板文件为Safari用户代理创建清单文件的示例。

    // Specify the LinkerOrder as Post... this does not replace the regular GWT linker and runs after it.
    @LinkerOrder(LinkerOrder.Order.POST)
    public class GwtAppCacheLinker extends AbstractLinker {
      public String getDescription() {
        return "to create an HTML5 application cache manifest JSP template.";
      }
    
      public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts) throws UnableToCompleteException {
        ArtifactSet newArtifacts = new ArtifactSet(artifacts);
        // search through each of the compilation results to find the one for Safari. Then 
        // generate application cache for that file
        for (CompilationResult compilationResult : artifacts.find(CompilationResult.class)) {
          // Only emit the safari version
          for (SelectionProperty property : context.getProperties()) {
            if (property.getName().equals("user.agent")) {
              String value = property.tryGetValue();
              // we only care about the Safari user agent in this case
              if (value != null && value.equals("safari")) {
                newArtifacts.add(createCache(logger, context, compilationResult));
                break;
              }
            }
          }
        }
    
        return newArtifacts;
      }
    
      private SyntheticArtifact createCache(TreeLogger logger, LinkerContext context, CompilationResult result)
          throws UnableToCompleteException {
        try {
          logger.log(TreeLogger.Type.INFO, "Using the Safari user agent for the manifest file.");
          // load a template JSP file into a string. This contains all of the files that we want in our cache
          // manifest and a placeholder for the GWT javascript file, which will replace with the actual file next
          String manifest = IOUtils.toString(getClass().getResourceAsStream("cache.template.manifest"));
          // replace the placeholder with the real file name
          manifest = manifest.replace("$SAFARI_HTML_FILE_CHECKSUM$", result.getStrongName());
          // return the Artifact named as the file we want to call it
          return emitString(logger, manifest, "cache.manifest.");
        } catch (IOException e) {
          logger.log(TreeLogger.ERROR, "Couldn't read cache manifest template.", e);
          throw new UnableToCompleteException();
        }
      }
    }
    
        3
  •  1
  •   Joseph Lust    11 年前