PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/drupal/profile/neurohub_modules_contrib/alfresco/lib/Alfresco/Service/NamespaceMap.php

https://bitbucket.org/drn05r/neurohub-dev-davidn
PHP | 175 lines | 121 code | 14 blank | 40 comment | 20 complexity | bcd226b08825c97479af7804f13d3936 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /*
  3. * Copyright (C) 2005 Alfresco, Inc.
  4. *
  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.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * As a special exception to the terms and conditions of version 2.0 of
  17. * the GPL, you may redistribute this Program in connection with Free/Libre
  18. * and Open Source Software ("FLOSS") applications as described in Alfresco's
  19. * FLOSS exception. You should have recieved a copy of the text describing
  20. * the FLOSS exception, and it is also available here:
  21. * http://www.alfresco.com/legal/licensing"
  22. */
  23. class AlfNamespaceMap {
  24. const DELIMITER = "_";
  25. /**
  26. * Singleton instance.
  27. */
  28. private static $smInstance = NULL;
  29. private $_namespaceMap = array(
  30. "d" => "http://www.alfresco.org/model/dictionary/1.0",
  31. "sys" => "http://www.alfresco.org/model/system/1.0",
  32. "cm" => "http://www.alfresco.org/model/content/1.0",
  33. "app" => "http://www.alfresco.org/model/application/1.0",
  34. "bpm" => "http://www.alfresco.org/model/bpm/1.0",
  35. "wf" => "http://www.alfresco.org/model/workflow/1.0",
  36. "fm" => "http://www.alfresco.org/model/forum/1.0",
  37. "view" => "http://www.alfresco.org/view/repository/1.0",
  38. "security" => "http://www.alfresco.org/model/security/1.0",
  39. "wcm" => "http://www.alfresco.org/model/wcmmodel/1.0",
  40. "wca" => "http://www.alfresco.org/model/wcmappmodel/1.0",
  41. "ia" => "http://www.alfresco.org/model/calendar",
  42. "lnk" => "http://www.alfresco.org/model/linksmodel/1.0",
  43. "imap" => "http://www.alfresco.org/model/imap/1.0",
  44. "inwf" => "http://www.alfresco.org/model/workflow/invite/nominated/1.0",
  45. "imwf" => "http://www.alfresco.org/model/workflow/invite/moderated/1.0",
  46. "wcmwf" => "http://www.alfresco.org/model/wcmworkflow/1.0",
  47. "act" => "http://www.alfresco.org/model/action/1.0",
  48. "ver" => "http://www.alfresco.org/model/versionstore/1.0",
  49. "ver2" => "http://www.alfresco.org/model/versionstore/2.0",
  50. "st" => "http://www.alfresco.org/model/site/1.0",
  51. "nt" => "http://www.jcp.org/jcr/nt/1.0",
  52. "jcr" => "http://www.jcp.org/jcr/1.0",
  53. "mix" => "http://www.jcp.org/jcr/mix/1.0",
  54. "sv" => "http://www.jcp.org/jcr/sv/1.0",
  55. "usr" => "http://www.alfresco.org/model/user/1.0",
  56. "rule" => "http://www.alfresco.org/model/rule/1.0",
  57. );
  58. /**
  59. * Constructor private to enforce singleton pattern
  60. */
  61. private function __construct() {
  62. }
  63. /**
  64. * Boilerplate singleton instantiation...
  65. */
  66. public static function getInstance() {
  67. if (is_null(self::$smInstance)) {
  68. self::$smInstance = new AlfNamespaceMap();
  69. }
  70. return self::$smInstance;
  71. }
  72. public function isShortName($shortName) {
  73. return ($shortName != $this->getFullName($shortName));
  74. }
  75. public function getFullName($shortName) {
  76. $result = $shortName;
  77. $index = strpos($shortName, AlfNamespaceMap::DELIMITER);
  78. if ($index !== false) {
  79. $prefix = substr($shortName, 0, $index);
  80. if (isset($this->_namespaceMap[$prefix]) == true) {
  81. $url = $this->_namespaceMap[$prefix];
  82. $name = substr($shortName, $index + 1);
  83. $name = str_replace("_", "-", $name);
  84. if ($name != null && strlen($name) != 0) {
  85. $result = "{" . $url . "}" . $name;
  86. }
  87. }
  88. }
  89. return $result;
  90. }
  91. public function getFullNames($fullNames) {
  92. $result = array();
  93. foreach($fullNames as $fullName) {
  94. $result[] = $this->getFullName($fullName);
  95. }
  96. return $result;
  97. }
  98. public function getShortName($fullName, $delimiter = AlfNamespaceMap::DELIMITER) {
  99. $result = $fullName;
  100. $index = strpos($fullName, "}");
  101. if ($index !== false) {
  102. $url = substr($fullName, 1, $index - 1);
  103. $prefix = $this->lookupPrefix($url);
  104. if ($prefix != null) {
  105. $name = substr($fullName, $index + 1);
  106. if ($name != null && strlen($name) != 0) {
  107. $name = str_replace("-", "_", $name);
  108. $result = $prefix . $delimiter . $name;
  109. }
  110. }
  111. }
  112. return $result;
  113. }
  114. private function lookupPrefix($value) {
  115. $result = null;
  116. foreach($this->_namespaceMap as $prefix => $url) {
  117. if ($url == $value) {
  118. $result = $prefix;
  119. break;
  120. }
  121. }
  122. return $result;
  123. }
  124. /**
  125. * aw@abcona.de 2009-10-30: Provide facility to load additional
  126. * namespace mappings
  127. */
  128. public function loadNamespaces($aPathOrFile, $merge = TRUE) {
  129. $filesToLoad = array();
  130. if (is_file($aPathOrFile)) {
  131. $filesToLoad[] = $aPathOrFile;
  132. } elseif (is_dir($aPathOrFile)) {
  133. $filesToLoad = glob($aPathOrFile . DIRECTORY_SEPARATOR . "*.php");
  134. }
  135. // wipe namespace map if merge not wanted
  136. if (!$merge) {
  137. $this->_namespaceMap = array();
  138. }
  139. $namespaceMap = $this->_namespaceMap;
  140. foreach($filesToLoad as $f) {
  141. // Each required file should work on $namespaceMap
  142. require ($f);
  143. }
  144. $this->_namespaceMap = $namespaceMap;
  145. // Return number of included files (in case anyone is interested in that
  146. return sizeof($filesToLoad);
  147. }
  148. public function getMapCount() {
  149. return sizeof($this->_namespaceMap);
  150. }
  151. public function getMappings() {
  152. $result = array();
  153. foreach($this->_namespaceMap as $key => $value) {
  154. $result[$key] = $value;
  155. }
  156. return $result;
  157. }
  158. }