You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2003/11/09 17:17:13 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/source/impl PartSource.java

vgritsenko    2003/11/09 08:17:13

  Modified:    src/java/org/apache/cocoon/components/source/impl
                        PartSource.java
  Log:
  zap tabs
  
  Revision  Changes    Path
  1.3       +120 -121  cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSource.java
  
  Index: PartSource.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/source/impl/PartSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PartSource.java	25 Oct 2003 22:31:39 -0000	1.2
  +++ PartSource.java	9 Nov 2003 16:17:13 -0000	1.3
  @@ -74,133 +74,132 @@
    */
   public class PartSource implements Source
   {
  -	/* hold a private ref to the protocol used to call the Source */
  -	private String protocol;
  +    /* hold a private ref to the protocol used to call the Source */
  +    private String protocol;
   
  -	/* hold a private ref to the full uri */
  -	private String uri;
  +    /* hold a private ref to the full uri */
  +    private String uri;
   
  -	/* hold a private ref to the Part which has been uploaded. */
  -	private Part part;
  +    /* hold a private ref to the Part which has been uploaded. */
  +    private Part part;
   
  -	/**
  +    /**
        * Builds a PartSource given an URI.
        * @param uri e.g., upload://formField1
        * @throws SourceException
        * @throws MalformedURLException
        */
  -	public PartSource(String uri, Map objectModel) throws MalformedURLException, SourceException
  -	{
  -		// set the uri for use in getURI()
  -	    this.uri = uri;
  -
  -		int position = uri.indexOf(':') + 1;
  -		if (position != 0)
  -		{
  -			// set the protocol for use in getScheme()
  -			this.protocol = uri.substring(0, position-1);
  -		}
  -		else
  -		{
  -			// if the URI is not correctly formatted then throw an excpetion
  -			throw new MalformedURLException("No protocol found for part source in " + uri);
  -        }
  -
  -		// get the request parameter name: the bit after ://
  -		String location = uri.substring(position + 2);
  -
  -		// get the cocoon request from the object model.
  -		Request request = ObjectModelHelper.getRequest(objectModel);
  -
  -		// try and cast the request object to a Part
  -		Object obj = request.get(location);
  -		if (obj instanceof Part)
  -		{
  -		     part = (Part) obj;
  -		}
  -		else
  -		{
  -		     throw new SourceException("Request object " + location + " is not an uploaded Part");
  -		}
  -	}
  -
  -	/**
  -	 * @see org.apache.excalibur.source.Source#getInputStream()
  -	 */
  -	public InputStream getInputStream() throws IOException, SourceNotFoundException
  -	{
  -		try
  -		{
  -			return part.getInputStream();
  -		}
  -		catch (Exception ex)
  -		{
  -			throw new SourceNotFoundException("The part source can not be found.");
  -		}
  -	}
  -
  -	/**
  -	 * @see org.apache.excalibur.source.Source#getMimeType()
  -	 */
  -	public String getMimeType()
  -	{
  -		return part.getMimeType();
  -	}
  -
  -	/**
  -	  * @return true if the resource exists.
  -	  */
  -	public boolean exists()
  -	{
  -		return part != null;
  -	}
  -
  -	/*
  -	 * @see org.apache.excalibur.source.Source#getURI()
  -	 */
  -	public String getURI()
  -	{
  -		return uri;
  -	}
  -
  -	/*
  -	 * @see org.apache.excalibur.source.Source#getScheme()
  -	 */
  -	public String getScheme()
  -	{
  -		return this.protocol;
  -	}
  -
  -	/*
  -	 * Not used, Parts are not cacheable.
  -	 */
  -	public SourceValidity getValidity()
  -	{
  -		// not sure what happens here.
  -		return null;
  -	}
  -
  -	/**
  -	  * @see org.apache.excalibur.source.Source#refresh()
  -	  */
  -	public void refresh()
  -	{
  -	}
  -
  -	/**
  -	 * @see org.apache.excalibur.source.Source#getContentLength()
  -	 */
  -	public long getContentLength()
  -	{
  -		return part.getSize();
  -	}
  -
  -	/**
  -	 * @see org.apache.excalibur.source.Source#getLastModified()
  -	 */
  -	public long getLastModified()
  -	{
  -		return 0;
  -	}
  +    public PartSource(String uri, Map objectModel) throws MalformedURLException, SourceException
  +    {
  +        // set the uri for use in getURI()
  +        this.uri = uri;
  +
  +        int position = uri.indexOf(':') + 1;
  +        if (position != 0)
  +        {
  +            // set the protocol for use in getScheme()
  +            this.protocol = uri.substring(0, position-1);
  +        }
  +        else
  +        {
  +            // if the URI is not correctly formatted then throw an excpetion
  +            throw new MalformedURLException("No protocol found for part source in " + uri);
  +        }
  +
  +        // get the request parameter name: the bit after ://
  +        String location = uri.substring(position + 2);
  +
  +        // get the cocoon request from the object model.
  +        Request request = ObjectModelHelper.getRequest(objectModel);
  +
  +        // try and cast the request object to a Part
  +        Object obj = request.get(location);
  +        if (obj instanceof Part)
  +        {
  +             part = (Part) obj;
  +        }
  +        else
  +        {
  +             throw new SourceException("Request object " + location + " is not an uploaded Part");
  +        }
  +    }
  +
  +    /**
  +     * @see org.apache.excalibur.source.Source#getInputStream()
  +     */
  +    public InputStream getInputStream() throws IOException, SourceNotFoundException
  +    {
  +        try
  +        {
  +            return part.getInputStream();
  +        }
  +        catch (Exception ex)
  +        {
  +            throw new SourceNotFoundException("The part source can not be found.");
  +        }
  +    }
   
  +    /**
  +     * @see org.apache.excalibur.source.Source#getMimeType()
  +     */
  +    public String getMimeType()
  +    {
  +        return part.getMimeType();
  +    }
  +
  +    /**
  +      * @return true if the resource exists.
  +      */
  +    public boolean exists()
  +    {
  +        return part != null;
  +    }
  +
  +    /*
  +     * @see org.apache.excalibur.source.Source#getURI()
  +     */
  +    public String getURI()
  +    {
  +        return uri;
  +    }
  +
  +    /*
  +     * @see org.apache.excalibur.source.Source#getScheme()
  +     */
  +    public String getScheme()
  +    {
  +        return this.protocol;
  +    }
  +
  +    /*
  +     * Not used, Parts are not cacheable.
  +     */
  +    public SourceValidity getValidity()
  +    {
  +        // not sure what happens here.
  +        return null;
  +    }
  +
  +    /**
  +      * @see org.apache.excalibur.source.Source#refresh()
  +      */
  +    public void refresh()
  +    {
  +    }
  +
  +    /**
  +     * @see org.apache.excalibur.source.Source#getContentLength()
  +     */
  +    public long getContentLength()
  +    {
  +        return part.getSize();
  +    }
  +
  +    /**
  +     * @see org.apache.excalibur.source.Source#getLastModified()
  +     */
  +    public long getLastModified()
  +    {
  +        return 0;
  +    }
   }