/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

====================================================================== */

package org.bodington.server;

import java.awt.Color;
import java.io.File;
import java.util.List;
import java.util.Vector;

import org.bodington.database.PrimaryKey;
import org.bodington.server.resources.Menu;
import org.bodington.server.resources.Resource;
import org.bodington.xml.XMLQuery;
/**
 * Represents a user's session with the site.  Subclasses may represent
 * a session with a specific resource or a navigating session that can change
 * its currently selected resource.  Contains methods appropriate to all
 * types of session.
 * 
 * @author Jon Maber
 * @version 1.0
 */
public interface BuildingSession
	{
        
    public void init( PrimaryKey user_id, PrimaryKey resource_id )
    throws BuildingServerException;

    public PrimaryKey getResourceId();
    public void setResourceId(PrimaryKey resourceId);
    public PrimaryKey getUserId();
    public void setUserId(PrimaryKey userId);
    
    /**
     * Set the current resource for this session. 
     * @param resource the the resource for this instance.
     * @throws BuildingServerException
     */
    public void setResource( Resource resource ) throws
        BuildingServerException;
		
    public long getPropertiesLastModifiedTime()
        throws BuildingServerException;
    
    public void unspecifyProperty( String name )
        throws BuildingServerException;
    public void specifyProperty( String name, String value )
        throws BuildingServerException;
    
    public String getSpecifiedProperty( String name )
        throws BuildingServerException;
    
    public String getProperty( String name )
        throws BuildingServerException;
    public String getProperty( String name, String def )
    	throws BuildingServerException;
    
    public Color getPropertyColor( String name )
        throws BuildingServerException;
    public Color getPropertyColor( String name, Color def )
        throws BuildingServerException;

	
    public PrimaryKey getStyleResourceId()
        throws BuildingServerException;
    public String[] getStyleResourcePath()
        throws BuildingServerException;
    
 	public String getNameOfUser( PrimaryKey uid )
		throws BuildingServerException;
	
	public void generateFileListing()
		throws BuildingServerException;

	public int importMetadata( String file_name )
		throws BuildingServerException;
		
	public String exportMetadata()
		throws BuildingServerException;
	
	public Vector searchMetadata( XMLQuery query )
		throws BuildingServerException;
	
	public String[] getFieldValuesFromMetadata( String elementName )
	    throws BuildingServerException;
	
    /**
     * Update the title and description metadata for the current resource.
     * @throws BuildingServerException
     */
	public void updateBasicMetadata( )
		throws BuildingServerException;
	
	public void updateMetaDataTitleField( String text, String languageCode );
	
	public void updateMetadataDescriptionField( String text, String languageCode );
	
	public void updateMetadataAuthorField( String authorName, String contactDetails );
	
	public void updateMetadataEditorField( String editorName, String contactDetails );
	
	public void updateMetadataContributorField( String roleName, String contributorName, String contactDetails, String languageCode );

	public void updateMetadataKeywords( String[] keywords, String languageCode );
	
	/**
	 * Not sure if this is the right place for this.... It depends on uploaded files.
	 */
	public void importImsPackage( String url, boolean parentacl, String zipfile )
		throws BuildingServerException;

		
	public Menu getResourceMenu()
		throws BuildingServerException;

	public void generateResourceMenu()
		throws BuildingServerException;

	public String transferResourceMenu( String current_pathname )
		throws BuildingServerException;
	
	public UploadedFileSession getUploadedFileSession()
		throws BuildingServerException;
    
    /**
     * Checks the names of resources at this level. If the requested name
     * for the new resource already exists, the requested name is modified
     * by appending a number (and is truncated if necessary).
     * @param url The requested name
     * @return newName A name that is not is use at this location
     */
    public String findUniqueName(String url) throws BuildingServerException;

    /**
     * Find the resource quota for the current resource. Includes all child 
     * resources that don't have their own quota set.
     * @return The quota for the current resource, <code>null</code> if there
     * isn't a quota.
     */
    public Quota getQuota() throws BuildingServerException;
    
    /**
     * Set the Resources quota for the current resource.
     * @param quota The quota limit.
     * @throws BuildingServerException If there is a problem setting the quota
     * for example the resource doesn't already have a quota set and has children.
     * @throws PermissionDeniedException If the current user doesn't have
     * permission to set the quota.
     */
    public void setQuota(long quota) throws BuildingServerException;

    /**
     * Create a quota for the current resource.
     * @param quota The quota limit.
     * @throws PermissionDeniedException If the current user doesn't have 
     * permission to create a quota.
     * @throws BuildingServerException If the resource already has a quota set
     * or there is a problem setting the quota.
     */
    public void createQuota(long quota) throws BuildingServerException;
    
    public void invalidateCache() throws BuildingServerException;

    public List visibleChildren() throws BuildingServerException;
    
	}

