You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ah...@apache.org on 2011/06/06 02:57:41 UTC

svn commit: r1132509 - in /oodt/trunk/balance: ./ lib/ lib/pear/ lib/pear/Boot/ lib/pear/Core/ lib/pear/Interfaces/ lib/pear/Providers/ lib/pear/Providers/Auth/ lib/pear/Providers/Authorization/ lib/pear/Providers/Data/ lib/pear/Providers/Error/

Author: ahart
Date: Mon Jun  6 00:57:40 2011
New Revision: 1132509

URL: http://svn.apache.org/viewvc?rev=1132509&view=rev
Log:
resolve OODT-186: patch applied. thanks to s.khudikyan and g.resneck for contributions

Added:
    oodt/trunk/balance/
    oodt/trunk/balance/lib/
    oodt/trunk/balance/lib/README.txt
    oodt/trunk/balance/lib/pear/
    oodt/trunk/balance/lib/pear/AUTHORS
    oodt/trunk/balance/lib/pear/Boot/
    oodt/trunk/balance/lib/pear/Boot/bootstrap.php
    oodt/trunk/balance/lib/pear/Core/
    oodt/trunk/balance/lib/pear/Core/Application.class.php
    oodt/trunk/balance/lib/pear/Core/ApplicationDataResponse.class.php
    oodt/trunk/balance/lib/pear/Core/ApplicationRequest.class.php
    oodt/trunk/balance/lib/pear/Core/ApplicationResponse.class.php
    oodt/trunk/balance/lib/pear/Interfaces/
    oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php
    oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php
    oodt/trunk/balance/lib/pear/Interfaces/IApplicationDataProvider.php
    oodt/trunk/balance/lib/pear/Interfaces/IApplicationErrorProvider.php
    oodt/trunk/balance/lib/pear/Interfaces/IApplicationWidget.php
    oodt/trunk/balance/lib/pear/Providers/
    oodt/trunk/balance/lib/pear/Providers/Auth/
    oodt/trunk/balance/lib/pear/Providers/Auth/LDAPAuthenticationProvider.class.php
    oodt/trunk/balance/lib/pear/Providers/Authorization/
    oodt/trunk/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php
    oodt/trunk/balance/lib/pear/Providers/Data/
    oodt/trunk/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php
    oodt/trunk/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php
    oodt/trunk/balance/lib/pear/Providers/Data/PDODataProvider.class.php
    oodt/trunk/balance/lib/pear/Providers/Error/
    oodt/trunk/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php
    oodt/trunk/balance/lib/pear/README
    oodt/trunk/balance/lib/pear/package.xml

Added: oodt/trunk/balance/lib/README.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/README.txt?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/README.txt (added)
+++ oodt/trunk/balance/lib/README.txt Mon Jun  6 00:57:40 2011
@@ -0,0 +1 @@
+Exported from trunk at rev 11894 on 21.April.2011

Added: oodt/trunk/balance/lib/pear/AUTHORS
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/AUTHORS?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/AUTHORS (added)
+++ oodt/trunk/balance/lib/pear/AUTHORS Mon Jun  6 00:57:40 2011
@@ -0,0 +1,5 @@
+Balance Library Authors
+=======================
+Andrew Hart             <ah...@apache.org>
+Shakeh Khudikyan        <sh...@jpl.nasa.gov>
+Gabe Resneck            <ga...@jpl.nasa.gov> 

Added: oodt/trunk/balance/lib/pear/Boot/bootstrap.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Boot/bootstrap.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Boot/bootstrap.php (added)
+++ oodt/trunk/balance/lib/pear/Boot/bootstrap.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,59 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * Bootstrap file to provide all framework base files necessary to 
+ * satisfy a resource request.
+ * 
+ * @author ahart
+ * 
+ */
+
+define("BALANCE_VERSION", '0.3-SNAPSHOT');
+
+// Include Required Framework Interfaces
+include("Org/Apache/Oodt/Balance/Interfaces/IApplicationWidget.php");
+include("Org/Apache/Oodt/Balance/Interfaces/IApplicationDataProvider.php");
+include("Org/Apache/Oodt/Balance/Interfaces/IApplicationAuthenticationProvider.php");
+include("Org/Apache/Oodt/Balance/Interfaces/IApplicationAuthorizationProvider.php");
+
+// Include Required Framework Classes
+include("Org/Apache/Oodt/Balance/Core/Application.class.php");
+include("Org/Apache/Oodt/Balance/Core/ApplicationRequest.class.php");
+include("Org/Apache/Oodt/Balance/Core/ApplicationResponse.class.php");
+include("Org/Apache/Oodt/Balance/Core/ApplicationDataResponse.class.php");
+
+
+class App {
+	
+	protected static $app = null;
+	
+	public static function Create($config) {
+		if (!self::$app) {
+			self::$app = new Org_Apache_Oodt_Balance_Core_Application($config);
+		} 
+		return self::$app;
+	}
+	
+	public static function Get() {
+		return self::$app;
+	}
+}

