EditableTemplateSupport.java

  1. /*
  2.  * #%L
  3.  * wcm.io
  4.  * %%
  5.  * Copyright (C) 2019 wcm.io
  6.  * %%
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *      http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  * #L%
  19.  */
  20. package io.wcm.wcm.commons.controller;

  21. import javax.annotation.PostConstruct;

  22. import org.apache.sling.api.SlingHttpServletRequest;
  23. import org.apache.sling.models.annotations.Model;
  24. import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
  25. import org.osgi.annotation.versioning.ProviderType;

  26. import com.day.cq.wcm.api.components.ComponentContext;

  27. import io.wcm.sling.models.annotations.AemObject;
  28. import io.wcm.wcm.commons.util.EditableTemplate;

  29. /**
  30.  * Helper model to check status in editable templates.
  31.  */
  32. @Model(adaptables = SlingHttpServletRequest.class)
  33. @ProviderType
  34. public final class EditableTemplateSupport {

  35.   @AemObject(injectionStrategy = InjectionStrategy.OPTIONAL)
  36.   private ComponentContext componentContext;

  37.   private boolean editRestricted;

  38.   @PostConstruct
  39.   private void activate() {
  40.     if (componentContext != null) {
  41.       this.editRestricted = EditableTemplate.isEditRestricted(componentContext);
  42.     }
  43.   }

  44.   /**
  45.    * @return true if editing of this component is forbidden in the editable template definition
  46.    */
  47.   public boolean isEditRestricted() {
  48.     return this.editRestricted;
  49.   }

  50. }