コード例 #1
0
  private void _setSpriteImages(ServletContext servletContext, Theme theme, String resourcePath)
      throws Exception {

    if (!resourcePath.startsWith(StringPool.SLASH)) {
      resourcePath = StringPool.SLASH.concat(resourcePath);
    }

    Set<String> resourcePaths = servletContext.getResourcePaths(resourcePath);

    if (resourcePaths == null) {
      return;
    }

    List<URL> imageURLs = new ArrayList<URL>(resourcePaths.size());

    for (String curResourcePath : resourcePaths) {
      if (curResourcePath.endsWith(StringPool.SLASH)) {
        _setSpriteImages(servletContext, theme, curResourcePath);
      } else if (curResourcePath.endsWith(".png")) {
        URL imageURL = servletContext.getResource(curResourcePath);

        if (imageURL != null) {
          imageURLs.add(imageURL);
        } else {
          if (ServerDetector.isTomcat()) {
            if (_log.isInfoEnabled()) {
              _log.info(ServletContextUtil.LOG_INFO_SPRITES);
            }
          } else {
            _log.error("Real path for " + curResourcePath + " is null");
          }
        }
      }
    }

    String spriteFileName = resourcePath.concat(PropsValues.SPRITE_FILE_NAME);
    String spritePropertiesFileName = resourcePath.concat(PropsValues.SPRITE_PROPERTIES_FILE_NAME);
    URL spritePropertiesRootURL = servletContext.getResource(StringPool.SLASH);

    Properties spriteProperties =
        SpriteProcessorUtil.generate(
            servletContext,
            imageURLs,
            spriteFileName,
            spritePropertiesFileName,
            spritePropertiesRootURL,
            16,
            16,
            10240);

    if (spriteProperties == null) {
      return;
    }

    String contextPath = ContextPathUtil.getContextPath(servletContext);

    spriteFileName = contextPath.concat(SpriteProcessor.PATH).concat(spriteFileName);

    theme.setSpriteImages(spriteFileName, spriteProperties);
  }
コード例 #2
0
  private void _setSpriteImages(ServletContext servletContext, Theme theme, String resourcePath)
      throws Exception {

    if (!resourcePath.startsWith(StringPool.SLASH)) {
      resourcePath = StringPool.SLASH.concat(resourcePath);
    }

    Set<String> resourcePaths = servletContext.getResourcePaths(resourcePath);

    if ((resourcePaths == null) || resourcePaths.isEmpty()) {
      return;
    }

    List<URL> imageURLs = new ArrayList<URL>(resourcePaths.size());

    for (String curResourcePath : resourcePaths) {
      if (curResourcePath.endsWith(StringPool.SLASH)) {
        _setSpriteImages(servletContext, theme, curResourcePath);
      } else if (curResourcePath.endsWith(".png")) {
        URL imageURL = servletContext.getResource(curResourcePath);

        if (imageURL != null) {
          imageURLs.add(imageURL);
        } else {
          _log.error("Resource URL for " + curResourcePath + " is null");
        }
      }
    }

    String spriteRootDirName = PropsValues.SPRITE_ROOT_DIR;
    String spriteFileName = resourcePath.concat(PropsValues.SPRITE_FILE_NAME);
    String spritePropertiesFileName = resourcePath.concat(PropsValues.SPRITE_PROPERTIES_FILE_NAME);
    String rootPath = ServletContextUtil.getRootPath(servletContext);

    Properties spriteProperties =
        SpriteProcessorUtil.generate(
            servletContext,
            imageURLs,
            spriteRootDirName,
            spriteFileName,
            spritePropertiesFileName,
            rootPath,
            16,
            16,
            10240);

    if (spriteProperties == null) {
      return;
    }

    String contextPath = ContextPathUtil.getContextPath(servletContext);

    spriteFileName = contextPath.concat(SpriteProcessor.PATH).concat(spriteFileName);

    theme.setSpriteImages(spriteFileName, spriteProperties);
  }
コード例 #3
0
  private void _setSpriteImages(ServletContext servletContext, Theme theme, String resourcePath)
      throws Exception {

    Set<String> resourcePaths = servletContext.getResourcePaths(resourcePath);

    if (resourcePaths == null) {
      return;
    }

    List<File> images = new ArrayList<File>(resourcePaths.size());

    for (String curResourcePath : resourcePaths) {
      if (curResourcePath.endsWith(StringPool.SLASH)) {
        _setSpriteImages(servletContext, theme, curResourcePath);
      } else if (curResourcePath.endsWith(".png")) {
        String realPath = ServletContextUtil.getRealPath(servletContext, curResourcePath);

        if (realPath != null) {
          images.add(new File(realPath));
        } else {
          if (ServerDetector.isTomcat()) {
            if (_log.isInfoEnabled()) {
              _log.info(ServletContextUtil.LOG_INFO_SPRITES);
            }
          } else {
            _log.error("Real path for " + curResourcePath + " is null");
          }
        }
      }
    }

    String spriteFileName = ".sprite.png";
    String spritePropertiesFileName = ".sprite.properties";
    String spritePropertiesRootPath =
        ServletContextUtil.getRealPath(servletContext, theme.getImagesPath());

    Properties spriteProperties =
        SpriteProcessorUtil.generate(
            images,
            spriteFileName,
            spritePropertiesFileName,
            spritePropertiesRootPath,
            16,
            16,
            10240);

    if (spriteProperties == null) {
      return;
    }

    spriteFileName =
        resourcePath.substring(theme.getImagesPath().length(), resourcePath.length())
            + spriteFileName;

    theme.setSpriteImages(spriteFileName, spriteProperties);
  }