Added: oodt/trunk/balance/lib/pear/Core/Application.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Core/Application.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Core/Application.class.php (added)
+++ oodt/trunk/balance/lib/pear/Core/Application.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,414 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * Main class for OODT Balance web applications. Contains utility
+ * methods and definitions that provide standard functionality across
+ * the site.
+ * 
+ * @author ahart
+ * 
+ */
+class Org_Apache_Oodt_Balance_Core_Application {
+	
+	public $request;
+	
+	public $subrequest;
+	
+	public $authProviderInstance = null;
+	
+	public $authorizationProviderInstance = null;
+	
+	public $response;
+	
+	public $settings;
+	
+	public $modulesLoaded;
+	
+	public function __construct($settings) {
+		
+		// Save the application settings
+		$this->settings = $settings;
+		
+		// Update the PHP include path to include the locations specified in
+		// the application configuration .ini file
+		if (isset($this->settings['classes_dir']) && is_array($this->settings['classes_dir'])) {
+			$customClassPath = implode(';',$this->settings['classes_dirs']);
+			set_include_path(get_include_path() . ';' . $customClassPath);
+		}
+		
+		// Initialize a session
+		session_start();
+		
+		// Define the application base url
+		define ("SITE_ROOT", ($settings['site_root'] == '/') 
+			? '' 
+			: $settings['site_root']);
+			
+	}
+	
+	
+	public function getResponse() {
+		
+		$this->setAuthProviderInstance();
+		$this->setAuthorizationProviderInstance();
+		
+		// Interpret the request uri of the current request
+		$uri = App::Get()->settings['site_root'] != '/'
+			? substr($_SERVER['REQUEST_URI'],strlen(App::Get()->settings['site_root']))
+			: $_SERVER['REQUEST_URI'];
+		$this->request = new Org_Apache_Oodt_Balance_Core_ApplicationRequest(
+			$this->settings,$uri);
+			
+		// Initialize a response object for the request
+		$this->response = new Org_Apache_Oodt_Balance_Core_ApplicationResponse(
+			$this->settings,$this->request);
+			
+		// Process the response
+		$this->response->process();
+			
+		// Return the processed response object
+		return $this->response;
+	}
+	
+	public function cleanup() {
+		
+	}
+	
+	/**
+	 * Determine whether the current request maps to resources associated
+	 * with an application module. 
+	 * 
+	 * If a view, script, or static asset is part of an application module,
+	 * the path to the file will differ than those for regular application
+	 * resources. This function provides a way to determine whether a given
+	 * request should be considered part of a module or of the general 
+	 * application. 
+	 * 
+	 * @param $requestURI - The request uri to test
+	 * @return boolean    - true indicates the request uri belongs to a module
+	 */
+	public function isModule($requestURI) {
+		// Determine whether a module is being requested
+		$filteredURI = $requestURI;
+		$filteredURI = ltrim($filteredURI,'/');
+		$parts = explode('/',$filteredURI);
+
+        if (is_dir(HOME . "/modules")) {
+			$handle = opendir(HOME . "/modules");
+			while (false !== ($dir = readdir($handle))) {
+				if ( $dir == $parts[0] && $module = $this->loadModule($dir) ) {
+					return $module;
+				}
+			}
+		}
+		return false;
+	}
+	
+	public function getAuthProvider() {
+		return $this->authProviderInstance;
+	}
+	
+	public function setAuthProviderInstance() {
+		
+		// Check if the user wants authentication for application 
+		if ( $this->settings['auth_class_path'] != null &&
+			 $this->settings['auth_class']      != null   ) {
+			 	
+			 	require_once $this->settings['auth_class_path'];
+				$authProvider 		  		= $this->settings['auth_class'];
+				$this->authProviderInstance = new $authProvider();
+		}
+	}
+	
+	public function getAuthorizationProvider() {
+		return $this->authorizationProviderInstance;
+	}
+	
+	public function setAuthorizationProviderInstance() {
+		
+		// Check if the user wants authentication for application 
+		if ( $this->settings['authorization_class_path'] != null &&
+			 $this->settings['authorization_class']      != null   ) {
+			 	
+			 	require_once $this->settings['authorization_class_path'];
+				$authProvider 		  				 = $this->settings['authorization_class'];
+				$this->authorizationProviderInstance = new $authProvider();
+		}
+	}
+	
+	public function loadModule($modName = null) {
+		// If the module name is null, a module is requesting that
+		// its own context be loaded
+		if ($modName === null) {
+			return $this->getModuleContext();
+		}
+
+		// If the module has been previously loaded, return its context
+		if (isset($this->modulesLoaded[$modName])) {
+			return $this->modulesLoaded[$modName];
+		}
+
+		// check if module path exists before loading module context
+		$modulePath = HOME . "/modules/{$modName}";
+		if ( is_dir($modulePath) ) {
+			
+			// create stdClass 
+			$modClass = new stdClass();
+			$modClass->modulePath   = $modulePath;
+			$modClass->moduleRoot   = SITE_ROOT . "/{$modName}";
+			$modClass->moduleStatic = SITE_ROOT . "/modules/{$modName}/static";
+
+			$this->modulesLoaded[$modName] = $modClass;
+
+			// Read in the module config file and append to application config
+			if (file_exists($modulePath . '/config.ini')) {
+				$moduleSettings   = parse_ini_file($modulePath . '/config.ini');
+				$this->settings  += $moduleSettings;
+			}
+			
+			// Return the configuration object
+			return $modClass;
+		} else {
+			return false;
+		}
+	}
+	
+	public function getModuleContext($which = null) {
+		
+		// If a module is requesting its own context...
+		if ( $which === null ) {
+			$req = ($this->subrequest != null) 
+				? $this->subrequest
+				: $this->request;
+			$uri = ltrim($req->uri,'/');
+			$moduleName = substr($uri,0,strpos($uri,'/'));
+							
+			return (!empty($moduleName)) 
+				? $this->loadModule($moduleName)
+				: false;
+		} 
+				
+		// otherwise, return the result of an attempt to load the module
+		return $this->loadModule($which);
+	}
+	
+	public static function SetMessage($content,$level = CAS_MSG_INFO) {
+		
+		switch ($level) {
+			case CAS_MSG_WARN:
+				$_SESSION['_messages'][] = '<div class="cas_msg warn">'  . $content . '</div>';
+				break;
+			case CAS_MSG_ERROR:
+				$_SESSION['_messages'][] = '<div class="cas_msg error">' . $content . '</div>';
+				break;
+			default:
+				$_SESSION['_messages'][] = '<div class="cas_msg info">'  . $content . '</div>';
+				break;
+		}
+	}
+	
+	public static function GetMessages() {
+		$response = isset($_SESSION['_messages']) 
+			? implode('', $_SESSION['_messages'])
+			: false;
+		unset($_SESSION['_messages']);
+		return $response;
+	}
+	
+	public function fatal($message) {
+		ApplicationResponse::sendFatal($message);
+		exit();
+	}
+	
+	public static function EndUserSession() {
+		// Unset all of the session variables.
+		$_SESSION = array();
+		
+		// Finally, destroy the session.
+		session_destroy();
+	}
+
+	public static function Redirect($newLocation) {
+		header("Location: {$newLocation}");
+		exit();
+	}
+	
+	/**
+	 * Returns an instance of the requested DataProvider class, ensuring
+	 * that all necessary prerequisites are correctly loaded. To load a 
+	 * custom DataProvider. The framework looks for a matching data
+	 * provider according to the following heirarchy, stopping when 
+	 * it first finds a matching class: If the request involves a module,
+	 * that module's /classes/dataProviders directory is checked, 
+	 * otherwise/then the application's classes/dataProviders directory 
+	 * is checked, and finally (if no match found yet) the webapp-base
+	 * /classes/dataProviders directory is checked.
+	 * Data providers must be named <ProviderName>.class.php, and must 
+	 * implement the IApplicationDataProvider interface.
+	 * 
+	 * @param $class        string  The name of the DataProvider class
+	 * @param $options      array   optional array of constructor options.
+	 * 						These are flowed down to the DataProvider's 
+	 * 						constructor function.
+	 * @return the data provider (must implement IApplicationDataProvider)
+	 * 
+	 * Example: to get an instance of a data provider:
+	 * 	  $p = $app->GetDataProvider('<ProviderName>');
+	 * 
+	 * Example 2: to get an instance and pass options to the constructor
+	 *    $p = $app->GetDataProvider('<ProviderName>',array('opt1'=>'val1'));
+	 *    
+	 * Note that this will not attempt to connect to your data provider.
+	 * All implementations of IApplicationDataProvider offer a ::connect()
+	 * function, which should be invoked on the returned class to initiate
+	 * a connection.
+	 * 
+	 */
+	public function getDataProvider($class,$options = array()) {
+		require_once( "Org/Apache/Oodt/Balance/Interfaces/IApplicationDataProvider.php");
+		$dataProviderPath = "/classes/dataProviders/{$class}.class.php";
+		
+		// Check for the requested data provider in one of 3 locations. It could be:
+		// 1) Part of a module
+		if ($this->request->isModule && 
+			is_file($this->request->moduleBase . $dataProviderPath)) {
+			require_once($this->request->moduleBase . $dataProviderPath);
+			
+			return new $class($options);
+		}
+		
+		// 2) Part of the application's widget collection
+		if (is_file(HOME . $dataProviderPath)) {
+			require_once(HOME . $dataProviderPath);
+			return new $class($options);
+		}
+		
+		// 3) Part of the webapp-base widget collection
+		if (is_file(LIB . $dataProviderPath)) {
+			require_once(LIB . $dataProviderPath);
+			return new $class($options);
+		}
+		return false;
+	}
+	
+	public function getErrorProvider(
+		$class = 'Org_Apache_Oodt_Balance_Providers_Error_DefaultErrorProvider',
+		$options = array()) {
+		
+		return new $class;
+	}
+	
+	
+	/**
+	 * Create an instance of the requested widget class. 
+	 * @deprecated
+	 * @param unknown_type $class
+	 * @param unknown_type $options
+	 */
+	public function createWidget($class,$options = array()) {
+		
+		require_once( "Org/Apache/Oodt/Balance/Interfaces/IApplicationWidget.php");
+		
+		$classPath = "/scripts/widgets/{$class}.php";
+		
+		// Check for the requested widget in one of 2 locations. It could be:
+		// 1) Part of a module
+		if ($this->request->isModule && 
+			is_file($this->request->moduleBase . $classPath)) {
+			require_once($this->request->moduleBase . $classPath);
+			return new $class($options);
+		}
+		
+		// 2) Part of the application's widget collection
+		if (is_file(HOME . $classPath)) {
+			require_once(HOME . $classPath);
+			return new $class($options);
+		}
+		
+		// No widget matching $class found...
+		return false;
+	}
+	
+	/**
+	 * Take any application view and 'widgetize' it. This allows developers to nest
+	 * application views, allowing for greater modularity and reuse.
+	 * 
+	 * As an example: given an application with URIs  /foo/bar and foo/baz (corresponding
+	 * to HOME/views/foo/bar.php and HOME/views/foo/baz.php), the content of /foo/baz can
+	 * be 'widgetized' (nested) within /foo/bar simply by calling this function from somewhere
+	 * within the host view (/foo/bar):
+	 * 
+	 * <div>
+	 *   <?php App::Get()->widgetizeView('/foo/baz');
+	 * </div>
+	 * 
+	 * will produce:
+	 * 
+	 * <div>
+	 *   <div class="bal_widget">...contents of HOME/views/foo/baz.php...</div>
+	 * </div>
+	 * 
+	 * The `cssClasses` parameter allows for specifying any css class definitions that should
+	 * be applied to the widget container. For example:
+	 * 
+	 * App::Get()->widgetizeView('/foo/baz','someClass someOtherClass');
+	 * 
+	 * will produce:
+	 * 
+	 * <div>
+	 *   <div class="bal_widget someClass someOtherClass">...contents...</div>
+	 * </div>
+	 * 
+	 * @param string $contentPath  The URI to the view to widgetize
+	 * @param string $cssClasses   Any css classes to append to the widget's `classes` attribute
+	 * @param mixed  $options      An array of options (for the future... none defined yet)
+	 */
+	public function widgetizeView($contentPath,$cssClasses = '',$options = array()) {
+	
+		// Create a request object for the content to be widgetized
+		$request  = $this->subrequest = new Org_Apache_Oodt_Balance_Core_ApplicationRequest(
+			$this->settings,$contentPath);
+			
+		// Store the application request object prior to processing this nested request
+		$parentRequest = $this->request;
+		
+		// Store the nested request in the application so that it can be accessed as
+		// expected via App::Get()->request (for accurate segment processing, for example)
+		$this->request = $request; 	
+		
+		// Generate a response for the nested request
+		$response = new Org_Apache_Oodt_Balance_Core_ApplicationResponse(
+			$this->settings,$request);
+		$response->process(array('skipHeader' => true,'skipFooter' => true,'skipHooks' => true));
+		
+		//TODO: Process any options (still need to define the options available)
+		
+		// send the wigitized content
+		echo '<div class="bal_widget ' . $cssClasses . '">'
+			. $response->getViewContent()
+			. '</div>';
+			
+		// Restore the application request
+		$this->request    = $parentRequest;
+		$this->subrequest = null;
+	}
+}

