forked from Adobe-Consulting-Services/acs-aem-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add page property injection (Adobe-Consulting-Services#3160)
* Add page property injection --------- Co-authored-by: Roy Teeuwen <[email protected]>
- Loading branch information
1 parent
790a32d
commit 2e90bf6
Showing
10 changed files
with
195 additions
and
21 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
61 changes: 61 additions & 0 deletions
61
bundle/src/main/java/com/adobe/acs/commons/models/injectors/annotation/PageProperty.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 @@ | ||
/* | ||
* ACS AEM Commons | ||
* | ||
* Copyright (C) 2013 - 2023 Adobe | ||
* | ||
* 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. | ||
*/ | ||
package com.adobe.acs.commons.models.injectors.annotation; | ||
|
||
|
||
import com.adobe.acs.commons.models.injectors.impl.HierarchicalPagePropertyInjector; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.models.annotations.Source; | ||
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; | ||
import org.apache.sling.models.spi.injectorspecific.InjectAnnotation; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* Injects a page property. | ||
* Note: not supported by the javax.Inject annotation because of performance reasons. Only direct annotation is supported. | ||
*/ | ||
@Target({METHOD, FIELD, PARAMETER}) | ||
@Retention(RUNTIME) | ||
@InjectAnnotation | ||
@Source(HierarchicalPagePropertyInjector.SOURCE) | ||
public @interface PageProperty { | ||
|
||
|
||
/** | ||
* Specifies the name of the value from the value map to take. | ||
* If empty, then the name is derived from the method or field. | ||
*/ | ||
String value() default StringUtils.EMPTY; | ||
|
||
|
||
/** | ||
* if set to REQUIRED injection is mandatory, if set to OPTIONAL injection is optional, in case of DEFAULT | ||
* the standard annotations ({@link org.apache.sling.models.annotations.Optional}, {@link org.apache.sling.models.annotations.Required}) are used. | ||
* If even those are not available the default injection strategy defined on the {@link org.apache.sling.models.annotations.Model} applies. | ||
* Default value = DEFAULT. | ||
*/ | ||
InjectionStrategy injectionStrategy() default InjectionStrategy.DEFAULT; | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
.../test/java/com/adobe/acs/commons/models/injectors/impl/model/TestPagePropertiesModel.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,27 @@ | ||
/* | ||
* ACS AEM Commons | ||
* | ||
* Copyright (C) 2013 - 2023 Adobe | ||
* | ||
* 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. | ||
*/ | ||
package com.adobe.acs.commons.models.injectors.impl.model; | ||
|
||
|
||
public interface TestPagePropertiesModel { | ||
|
||
String getPagePropertyString(); | ||
|
||
String getHierarchicalPagePropertyString(); | ||
|
||
} |
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
49 changes: 49 additions & 0 deletions
49
.../adobe/acs/commons/models/injectors/impl/model/impl/TestPagePropertiesModelModelImpl.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,49 @@ | ||
/* | ||
* ACS AEM Commons | ||
* | ||
* Copyright (C) 2013 - 2023 Adobe | ||
* | ||
* 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. | ||
*/ | ||
package com.adobe.acs.commons.models.injectors.impl.model.impl; | ||
|
||
import com.adobe.acs.commons.models.injectors.annotation.PageProperty; | ||
import com.adobe.acs.commons.models.injectors.impl.model.TestPagePropertiesModel; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.models.annotations.DefaultInjectionStrategy; | ||
import org.apache.sling.models.annotations.Model; | ||
|
||
@Model( | ||
adapters = TestPagePropertiesModel.class, | ||
adaptables = {SlingHttpServletRequest.class, Resource.class}, | ||
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL | ||
) | ||
public class TestPagePropertiesModelModelImpl implements TestPagePropertiesModel { | ||
|
||
@PageProperty | ||
private String hierarchicalPagePropertyString; | ||
@PageProperty | ||
private String pagePropertyString; | ||
|
||
@Override | ||
public String getPagePropertyString() { | ||
return pagePropertyString; | ||
} | ||
|
||
@Override | ||
public String getHierarchicalPagePropertyString() { | ||
return hierarchicalPagePropertyString; | ||
} | ||
|
||
} |
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