2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.eclipse
.ui
.jcr
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.List
;
22 import javax
.jcr
.Node
;
23 import javax
.jcr
.RepositoryException
;
24 import javax
.jcr
.Session
;
26 import org
.argeo
.ArgeoException
;
27 import org
.argeo
.jcr
.JcrUtils
;
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;
34 public SimpleNodeContentProvider(Session session
, String
... basePaths
) {
35 this(session
, Arrays
.asList(basePaths
));
38 public SimpleNodeContentProvider(Session session
, List
<String
> basePaths
) {
40 this.basePaths
= basePaths
;
44 protected Boolean
isBasePath(String path
) {
45 if (basePaths
.contains(path
))
47 return super.isBasePath(path
);
50 public Object
[] getElements(Object inputElement
) {
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
));
57 baseNodes
.add(getSession().getNode(basePath
));
58 return baseNodes
.toArray();
59 } catch (RepositoryException e
) {
60 throw new ArgeoException("Cannot get base nodes for " + basePaths
,
65 public List
<String
> getBasePaths() {
69 public void setMkdirs(Boolean mkdirs
) {