-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved SLING-7643 - Adding support for CA Configs in JSP TagLib
- Loading branch information
Showing
7 changed files
with
373 additions
and
17 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
124 changes: 124 additions & 0 deletions
124
src/main/java/org/apache/sling/scripting/jsp/taglib/AbstractCATag.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,124 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.sling.scripting.jsp.taglib; | ||
|
||
import javax.servlet.jsp.tagext.TagSupport; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.scripting.SlingBindings; | ||
import org.apache.sling.api.scripting.SlingScriptHelper; | ||
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver; | ||
|
||
/** | ||
* Abstract class for Tags for interactiving with Context-Aware Configuration | ||
* resources to extend. | ||
*/ | ||
public abstract class AbstractCATag extends TagSupport { | ||
|
||
/** Serialization UID */ | ||
private static final long serialVersionUID = -3083138119694952836L; | ||
|
||
/** The bucket. */ | ||
private String bucket; | ||
|
||
/** The name. */ | ||
private String name; | ||
|
||
/** The resource for which to get the configuration. */ | ||
private Resource resource; | ||
|
||
/** The var. */ | ||
private String var; | ||
|
||
/** | ||
* @return the bucket | ||
*/ | ||
public String getBucket() { | ||
return bucket; | ||
} | ||
|
||
/** | ||
* @return the name | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @return the resource | ||
*/ | ||
public Resource getResource() { | ||
return resource; | ||
} | ||
|
||
/** | ||
* Method for retrieving the ConfigurationResourceResolver from the page | ||
* context. | ||
* | ||
* @return the resource resolver | ||
*/ | ||
protected ConfigurationResourceResolver getConfigurationResourceResolver() { | ||
final SlingBindings bindings = (SlingBindings) pageContext.getRequest() | ||
.getAttribute(SlingBindings.class.getName()); | ||
final SlingScriptHelper scriptHelper = bindings.getSling(); | ||
final ConfigurationResourceResolver resolver = scriptHelper.getService(ConfigurationResourceResolver.class); | ||
return resolver; | ||
} | ||
|
||
/** | ||
* Gets the variable name to which to save the list of children. | ||
* | ||
* @return the variable name | ||
*/ | ||
public String getVar() { | ||
return var; | ||
} | ||
|
||
/** | ||
* @param bucket | ||
* the bucket to set | ||
*/ | ||
public void setBucket(String bucket) { | ||
this.bucket = bucket; | ||
} | ||
|
||
/** | ||
* @param name | ||
* the name to set | ||
*/ | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* @param resource | ||
* the resource to set | ||
*/ | ||
public void setResource(Resource resource) { | ||
this.resource = resource; | ||
} | ||
|
||
/** | ||
* Sets the variable name to which to save the list of children. | ||
* | ||
* @param var | ||
* the variable name | ||
*/ | ||
public void setVar(String var) { | ||
this.var = var; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/apache/sling/scripting/jsp/taglib/GetCAConfigResourceTag.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,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.sling.scripting.jsp.taglib; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Tag for retrieving Context-Aware Configuration resources for a specified | ||
* resource, bucket and name. | ||
*/ | ||
public class GetCAConfigResourceTag extends AbstractCATag { | ||
|
||
/** Serialization UID */ | ||
private static final long serialVersionUID = -8191004532757820167L; | ||
|
||
/** The Constant log. */ | ||
private static final Logger log = LoggerFactory.getLogger(GetCAConfigResourceTag.class); | ||
|
||
@Override | ||
public int doEndTag() { | ||
log.trace("doEndTag"); | ||
|
||
ConfigurationResourceResolver caResourceResolver = this.getConfigurationResourceResolver(); | ||
|
||
log.debug("Finding configuration with {}/{} for {}", getBucket(), getName(), getResource()); | ||
Resource config = caResourceResolver.getResource(getResource(), getBucket(), getName()); | ||
|
||
log.debug("Saving {} to variable {}", config, getVar()); | ||
pageContext.setAttribute(getVar(), config); | ||
|
||
return EVAL_PAGE; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/apache/sling/scripting/jsp/taglib/GetCAConfigResourcesTag.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,54 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.sling.scripting.jsp.taglib; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Tag for retrieving Context-Aware Configuration resource collection for a | ||
* specified resource, bucket and name. | ||
*/ | ||
public class GetCAConfigResourcesTag extends AbstractCATag { | ||
|
||
/** Serialization UID */ | ||
private static final long serialVersionUID = -8191004532757820167L; | ||
|
||
/** The Constant log. */ | ||
private static final Logger log = LoggerFactory.getLogger(GetCAConfigResourceTag.class); | ||
|
||
|
||
@Override | ||
public int doEndTag() { | ||
log.trace("doEndTag"); | ||
|
||
ConfigurationResourceResolver caResourceResolver = this.getConfigurationResourceResolver(); | ||
|
||
log.debug("Finding configuration with {}/{} for {}", getBucket(), getName(), getResource()); | ||
Iterator<Resource> config = caResourceResolver.getResourceCollection(getResource(), getBucket(), getName()).iterator(); | ||
|
||
log.debug("Saving {} to variable {}", config, getVar()); | ||
pageContext.setAttribute(getVar(), config); | ||
|
||
return EVAL_PAGE; | ||
} | ||
|
||
} |
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.