StatisticCollectorFilter.java :  » Mobile » mreunion » net » mreunion » web » infrastructure » Java Open Source

Java Open Source » Mobile » mreunion 
mreunion » net » mreunion » web » infrastructure » StatisticCollectorFilter.java
package net.mreunion.web.infrastructure;

import java.io.IOException;

import net.mreunion.web.services.StatisticCollector;
import net.mreunion.web.util.ResourceUtil;

import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.RequestFilter;
import org.apache.tapestry5.services.RequestHandler;
import org.apache.tapestry5.services.Response;

public class StatisticCollectorFilter implements RequestFilter{
  private final StatisticCollector statCollector;

  public StatisticCollectorFilter(StatisticCollector statCollector) {
    this.statCollector = statCollector;
  }
  
  @Override
  public boolean service(Request request, Response response,
      RequestHandler handler) throws IOException {
    
    String path = request.getPath();
    
    // add the statistics if someone download our apk
    // better to have this on a different contribution/filter file
    // but its enough for now
//    if (path.startsWith("/assets") &&
//        ResourceUtil.getExtension(path).toLowerCase().equalsIgnoreCase("apk")) {

    if (path.startsWith("/assets") &&
        ResourceUtil.getFileName(path).toLowerCase().equalsIgnoreCase("cinemator.apk")) {
      
//        statCollector.collectStatistics();
      
      // continue the chain because we only gather statistics
    }
    
    return handler.service(request, response);
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.