Package com.google.diffable.data

Examples of com.google.diffable.data.DiffableContext


    if (inj == null) {
      inj = TagUtils.getInjector(pageContext);
    }
    PageCoordinator coord = TagUtils.getCoordinator(pageContext, inj);
   
    DiffableContext ctx =
      (DiffableContext) pageContext.getServletContext().getAttribute(
        Constants.DIFFABLE_CONTEXT);
    if(ctx == null){
      throw new JspException("No diffable context defined!");
    }
    if (ctx.getServletPrefix() == null) {
      throw new JspException(
        "No servlet prefix defined!");
    }

    File found = null;
    if (!(new File(resource).exists())) {
      for (File folder : ctx.getResourceFolders()) {
        File test =
          new File(folder.getAbsolutePath() +
               File.separator + resource);
        if (test.exists()) {
          found = test;
          break;
        }
      }
    } else {
      found = new File(resource);
    }
    if (found == null) {
      throw new JspException("Cannot find resource " +
          resource + " referenced in DiffableTag");
    } else {
      Map<File, String> currentVersions = ctx.getCurrentVersions();
      if(!currentVersions.containsKey(found)) {
        throw new JspException(
          "Cannot find current version of resource '" +
          found.getAbsolutePath() + ".'");
      } else {
        try {
          String resourceHash = hashPath(found);
          pageContext.getOut().println("<script type='text/javascript'>");
          pageContext.getOut().println(
            "window['diffable']['" + resourceHash + "']={};");
          pageContext.getOut().println(
            "window['diffable']['" + resourceHash + "']" +
            "['cv'] = '" +
            currentVersions.get(found) + "';");
          pageContext.getOut().println(
              "window['diffable']['" + resourceHash + "']" +
              "['diff_url'] = '" +
              ctx.getServletPrefix() + "/';");
          pageContext.getOut().println(
            "window['diffable']['addResource']('" +
            ctx.getServletPrefix() + "/" + resourceHash + "');"
          );
          pageContext.getOut().println("</script>");
          //pageContext.getOut().println(
          //    "<script type='text/javascript' src='" +
          //  ctx.getServletPrefix() + "/" + resourceHash + "'></script>");
View Full Code Here


   
    // Inject members into the listener via Guice.
    inj.getMembersInjector(DiffableListener.class).injectMembers(this);
   
    // Initialize the diffable context
    DiffableContext diffableCtx = new DiffableContext();
    ctx.setAttribute(Constants.DIFFABLE_CONTEXT, diffableCtx);
   
    // Initialize the resource manager. For testing, the DiffableListener
    // is retrieved via Guice with a mock ResourceManager injected already,
    // which is why this conditional check is performed.
    if (mgr == null) {
      mgr = inj.getInstance(ResourceManager.class);
    }
   
    // Initialize the resource.
    try {
      String webAppBaseDir = ctx.getRealPath("/");
      mgr.initialize(webAppBaseDir, diffableCtx);
    } catch (ResourceManagerException exc) {
      provider.error(logger, "resourcestore.problem");
      printer.print(exc);
    }
   
    // Retrieve the directories containing resources to be managed and
    // crawl them for resources, adding them to the resource manager as
    // they are found.  If the path begins with a slash, it will be
    // interpreted as absolute. Otherwise, it will be interpreted as
    // relative to the web app directory. If multiple folders are specified,
    // they should be separated by commas.
    String currentPath = ctx.getRealPath("");
    String resourceFolders = ctx.getInitParameter("ResourceFolders");
    ArrayList<File> foundFolders = new ArrayList<File>();
   
    if (resourceFolders == null) {
      String error =
        provider.getMessage(
          "ErrorMessages", "resourcefolders.none");
      logger.error(error);
    } else {
      String[] folders = resourceFolders.split(",");
      for (String path : folders) {
        File folder = path.startsWith("/") ?
          new File(path) :
          new File(currentPath + File.separator + path);
        if (!folder.exists()) {
          provider.error(logger, "resourcefolders.nonexistent",
                   folder.getAbsolutePath());
        } else if (!folder.isDirectory()) {
          provider.error(logger, "resourcefolders.notfolder",
                   folder.getAbsolutePath());
        } else {
          foundFolders.add(folder);
        }
      }
      // Set the folders on the DiffableTag so it can locate resources.
      //DiffableResourceTag.setFolder(foundFolders);
      diffableCtx.setFolder(foundFolders);
     
      // Start up the monitoring thread.
      monitor.setFolderAndManager(foundFolders, mgr);
      timer.schedule(monitor, 0, interval);
    }
   
    // Get the servlet prefix initialization parameter.  This is mandatory
    // for correctly linking to managed resources, and an exception is
    // thrown if this parameter is not defined.
    String servletPrefix = ctx.getInitParameter("ServletPrefix");
    if (servletPrefix != null) {
      diffableCtx.setServletPrefix(servletPrefix);
    } else {
      provider.error(logger, "servlet.noservletprefix");
    }
   
  }
View Full Code Here

TOP

Related Classes of com.google.diffable.data.DiffableContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.