V1.3 to HEAD (3005, 3014, 3021, 3027, 3045, 3064, 3105, 3106)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3162 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-06-20 11:13:29 +00:00
parent 5431702cf3
commit 71f57ee6c7
18 changed files with 344 additions and 208 deletions

View File

@@ -17,6 +17,8 @@
package org.alfresco.service.cmr.repository;
import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -27,9 +29,9 @@ import org.alfresco.error.AlfrescoRuntimeException;
*/
public final class NodeRef implements EntityRef, Serializable
{
private static final long serialVersionUID = 3760844584074227768L;
private static final String URI_FILLER = "/";
private static final Pattern nodeRefPattern = Pattern.compile(".+://.+/.+");
private final StoreRef storeRef;
private final String id;
@@ -44,8 +46,7 @@ public final class NodeRef implements EntityRef, Serializable
{
if (storeRef == null)
{
throw new IllegalArgumentException(
"Store reference may not be null");
throw new IllegalArgumentException("Store reference may not be null");
}
if (id == null)
{
@@ -128,6 +129,18 @@ public final class NodeRef implements EntityRef, Serializable
return id;
}
/**
* Determine if passed string conforms to the pattern of a node reference
*
* @param nodeRef the node reference as a string
* @return true => it matches the pattern of a node reference
*/
public static boolean isNodeRef(String nodeRef)
{
Matcher matcher = nodeRefPattern.matcher(nodeRef);
return matcher.matches();
}
/**
* Helper class to convey the status of a <b>node</b>.
*

View File

@@ -50,4 +50,13 @@ public class NodeRefTest extends TestCase
NodeRef nodeRef2 = new NodeRef(storeRef, "456");
assertEquals("equals failure", nodeRef, nodeRef2);
}
public void testNodeRefPattern() throws Exception
{
StoreRef storeRef = new StoreRef("ABC", "123");
NodeRef nodeRef = new NodeRef(storeRef, "456");
assertTrue(NodeRef.isNodeRef(nodeRef.toString()));
assertFalse(NodeRef.isNodeRef("sdfsdf:sdfsdf"));
}
}