Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/alfresco/Service/NamespaceMap.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  * Copyright (C) 2005 Alfresco, Inc.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 
00019  * As a special exception to the terms and conditions of version 2.0 of 
00020  * the GPL, you may redistribute this Program in connection with Free/Libre 
00021  * and Open Source Software ("FLOSS") applications as described in Alfresco's 
00022  * FLOSS exception.  You should have recieved a copy of the text describing 
00023  * the FLOSS exception, and it is also available here: 
00024  * http://www.alfresco.com/legal/licensing"
00025  */
00026 
00027 class NamespaceMap
00028 {
00029         const DELIMITER = "_";
00030         
00031         private $namespaceMap = array(
00032                 "d" => "http://www.alfresco.org/model/dictionary/1.0",
00033                 "sys" => "http://www.alfresco.org/model/system/1.0",
00034                 "cm" => "http://www.alfresco.org/model/content/1.0",
00035                 "app" => "http://www.alfresco.org/model/application/1.0",
00036                 "bpm" => "http://www.alfresco.org/model/bpm/1.0",
00037                 "wf" => "http://www.alfresco.org/model/workflow/1.0",
00038                 "fm" => "http://www.alfresco.org/model/forum/1.0",
00039                 "view" => "http://www.alfresco.org/view/repository/1.0",
00040                 "security" => "http://www.alfresco.org/model/security/1.0",
00041                 "wcm" => "http://www.alfresco.org/model/wcmmodel/1.0",
00042                 "wca" => "http://www.alfresco.org/model/wcmappmodel/1.0");
00043         
00044         public function isShortName($shortName)
00045         {
00046                 return ($shortName != $this->getFullName($shortName));
00047         }
00048                 
00049         public function getFullName($shortName)
00050         {
00051                 $result = $shortName;
00052                 
00053                 $index = strpos($shortName, NamespaceMap::DELIMITER);
00054                 if ($index !== false)
00055                 {
00056                         $prefix = substr($shortName, 0, $index);
00057                                                 
00058                         if (isset($this->namespaceMap[$prefix]) == true)        
00059                         {
00060                                 $url = $this->namespaceMap[$prefix];
00061                                 $name = substr($shortName, $index+1);
00062                                 $name = str_replace("_", "-", $name);
00063                                 if ($name != null && strlen($name) != 0)
00064                                 {
00065                                         $result = "{".$url."}".$name;
00066                                 }
00067                         }
00068                 }
00069                 
00070                 return $result;
00071         }
00072         
00073         public function getFullNames($fullNames)
00074         {
00075                 $result = array();
00076                 
00077                 foreach ($fullNames as $fullName)
00078                 {
00079                         $result[] = $this->getFullName($fullName);                      
00080                 }               
00081                 return $result;
00082         }
00083         
00084         public function getShortName($fullName)
00085         {
00086                 $result = $fullName;
00087                 
00088                 $index = strpos($fullName, "}");
00089                 if ($index !== false)
00090                 {
00091                         $url = substr($fullName, 1, $index-1);
00092                         $prefix = $this->lookupPrefix($url);
00093                         if ($prefix != null)
00094                         {
00095                                 $name = substr($fullName, $index+1);
00096                                 if ($name != null && strlen($name) != 0)
00097                                 {                                       
00098                                         $name = str_replace("-", "_", $name);                   
00099                                         $result = $prefix.NamespaceMap::DELIMITER.$name;
00100                                 }
00101                         }
00102                 }
00103                 
00104                 return $result; 
00105         }
00106         
00107         private function lookupPrefix($value)
00108         {
00109                 $result = null;
00110                 foreach($this->namespaceMap as $prefix => $url)
00111                 {
00112                         if ($url == $value)
00113                         {
00114                                 $result = $prefix;
00115                         }
00116                 }
00117                 return $result;
00118         } 
00119 }
00120 
00121 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations