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

File AbstractNestedPageFilter.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

6
15
5
1
81
48
8
0.53
3
5
1.6

Classes

Class Line # Actions
AbstractNestedPageFilter 33 15 0% 8 4
0.8461538684.6%
 

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.List;
23   
24    import org.xwiki.query.QueryFilter;
25   
26    /**
27    * Base class for nested pages query filters.
28    *
29    * @version $Id: 1a14fa2904592aff11c3d7e74e3b6bb7aad63de6 $
30    * @since 8.3RC1
31    * @since 7.4.5
32    */
 
33    public abstract class AbstractNestedPageFilter implements QueryFilter
34    {
 
35  22 toggle @Override
36    public List<?> filterResults(@SuppressWarnings("rawtypes") List results)
37    {
38  22 return results;
39    }
40   
 
41  22 toggle @Override
42    public String filterStatement(String statement, String language)
43    {
44  22 int unionIndex = statement.indexOf("union all");
45  22 if (unionIndex < 0) {
46  8 return filterNestedPagesStatement(statement);
47    } else {
48  14 int nestedPagesStatementStart = statement.indexOf("(select") + 1;
49  14 int nestedPagesStatementEnd = statement.substring(0, unionIndex).lastIndexOf(')');
50  14 int terminalPagesStatementStart = statement.indexOf('(', unionIndex) + 1;
51  14 int terminalPagesStatementEnd =
52    statement.substring(0, statement.lastIndexOf(") xwikiPage")).lastIndexOf(')');
53  14 return statement.substring(0, nestedPagesStatementStart)
54    + filterNestedPagesStatement(statement.substring(nestedPagesStatementStart, nestedPagesStatementEnd))
55    + statement.substring(nestedPagesStatementEnd, terminalPagesStatementStart)
56    + filterTerminalPagesStatement(
57    statement.substring(terminalPagesStatementStart, terminalPagesStatementEnd))
58    + statement.substring(terminalPagesStatementEnd);
59    }
60    }
61   
 
62  0 toggle protected String filterNestedPagesStatement(String statement)
63    {
64  0 return statement;
65    }
66   
 
67  0 toggle protected String filterTerminalPagesStatement(String statement)
68    {
69  0 return statement;
70    }
71   
 
72  22 toggle protected String insertWhereConstraint(String statement, String constraint)
73    {
74  22 int insertionPoint = statement.lastIndexOf("order by ");
75  22 if (insertionPoint < 0) {
76  14 insertionPoint = statement.length();
77    }
78  22 return statement.substring(0, insertionPoint) + (statement.lastIndexOf("where ") < 0 ? " where " : " and ")
79    + constraint + statement.substring(insertionPoint);
80    }
81    }