@Override public List<String> getTagIds() { final TagManager tagManager = resourceResolver.adaptTo(TagManager.class); final List<String> tagIds = new ArrayList<String>(); for (Tag tag : tagManager.getTags(resource)) { tagIds.add(tag.getTagID()); } return tagIds; }
protected static boolean hasTags(ResourceResolver rr, RequestParameter[] params) { if (params == null) { return false; } else { TagManager tagManager = rr.adaptTo(TagManager.class); return Stream.of(params).allMatch( param -> looksLikeTag(param.getString()) && tagManager.resolve(param.getString()) != null); } }
private TagsLocation resolveTagsLocation(ResourceResolver resourceResolver) { final TagManager tagManager = resourceResolver.adaptTo(TagManager.class); final Tag[] namespaces = tagManager.getNamespaces(); if (namespaces.length > 0) { final Tag tag = namespaces[0]; if (StringUtils.startsWith(tag.getPath(), CONTENT_LOCATION)) { return TagsLocation.CONTENT; } else { return TagsLocation.ETC; } } return TagsLocation.UNKNOWN; }
private void createTag(TagDefinition tagDefinition, TagManager tagManager) { ReportRowSatus status; try { if (tagManager.resolve(tagDefinition.getId()) == null) { status = ReportRowSatus.CREATED; } else { status = ReportRowSatus.UPDATED_EXISTING; } final Tag tag = tagManager.createTag( tagDefinition.getId(), tagDefinition.getTitle(), tagDefinition.getDescription(), false); if (tag != null) { setTitles(tag, tagDefinition); record(status, tag.getTagID(), tag.getPath(), tag.getTitle()); log.debug("Created tag [ {} -> {} ]", tagDefinition.getId(), tagDefinition.getTitle()); } else { log.error("Tag [ {} ] is null", tagDefinition.getId()); } } catch (Exception e) { record(ReportRowSatus.FAILED_TO_CREATE, tagDefinition.getId(), tagDefinition.getPath(), tagDefinition.getTitle()); log.error("Unable to create tag [ {} -> {} ]", tagDefinition.getId(), tagDefinition.getTitle()); } }
final Tag tag = tagManager.createTag(tagId, tagData.getTitle(), tagData.getDescription()); if (tagManager.getSession().hasPendingChanges()) { final long start = System.currentTimeMillis(); tagManager.getSession().save(); if (log.isInfoEnabled()) { log.info("Persisting tags to JCR in {} ms", System.currentTimeMillis() - start);
private void populateTagListItems() { listItems = new ArrayList<>(); String[] tags = properties.get(PN_TAGS, new String[0]); boolean matchAny = properties.get(PN_TAGS_MATCH, TAGS_MATCH_ANY_VALUE).equals(TAGS_MATCH_ANY_VALUE); if (ArrayUtils.isNotEmpty(tags)) { Page rootPage = getRootPage(PN_TAGS_PARENT_PAGE); if (rootPage != null) { TagManager tagManager = resourceResolver.adaptTo(TagManager.class); if (tagManager != null) { RangeIterator<Resource> resourceRangeIterator = tagManager.find(rootPage.getPath(), tags, matchAny); if (resourceRangeIterator != null) { while (resourceRangeIterator.hasNext()) { Page containingPage = pageManager.getContainingPage(resourceRangeIterator.next()); if (containingPage != null) { listItems.add(containingPage); } } } } } } }
@Override public String getValue(Object result) { Resource resource = (Resource) result; TagManager tagMgr = resource.getResourceResolver().adaptTo(TagManager.class); log.debug("Loading tags from {}@{}", resource.getPath(), property); List<String> tags = new ArrayList<String>(); String[] values = resource.getValueMap().get(property, String[].class); if (values != null) { for (String value : values) { tags.add(tagMgr.resolve(value).getTitle()); } } log.debug("Loaded {} tags", tags); return StringUtils.join(tags,";"); }
@PostConstruct public void init() throws SlingModelsException { final Resource authorResource = resource.getResourceResolver().resolve(authorRef + "/profile"); final GeometrixxMediaAuthorSummary authorSummary = authorResource.adaptTo(GeometrixxMediaAuthorSummary.class); final TagManager tagManager = resource.getResourceResolver().adaptTo(TagManager.class); id = resource.getParent().getPath(); url = id + ".html"; author = authorSummary != null ? authorSummary : new GeometrixxMediaAuthorSummary(); body = articleBody != null ? articleBody : new GeometrixxMediaArticleBody(""); tags = tagManager.getTags(resource); }
public List<Tag> getTags() { TagManager tagMgr = request.getResourceResolver().adaptTo(TagManager.class); Resource resource = (Resource) request.getAttribute("result"); log.debug("Loading tags from {}@{}", resource.getPath(), property); List<Tag> tags = new ArrayList<Tag>(); String[] values = resource.getValueMap().get(property, String[].class); if (values != null) { for (String value : values) { tags.add(tagMgr.resolve(value)); } } log.debug("Loaded {} tags", tags.size()); return tags; } }
public List<PredicateOption> getPredicateOptions(SlingHttpServletRequest request, String namespaceName) { final List<PredicateOption> options = new ArrayList<PredicateOption>(); final TagManager tagManager = request.getResourceResolver().adaptTo(TagManager.class); final Tag namespace = tagManager.resolve("/etc/tags/" + namespaceName); if (namespace == null) { log.error("Unable to resolve [ {} ] to a Tag namespace", namespaceName); return options; } final Iterator<Tag> tags = namespace.listChildren(); while (tags.hasNext()) { Tag tag = tags.next(); options.add(new PredicateOption(StringUtils.defaultIfEmpty(tag.getTitle(request.getLocale()), tag.getTitle()), tag.getTagID())); } // Sort Alphabetically by Label Collections.sort(options, new PredicateOption.AlphabeticalByLabel()); return options; } }