Added: oodt/trunk/balance/lib/pear/Core/ApplicationDataResponse.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Core/ApplicationDataResponse.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Core/ApplicationDataResponse.class.php (added)
+++ oodt/trunk/balance/lib/pear/Core/ApplicationDataResponse.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,81 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * ApplicationDataResponse provides a standard response object for use by application
+ * data providers. 
+ * 
+ * The ApplicationDataResponse works off of the idea that the KEY=>VALUE paradigm
+ * is more or less universal and suits (or is at least compatible with) a broad array
+ * of data sources. By guaranteeing that all data providers will return objects of this type
+ * in response to data requests, it is possible to simplify the process of integrating
+ * and assimilating data from multiple heterogeneous sources
+ * 
+ * @author ahart
+ * 
+ */
+class Org_Apache_Oodt_Balance_Core_ApplicationDataResponse {
+	
+	public $requestString;
+	public $data;
+	public $errorOccurred;
+	public $errorMessage;
+	
+	public function __construct($seed = array()) {
+		$this->data = $seed;
+		$this->errorOccurred = false;
+	}
+	
+	public function size() {
+		return count($this->data);
+	}
+	
+	public function count() {
+		return count($this->data);
+	}
+	
+	public function add($key,$value) {
+		$this->data[$key] = $value;
+	}
+	
+	public function bulkAdd($data) {
+		$this->data = array_merge($this->data,$data);
+	}
+	
+	public function get($key) {
+		return (isset($this->data['key']))
+			? $this->data['key']
+			: false;
+	}
+	
+	public function setRequestString($request) {
+		$this->requestString = $request;
+	}
+	
+	public function error() {
+		return ($this->errorOccurred);
+	}
+	
+	public function setError($message) {
+		$this->errorOccurred = true;
+		$this->errorMessage  = true;
+	}
+}

Added: oodt/trunk/balance/lib/pear/Core/ApplicationRequest.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Core/ApplicationRequest.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Core/ApplicationRequest.class.php (added)
+++ oodt/trunk/balance/lib/pear/Core/ApplicationRequest.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,169 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * ApplicationRequest: Provides methods for interpreting and processing
+ * a resource request.
+ * 
+ * @author ahart
+ * 
+ */
+class Org_Apache_Oodt_Balance_Core_ApplicationRequest {
+	
+	public $isScript;
+	
+	public $config;
+	
+	public $uri;
+	
+	public $segments;
+	
+	public $data;
+	
+	public $viewPath;
+	
+	public $scriptPath;
+	
+	public $isModule;
+	
+	public $modulePath;	// Filesystem path for module
+
+	public $moduleRoot;	// URL base for module
+
+	public $moduleStatic;	// URL base for  static module assests (images,css,js,etc)
+
+	public function __construct($config,$requestURI) {
+		
+		// Determine if this request is a script or a view
+		$this->isScript = $this->isScript($requestURI);
+	
+		// Store the config as provided
+		$this->config = $config;
+		
+		// Store the uri as provided
+		$this->uri = $requestURI;
+		
+		// Initialize the segments and view path
+		$this->segments = array();
+		$this->viewPath = false;
+		
+		// Store data associated with the request
+		$this->data = $_GET;
+		$this->data = array_merge($this->data,$_POST);
+		
+		if ($this->isScript) {
+			$this->processAsScript();
+		} else {
+			$this->processAsView();
+		}
+	} 
+	
+	protected function processAsView() {
+		// Determine the view to use
+		list($thePage) = explode('index.php',$this->uri);
+		$thePage = ltrim($thePage,'/');
+
+		if ($thePage == '') { $thePage = 'index'; }	
+		$parts = explode('/',$thePage);
+
+		// Determine whether a module is being requested
+		$module = App::Get()->isModule($thePage);
+		
+		if ($module) {
+			$this->isModule   = true;
+			$this->modulePath   = $module->modulePath;
+            $this->moduleRoot   = $module->moduleRoot;
+            $this->moduleStatic = $module->moduleStatic;
+			array_shift($parts);
+		}
+
+		// Starting with the full request string, test for the existance of
+		// a corresponding view. If none is found in the HOME
+		// directory, chop off the last segment and try again. Add the chopped
+		// segment to the "segments" array since it is likely a parameter.
+		$partCount = count($parts);
+		while ($partCount > 0) {
+			$testPath    = implode('/',$parts);
+			$homeTest    = (($this->isModule) ? "{$this->modulePath}/views" : $this->config['views_dir']) . '/' . $testPath . '.php';
+			$homeIdxTest = (($this->isModule) ? "{$this->modulePath}/views" : $this->config['views_dir']) . '/' . $testPath . '/index.php';
+			
+			
+			if (is_file($homeTest)) { 
+				$this->viewPath = $homeTest;
+				break;
+			}
+			if (is_file($homeIdxTest)) {
+				$this->viewPath = $homeIdxTest;
+				break;
+			}
+			
+			// If here, neither is a valid view, so chop the last segment
+			$this->segments[] = $parts[$partCount - 1];
+			array_pop($parts);
+			$partCount--;
+		}
+		
+		// If no view has been found by this point, display a 404 message
+		if (!$this->viewPath) {
+			$this->viewPath = dirname(dirname(__FILE__)) . "/views/error/404.php";
+		}
+		
+		// Reverse the segments array so that params appear in the proper order
+		$this->segments = array_reverse($this->segments);
+	}
+	
+	protected function processAsScript() {
+		
+		// Determine the desired script
+		list($theScript) = explode("_init.php",$this->uri);
+		if ($GLOBALS['app']->settings['site_root'] != '/') {
+			$theScript   = str_replace($GLOBALS['app']->settings['site_root'],'',$theScript);
+		}
+		$theScript       = str_replace(".do",".php",$theScript);
+		$theScript       = strpos($theScript,'?') 
+			? substr($theScript,0,strpos($theScript,'?'))
+			: $theScript;
+		$theScript       = ltrim($theScript,'/');
+		$module          = $GLOBALS['app']->isModule($theScript);
+		if ($module) {
+			$this->isModule   = true;
+			$this->modulePath   = $module->modulePath;
+            $this->moduleRoot   = $module->moduleRoot;
+            $this->moduleStatic = $module->moduleStatic;
+			$theScript        = substr($theScript,strpos($theScript,'/')+1);
+			$path             = $module->modulePath . "/scripts/{$theScript}";
+		} else {
+			$path = HOME . "/scripts/{$theScript}";
+		}
+		
+		$this->scriptPath   = $path;
+	}
+	
+	
+	protected function isScript($requestURI) {
+		// Is this a script? (does the script filename end in .do?)
+		$test = $requestURI;
+		if (strpos($test,'?')) {
+			$test = substr($test,0,strpos($test,'?'));
+		}
+		return (substr($test,-3,3) == '.do');
+	}
+}

