-
Notifications
You must be signed in to change notification settings - Fork 16
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
8 changed files
with
265 additions
and
38 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
20 changes: 19 additions & 1 deletion
20
app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSource.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
19 changes: 19 additions & 0 deletions
19
app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/DataSourceInvoker.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
42 changes: 42 additions & 0 deletions
42
app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/LowerDataSource.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,42 @@ | ||
/* | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
package com.cognifide.apm.core.grammar.datasource; | ||
|
||
import com.cognifide.apm.core.grammar.ApmString; | ||
import com.cognifide.apm.core.grammar.ApmType; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class LowerDataSource implements DataSource { | ||
|
||
@Override | ||
public String getName() { | ||
return "LOWER"; | ||
} | ||
|
||
@Override | ||
public ApmType determine(ResourceResolver resolver, List<ApmType> parameters) { | ||
String value = parameters.get(0).getString(); | ||
return new ApmString(value.toLowerCase()); | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
...aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/NodeNamesDataSource.java
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/NodesDataSource.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,62 @@ | ||
/* | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
package com.cognifide.apm.core.grammar.datasource; | ||
|
||
import com.cognifide.apm.core.grammar.ApmList; | ||
import com.cognifide.apm.core.grammar.ApmMap; | ||
import com.cognifide.apm.core.grammar.ApmString; | ||
import com.cognifide.apm.core.grammar.ApmType; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
@Component | ||
public class NodesDataSource implements DataSource { | ||
|
||
@Override | ||
public String getName() { | ||
return "NODES"; | ||
} | ||
|
||
@Override | ||
public ApmType determine(ResourceResolver resolver, List<ApmType> parameters) { | ||
String path = parameters.get(0).getString(); | ||
String regex = parameters.size() >= 2 ? parameters.get(1).getString() : "[^:]+"; | ||
Pattern pattern = Pattern.compile(regex); | ||
Resource root = resolver.getResource(path); | ||
List<ApmMap> values = StreamSupport.stream(root.getChildren().spliterator(), false) | ||
.filter(resource -> pattern.matcher(resource.getName()).matches()) | ||
.map(resource -> { | ||
Map<String, ApmType> map = new HashMap<>(); | ||
map.put("path", new ApmString(resource.getPath())); | ||
map.put("name", new ApmString(resource.getName())); | ||
return new ApmMap(map); | ||
}) | ||
.collect(Collectors.toList()); | ||
return new ApmList(values); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/UpperDataSource.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,42 @@ | ||
/* | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
package com.cognifide.apm.core.grammar.datasource; | ||
|
||
import com.cognifide.apm.core.grammar.ApmString; | ||
import com.cognifide.apm.core.grammar.ApmType; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class UpperDataSource implements DataSource { | ||
|
||
@Override | ||
public String getName() { | ||
return "UPPER"; | ||
} | ||
|
||
@Override | ||
public ApmType determine(ResourceResolver resolver, List<ApmType> parameters) { | ||
String value = parameters.get(0).getString(); | ||
return new ApmString(value.toUpperCase()); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app/aem/core/src/main/java/com/cognifide/apm/core/grammar/datasource/ValueMapDataSource.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,61 @@ | ||
/* | ||
* ========================LICENSE_START================================= | ||
* AEM Permission Management | ||
* %% | ||
* Copyright (C) 2013 Wunderman Thompson Technology | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
package com.cognifide.apm.core.grammar.datasource; | ||
|
||
import com.cognifide.apm.core.grammar.*; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.apache.sling.api.resource.ValueMap; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
public class ValueMapDataSource implements DataSource { | ||
|
||
@Override | ||
public String getName() { | ||
return "VALUEMAP"; | ||
} | ||
|
||
@Override | ||
public ApmType determine(ResourceResolver resolver, List<ApmType> parameters) { | ||
String path = parameters.get(0).getString(); | ||
ValueMap valueMap = resolver.getResource(path).getValueMap(); | ||
Map<String, ApmType> map = new HashMap<>(); | ||
for (Map.Entry<String, Object> entry : valueMap.entrySet()) { | ||
String key = entry.getKey(); | ||
Object value = entry.getValue(); | ||
if (value instanceof Object[]) { | ||
List<ApmType> list = Arrays.stream((Object[]) value) | ||
.map(item -> new ApmString(item.toString())) | ||
.collect(Collectors.toList()); | ||
map.put(key, new ApmList(list)); | ||
} else { | ||
map.put(key, new ApmString(value.toString())); | ||
} | ||
} | ||
return new ApmMap(map); | ||
} | ||
} |