]> git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/SimpleNodeContentProvider.java
Update license headers
[lgpl/argeo-commons.git] / base / runtime / org.argeo.eclipse.ui.jcr / src / main / java / org / argeo / eclipse / ui / jcr / SimpleNodeContentProvider.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.eclipse.ui.jcr;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
21
22 import javax.jcr.Node;
23 import javax.jcr.RepositoryException;
24 import javax.jcr.Session;
25
26 import org.argeo.ArgeoException;
27 import org.argeo.jcr.JcrUtils;
28
29 /** Simple JCR node content provider taking a list of String as base path. */
30 public class SimpleNodeContentProvider extends AbstractNodeContentProvider {
31 private final List<String> basePaths;
32 private Boolean mkdirs = false;
33
34 public SimpleNodeContentProvider(Session session, String... basePaths) {
35 this(session, Arrays.asList(basePaths));
36 }
37
38 public SimpleNodeContentProvider(Session session, List<String> basePaths) {
39 super(session);
40 this.basePaths = basePaths;
41 }
42
43 @Override
44 protected Boolean isBasePath(String path) {
45 if (basePaths.contains(path))
46 return true;
47 return super.isBasePath(path);
48 }
49
50 public Object[] getElements(Object inputElement) {
51 try {
52 List<Node> baseNodes = new ArrayList<Node>();
53 for (String basePath : basePaths)
54 if (mkdirs && !getSession().itemExists(basePath))
55 baseNodes.add(JcrUtils.mkdirs(getSession(), basePath));
56 else
57 baseNodes.add(getSession().getNode(basePath));
58 return baseNodes.toArray();
59 } catch (RepositoryException e) {
60 throw new ArgeoException("Cannot get base nodes for " + basePaths,
61 e);
62 }
63 }
64
65 public List<String> getBasePaths() {
66 return basePaths;
67 }
68
69 public void setMkdirs(Boolean mkdirs) {
70 this.mkdirs = mkdirs;
71 }
72
73 }