1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.index.tree.internal.nestedpages

File AbstractDocumentTreeNode.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

8
26
8
1
123
80
18
0.69
3.25
8
2.25

Classes

Class Line # Actions
AbstractDocumentTreeNode 39 26 0% 18 17
0.595238159.5%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.index.tree.internal.nestedpages;
21   
22    import java.util.Collections;
23    import java.util.List;
24   
25    import org.apache.commons.lang3.StringUtils;
26    import org.apache.commons.lang3.exception.ExceptionUtils;
27    import org.xwiki.index.tree.internal.AbstractEntityTreeNode;
28    import org.xwiki.model.EntityType;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.EntityReference;
31   
32    /**
33    * Base class for document tree nodes.
34    *
35    * @version $Id: 9b288ddd2a68509adb5b9a4d81c817e913162214 $
36    * @since 8.3M2
37    * @since 7.4.5
38    */
 
39    public abstract class AbstractDocumentTreeNode extends AbstractEntityTreeNode
40    {
41    private final String nodeType;
42   
43    /**
44    * Creates a new node with the specified type.
45    *
46    * @param nodeType the type of document node
47    */
 
48  576 toggle public AbstractDocumentTreeNode(String nodeType)
49    {
50  576 this.nodeType = nodeType;
51    }
52   
 
53  10 toggle @Override
54    public List<String> getChildren(String nodeId, int offset, int limit)
55    {
56  10 EntityReference documentReference = resolve(nodeId);
57  10 if (documentReference != null && documentReference.getType() == EntityType.DOCUMENT) {
58  10 try {
59  10 return getChildren(new DocumentReference(documentReference), offset, limit);
60    } catch (Exception e) {
61  0 this.logger.warn("Failed to retrieve the children of [{}]. Root cause [{}].", nodeId,
62    ExceptionUtils.getRootCauseMessage(e));
63    }
64    }
65  0 return Collections.emptyList();
66    }
67   
 
68  0 toggle protected List<String> getChildren(DocumentReference documentReference, int offset, int limit) throws Exception
69    {
70  0 return Collections.emptyList();
71    }
72   
 
73  118 toggle @Override
74    public int getChildCount(String nodeId)
75    {
76  118 EntityReference documentReference = resolve(nodeId);
77  118 if (documentReference != null && documentReference.getType() == EntityType.DOCUMENT) {
78  118 try {
79  118 return getChildCount(new DocumentReference(documentReference));
80    } catch (Exception e) {
81  0 this.logger.warn("Failed to count the children of [{}]. Root cause [{}].", nodeId,
82    ExceptionUtils.getRootCauseMessage(e));
83    }
84    }
85  0 return 0;
86    }
87   
 
88  0 toggle protected int getChildCount(DocumentReference documentReference) throws Exception
89    {
90  0 return 0;
91    }
92   
 
93  5 toggle @Override
94    public String getParent(String nodeId)
95    {
96  5 EntityReference documentReference = resolve(nodeId);
97  5 if (documentReference != null && documentReference.getType() == EntityType.DOCUMENT) {
98  5 try {
99  5 return serialize(getParent(new DocumentReference(documentReference)));
100    } catch (Exception e) {
101  0 this.logger.warn("Failed to retrieve the parent of [{}]. Root cause [{}].", nodeId,
102    ExceptionUtils.getRootCauseMessage(e));
103    }
104    }
105  0 return null;
106    }
107   
 
108  0 toggle protected EntityReference getParent(DocumentReference documentReference) throws Exception
109    {
110    // Most pseudo-document nodes are children of a real document node with the same reference.
111  0 return documentReference;
112    }
113   
 
114  133 toggle @Override
115    protected EntityReference resolve(String nodeId)
116    {
117  133 String prefix = this.nodeType + ':';
118  133 if (StringUtils.startsWith(nodeId, prefix)) {
119  133 return super.resolve("document:" + nodeId.substring(prefix.length()));
120    }
121  0 return null;
122    }
123    }