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

File DocumentReferenceResolverFilter.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

6
16
3
1
96
61
6
0.38
5.33
3
2

Classes

Class Line # Actions
DocumentReferenceResolverFilter 48 16 0% 6 6
0.7676%
 

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.query;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.model.EntityType;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.model.reference.DocumentReferenceResolver;
33    import org.xwiki.model.reference.EntityReferenceProvider;
34    import org.xwiki.model.reference.SpaceReference;
35    import org.xwiki.model.reference.SpaceReferenceResolver;
36    import org.xwiki.query.QueryFilter;
37   
38    /**
39    * Transforms the results of a nested page query into a list of {@link DocumentReference}s.
40    *
41    * @version $Id: 6152846e4cadbbbca4f28475934d3012a348b671 $
42    * @since 8.3RC1
43    * @since 7.4.5
44    */
45    @Component
46    @Named("documentReferenceResolver/nestedPages")
47    @Singleton
 
48    public class DocumentReferenceResolverFilter implements QueryFilter
49    {
50    @Inject
51    @Named("current")
52    protected DocumentReferenceResolver<String> currentDocumentReferenceResolver;
53   
54    @Inject
55    @Named("current")
56    protected SpaceReferenceResolver<String> currentSpaceReferenceResolver;
57   
58    @Inject
59    private EntityReferenceProvider defaultEntityReferenceProvider;
60   
 
61  11 toggle @Override
62    public List<?> filterResults(@SuppressWarnings("rawtypes") List results)
63    {
64  11 String defaultDocumentName =
65    this.defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT).getName();
66  11 List<DocumentReference> documentReferences = new ArrayList<DocumentReference>();
67  11 for (Object result : results) {
68  15 String reference = (String) ((Object[]) result)[0];
69  15 boolean terminal = toBoolean(((Object[]) result)[1]);
70  15 if (terminal) {
71  2 documentReferences.add(this.currentDocumentReferenceResolver.resolve(reference));
72    } else {
73  13 SpaceReference spaceReference = this.currentSpaceReferenceResolver.resolve(reference);
74  13 documentReferences.add(new DocumentReference(defaultDocumentName, spaceReference));
75    }
76    }
77  11 return documentReferences;
78    }
79   
 
80  11 toggle @Override
81    public String filterStatement(String statement, String language)
82    {
83  11 return statement;
84    }
85   
 
86  15 toggle protected boolean toBoolean(Object value)
87    {
88  15 if (value instanceof Boolean) {
89  15 return (Boolean) value;
90  0 } else if (value instanceof Number) {
91  0 return ((Number) value).intValue() != 0;
92    } else {
93  0 return false;
94    }
95    }
96    }