This project has retired. For details please refer to its
Attic page.
JcrVersion xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */1920package org.apache.chemistry.opencmis.jcr;
2122import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
2324import javax.jcr.Node;
25import javax.jcr.RepositoryException;
26import javax.jcr.version.Version;
27import java.util.regex.Matcher;
28import java.util.regex.Pattern;
2930/**31 * Instances of this class represent a specific version of a cmis:document backed by an underlying32 * JCR <code>Node</code>.33 */34publicclassJcrVersionextendsJcrVersionBase {
35privatestaticfinal Pattern VERSION_LABEL_PATTERN = Pattern.compile("(\\d+)(\\.(\\d+))?.*");
36privatestaticfinalint GROUP_MAJOR = 1;
37privatestaticfinalint GROUP_MINOR = 3;
3839privatefinal Version version;
4041publicJcrVersion(Node node, Version version, JcrTypeManager typeManager, PathManager pathManager,
42JcrTypeHandlerManager typeHandlerManager) {
4344super(node, typeManager, pathManager, typeHandlerManager);
45this.version = version;
46 }
4748//------------------------------------------< protected >---4950 @Override
51protected Node getContextNode() throws RepositoryException {
52 Node frozen = version.getFrozenNode();
53if (frozen.hasNode(Node.JCR_CONTENT)) {
54return frozen.getNode(Node.JCR_CONTENT);
55 }
56else {
57return getNode().getNode(Node.JCR_CONTENT); // root version58 }
59 }
6061 @Override
62protected String getObjectId() throws RepositoryException {
63return getVersionSeriesId() + '/' + version.getName();
64 }
6566 @Override
67protectedboolean isLatestVersion() throws RepositoryException {
68 Version baseVersion = getBaseVersion(getNode());
69return baseVersion.isSame(version);
70 }
7172 @Override
73protectedboolean isMajorVersion() {
74returntrue;
75 }
7677 @Override
78protectedboolean isLatestMajorVersion() throws RepositoryException {
79return isLatestVersion();
80 }
8182 @Override
83protected String getVersionLabel() throws RepositoryException {
84 String name = version.getName();
85 String major = parseVersion(name, GROUP_MINOR);
8687return major == null88 ? name
89 : (Integer.parseInt(major) + 1) + ".0";
90 }
9192 @Override
93protected String getCheckInComment() throws RepositoryException {
94// todo set checkinComment95return"";
96 }
9798//------------------------------------------< private >---99100privatestatic String parseVersion(String name, int group) {
101 Matcher matcher = VERSION_LABEL_PATTERN.matcher(name);
102return matcher.matches()
103 ? matcher.group(group)
104 : null;
105 }
106107108 }