Added: oodt/trunk/balance/lib/pear/Core/ApplicationResponse.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Core/ApplicationResponse.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Core/ApplicationResponse.class.php (added)
+++ oodt/trunk/balance/lib/pear/Core/ApplicationResponse.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,265 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * ApplicationResponse: Provides functions for dynamically constructing
+ * and delivering a response to a resource request.
+ * 
+ * @author ahart
+ * 
+ */
+class Org_Apache_Oodt_Balance_Core_ApplicationResponse {
+	
+	protected $config;
+	protected $request;
+	
+	protected $headers;
+	
+	protected $header;
+	protected $view;
+	protected $footer;
+	
+	protected $stylesheets = array();
+	protected $javascripts = array();
+	
+	const DYN_JS_TAG  = '<!-- JAVASCRIPTS -->';
+	const DYN_CSS_TAG = '<!-- STYLESHEETS -->';
+	
+	/**
+	 * Constructor
+	 * 
+	 * @param array $config
+	 * @param Org_Apache_Oodt_Balance_Core_ApplicationRequest $request
+	 */
+	public function __construct($config, 
+		Org_Apache_Oodt_Balance_Core_ApplicationRequest $request) {
+		
+		$this->config   = $config;
+		
+		$this->request = $request;
+		
+		$this->headers  = array();
+		
+		$this->header   = HOME . "/{$config['header_file_path']}";
+		$this->footer   = HOME . "/{$config['footer_file_path']}";
+	}
+	
+	/**
+	 * Generates a response by processing the requested view,
+	 * including any header and footer views (if needed) as specified
+	 * by the application config file.
+	 * 
+	 * Available options:
+	 *   skipHeader: boolean (default = false) If present, omits header processing
+	 *   skipFooter: boolean (default = false) If present, omits footer processing
+	 *   skipHooks:  boolean (default = false) If present, omits hook processing
+	 *
+	 * @param array $options
+	 */
+	public function process($options = array()) {
+		
+		// Merge defaults with provided options
+		$defaults = array(
+			'skipHeader' => false,
+			'skipFooter' => false,
+			'skipHooks'  => false,
+		);
+		$options += $defaults;
+		
+		// Preprocessing for a view
+		if (!$this->request->isScript) {
+			ob_start();	// Start buffering the output
+			
+			// Include the appropriate hooks.php file
+			if (!$options['skipHooks']) {
+				include ((App::Get()->request->isModule 
+                          ? App::Get()->request->modulePath 
+                          : HOME ) . '/hooks.php');
+			}
+			
+			// Check that the requested view exists
+			if (file_exists($this->request->viewPath)) {
+				
+				// Run the beforeView hook
+				if (!$options['skipHooks'] && function_exists('hook_before_view')) {
+					hook_before_view();
+				}
+				// Process the view
+				include($this->request->viewPath);
+			} else { 
+				include(HOME . "/views/errors/404.php"); // 404 error page
+			}
+			
+			$this->view = ob_get_contents();
+			ob_clean();
+			
+			// Determine the header view (if any) to include
+			if (!$options['skipHeader'] && $this->header && is_file($this->header)) {
+				// Run the beforeHeader hook
+				if (!$options['skipHooks'] && function_exists('hook_before_header')) {
+					hook_before_header();
+				}
+				
+				// Process the header
+				if (!empty($this->header)) {include($this->header);}
+
+				$this->header = ob_get_contents();
+				ob_clean();
+			}
+			
+			// Determine the footer view (if any) to include
+			if (!$options['skipFooter'] && $this->footer && is_file($this->footer)) {
+				// Run the beforeFooter hook
+				if (!$options['skipHooks'] && function_exists('hook_before_footer')) {
+					hook_before_footer();
+				}
+				
+				// Process the footer
+				if (!empty($this->footer)) {include($this->footer);}
+				
+				$this->footer = ob_get_contents();
+				ob_clean();
+			}
+
+			ob_end_clean();	// Stop buffering the output
+		} else {
+			require_once( $this->request->scriptPath );
+			exit();
+		}
+	}
+	
+	/**
+	 * Actually sends the response (using 'echo') out to the 
+	 * client's browser.
+	 */
+	public function send() {
+		
+		if ($this->request->isScript) {	
+			if (is_file($this->request->scriptPath)) {
+				require_once($this->request->scriptPath);
+			} else {
+				header("Location: " . SITE_ROOT . "/errors/404");
+			}
+		} else {
+			// Process any dynamically added content
+			$this->processDynamicContent();
+			
+			// Run the beforeSend hook
+			if (function_exists('hook_before_send')) {
+				hook_before_send();
+			}
+			foreach ($this->headers as $header) {
+				header($header);
+			}
+			if ($this->header) {
+				echo $this->header;
+			}
+			echo $this->view;
+			if ($this->footer) {
+				echo $this->footer;
+			}
+			// Run the afterSend hook
+			if (function_exists('hook_after_send')) {
+				hook_after_send();
+			}
+		}
+	}
+
+	public static function sendFatal($message) {
+		// Store the message in the session
+		$_SESSION['fail_message'] = $message;
+		
+		// Clear any old output and restart buffering the output
+		ob_clean();
+		ob_start();
+	
+		// Build the 404 error page
+		include(LIB . "/views/errors/fail.php");
+		
+		// Get the contents as a string and flush the buffer
+		$content = ob_get_contents();
+		
+		// Stop buffering output
+		ob_end_clean();
+		
+		// Send the response
+		echo $content;
+		
+		exit();
+	}
+	
+	/**
+	 * Replace special tags with their dynamically assigned content. Currently, the only
+	 * special tags are for defining an area for CSS and JavaScript imports.
+	 * 
+	 */
+	protected function processDynamicContent() {
+		
+		// Dynamically insert CSS
+		$this->header = str_replace(self::DYN_CSS_TAG,implode("\r\n",$this->stylesheets),$this->header);
+		$this->view   = str_replace(self::DYN_CSS_TAG,implode("\r\n",$this->stylesheets),$this->view);
+		$this->footer = str_replace(self::DYN_CSS_TAG,implode("\r\n",$this->stylesheets),$this->footer);
+		
+		// Dynamically insert JS
+		$this->header = str_replace(self::DYN_JS_TAG,implode("\r\n",$this->javascripts),$this->header);
+		$this->view   = str_replace(self::DYN_JS_TAG,implode("\r\n",$this->javascripts),$this->view);
+		$this->footer = str_replace(self::DYN_JS_TAG,implode("\r\n",$this->javascripts),$this->footer);
+		
+	}
+	
+	public function useHeaderFile($path) {
+		$this->header = $path;
+	}
+	
+	public function useFooterFile($path) {
+		$this->footer = $path;
+	}
+	
+	public function sendHeader($headerContent) {
+		$this->headers[] = $headerContent;
+	}
+	
+	public function getHeaderContent() {
+		return $this->header;
+	}
+	public function getViewContent() {
+		return $this->view;
+	}
+	public function getFooterContent() {
+		return $this->footer;
+	}
+	
+	public function addStylesheet($href,$condition='') {
+		// Build the string for the css import
+		$str = "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$href}\"/>";
+		if (!empty($condition)) {
+			$str = "<!--[if {$condition}]>{$str}<![endif]-->";
+		}
+		$this->stylesheets[] = $str;
+	}
+	
+	public function addJavascript($src) {
+		// Build the string for the javascript import
+		$str = "<script type=\"text/javascript\" src=\"{$src}\"></script>";
+		$this->javascripts[] = $str;
+	}
+	
+}

Added: oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php (added)
+++ oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthenticationProvider.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,162 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * IApplicationAuthenticationProvider defines an interface that should be 
+ * implemented by all authentication providers to simplify the process of 
+ * accessing and retrieving information about the underlying system. 
+ * 
+ * The interface defines five mandatory functions:
+ *    - __construct: Provide any necessary configuration information but do
+ *               not actually establish a connection to the underlying system.
+ *    - connect: This function does the work of actually connecting to the 
+ *               underlying system. Options can be provided either here or in 
+ *               the constructor arguments (or both), but the connection to the 
+ *               underlying system should not be initiated until this function 
+ *               is invoked.
+ *    - disconnect: Disconnect from the underlying system, performing any
+ *               necessary clean up operations in the process.
+ *    - checkLogin: Check if a valid user has logged in.
+ *    - login:   Determine the ability to gain access to the underlying system 
+ *    			 as a legitimate user. The requirements are a valid username 
+ *    			 (or user ID) and password.
+ *    - logout:  Ending the user's session to the underlying system.
+ *               
+ *               
+ *   Framework implementations of common authentication providers can be found in:
+ *   {LIB}/classes/authenticationProviders   and should be named FooAuthenticationProvider.class.php.
+ *   Framework authentication providers can be invoked by doing:
+ *          $app->GetAuthenticationProvider('FooAuthenticationProvider');
+ *   
+ *   Custom authentication providers should be placed in:
+ *   {HOME}/classes/authenticationProviders  and should be named FooAuthenticationProvider.class.php.
+ *   Custom authentication providers can be invoked by doing:
+ *          $app->GetAuthenticationProvider('foo',true); // true --> custom
+ * 
+ * @author s.khudikyan
+ * 
+ */
+interface Org_Apache_Oodt_Balance_Interfaces_IApplicationAuthenticationProvider {
+	
+	/**
+	 * Constructor - Instantiate the provider but do not yet connect
+	 * to the underlying system.
+	 * 
+	 */
+	public function __construct();
+	
+	/**
+	 * Initiate a connection to the underlying system.
+	 * 
+	 * @return boolean            True or false depending on the result
+	 */
+	public function connect();
+	
+	/**
+	 * Disconnect from the underlying system and perform any cleanup 
+	 * operations necessary.
+	 * 
+	 * @return boolean 		      True or false depending on the result
+	 */
+	public function disconnect();
+	
+	/**
+	 * Check if a valid user has logged in.
+	 * 
+	 * @return boolean 		      True or false depending on the result
+	 */	
+	public function isLoggedIn();
+	
+	/**
+	 * Determine whether privileges will be granted to a particular user
+	 * using credentials provided.
+	 * 
+	 * @param $username    mixed  The username is usually a string. 
+	 * @param $password    mixed  The password is usually a string. 
+	 * @return mixed	          True or false depending on the success of login
+	 */
+	public function login( $username, $password );
+	
+	/**
+	 * Ending the user's session to the underlying system.
+	 * 
+	 */
+	public function logout();
+	
+	/**
+	 * Get current user's username.
+	 * 
+	 */
+	public function getCurrentUsername();
+	
+	/**
+	 * Change current user's password.
+	 * 
+	 * @param $newPassword string
+	 * @return boolean			   True or false depending on the success of password change
+	 */
+	public function changePassword( $newPassword );
+
+	/**
+	 * Checks if user is logged in. If true, validates rules from config file and uses 
+	 * {@link changePassword} to change password.
+	 * 
+	 * @param $newPass            string  The new password
+	 * @param $encryptionMethod   string  The encryption method used
+	 */
+	public function validateChangePassword( $newPass, $encryptionMethod = "SHA" );
+	
+	/**
+	 * Retrieves the set of attributes from the user's entry 
+	 * 
+	 * @param $username    string  The user for which attributes will be returned
+	 * @param $attributes  array   Attributes to retrieve
+	 * @return array               An empty array or requested attributes
+	 */
+	public function retrieveUserAttributes( $username, $attributes );
+	
+	/**
+	 * Creates a new account with the user information provided
+	 * 
+	 * @param $userInfo    array  Can include different values depending on provider
+	 * 								i.e. username, firstname, lastname, email
+	 */
+	public function addUser( $userInfo );
+	
+	/**
+	 * Uses {@link retrieveUserAttributes} to retrieve information about the provided 
+	 * user. If count of array returned is > 0 then the username is not available.
+	 * 
+	 * @param $username	   string The username for which a user is checking the 
+	 * 								availability of
+	 */	
+	public function usernameAvailability( $username );
+	
+	/**
+	 * Updates user information with the values of provided attributes
+	 * 
+	 * @param $newInfo     array  (key, value) based array, where keys are the user's 
+ 	 * 								entry attribute ids and the values will replace 
+ 	 * 								the values of those attributes 
+	 */
+	public function updateProfile( $newInfo );
+	
+}

