KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > jcr > api > JCRNodeRef


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.jcr.api;
18
19 import javax.jcr.Node;
20 import javax.jcr.Property;
21 import javax.jcr.RepositoryException;
22
23 import org.alfresco.model.ContentModel;
24 import org.alfresco.service.cmr.repository.NodeRef;
25 import org.alfresco.service.cmr.repository.StoreRef;
26 import org.alfresco.service.namespace.NamespaceService;
27 import org.alfresco.util.ParameterCheck;
28
29
30 /**
31  * Helper to retrieve an Alfresco Node Reference from a JCR Node
32  *
33  * @author David Caruana
34  */

35 public class JCRNodeRef
36 {
37
38     /**
39      * Gets the Node Reference for the specified Node
40      *
41      * @param node JCR Node
42      * @return Alfresco Node Reference
43      * @throws RepositoryException
44      */

45     public static NodeRef getNodeRef(Node node)
46         throws RepositoryException
47     {
48         ParameterCheck.mandatory("Node", node);
49
50         Property protocol = node.getProperty(NamespaceService.SYSTEM_MODEL_PREFIX + ":" + ContentModel.PROP_STORE_PROTOCOL.getLocalName());
51         Property identifier = node.getProperty(NamespaceService.SYSTEM_MODEL_PREFIX + ":" + ContentModel.PROP_STORE_IDENTIFIER.getLocalName());
52         Property uuid = node.getProperty(NamespaceService.SYSTEM_MODEL_PREFIX + ":" + ContentModel.PROP_NODE_UUID.getLocalName());
53         
54         return new NodeRef(new StoreRef(protocol.getString(), identifier.getString()), uuid.getString());
55     }
56     
57     
58 }
59
Popular Tags