private void initTagsStructure() {
    Resource defaultNamespace =
        resourceResolver.getResource(TAGS_ROOT + "/" + TagConstants.DEFAULT_NAMESPACE);
    // if it's already existing, then don't proceed any further
    if (defaultNamespace != null) {
      return;
    }
    Map<String, Object> etcProperties = new HashMap<String, Object>();
    etcProperties.put(JcrConstants.JCR_PRIMARYTYPE, JcrResourceConstants.NT_SLING_FOLDER);

    Map<String, Object> tagsProperties = new HashMap<String, Object>();
    tagsProperties.put(JcrConstants.JCR_PRIMARYTYPE, JcrResourceConstants.NT_SLING_FOLDER);
    tagsProperties.put(JcrConstants.JCR_TITLE, "Tags");
    // locale strings that are recognized languages in child tags
    tagsProperties.put(
        "languages",
        new String[] {"en", "de", "es", "fr", "it", "pt_br", "zh_cn", "ch_tw", "ja", "ko_kr"});

    try {
      ResourceUtil.getOrCreateResource(resourceResolver, "/etc", etcProperties, null, true);
      ResourceUtil.getOrCreateResource(resourceResolver, TAGS_ROOT, tagsProperties, null, true);
      createTag(TagConstants.DEFAULT_NAMESPACE_ID, "Standard Tags", null);
    } catch (PersistenceException | InvalidTagFormatException e) {
      log.error("Error creating tags tree", e);
    }
  }
示例#2
0
 /**
  * If the voucher is part of a campaign, return the campaign's priority. Otherwise return 100.
  *
  * @return The priority
  */
 public long getPriority() {
   for (Page parent = page.getParent(); parent != null; parent = parent.getParent()) {
     if (ResourceUtil.isA(
         parent.getContentResource(), "cq/personalization/components/campaignpage")) {
       return ResourceUtil.getValueMap(parent.getContentResource()).get("priority", 100);
     }
   }
   return VOUCHER_DEFAULT_PRIORITY;
 }
示例#3
0
 public ForumSearchImpl(final SlingHttpServletRequest request) {
   this.request = request;
   resolver = request.getResourceResolver();
   properties = ResourceUtil.getValueMap(request.getResource());
   searchPaths = properties.get(PN_SEARCHPATHS, new String[0]);
   query = getParameter(REQUEST_PARAM_QUERY);
   scopeProps = request.getParameterValues(REQUEST_PARAM_QUERY_SCOPE);
   request.setAttribute(ATTRIBUTE_NAME_SEARCH, this);
 }
示例#4
0
 /**
  * Valid if the parent campaign's onTime has been reached and the offTime hasn't, or if the times
  * are not specified.
  *
  * @return <code>true</code> if voucher is valid, <code>false</code> otherwise
  */
 public boolean isValid(SlingHttpServletRequest request) {
   for (Page parent = page.getParent(); parent != null; parent = parent.getParent()) {
     if (ResourceUtil.isA(
         parent.getContentResource(), "cq/personalization/components/campaignpage")) {
       return parent.isValid();
     }
   }
   return false;
 }
示例#5
0
 public AbstractJcrVoucher(Resource resource) throws CommerceException {
   this.resource = resource;
   page = resource.adaptTo(Page.class);
   if (page == null
       || !ResourceUtil.isA(
           resource.getChild("jcr:content"), AbstractJcrVoucher.VOUCHER_RESOURCE_TYPE)) {
     throw new CommerceException("Resource is not a JcrVoucher.");
   }
 }
示例#6
0
 /** Return a shopper-visible message detailing why the voucher is invalid. */
 public String getInvalidMessage(SlingHttpServletRequest request) {
   final I18n i18n = new I18n(request);
   for (Page parent = page.getParent(); parent != null; parent = parent.getParent()) {
     if (ResourceUtil.isA(
         parent.getContentResource(), "cq/personalization/components/campaignpage")) {
       long time = parent.timeUntilValid();
       if (time > 0) {
         return i18n.get("Invalid coupon code."); // Don't leak that it might be valid later
       } else if (time < 0) {
         return i18n.get("Coupon expired.");
       }
     }
   }
   return "";
 }
 /**
  * Given the node path, resource type and supported resource types, return true if this node
  * should be indexed.
  *
  * @param resolver the ResourceResolver.
  * @param nodePath the path to the node.
  * @param resourceType the resource type of the node.
  * @param supportedResourceTypes the set of resource types that we should index.
  * @return true if the given node should be indexed.
  */
 private boolean checkResourceType(
     final ResourceResolver resolver,
     final String nodePath,
     final String resourceType,
     final Set<String> supportedResourceTypes) {
   if (indexResourceSubTypes) {
     final Resource resource = resolver.getResource(nodePath);
     for (final String rType : supportedResourceTypes) {
       if (ResourceUtil.isA(resource, rType)) {
         return true;
       }
     }
     return false;
   } else {
     return supportedResourceTypes.contains(resourceType);
   }
 }
  @Override
  public Tag createTag(String tagID, String title, String description, boolean autoSave)
      throws AccessControlException, InvalidTagFormatException {
    String tagPath = getPathFromID(tagID);
    Resource tagResource = resourceResolver.getResource(tagPath);
    if (tagResource != null) {
      return tagResource.adaptTo(Tag.class);
    }

    // ensure the parent exists first
    String parentTagPath = tagPath.substring(0, tagPath.lastIndexOf("/"));
    if (!TAGS_ROOT.equals(parentTagPath)) {
      createTag(parentTagPath, null, null, false);
    }

    // otherwise it needs to be made
    Map<String, Object> tagProps = new HashMap<String, Object>();
    tagProps.put(JcrConstants.JCR_PRIMARYTYPE, TagConstants.NT_TAG);
    tagProps.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, TAG_RESOURCE_TYPE);
    if (title != null) {
      tagProps.put(JcrConstants.JCR_TITLE, title);
    }
    if (description != null) {
      tagProps.put(JcrConstants.JCR_DESCRIPTION, description);
    }
    tagProps.put(NameConstants.PN_LAST_MOD, Calendar.getInstance());
    tagProps.put(NameConstants.PN_LAST_MOD_BY, resourceResolver.getUserID());

    try {
      tagResource =
          ResourceUtil.getOrCreateResource(resourceResolver, tagPath, tagProps, null, autoSave);

      return tagResource.adaptTo(Tag.class);
    } catch (PersistenceException e) {
      log.error("failed to create tag", e);
      // throw this as a failure to indicate it failed
      throw new AccessControlException("failed to create tag");
    }
  }
 /**
  * Gets the SuperResourceType of a Resource to be created.
  *
  * @param request request used to create the resource
  * @param resourceType Resource type being created
  * @return String that is the resource's supertype
  */
 protected String getResourceSuperType(
     final SlingHttpServletRequest request, final String resourceType) {
   final String type =
       ResourceUtil.getResourceSuperType(request.getResourceResolver(), resourceType);
   return type;
 }