Added: oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php (added)
+++ oodt/trunk/balance/lib/pear/Interfaces/IApplicationAuthorizationProvider.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,62 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * LDAPAuthorizationProvider defines an interface that will determine what level 
+ * of access a particular user should have to secured resources. 
+ * 
+ * The interface defines five mandatory functions:
+ *    - __construct: Provide any necessary configuration information 
+ *               
+ *               
+ *   Framework implementations of common authorization providers can be found in:
+ *   Balance/Providers/Authorization 
+ *   Framework authorization providers can be invoked by doing:
+ *          App:Get()->getAuthorizationProvider();
+ * 
+ * @author s.khudikyan
+ * 
+ */
+
+interface Org_Apache_Oodt_Balance_Interfaces_IApplicationAuthorizationProvider {
+	
+	/**
+	 * Constructor - Instantiate the provider
+	 * 
+	 */
+	public function __construct();
+	
+	/**
+	 * Initiate a connection to the underlying system.
+	 * 
+	 * @return boolean            True or false depending on the result
+	 */
+	public function connect();
+	
+	/**
+	 * Retrieves the set of groups for specified user
+	 * 
+	 * @param $username    string  The user for which groups will be returned
+	 * @return array               An empty array or groups the user belongs to
+	 */
+	public function retrieveGroupsForUser( $username );
+		
+}

Added: oodt/trunk/balance/lib/pear/Interfaces/IApplicationDataProvider.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Interfaces/IApplicationDataProvider.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Interfaces/IApplicationDataProvider.php (added)
+++ oodt/trunk/balance/lib/pear/Interfaces/IApplicationDataProvider.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,125 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * IApplicationDataProvider defines an interface that should be implemented
+ * by all data providers to simplify the process of integrating and accessing
+ * multiple heterogeneous data sources. A data source could be a relational
+ * SQL-like database, a CAS File Manager, an LDAP server, anything that can
+ * be queried for data. 
+ * 
+ * The interface defines five mandatory functions:
+ *    - __construct: Provide any necessary configuration information but do
+ *               not actually establish a connection to the underlying data
+ *               source.
+ *    - connect: This function does the work of actually connecting to the 
+ *               underlying data source. Options can be provided either here
+ *               or in the constructor arguments (or both), but the connection
+ *               to the underlying data source should not be initiated until
+ *               this function is invoked.
+ *    - disconnect: Disconnect from the underlying data source, performing any
+ *               necessary clean up operations in the process.
+ *    - request: Satisfy a request for data. The format that this request takes
+ *               will likely differ across implementations. An array of further
+ *               options may be provided as an optional second argument. As a 
+ *               concrete  example, an SQL-like data source may support string 
+ *               requests like "SELECT * FROM foo WHERE bar='baz'". The 
+ *               response from this call must be an ApplicationDataResponse object
+ *               containing the (possibly multidimensional) array of response info. 
+ *    - command: Send a command to the underlying data source. As with request,
+ *               the format that this command takes will likely differ across
+ *               implementations. As a concrete example, an SQL-like data source
+ *               may support string commands like "UPDATE foo set bar='baz'". 
+ *               Command should not be expected to return a value, other than
+ *               possibly true/false to indicate the success of the call.
+ *               
+ *               
+ *   Framework implementations of common data providers can be found in:
+ *   {LIB}/classes/dataProviders   and should be named FooDataProvider.class.php.
+ *   Framework data providers can be invoked by doing:
+ *          $app->GetDataProvider('FooDataProvider');
+ *   
+ *   Custom data providers should be placed in:
+ *   {HOME}/classes/dataProviders  and should be named FooDataProvider.class.php.
+ *   Custom data providers can be invoked by doing:
+ *          $app->GetDataProvider('foo',true); // true --> custom
+ * 
+ * @author ahart
+ * 
+ */
+interface Org_Apache_Oodt_Balance_Interfaces_IApplicationDataProvider {
+	
+	/**
+	 * Constructor - Instantiate the provider but do not yet connect
+	 * to the underlying data source.
+	 * 
+	 * @param $options  array   An optional set of configuration values
+	 */
+	public function __construct($options = array());
+	
+	/**
+	 * Initiate a connection to the underlying data source
+	 * 
+	 * @param $options  array  An optional set of configuration values
+	 * @return boolean         True or false depending on the result
+	 */
+	public function connect($options = array());
+	
+	/**
+	 * Disconnect from the underlying data source and perform any
+	 * cleanup operations necessary.
+	 * 
+	 * @param $options  array  An optional set of configuration values
+	 * @return unknown_type    True or false depending on the result
+	 */
+	public function disconnect($options = array());
+	
+	/**
+	 * Request data from the underlying data source.
+	 * 
+	 * @param $request  mixed  The request itself, usually a string. The nature
+	 *                         of the request is necessarily implementation 
+	 *                         specific and will vary across providers. For a 
+	 *                         SQL-like relational provider, this will likely be
+	 *                         a "SELECT ..." string.
+	 * @param $options  array  An array of options to configure the request.
+	 *                         These will be implementation-specific and 
+	 *                         therefore will likely differ across providers.
+	 * @return ApplicationDataResponse  The resulting data retrieved
+	 */
+	public function request($request,$options = array());
+	
+	/**
+	 * Send a command to the underlying data source.
+	 * 
+	 * @param $command mixed   The command itself, usually a string. The nature
+	 *                         of the command is necessarily implementation 
+	 *                         specific and will vary across providers. For a 
+	 *                         SQL-like relational provider, this will likely be
+	 *                         a "UPDATE ...", or "CREATE ..." string.
+	 * @param $options  array  An array of options to configure the command.
+	 *                         These will be implementation-specific and 
+	 *                         therefore will likely differ across providers.
+	 * @return boolean         True or false depending on the success of the command
+	 */
+	public function command($command,$options = array());
+	
+}

Added: oodt/trunk/balance/lib/pear/Interfaces/IApplicationErrorProvider.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Interfaces/IApplicationErrorProvider.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Interfaces/IApplicationErrorProvider.php (added)
+++ oodt/trunk/balance/lib/pear/Interfaces/IApplicationErrorProvider.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,39 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * IApplicationErrorProvider defines an interface that should be implemented
+ * by all error providers to simplify the process of formatting and displaying
+ * application errors.
+ * 
+ * 
+ * @author ahart
+ */
+interface Org_Apache_Oodt_Balance_Interfaces_IApplicationErrorProvider {
+	
+	/**
+	 * Causes an error response to be sent to the sender
+	 * 
+	 * @param integer $httpResponseCode  The HTTP response code to send
+	 * @param string  $message           A contextual message to include or log
+	 */
+	public function error($httpResponseCode,$message = '',$options=array());
+}

Added: oodt/trunk/balance/lib/pear/Interfaces/IApplicationWidget.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Interfaces/IApplicationWidget.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Interfaces/IApplicationWidget.php (added)
+++ oodt/trunk/balance/lib/pear/Interfaces/IApplicationWidget.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,67 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * Interface for developing widgets (reusable bits of view code) that can
+ * be placed on different application pages.
+ * 
+ * This interface defines two mandatory functions:
+ *  - construct : Intialize the widget and provide any necessary 
+ *                configuration information
+ *  - render    : Build the HTML output that constitutes the widget. This
+ *                function does not accept arguments (any config should
+ *                be provided either in the controller or via other "set"
+ *                functions. This function should return a string composed
+ *                of the final HTML output of the widget.
+ *        
+ * Framework widgets can be found inside the {LIB}/scripts/widgets directory.              
+ * 
+ * Framework Widgets can be invoked from view code as follows:
+ *    // Create an instance of the widget (will transparently call __construct)
+ *    $myFooWidget = $app->createWidget('FooWidget',array(..config..))
+ *  
+ * Custom widgets should be placed inside the {HOME}/scripts/widgets directory and 
+ * can be named FooWidget.php. All widgets must implement this interface.
+ * 
+ * Custom Widgets can be invoked from view code as follows:
+ *    // Create an instance of the widget (will transparently call __construct)
+ *    $myFooWidget = $app->createWidget('FooWidget',array(..config..),true) // true --> custom
+ * 
+ * <!-- (all widgets, framework or custom): display widget contents -->
+ * <span><?php echo $myFooWidget->render()?></span>
+ * 
+ * @author ahart
+ * 
+ */
+interface Org_Apache_Oodt_Balance_Interfaces_IApplicationWidget {
+	
+	public function __construct($options = array());
+	
+	/**
+	 * Build the HTML output that constitutes the widget.
+	 * 
+	 * @param boolean $bEcho (default = true) If true, the function should
+	 *        echo the contents directly. If false, the contents should be
+	 *        returned as a string.
+	 */
+	public function render($bEcho = true);
+	
+}

Added: oodt/trunk/balance/lib/pear/Providers/Auth/LDAPAuthenticationProvider.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Providers/Auth/LDAPAuthenticationProvider.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Providers/Auth/LDAPAuthenticationProvider.class.php (added)
+++ oodt/trunk/balance/lib/pear/Providers/Auth/LDAPAuthenticationProvider.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,174 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * Implementation of iApplicationAuthenticationProvider, which extends SingleSignOn.
+ * 
+ * Note: This class has a dependency on the OODT CAS-SSO package 
+ *      (http://oodt.jpl.nasa.gov/repo/framework/cas-sso/trunk/src/php/pear)
+ *      
+ *      To build this dependency, check out the above project and then:
+ *      1) cd into the checked out project (you should see a package.xml file)
+ *      2) pear package
+ *      3) (sudo) pear install --force Org_Apache...tar.gz
+ * 
+ * @author s.khudikyan
+ * @author ahart
+ * 
+ */
+require("Org/Apache/Oodt/Cas/Security/SingleSignOn.php");
+
+class Org_Apache_Oodt_Balance_Providers_Auth_LDAPAuthenticationProvider
+	extends Org_Apache_Oodt_Cas_Security_SingleSignOn 
+	implements Org_Apache_Oodt_Balance_Interfaces_IApplicationAuthenticationProvider {
+
+	/**
+	 * If authentication config file exists, require(file_name) file
+	 */
+	public function __construct() {
+		
+		// set LDAP constants
+		define("CAS_SECURITY",true);
+		define("SSO_LDAP_HOST", App::Get()->settings['ldap_host']);
+		define("SSO_LDAP_PORT", App::Get()->settings['ldap_port']);
+		define("SSO_BASE_DN", App::Get()->settings['ldap_base_dn']);
+		define("SSO_GROUPS_DN", App::Get()->settings['ldap_group_dn']);
+		define("SSO_COOKIE_KEY", App::Get()->settings['cookie_key']);
+		
+	}
+	
+	public function connect() {
+		return parent::connect(func_get_arg(0),func_get_arg(1));
+	}
+	
+	public function disconnect() {
+		
+	}
+	
+	public function isLoggedIn() {
+		return parent::isLoggedIn();
+	}
+	
+	public function login( $username, $password ) {
+		return parent::login( $username, $password );
+	}
+	
+	public function logout() {
+		parent::logout();
+	}
+
+	public function getCurrentUsername() {
+		return parent::getCurrentUsername();
+	}
+	
+	public function changePassword( $newPassword ) {
+		if ( App::Get()->settings['auth_encryption_method'] ) {
+			return parent::changePassword( $newPassword, App::Get()->settings['auth_encryption_method'] );
+		}
+		return parent::changePassword( $newPassword );
+	}
+	
+	public function validateChangePassword( $newPass, $encryptionMethod = "SHA" ) {
+		$isValid = true;
+		$messages = array();
+		// validate rules from config file
+		$rules = App::Get()->settings['security_password_rules'];
+
+		if ( isset($rules) ) {
+			foreach( $rules as $rule ){
+				
+				// Separate the rule from the error message
+				list($regularExpression,$errorMessage) = explode('|',$rule,2);
+				
+				// Test the rule
+				$rulePassed = preg_match($regularExpression, $newPass);
+				
+				// If the rule failed, append the error message
+				if (!$rulePassed) {
+					$messages[] = $errorMessage;
+					$isValid    = false;
+				}
+			}
+		}
+
+		if ($isValid && $this->connect(SSO_LDAP_HOST,SSO_LDAP_PORT)) {
+		  $result = $this->changePassword($newPass,$encryptionMethod);
+		  return true;
+		} else
+		  return $messages;
+	}
+	
+	public function retrieveUserAttributes( $username, $attributes ) {
+		$rawArray 		= parent::retrieveUserAttributes( $username, $attributes );
+		$userAttributes = array();
+		
+		if ( count($rawArray) > 1 ) {
+			$rawArray = $rawArray[0];
+			// Get only necessary attributes to return
+			foreach ( $rawArray as $key=>$keyValue ) {
+				foreach ( $attributes as $value ) {
+					if ( $key === $value ) {
+						$userAttributes[$key] = $keyValue[0];
+					}
+				}
+			}
+		}
+		return $userAttributes;
+	}
+	
+	public function addUser($userInfo) {
+		$ldapconn = $this->connect(SSO_LDAP_HOST,SSO_LDAP_PORT);
+		if ($ldapconn) {
+			$user  = "uid={$userInfo[ "uid" ]}," . SSO_BASE_DN;
+			return ldap_add($ldapconn,$user,$userInfo);
+		}
+		// connection failed
+		return false;
+	}
+	
+	public function usernameAvailability( $username ) {
+		$justthese = array( App::Get()->settings['username_attr'] );
+		$profile = $this->retrieveUserAttributes($username, $justthese);
+		if (count($profile) > 0) {
+			return false;
+		} else {
+			// available
+			return true;
+		}
+	}
+	
+	public function updateProfile($newInfo) {
+
+		if ($this->isLoggedIn()) {
+			$user  = "uid={$this->getCurrentUsername()}," . SSO_BASE_DN ;
+			$ldapconn = $this->connect(SSO_LDAP_HOST,SSO_LDAP_PORT);
+			
+			if (ldap_mod_replace($ldapconn,$user,$newInfo)) {
+				return true;
+			} else {
+				return false;
+			}
+		} else {
+			return false;
+		}
+	}
+	
+}

