-
Notifications
You must be signed in to change notification settings - Fork 7
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
24 changed files
with
643 additions
and
35 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
84 changes: 84 additions & 0 deletions
84
bundle/src/main/java/io/wcm/caconfig/editor/ConfigurationCategory.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,84 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2022 wcm.io | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package io.wcm.caconfig.editor; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.osgi.annotation.versioning.ProviderType; | ||
|
||
/** | ||
* Describes a configuration category. | ||
*/ | ||
@ProviderType | ||
public final class ConfigurationCategory implements Comparable<ConfigurationCategory> { | ||
|
||
private final String category; | ||
private String label; | ||
|
||
/** | ||
* @param category Category name | ||
*/ | ||
public ConfigurationCategory(@NotNull String category) { | ||
this.category = category; | ||
} | ||
|
||
/** | ||
* @return Category name | ||
*/ | ||
public @NotNull String getCategory() { | ||
return this.category; | ||
} | ||
|
||
/** | ||
* @return Category label. Falls back to category name if not defined. | ||
*/ | ||
public @NotNull String getLabel() { | ||
return StringUtils.defaultString(this.label, this.category); | ||
} | ||
|
||
/** | ||
* @param value Category label | ||
* @return this | ||
*/ | ||
public ConfigurationCategory label(@Nullable String value) { | ||
this.label = value; | ||
return this; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return this.category.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof ConfigurationCategory) { | ||
return this.category.equals(((ConfigurationCategory)obj).category); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int compareTo(ConfigurationCategory other) { | ||
return this.category.compareTo(other.category); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
bundle/src/main/java/io/wcm/caconfig/editor/ConfigurationCategoryProvider.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,57 @@ | ||
/* | ||
* #%L | ||
* wcm.io | ||
* %% | ||
* Copyright (C) 2022 wcm.io | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package io.wcm.caconfig.editor; | ||
|
||
import org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.osgi.annotation.versioning.ConsumerType; | ||
|
||
import io.wcm.sling.commons.caservice.ContextAwareService; | ||
|
||
/** | ||
* Provides metadata for configuration categories used by an application. | ||
* <p> | ||
* Applications can set service properties or bundle headers as defined in {@link ContextAwareService} to apply this | ||
* configuration only for resources that match the relevant resource paths. | ||
* </p> | ||
*/ | ||
@ConsumerType | ||
public interface ConfigurationCategoryProvider extends ContextAwareService { | ||
|
||
/** | ||
* Get metadata for a given configuration name. | ||
* @param category Category name | ||
* @return Metadata or null if category is not known | ||
*/ | ||
@Nullable | ||
ConfigurationCategory getCategoryMetadata(@NotNull String category); | ||
|
||
/** | ||
* This method is called for configurations that are in use and do not have a category name assigned. | ||
* With this method it's possible to assign categories by inspecting the configuration metadata, or | ||
* to just assign a default category. | ||
* @param configurationMetadata Metadata of configuration that does not have a category defined | ||
* @return Category name or null if no category should be assigned | ||
*/ | ||
@Nullable | ||
String getCategory(@NotNull ConfigurationMetadata configurationMetadata); | ||
|
||
} |
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.