Username:   Password:  

Url Filter Rev

class relativeUrlFilter extends sfFilter 
{
    public function execute($filterChain){
        $context  = $this->getContext();
        $request  = $context->getRequest();
 
        $relative = preg_replace('#/[^/]+.php5?$#', '', $request->getScriptName());
        $webDir = str_replace('\', '/', sfConfig::get('sf_web_dir'));
        $intercept = '/'.implode('/', array_intersect(explode('/',$relative), explode('/',$webDir)));       
        $position = strpos($webDir, $intercept);
        $request->setRelativeUrlRoot(substr($webDir, $position));                
        $filterChain->execute();
    }
}
 

[Funny Games](http://www.asgames.net)

Tags

relative url

Filter Analytics

// newClass for gaFilter extends sfFilter
class gaFilter extends sfFilter
{
  public function execute($filterChain)
  {
    // anything before action
    $filterChain->execute();
    // Find google code and check if current module is not disabled
    if(($gaCode = sfConfig::get("app_ga_code",false)) !== false
    && !in_array($this->getContext()->getModuleName(),sfConfig::get("app_ga_disabled_modules",array()))) {
      //RResponse with the tracker code.
      $response = $this->getContext()->getResponse();
      $response->setContent(str_ireplace('</body>', $gaCode.'</body>',$response->getContent())); 
    }
   }
}
 

Here's a filtered analytics code. <a href="http://www.asgames.net">Funny Games</a>

Tags

analytics php filter

sakesh_snippet

import java.io.*;
import ariba.util.scheduler.ScheduledTask;
import ariba.util.scheduler.ScheduledTaskException;
import ariba.base.core.Base;
import ariba.base.core.BaseId;
import ariba.base.core.aql.*;
import ariba.base.core.Partition;
import ariba.base.fields.ValueSource;
import ariba.collaborate.util.CollaborateUtil;
import ariba.collaborate.util.Log;
import java.sql.*;
import ariba.util.core.IOUtil;
import java.io.IOException;
import ariba.util.core.SystemUtil;
import java.util.Map;
import ariba.base.core.Partition;
import java.util.Iterator;
 
// queryString  - Will be the above query
// exportFile – Will be the location of file
 
 public void extractDoc(String queryString,String exportFile) throws Exception 
 
{
 
        try
 {
           // Creating database connection 
 
 	String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);
            Connection conn = DriverManager.getConnection(url, username, password);
            Statement stmt = conn.createStatement();
 
            // Executing the query
 
ResultSet results = stmt.executeQuery(queryString);
           debug(" results size :"+results.getFetchSize());
 
 
// result set contains details of all the documents linked to a 
particular project            
while(results.next())
            {
 
           // project internal id  
           String wsInternalId = results.getString(6);
 
          // Status of document		
            String Status = results.getString(7);
 
// If we are extracting the documents for multiple projects we need to create          separate folders in the file system for each project.
 
String FolderName = results.getString(6); // we are giving InternalId of project as folder name
 
	// Getting blob object.
             Blob blob = results.getBlob(2);
 
           // Title of the document, title also contains the extension of the file.
              So we  don’t need to worry about the extension of the file.
 
            String documentTitle = (String)results.getString(3);
 
            String folderName = exportFile+"/"+FolderName; 
 
// so if exportFile value is like config/../data/Extract_Document then
folder structure could be like thisconfig/../data/ExtractDocument/InternalID(value)
 
 
           // getting binary stream from blob object
            InputStream blobStream = blob.getBinaryStream();
 
            File file = new File(folderName);
            file.mkdirs();
 
            String fileName = folderName +"/" + documentTitle;
          // fileName would be like 
             config/../data/ExtractDocument/InternalId(value)/XXX.FileExtension
 
            File fileOut = new File(fileName);
 
           debug("Calling writeToFile function to write the csv in Document");
           writeToFile(blobStream, fileOut);
}
 
 
private void writeToFile (InputStream in, File outputFile) throws Exception 
{
        FileOutputStream out = new FileOutputStream(outputFile);
 
        // We are using ariba IOUtil instead of java functionality 
        boolean written = IOUtil.inputStreamToOutputStream(in, out);
 
 if(written) 
       	{
            	debug("Done !!!");
        	}
 else
       	{
            	debug("Error while writing file...");
            	throw new Exception("Error in writing output file");
        	}
 }
 

test

	import java.io.FileOutputStream;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.OutputStream;
 
	public class Test
	{
		public static void main (String args[]) throws IOException
		{
			String from = "D:/src/test.jpg";
			String to = "D:/dest/test.jpg";
			copy(from, to);
		}
		public static void copy (String from, String to) throws IOException
		{
			InputStream in = null;
			OutputStream out = null;
			System.out.println(System.currentTimeMillis())
			{
				try
				{
					InputStream inFile = new FileInputStream (from);
					in = new BufferedInputStream (inFile);
					OutputStream out = new FileOutputStream (to);
					out = new BufferedOutputstream (outFile);
					while (true)
					{
						int data = in.read();
						if (data == -1)
						{
							break;
						}
						out.write(data);
					}
					System.out.println(System.currentTimeMillis());
				}
				finally
				{
					if (in != null)
					{
						in.close();
					}
					if (out != null)
					{
						out.close();
					}
				}
			}
		}

test

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
public class Test
{
	public static void main (String args[]) throws IOException
	{
		String from = "D:/src/test.jpg";
		String to = "D:/dest/test.jpg";
		copy(from, to);
	}
	public static void copy (String from, String to) throws IOException
	{
		InputStream in = null;
		OutputStream out = null;
		System.out.println(System.currentTimeMillis())
		{
			try
			{
				in = new FileInputStream(from);
				out = new FileOutputStream(to);
				while(true)
				{
					int data = in.read();
					if (data == -1)
					{
						break;
					}
					out.write(data)
				}
				System.out.println(System.currentTimeMillis())
			}
			finally
			{
				if (in != null)
				{
					in.close();
				}
				if (out != null)
				{
					out.close();
				}
			}
		}
	}

<< older  newer >>