Added: oodt/trunk/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php (added)
+++ oodt/trunk/balance/lib/pear/Providers/Authorization/LDAPAuthorizationProvider.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,109 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * IApplicationAuthenticationProvider defines an interface that should be 
+ * implemented by all authentication providers to simplify the process of 
+ * accessing and retrieving information about the underlying system. 
+ * 
+ * The interface defines five mandatory functions:
+ *    - __construct: Provide any necessary configuration information but do
+ *               not actually establish a connection to the underlying system.
+ *    - connect: This function does the work of actually connecting to the 
+ *               underlying system. Options can be provided either here or in 
+ *               the constructor arguments (or both), but the connection to the 
+ *               underlying system should not be initiated until this function 
+ *               is invoked.
+ *    - disconnect: Disconnect from the underlying system, performing any
+ *               necessary clean up operations in the process.
+ *    - checkLogin: Check if a valid user has logged in.
+ *    - login:   Determine the ability to gain access to the underlying system 
+ *    			 as a legitimate user. The requirements are a valid username 
+ *    			 (or user ID) and password.
+ *    - logout:  Ending the user's session to the underlying system.
+ *               
+ *               
+ *   Framework implementations of common authentication providers can be found in:
+ *   {LIB}/classes/authenticationProviders   and should be named FooAuthenticationProvider.class.php.
+ *   Framework authentication providers can be invoked by doing:
+ *          $app->GetAuthenticationProvider('FooAuthenticationProvider');
+ *   
+ *   Custom authentication providers should be placed in:
+ *   {HOME}/classes/authenticationProviders  and should be named FooAuthenticationProvider.class.php.
+ *   Custom authentication providers can be invoked by doing:
+ *          $app->GetAuthenticationProvider('foo',true); // true --> custom
+ * 
+ * @author s.khudikyan
+ * 
+ */
+
+class Org_Apache_Oodt_Balance_Providers_Authorization_LDAPAuthorizationProvider 
+	implements Org_Apache_Oodt_Balance_Interfaces_IApplicationAuthorizationProvider {
+	
+	/**
+	 * If authorization config file exists, require(file_name) file
+	 */
+	public function __construct() {
+		// Set LDAP constants
+		define("AUTH_BASE_DN",   App::Get()->settings['authorization_ldap_base_dn']);
+		define("AUTH_GROUPS_DN", App::Get()->settings['authorization_ldap_group_dn']);
+		define("AUTH_LDAP_HOST", App::Get()->settings['authorization_ldap_host']);
+		define("AUTH_LDAP_PORT", App::Get()->settings['authorization_ldap_port']);
+	}
+	
+	public function retrieveGroupsForUser($username,$searchDirectory = AUTH_GROUPS_DN) {
+		
+		// attempt to connect to ldap server 
+		$ldapconn = $this->connect(AUTH_LDAP_HOST,AUTH_LDAP_PORT);
+		$groups   = array();
+		if ($ldapconn) {
+			$filter = "(&(objectClass=groupOfUniqueNames)"
+				."(uniqueMember=uid={$username}," . AUTH_BASE_DN . "))";
+			$result = ldap_search($ldapconn,$searchDirectory,$filter,array('cn'));
+			
+			if ($result) {
+				$entries = ldap_get_entries($ldapconn,$result);
+				foreach ($entries as $rawGroup) {
+					if (isset($rawGroup['cn'][0]) 
+					&& $rawGroup['cn'][0] != '') {
+						$groups[] = $rawGroup['cn'][0];
+					}
+				}
+			}
+		} 
+		return $groups;
+	}
+			
+	public function connect() {
+		if ($conn = ldap_connect(func_get_arg(0),func_get_arg(1))) {
+			// Connection established
+			$this->connectionStatus = 1;
+			ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
+			ldap_set_option($conn, LDAP_OPT_DEBUG_LEVEL, 7);
+			ldap_set_option($conn, LDAP_OPT_REFERRALS, 0);	
+			$this->conn = $conn;
+			return $conn;
+		} else {
+			// Connection failed
+			return false;
+		}
+	}		
+}

Added: oodt/trunk/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php (added)
+++ oodt/trunk/balance/lib/pear/Providers/Data/MDB2DataProvider.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,137 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * Implementation of IApplicationDataProvider for PEAR MDB2.
+ * 
+ * @author s.khudikyan
+ * @author ahart
+ * 
+ */
+require_once( 'MDB2.php' );
+
+class Org_Apache_Oodt_Balance_Providers_Data_MDB2DataProvider 
+	implements Org_Apache_Oodt_Balance_Interfaces_IApplicationDataProvider {
+	
+	public $link;
+	
+	public function __construct($options = array()) {
+		
+	}
+	
+	public function connect($options = array()) {
+		$dsn = 'mysql://'.$options['username'].':'.$options['password'].'@'.$options['server'].'/'.$options['database'];
+		$this->link = MDB2::singleton( $dsn );
+		
+		if ( PEAR::isError($this->link) ) {
+
+			die("There was an error connecting to the database: " . $this->link->getMessage());
+		}
+	}
+	
+	public function disconnect($options = array()) {
+		if ($this->link) {
+			$this->link->disconnect();
+		}
+	}
+	
+	public function request($request,$options = array() ) { 
+		$data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+		
+		if ($this->link) {
+			
+			// Handle associative array
+			if (isset($options['format']) && 
+				strtolower($options['format']) == 'assoc') {
+					
+					// Execute the request and build a response object
+					$result  = $this->link->queryAll($request,null,MDB2_FETCHMODE_ASSOC);
+			}
+
+			// Handle numeric array
+			else {
+				
+				// Execute the request and build a response object
+				$result  = $this->link->queryAll($request,null,MDB2_FETCHMODE_ORDERED);
+			}
+			
+			if ( PEAR::isError($result) ) {
+				
+				$data->setError($result->getMessage());
+				return $data;
+			} else {
+				
+				// Store the request used to generate the data
+				$data->bulkAdd($result);
+				
+				// Free the request
+				$this->link->free();
+				
+				// Return the requested data
+				return $data;
+			}
+		} else {
+			$data->setError("Unable to establish connection to data source");
+			return $data;
+		}
+	}
+	
+	public function command($command,$options = array()) {
+		$data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+		
+		if ($this->link) {
+			
+			$result = $this->link->exec($command);
+			
+			if ( PEAR::isError($result) ) {
+				
+				$data->setError($result->getMessage());
+				return $data;
+			}
+		} else {
+			$data->setError("Unable to establish connection to data source");
+			return $data;
+		}
+	}
+	
+	public function lastInsertedId($options = array()){
+		$data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+		
+		if ($this->link) {
+			
+			$result = $this->link->lastInsertId();
+			
+			if ( PEAR::isError($result) ) {
+				
+				$data->setError($result->getMessage());
+				return $data;
+			} else {
+							
+				return $result;
+				
+			}
+		} else {
+			$data->setError("Unable to establish connection to data source");
+			return $data;
+		}
+	}
+	
+}

Added: oodt/trunk/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php (added)
+++ oodt/trunk/balance/lib/pear/Providers/Data/MySqlDataProvider.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,128 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * Implementation of IApplicationDataProvider for a MySql database.
+ * 
+ * @author ahart
+ * 
+ */
+class Org_Apache_Oodt_Balance_Providers_Data_MySqlDataProvider 
+	implements Org_Apache_Oodt_Balance_Interfaces_IApplicationDataProvider {
+	
+	public $link;
+	
+	public function __construct($options = array()) {
+		
+	}
+	
+	public function connect($options = array()) {
+		$this->link = mysql_connect($options['server'],
+			$options['username'],
+			$options['password']) or 
+			die("Could not connect: " . mysql_error());
+			mysql_select_db($options['database'],$this->link) or
+			die("Could not select database: " . mysql_error());
+	}
+	
+	public function disconnect($options = array()) {
+		if ($this->link) {
+			mysql_close($this->link);
+		}
+	}
+	
+	public function request($request,$options = array()) {
+		if ($this->link) {
+			
+			// Execute the request and build a response object
+			$raw  = mysql_query($request,$this->link);
+			$data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+			
+			if ('' != ($errMessage = mysql_error($this->link))) {
+				$data->setError($errMessage);
+				return $data;
+			} else {
+			
+				// Handle associative array
+				if (isset($options['format']) && 
+					strtolower($options['format']) == 'assoc') {
+					$idx = 0;
+					while (false !== $row = mysql_fetch_assoc($raw)) {
+						if (isset($options['indexKey'])) {
+							$data->add($raw[$options['indexKey']],$row);
+						} else {
+							$data->add($idx++,$row);
+						}
+					}
+				} 
+				
+				// Handle numeric array
+				else {
+					$idx = 0;
+					while (false !== $row = mysql_fetch_row($raw)) {
+						if (isset($options['indexKey'])) {
+							$data->add($raw[$options['indexKey']],$row);
+						} else {
+							$data->add($idx++,$row);
+						}
+					}
+				}
+				
+				// Store the request used to generate the data
+				$data->setRequestString($request);
+				
+				// Free the request
+				mysql_free_result($raw);
+				
+				// Return the requested data
+				return $data;
+			}
+		} else {
+			$data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+			$data->setError("Unable to establish connection to data source");
+			return $data;
+		}
+	}
+	
+	public function command($command,$options = array()) {
+		if ($this->link) {
+			
+			mysql_query($command);
+			
+		} else {
+			$data = Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+			$data->setError("Unable to establish connection to data source");
+			return $data;
+		}
+	}
+	
+	public function lastInsertedId($options = array()){
+		if ($this->link) {
+			
+			return mysql_insert_id();
+			
+		} else {
+			$data = Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+			$data->setError("Unable to establish connection to data source");
+			return $data;
+		}
+	}
+}

