Skip to content

Commit

Permalink
implementing session namespace operations, except for remapping names…
Browse files Browse the repository at this point in the history
…paces inside session
  • Loading branch information
dbu committed May 26, 2011
1 parent c4e96d1 commit d92b3a6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 72 deletions.
2 changes: 1 addition & 1 deletion api-test/suite
57 changes: 0 additions & 57 deletions src/Jackalope/NamespaceManager.php

This file was deleted.

38 changes: 28 additions & 10 deletions src/Jackalope/NamespaceRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ class NamespaceRegistry implements \IteratorAggregate, \PHPCR\NamespaceRegistryI
*/
protected $userNamespaces = array();

/**
* Instance of the NamespaceManager
*
* @var NamespaceManager
*/
protected $namespaceManager = null;

/**
* Initializes the created object.
*
Expand All @@ -53,7 +46,6 @@ public function __construct($factory, TransportInterface $transport)
{
$this->factory = $factory;
$this->transport = $transport;
$this->namespaceManager = $this->factory->get('NamespaceManager', array($this->defaultNamespaces));

$namespaces = $transport->getNamespaces();
foreach ($namespaces as $prefix => $uri) {
Expand Down Expand Up @@ -99,7 +91,7 @@ public function registerNamespace($prefix, $uri)
throw new NotImplementedException('Write');

// prevent default namespace to be overridden.
$this->namespaceManager->checkPrefix($prefix);
$this->checkPrefix($prefix);

// update local info
$this->userNamespaces[$prefix] = $uri;
Expand Down Expand Up @@ -202,7 +194,7 @@ public function registerNamespace($prefix, $uri)
*/
public function unregisterNamespace($prefix)
{
$this->namespaceManager->checkPrefix($prefix);
$this->checkPrefix($prefix);
if (! array_key_exists($prefix, $this->userNamespaces)) {
//defaultNamespaces would throw an exception in checkPrefix already
throw new \PHPCR\NamespaceException("Prefix $prefix is not currently registered");
Expand Down Expand Up @@ -296,4 +288,30 @@ public function getIterator()
{
return new \ArrayIterator(array_merge($this->defaultNamespaces, $this->userNamespaces));
}

/**
* Verifies whether this is a valid prefix
*
*
* Throws the \PHPCR\NamespaceException if trying to use one of the
* built-in prefixes or a prefix that begins with the characters "xml"
* (in any combination of case)
*
*
* @return void
*
* @throws \PHPCR\NamespaceException if re-assign built-in prefix or prefix starting with xml
*/
public function checkPrefix($prefix)
{
if (! strncasecmp('xml', $prefix, 3)) {
throw new \PHPCR\NamespaceException("Do not use xml in prefixes for namespace changes: '$prefix'");
}
if (array_key_exists($prefix, $this->defaultNamespaces)) {
throw new \PHPCR\NamespaceException("Do not change the predefined prefixes: '$prefix'");
}
if (false !== strpos($prefix, ' ') || false !== strpos($prefix, ':')) {
throw new \PHPCR\NamespaceException("Not a valid namespace prefix '$prefix'");
}
}
}
2 changes: 2 additions & 0 deletions src/Jackalope/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,8 @@ public function clear()
* Implementation specific: Transport is used elsewhere, provide it here for Session
*
* @return TransportInterface
*
* @private
*/
public function getTransport()
{
Expand Down
29 changes: 25 additions & 4 deletions src/Jackalope/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ class Session implements \PHPCR\SessionInterface
protected $objectManager;
protected $credentials;
protected $logout = false;
/**
* The namespace registry.
*
* It is only used to check prefixes and at setup.
* Session remapping must be handled locally.
*/
protected $namespaceRegistry;

/**
* List of local namespaces
*
* TODO: implement local namespace rewriting
* see jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java and friends
* for how this is done in jackrabbit
*/
//protected $localNamespaces;

/** creates the corresponding workspace */
public function __construct($factory, Repository $repository, $workspaceName, \PHPCR\SimpleCredentials $credentials, TransportInterface $transport)
Expand All @@ -37,6 +53,7 @@ public function __construct($factory, Repository $repository, $workspaceName, \P
$this->objectManager = $this->factory->get('ObjectManager', array($transport, $this));
$this->workspace = $this->factory->get('Workspace', array($this, $this->objectManager, $workspaceName));
$this->credentials = $credentials;
$this->namespaceRegistry = $this->workspace->getNamespaceRegistry();
}

/**
Expand Down Expand Up @@ -634,7 +651,8 @@ public function exportDocumentView($absPath, $out, $skipBinary, $noRecurse)
*/
public function setNamespacePrefix($prefix, $uri)
{
throw new NotImplementedException();
$this->namespaceRegistry->checkPrefix($prefix);
throw new NotImplementedException('TODO: implement session scope remapping of namespaces'); //this will lead to rewrite all names and paths in requests and replies
}

/**
Expand All @@ -646,7 +664,8 @@ public function setNamespacePrefix($prefix, $uri)
*/
public function getNamespacePrefixes()
{
throw new NotImplementedException();
//TODO: once setNamespacePrefix is implemented, must take session remaps into account
return $this->namespaceRegistry->getPrefixes();
}

/**
Expand All @@ -661,7 +680,8 @@ public function getNamespacePrefixes()
*/
public function getNamespaceURI($prefix)
{
throw new NotImplementedException();
//TODO: once setNamespacePrefix is implemented, must take session remaps into account
return $this->namespaceRegistry->getURI($prefix);
}

/**
Expand All @@ -676,7 +696,8 @@ public function getNamespaceURI($prefix)
*/
public function getNamespacePrefix($uri)
{
throw new NotImplementedException();
//TODO: once setNamespacePrefix is implemented, must take session remaps into account
return $this->namespaceRegistry->getPrefix($uri);
}

/**
Expand Down

0 comments on commit d92b3a6

Please sign in to comment.