Loading src/com/owncloud/android/lib/resources/files/SearchOperation.java +24 −13 Original line number Original line Diff line number Diff line /** /* * Nextcloud Android client application * Nextcloud Android client application * * * @author Mario Danic * @author Mario Danic * Copyright (C) 2017 Mario Danic * Copyright (C) 2017 Mario Danic * <p> * * This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or * at your option) any later version. * at your option) any later version. * <p> * * This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * GNU Affero General Public License for more details. * <p> * * You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>. */ */ Loading Loading @@ -66,10 +66,12 @@ public class SearchOperation extends RemoteOperation { private String searchQuery; private String searchQuery; private SearchType searchType; private SearchType searchType; private boolean onlyFolder; public SearchOperation(String query, SearchType searchType) { public SearchOperation(String query, SearchType searchType, boolean onlyFolder) { this.searchQuery = query; this.searchQuery = query; this.searchType = searchType; this.searchType = searchType; this.onlyFolder = onlyFolder; } } @Override @Override Loading @@ -84,18 +86,15 @@ public class SearchOperation extends RemoteOperation { try { try { int optionsStatus = client.executeMethod(optionsMethod); int optionsStatus = client.executeMethod(optionsMethod); boolean isSearchSupported = optionsMethod.isAllowed("SEARCH"); boolean isSearchSupported = optionsMethod.isAllowed("SEARCH"); if (isSearchSupported) { searchMethod = new SearchMethod(webDavUrl, new SearchInfo("NC", if (isSearchSupported) { Namespace.XMLNS_NAMESPACE, "NC")); searchMethod = new SearchMethod(webDavUrl, new SearchInfo("NC", Namespace.XMLNS_NAMESPACE, "NC")); int status = client.executeMethod(searchMethod); int status = client.executeMethod(searchMethod); // check and process response // check and process response boolean isSuccess = ( boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK); status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK ); if (isSuccess) { if (isSuccess) { // get data from remote folder // get data from remote folder MultiStatus dataInServer = searchMethod.getResponseBodyAsMultiStatus(); MultiStatus dataInServer = searchMethod.getResponseBodyAsMultiStatus(); Loading Loading @@ -208,6 +207,10 @@ public class SearchOperation extends RemoteOperation { Text hrefTextElement = query.createTextNode("/files/" + getClient().getCredentials().getUsername()); Text hrefTextElement = query.createTextNode("/files/" + getClient().getCredentials().getUsername()); Text depthTextElement = query.createTextNode("infinity"); Text depthTextElement = query.createTextNode("infinity"); Element whereElement = query.createElementNS(DAV_NAMESPACE, "d:where"); Element whereElement = query.createElementNS(DAV_NAMESPACE, "d:where"); Element folderElement = null; if (onlyFolder) { folderElement = query.createElementNS(DAV_NAMESPACE, "d:is-collection"); } Element equalsElement; Element equalsElement; if (searchType == SearchType.FAVORITE_SEARCH) { if (searchType == SearchType.FAVORITE_SEARCH) { equalsElement = query.createElementNS(DAV_NAMESPACE, "d:eq"); equalsElement = query.createElementNS(DAV_NAMESPACE, "d:eq"); Loading Loading @@ -279,7 +282,14 @@ public class SearchOperation extends RemoteOperation { scopeElement.appendChild(depthElement); scopeElement.appendChild(depthElement); hrefElement.appendChild(hrefTextElement); hrefElement.appendChild(hrefTextElement); depthElement.appendChild(depthTextElement); depthElement.appendChild(depthTextElement); if (folderElement != null) { Element andElement = query.createElementNS(DAV_NAMESPACE, "d:and"); andElement.appendChild(folderElement); andElement.appendChild(equalsElement); whereElement.appendChild(andElement); } else { whereElement.appendChild(equalsElement); whereElement.appendChild(equalsElement); } equalsElement.appendChild(propElement); equalsElement.appendChild(propElement); equalsElement.appendChild(literalElement); equalsElement.appendChild(literalElement); propElement.appendChild(queryElement); propElement.appendChild(queryElement); Loading @@ -290,3 +300,4 @@ public class SearchOperation extends RemoteOperation { } } } } Loading
src/com/owncloud/android/lib/resources/files/SearchOperation.java +24 −13 Original line number Original line Diff line number Diff line /** /* * Nextcloud Android client application * Nextcloud Android client application * * * @author Mario Danic * @author Mario Danic * Copyright (C) 2017 Mario Danic * Copyright (C) 2017 Mario Danic * <p> * * This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or * at your option) any later version. * at your option) any later version. * <p> * * This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * GNU Affero General Public License for more details. * <p> * * You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>. */ */ Loading Loading @@ -66,10 +66,12 @@ public class SearchOperation extends RemoteOperation { private String searchQuery; private String searchQuery; private SearchType searchType; private SearchType searchType; private boolean onlyFolder; public SearchOperation(String query, SearchType searchType) { public SearchOperation(String query, SearchType searchType, boolean onlyFolder) { this.searchQuery = query; this.searchQuery = query; this.searchType = searchType; this.searchType = searchType; this.onlyFolder = onlyFolder; } } @Override @Override Loading @@ -84,18 +86,15 @@ public class SearchOperation extends RemoteOperation { try { try { int optionsStatus = client.executeMethod(optionsMethod); int optionsStatus = client.executeMethod(optionsMethod); boolean isSearchSupported = optionsMethod.isAllowed("SEARCH"); boolean isSearchSupported = optionsMethod.isAllowed("SEARCH"); if (isSearchSupported) { searchMethod = new SearchMethod(webDavUrl, new SearchInfo("NC", if (isSearchSupported) { Namespace.XMLNS_NAMESPACE, "NC")); searchMethod = new SearchMethod(webDavUrl, new SearchInfo("NC", Namespace.XMLNS_NAMESPACE, "NC")); int status = client.executeMethod(searchMethod); int status = client.executeMethod(searchMethod); // check and process response // check and process response boolean isSuccess = ( boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK); status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK ); if (isSuccess) { if (isSuccess) { // get data from remote folder // get data from remote folder MultiStatus dataInServer = searchMethod.getResponseBodyAsMultiStatus(); MultiStatus dataInServer = searchMethod.getResponseBodyAsMultiStatus(); Loading Loading @@ -208,6 +207,10 @@ public class SearchOperation extends RemoteOperation { Text hrefTextElement = query.createTextNode("/files/" + getClient().getCredentials().getUsername()); Text hrefTextElement = query.createTextNode("/files/" + getClient().getCredentials().getUsername()); Text depthTextElement = query.createTextNode("infinity"); Text depthTextElement = query.createTextNode("infinity"); Element whereElement = query.createElementNS(DAV_NAMESPACE, "d:where"); Element whereElement = query.createElementNS(DAV_NAMESPACE, "d:where"); Element folderElement = null; if (onlyFolder) { folderElement = query.createElementNS(DAV_NAMESPACE, "d:is-collection"); } Element equalsElement; Element equalsElement; if (searchType == SearchType.FAVORITE_SEARCH) { if (searchType == SearchType.FAVORITE_SEARCH) { equalsElement = query.createElementNS(DAV_NAMESPACE, "d:eq"); equalsElement = query.createElementNS(DAV_NAMESPACE, "d:eq"); Loading Loading @@ -279,7 +282,14 @@ public class SearchOperation extends RemoteOperation { scopeElement.appendChild(depthElement); scopeElement.appendChild(depthElement); hrefElement.appendChild(hrefTextElement); hrefElement.appendChild(hrefTextElement); depthElement.appendChild(depthTextElement); depthElement.appendChild(depthTextElement); if (folderElement != null) { Element andElement = query.createElementNS(DAV_NAMESPACE, "d:and"); andElement.appendChild(folderElement); andElement.appendChild(equalsElement); whereElement.appendChild(andElement); } else { whereElement.appendChild(equalsElement); whereElement.appendChild(equalsElement); } equalsElement.appendChild(propElement); equalsElement.appendChild(propElement); equalsElement.appendChild(literalElement); equalsElement.appendChild(literalElement); propElement.appendChild(queryElement); propElement.appendChild(queryElement); Loading @@ -290,3 +300,4 @@ public class SearchOperation extends RemoteOperation { } } } }