3 * This file is (c) Copyright 2010 by Sabri LABBENE, Institut TELECOM
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 require_once('HTTP.php');
20 $exceptions_dir = dirname( dirname( __FILE__ )) . DIRECTORY_SEPARATOR. 'exceptions'. DIRECTORY_SEPARATOR;
21 require_once($exceptions_dir . 'oslcException.php');
27 class CompactController extends Zend_Rest_Controller {
29 private static $supportedAcceptMimeTypes = array(
31 'application/x-oslc-compact+xml' => 'xml'
33 'oslccompactuser' => array(
34 'application/x-oslc-compact+xml' => 'xml'
36 'oslccompactusersmall' => array(
37 'application/x-oslc-compact+xml' => 'xml'
41 private $rest_controller;
44 * Initilizes the Zend REST controler
46 public function init() {
47 $controller_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
48 require_once($controller_dir . 'FusionForgeCompactController.php');
51 public function getSupportedAcceptMimeTypes(){
52 return self::$supportedAcceptMimeTypes;
55 public function checkSupportedActionMimeType($mime_types, $action) {
56 $req = $this->getRequest();
58 // check Accept header's mime type
59 $accept = $req->getHeader('Accept');
61 // prepare an array of accepted types
62 $accepted_types = array();
63 if(isset($mime_types[$action])) {
64 $accepted_types = array_keys($mime_types[$action]);
66 // make sure text/html is always an option (in last option)
67 $accepted_types[]='text/html';
69 // If we can't directly find the accept header, then, have to negociate maybe among alternatives
70 if(!isset($mime_types[$action][$accept])) {
71 // use PEAR's HTTP::negotiateMimeType to identify the preferred content-type
72 //$accept = HTTP::negotiateMimeType($accepted_types,'');
74 $content_type = $http->negotiateMimeType($accepted_types,'');
76 // perfect, just found it directly (note that the 'get' action needs all of them)
77 $content_type = $accept;
79 //print($content_type); die();
80 if (!isset($content_type)) {
81 // unsupported accept type
82 throw new NotAcceptableForCRCollectionException("Accept header '".$req->getHeader('Accept')."' not supported for action .'".$action."' !");
88 public function getAction(){
89 switch (TRACKER_TYPE) {
91 $this->_forward('get', 'fusionforgecompact');
98 public function putAction() {
102 public function postAction() {
106 public function deleteAction() {
110 public function indexAction() {