View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
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   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.wcm.core;
18  
19  import javax.jcr.Node;
20  import javax.jcr.RepositoryException;
21  import javax.jcr.Session;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.exoplatform.services.jcr.core.ManageableRepository;
25  
26  /*
27   * Created by The eXo Platform SAS
28   * @author : Hoa.Pham
29   *          hoa.pham@exoplatform.com
30   * Jun 23, 2008
31   */
32  public class NodeIdentifier {
33  
34    private String repository;
35    private String workspace;
36    private String uuid;
37  
38    public NodeIdentifier(final String repository, final String workspace, final String uuid) {
39      this.repository = repository;
40      this.workspace = workspace;
41      this.uuid = uuid;
42    }
43  
44    public String getRepository() { return repository; }
45    public void setRepository(final String repository) { this.repository = repository; }
46  
47    public String getWorkspace() { return workspace; }
48    public void setWorkspace(final String workspace) { this.workspace = workspace; }
49  
50    public String getUUID() {  return uuid; }
51    public void setUUID(final String uuid) {  this.uuid = uuid; }
52  
53    public final static NodeIdentifier parse(final String expr) {
54      String[] temp = expr.split("::");
55      if (temp.length == 3 && StringUtils.isNumeric(temp[2])) {
56        return new NodeIdentifier(temp[0], temp[1], temp[2]);
57      }
58      return null;
59    }
60  
61    public final static NodeIdentifier make(final Node node) throws RepositoryException {
62      Session session = node.getSession();
63      String repository = ((ManageableRepository)session.getRepository()).getConfiguration().getName();
64      String workspace = session.getWorkspace().getName();
65      String uuid = node.getUUID();
66      return new NodeIdentifier(repository, workspace, uuid);
67    }
68  
69    public final static String serialize(final NodeIdentifier identifier) {
70      StringBuffer buffer = new StringBuffer();
71      buffer.append(identifier.getRepository()).append("::")
72      .append(identifier.getWorkspace()).append("::")
73      .append(identifier.getUUID());
74      return buffer.toString();
75    }
76  }