[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/alfresco/Service/ -> NamespaceMap.php (source)

   1  <?php
   2  /*

   3   * Copyright (C) 2005-2010 Alfresco Software Limited.

   4   *

   5   * This file is part of Alfresco

   6   *

   7   * Alfresco is free software: you can redistribute it and/or modify

   8   * it under the terms of the GNU Lesser General Public License as published by

   9   * the Free Software Foundation, either version 3 of the License, or

  10   * (at your option) any later version.

  11   *

  12   * Alfresco is distributed in the hope that it will be useful,

  13   * but WITHOUT ANY WARRANTY; without even the implied warranty of

  14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

  15   * GNU Lesser General Public License for more details.

  16   *

  17   * You should have received a copy of the GNU Lesser General Public License

  18   * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.

  19   */
  20  
  21  class NamespaceMap
  22  {
  23      const DELIMITER = "_";
  24      
  25      private $namespaceMap = array(
  26          "d" => "http://www.alfresco.org/model/dictionary/1.0",
  27          "sys" => "http://www.alfresco.org/model/system/1.0",
  28          "cm" => "http://www.alfresco.org/model/content/1.0",
  29          "app" => "http://www.alfresco.org/model/application/1.0",
  30          "bpm" => "http://www.alfresco.org/model/bpm/1.0",
  31          "wf" => "http://www.alfresco.org/model/workflow/1.0",
  32          "fm" => "http://www.alfresco.org/model/forum/1.0",
  33          "view" => "http://www.alfresco.org/view/repository/1.0",
  34          "security" => "http://www.alfresco.org/model/security/1.0",
  35          "wcm" => "http://www.alfresco.org/model/wcmmodel/1.0",
  36          "wca" => "http://www.alfresco.org/model/wcmappmodel/1.0");
  37      
  38  	public function isShortName($shortName)
  39      {
  40          return ($shortName != $this->getFullName($shortName));
  41      }
  42          
  43  	public function getFullName($shortName)
  44      {
  45          $result = $shortName;
  46          
  47          $index = strpos($shortName, NamespaceMap::DELIMITER);
  48          if ($index !== false)
  49          {
  50              $prefix = substr($shortName, 0, $index);
  51                          
  52              if (isset($this->namespaceMap[$prefix]) == true)    
  53              {
  54                  $url = $this->namespaceMap[$prefix];
  55                  $name = substr($shortName, $index+1);
  56                  $name = str_replace("_", "-", $name);
  57                  if ($name != null && strlen($name) != 0)
  58                  {
  59                      $result = "{".$url."}".$name;
  60                  }
  61              }
  62          }
  63          
  64          return $result;
  65      }
  66      
  67  	public function getFullNames($fullNames)
  68      {
  69          $result = array();
  70          
  71          foreach ($fullNames as $fullName)
  72          {
  73              $result[] = $this->getFullName($fullName);            
  74          }        
  75          return $result;
  76      }
  77      
  78  	public function getShortName($fullName)
  79      {
  80          $result = $fullName;
  81          
  82          $index = strpos($fullName, "}");
  83          if ($index !== false)
  84          {
  85              $url = substr($fullName, 1, $index-1);
  86              $prefix = $this->lookupPrefix($url);
  87              if ($prefix != null)
  88              {
  89                  $name = substr($fullName, $index+1);
  90                  if ($name != null && strlen($name) != 0)
  91                  {                    
  92                      $name = str_replace("-", "_", $name);            
  93                      $result = $prefix.NamespaceMap::DELIMITER.$name;
  94                  }
  95              }
  96          }
  97          
  98          return $result;    
  99      }
 100      
 101  	private function lookupPrefix($value)
 102      {
 103          $result = null;
 104          foreach($this->namespaceMap as $prefix => $url)
 105          {
 106              if ($url == $value)
 107              {
 108                  $result = $prefix;
 109              }
 110          }
 111          return $result;
 112      } 
 113  }
 114  
 115  ?>


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1