Added: oodt/trunk/balance/lib/pear/Providers/Data/PDODataProvider.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Providers/Data/PDODataProvider.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Providers/Data/PDODataProvider.class.php (added)
+++ oodt/trunk/balance/lib/pear/Providers/Data/PDODataProvider.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,142 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * Implementation of IApplicationDataProvider for PHP PDO.
+ * 
+ * @author s.khudikyan
+ * @author ahart
+ * 
+ */
+class Org_Apache_Oodt_Balance_Providers_Data_PDODataProvider 
+	implements Org_Apache_Oodt_Balance_Interfaces_IApplicationDataProvider {
+	
+	public $link;
+	
+	public function __construct($options = array()) {
+		
+	}
+	
+	public function connect($options = array()) {
+		try {
+			$dsn = 'mysql:host='.$options['server'].';dbname='.$options['database'];
+			$this->link = new PDO( $dsn, $options['username'], $options['password'] );
+		} catch (PDOException $e) {
+			die("There was an error connecting to the database: " . $e->getMessage());
+		}
+	}
+	
+	public function disconnect($options = array()) {
+		if ($this->link) {
+			/*** close the database connection ***/
+    		$this->link = null;
+		}
+	}
+	
+	public function request($request,$options = array() ) {
+		$data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+		
+		if ($this->link) {
+			
+			// Handle associative array
+			if (isset($options['format']) && 
+				strtolower($options['format']) == 'assoc') {
+					
+					try {
+						// fetch into an PDOStatement object
+    					$stmt = $this->link->queryAll($request);
+    					$result = $stmt->fetch(PDO::FETCH_ASSOC);
+					} catch (PDOException $e) {
+						
+						$data->setError( $e->getMessage() );
+						return $data;
+					}
+			}
+
+			// Handle numeric array
+			else {
+					try {	
+						// fetch into an PDOStatement object
+    					$stmt = $this->link->queryAll($request);
+    					$result = $stmt->fetch(PDO::FETCH_NUM);
+					} catch (PDOException $e) {
+						
+						$data->setError( $e->getMessage() );
+						return $data;
+					}
+			}
+				
+			// Store the request used to generate the data
+			$data->bulkAdd($result);
+			
+			// Free the request
+			$this->link->free();
+			
+			// Return the requested data
+			return $data;
+
+		} else {
+			$data->setError("Unable to establish connection to data source");
+			return $data;
+		}
+	}
+	
+	public function command($command,$options = array()) {
+		$data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+		
+		if ($this->link) {
+			
+			try {
+				
+				$result = $this->link->exec( $command );
+			} catch (PDOException $e) {
+				
+				$data->setError( $e->getMessage() );
+				return $data;
+			}
+			
+		} else {
+			$data->setError( "Unable to establish connection to data source" );
+			return $data;
+		}
+	}
+	
+	public function lastInsertedId($options = array()){
+		$data = new Org_Apache_Oodt_Balance_Core_ApplicationDataResponse();
+		
+		if ($this->link) {
+			
+			try {
+				$lastId = $this->link->lastInsertId();				
+			} catch (PDOException $e) {
+				
+				$data->setError( $e->getMessage() );
+				return $data;
+			}
+			return $lastId;
+			
+		} else {
+			$data->setError("Unable to establish connection to data source");
+			return $data;
+		}
+	}
+	
+}

Added: oodt/trunk/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php (added)
+++ oodt/trunk/balance/lib/pear/Providers/Error/DefaultErrorProvider.class.php Mon Jun  6 00:57:40 2011
@@ -0,0 +1,38 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+/**
+ * 
+ * OODT Balance
+ * Web Application Base Framework
+ * 
+ * A very simple default implementation of the IApplicationErrorProvider 
+ * interface that simply looks for a view in HOME/views/common/###.php where
+ * ### matches the provided http code.
+ * 
+ * @author ahart
+ */
+class Org_Apache_Oodt_Balance_Providers_Error_DefaultErrorProvider 
+	implements Org_Apache_Oodt_Balance_Interfaces_IApplicationErrorProvider {
+		
+
+	public function error($httpResponseCode,$message = '',$options = array()) {
+		require(HOME . '/views/error/' . $httpResponseCode . '.php');
+		exit();
+	}
+		
+}

Added: oodt/trunk/balance/lib/pear/README
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/README?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/README (added)
+++ oodt/trunk/balance/lib/pear/README Mon Jun  6 00:57:40 2011
@@ -0,0 +1,34 @@
+OODT Balance - Framework Library
+
+OVERVIEW
+====================
+
+This is the OODT Balance Framework library. It provides a common codebase
+upon which to build PHP web applications utilizing the OODT framework.
+
+More information about the project is available at http://balance.jpl.nasa.gov
+
+INSTALLATION
+====================
+
+The library is provided as a PHP Extension and Application Repository (PEAR)
+package. More information on how to install the PEAR package manager on your
+system can be found at: http://pear.php.net/manual/en/installation.php
+
+Assuming you have the PEAR package manager installed correctly:
+
+1) "cd" into the src/pear directory (you should see a package.xml file)
+2) Build the pear package: 
+   $ pear package
+3) Install the resulting tarball:
+   $ (sudo) pear install --force Org_Apache_Oodt_Balance_...tgz
+
+
+USAGE
+=====================
+
+This library forms a codebase upon which applications can be developed. It is a
+prerequisite for Balance application development, but can do nothing on its own.
+For information on creating and developing applications that target this library,
+visit http://balance.jpl.nasa.gov/
+

Added: oodt/trunk/balance/lib/pear/package.xml
URL: http://svn.apache.org/viewvc/oodt/trunk/balance/lib/pear/package.xml?rev=1132509&view=auto
==============================================================================
--- oodt/trunk/balance/lib/pear/package.xml (added)
+++ oodt/trunk/balance/lib/pear/package.xml Mon Jun  6 00:57:40 2011
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_Apache_Oodt_Balance
+   @author Andrew F. Hart
+   @version $Id$
+-->
+<package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0"
+  xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0.xsd
+         http://pear.php.net/dtd/package-2.0
+         http://pear.php.net/dtd/package-2.0.xsd">
+  <name>Org_Apache_Oodt_Balance</name>
+  <uri>http://balance.jpl.nasa.gov</uri>
+  <!-- <channel/>-->
+  <summary>OODT Balance Webapp Base Package</summary>
+  <description>
+    This package provides the OODT Balance webapp-base package required
+    by all Balance-based web applications.
+  </description>
+  <lead>
+    <name>Andrew Hart</name>
+    <user>ahart</user>
+    <email>ahart@apache.org</email>
+    <active>yes</active>
+  </lead>
+  <date>2011-04-23</date>
+  <version>
+    <release>0.3.0</release>
+    <api>0.3.0</api>
+  </version>
+  <stability>
+    <release>beta</release>
+    <api>beta</api>
+  </stability>
+  <license uri="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0 License</license>
+  <notes>
+    This package provides the OODT Balance webapp-base package required
+    by all Balance-based web applications.
+  </notes>
+  <contents>
+    <dir name="/" baseinstalldir="Org/Apache/Oodt/Balance">
+      <dir name="Boot">
+        <file name="bootstrap.php" role="php"/>
+      </dir>
+      <dir name="Core">
+		<file name="Application.class.php" role="php"/>
+        <file name="ApplicationDataResponse.class.php" role="php"/>
+		<file name="ApplicationRequest.class.php" role="php"/>
+		<file name="ApplicationResponse.class.php" role="php"/>
+      </dir>
+      <dir name="Interfaces">
+        <file name="IApplicationAuthenticationProvider.php" role="php"/>
+        <file name="IApplicationAuthorizationProvider.php"  role="php"/>
+        <file name="IApplicationDataProvider.php" role="php"/>
+        <file name="IApplicationErrorProvider.php" role="php"/>
+        <file name="IApplicationWidget.php" role="php"/>
+      </dir>
+      <dir name="Providers">
+        <dir name="Auth">
+          <file name="LDAPAuthenticationProvider.class.php" role="php"/>
+        </dir>
+        <dir name="Authorization">
+          <file name="LDAPAuthorizationProvider.class.php" role="php"/>
+        </dir>
+        <dir name="Data">
+          <file name="MySqlDataProvider.class.php" role="php"/>
+        </dir>    
+        <dir name="Error">
+          <file name="DefaultErrorProvider.class.php" role="php"/>
+        </dir> 
+      </dir>
+    </dir><!-- / -->
+  </contents>
+  <dependencies>
+    <required>
+      <php>
+        <min>5.1.6</min>
+      </php>
+      <pearinstaller>
+        <min>1.6.1</min>
+      </pearinstaller>
+    </required>
+  </dependencies>
+  <phprelease />
+  <changelog>
+    <release>
+      <version>
+        <release>0.2.0</release>
+        <api>0.2.0</api>
+      </version>
+      <stability>
+        <release>stable</release>
+        <api>stable</api>
+      </stability>
+      <date>2011-02-03</date>
+      <license uri="http://oodt.jpl.nasa.gov">OODT License</license>
+      <notes>
+      Improvements to the core library to support more flexible use
+      of modules and greater reusability.
+      </notes>     
+    </release>
+    <release>
+      <version>
+        <release>0.1.0</release>
+        <api>0.1.0</api>
+      </version>
+      <stability>
+        <release>stable</release>
+        <api>stable</api>
+      </stability>
+      <date>2010-11-01</date>
+      <license uri="http://oodt.jpl.nasa.gov">OODT License</license>
+      <notes>
+      This release marks the first release of the OODT Balance webapp-base package.
+      </notes>     
+    </release>
+  </changelog>
+</package>