This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
The following commit(s) were added to refs/heads/master by this push:
new 190bc55 Minor code quality cleanups
190bc55 is described below
commit 190bc55139e05387f662c6158e8673c14fe9745c
Author: Dan Klco <[email protected]>
AuthorDate: Tue Apr 16 16:49:26 2019 -0400
Minor code quality cleanups
---
.../apache/sling/cms/core/models/ErrorHandler.java | 3 +-
.../apache/sling/cms/core/models/LocaleList.java | 1 -
.../apache/sling/cms/reference/models/Search.java | 254 ++++++++++-----------
3 files changed, 128 insertions(+), 130 deletions(-)
diff --git
a/core/src/main/java/org/apache/sling/cms/core/models/ErrorHandler.java
b/core/src/main/java/org/apache/sling/cms/core/models/ErrorHandler.java
index 38efe69..a87e46e 100644
--- a/core/src/main/java/org/apache/sling/cms/core/models/ErrorHandler.java
+++ b/core/src/main/java/org/apache/sling/cms/core/models/ErrorHandler.java
@@ -17,7 +17,6 @@
package org.apache.sling.cms.core.models;
import java.util.Collections;
-import java.util.HashMap;
import javax.annotation.PostConstruct;
import javax.inject.Named;
@@ -218,7 +217,7 @@ public class ErrorHandler {
log.debug("Calculating error handling scripts for resource {} and
error code {}", resource, errorCode);
if (slingRequest.getAttribute(SlingConstants.ERROR_EXCEPTION) != null)
{
- log.warn("Handing exception of type {}", errorCode,
+ log.warn("Handing exception of type {} {}", errorCode,
slingRequest.getAttribute(SlingConstants.ERROR_EXCEPTION));
}
diff --git
a/core/src/main/java/org/apache/sling/cms/core/models/LocaleList.java
b/core/src/main/java/org/apache/sling/cms/core/models/LocaleList.java
index a2388fa..b177c3b 100644
--- a/core/src/main/java/org/apache/sling/cms/core/models/LocaleList.java
+++ b/core/src/main/java/org/apache/sling/cms/core/models/LocaleList.java
@@ -17,7 +17,6 @@
package org.apache.sling.cms.core.models;
import java.text.DateFormat;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
diff --git
a/reference/src/main/java/org/apache/sling/cms/reference/models/Search.java
b/reference/src/main/java/org/apache/sling/cms/reference/models/Search.java
index 5f2082f..7a7acc5 100644
--- a/reference/src/main/java/org/apache/sling/cms/reference/models/Search.java
+++ b/reference/src/main/java/org/apache/sling/cms/reference/models/Search.java
@@ -1,5 +1,5 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
+d * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
@@ -45,143 +45,143 @@ import org.slf4j.LoggerFactory;
@Model(adaptables = SlingHttpServletRequest.class)
public class Search {
- private static final Logger log = LoggerFactory.getLogger(Search.class);
+ private static final Logger log = LoggerFactory.getLogger(Search.class);
- public static final String TERM_PARAMETER = "q";
+ public static final String TERM_PARAMETER = "q";
- @ValueMapValue
- private String basePath;
+ @ValueMapValue
+ private String basePath;
- private int count;
+ private int count;
- private int end;
+ private int end;
- @ValueMapValue
- private int limit;
+ @ValueMapValue
+ private int limit;
- private int page;
+ private int page;
- private Integer[] pages;
+ private Integer[] pages;
- private SlingHttpServletRequest request;
+ private SlingHttpServletRequest request;
- private List<Resource> results = new ArrayList<Resource>();
+ private List<Resource> results = new ArrayList<>();
- @OSGiService
- private SearchService searchService;
+ @OSGiService
+ private SearchService searchService;
- private int start;
-
- private ResourceResolver resolver;
+ private int start;
+
+ private ResourceResolver resolver;
- public Search(SlingHttpServletRequest request) {
- this.request = request;
- }
+ public Search(SlingHttpServletRequest request) {
+ this.request = request;
+ }
- public int getCount() {
- return count;
- }
-
- public int getCurrentPage() {
- return page + 1;
- }
-
- public int getEnd() {
- return end;
- }
-
- public Integer[] getPages() {
- return pages;
- }
-
- public List<Resource> getResults() {
- return results;
- }
-
- public int getStart() {
- return start;
- }
-
- public String getTerm() {
- return request.getParameter(TERM_PARAMETER);
- }
-
- @PostConstruct
- public void init() {
-
- Set<String> distinct = new HashSet<>();
-
- String term =
Text.escapeIllegalXpathSearchChars(request.getParameter(TERM_PARAMETER)).replaceAll("'",
"''");
-
- resolver = searchService.getResourceResolver(request);
-
- String query = "SELECT * FROM [sling:Page] AS p WHERE
[jcr:content/published]=true AND (p.[jcr:content/hideInSitemap] IS NULL OR
p.[jcr:content/hideInSitemap] <> true) AND ISDESCENDANTNODE(p, '"
- + basePath + "') AND CONTAINS(p.*, '" + term +
"') ORDER BY [jcr:score]";
- log.debug("Searching for pages with {} under {} with query:
{}", term, basePath, query);
- Iterator<Resource> res = resolver.findResources(query,
Query.JCR_SQL2);
- while (res.hasNext()) {
- Resource result = res.next();
- if (!distinct.contains(result.getPath())) {
- results.add(result);
- distinct.add(result.getPath());
- }
- }
- count = results.size();
- log.debug("Found {} results", count);
-
- if (StringUtils.isNotBlank(request.getParameter("page")) &&
request.getParameter("page").matches("\\d+")) {
- page = Integer.parseInt(request.getParameter("page"),
10) - 1;
- log.debug("Using page {}", page);
- } else {
- page = 0;
- log.debug("Page {} not specified or not valid",
request.getParameter("page"));
- }
-
- if (page * limit >= count) {
- start = count;
- } else {
- start = page * limit;
- }
- log.debug("Using start {}", start);
-
- if ((page * limit) + limit >= count) {
- end = count;
- } else {
- end = (page * limit) + limit;
- }
- log.debug("Using end {}", end);
- results = results.subList(start, end);
-
- List<Integer> pgs = new ArrayList<>();
- int max = ((int) Math.ceil((double) count / limit)) + 1;
- for (int i = 1; i < max; i++) {
- pgs.add(i);
- }
- pages = pgs.toArray(new Integer[pgs.size()]);
- if (log.isDebugEnabled()) {
- log.debug("Loaded pages {}", Arrays.toString(pages));
- }
- }
-
- /**
- * This is a horrible hack to close the resource resolver used for
retrieving
- * the search results
- *
- * @return true, always
- */
- public String getFinalize() {
- searchService.closeResolver(resolver);
- return "";
- }
-
- public boolean isFirst() {
- return page == 0;
- }
-
- public boolean isLast() {
- if (pages.length > 0) {
- return page + 1 == pages[pages.length - 1];
- }
- return true;
- }
+ public int getCount() {
+ return count;
+ }
+
+ public int getCurrentPage() {
+ return page + 1;
+ }
+
+ public int getEnd() {
+ return end;
+ }
+
+ public Integer[] getPages() {
+ return pages;
+ }
+
+ public List<Resource> getResults() {
+ return results;
+ }
+
+ public int getStart() {
+ return start;
+ }
+
+ public String getTerm() {
+ return request.getParameter(TERM_PARAMETER);
+ }
+
+ @PostConstruct
+ public void init() {
+
+ Set<String> distinct = new HashSet<>();
+
+ String term =
Text.escapeIllegalXpathSearchChars(request.getParameter(TERM_PARAMETER)).replaceAll("'",
"''");
+
+ resolver = searchService.getResourceResolver(request);
+
+ String query = "SELECT * FROM [sling:Page] AS p WHERE
[jcr:content/published]=true AND (p.[jcr:content/hideInSitemap] IS NULL OR
p.[jcr:content/hideInSitemap] <> true) AND ISDESCENDANTNODE(p, '"
+ + basePath + "') AND CONTAINS(p.*, '" + term + "') ORDER BY
[jcr:score]";
+ log.debug("Searching for pages with {} under {} with query: {}", term,
basePath, query);
+ Iterator<Resource> res = resolver.findResources(query, Query.JCR_SQL2);
+ while (res.hasNext()) {
+ Resource result = res.next();
+ if (!distinct.contains(result.getPath())) {
+ results.add(result);
+ distinct.add(result.getPath());
+ }
+ }
+ count = results.size();
+ log.debug("Found {} results", count);
+
+ if (StringUtils.isNotBlank(request.getParameter("page")) &&
request.getParameter("page").matches("\\d+")) {
+ page = Integer.parseInt(request.getParameter("page"), 10) - 1;
+ log.debug("Using page {}", page);
+ } else {
+ page = 0;
+ log.debug("Page {} not specified or not valid",
request.getParameter("page"));
+ }
+
+ if (page * limit >= count) {
+ start = count;
+ } else {
+ start = page * limit;
+ }
+ log.debug("Using start {}", start);
+
+ if ((page * limit) + limit >= count) {
+ end = count;
+ } else {
+ end = (page * limit) + limit;
+ }
+ log.debug("Using end {}", end);
+ results = results.subList(start, end);
+
+ List<Integer> pgs = new ArrayList<>();
+ int max = ((int) Math.ceil((double) count / limit)) + 1;
+ for (int i = 1; i < max; i++) {
+ pgs.add(i);
+ }
+ pages = pgs.toArray(new Integer[pgs.size()]);
+ if (log.isDebugEnabled()) {
+ log.debug("Loaded pages {}", Arrays.toString(pages));
+ }
+ }
+
+ /**
+ * This is a horrible hack to close the resource resolver used for
retrieving
+ * the search results
+ *
+ * @return true, always
+ */
+ public String getFinalize() {
+ searchService.closeResolver(resolver);
+ return "";
+ }
+
+ public boolean isFirst() {
+ return page == 0;
+ }
+
+ public boolean isLast() {
+ if (pages.length > 0) {
+ return page + 1 == pages[pages.length - 1];
+ }
+ return true;
+ }
}