-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
413 additions
and
1,040 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeExistence.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2021 Valtech GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package de.valtech.aecu.api.groovy.console.bindings.filters; | ||
|
||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.resource.Resource; | ||
|
||
|
||
/** | ||
* Filters resources by absolute or relative node path. Only resources that (not) exist in the | ||
* repository are accepted. | ||
* | ||
* @author Vugar Aghayev | ||
*/ | ||
public class FilterByNodeExistence implements FilterBy { | ||
|
||
private String path; | ||
private boolean nodeExists; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param path absolute or relative resource path | ||
* @param nodeExists node exists option | ||
*/ | ||
public FilterByNodeExistence(@Nonnull String path, boolean nodeExists) { | ||
this.path = path; | ||
this.nodeExists = nodeExists; | ||
} | ||
|
||
@Override | ||
public boolean filter(@Nonnull Resource resource, StringBuilder output) { | ||
if (StringUtils.isBlank(path)) { | ||
return true; | ||
} | ||
|
||
if (isAbsolutePath(path)) { | ||
return (nodeExists && null != resource.getResourceResolver().getResource(path)) | ||
|| (!nodeExists && null == resource.getResourceResolver().getResource(path)); | ||
} else { | ||
return (nodeExists && null != resource.getChild(path)) || (!nodeExists && null == resource.getChild(path)); | ||
} | ||
} | ||
|
||
/** | ||
* checks whether given path is absolute or not. | ||
* | ||
* @param path jcr path | ||
* @return true if the given path is the absolute path. Otherwise false. | ||
*/ | ||
private boolean isAbsolutePath(String path) { | ||
return path.startsWith("/"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.