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; }
@Override public List<String> getTagIds() { final List<String> tagIds = new ArrayList<String>(); for (Tag tag : page.getTags()) { tagIds.add(tag.getTagID()); } return tagIds; }
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()); } }
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; } }
final Tag tag = tagManager.createTag(tagId, tagData.getTitle(), tagData.getDescription()); Node node = tag.adaptTo(Node.class); for (Map.Entry<String, String> entry : translationsMap.entrySet()) { node.setProperty("jcr:title."+entry.getKey(), entry.getValue()); log.trace("Created Tag [ {} ] with Title [ {} ]", tag.getTagID(), tagData.getTitle()); 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);
@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,";"); }
protected JSONObject getJson() { JSONObject json = new JSONObject(); json.put(ID, getId()); json.put(TITLE, getTitle()); json.put(DESCRIPTION, getDescription()); json.put(BODY, getBody().getBodyAsText()); json.put(AUTHOR, getAuthor().displayName()); json.put(LAST_MODIFIED, SolrTimestamp.convertToUtcAndUseNowIfNull(getLastUpdate())); json.put(PUBLISH_DATE, SolrTimestamp.convertToUtcAndUseNowIfNull(getPublishDate())); json.put(SLING_RESOUCE_TYPE, getSlingResourceType()); json.put(URL, getUrl()); JSONArray tags = new JSONArray(); for (Tag tag : getTags()) { tags.add(tag.getTitle()); } json.put(TAGS, tags); return json; }
private void setTitles(final Tag tag, final TagDefinition tagDefinition) throws RepositoryException { final Node node = tag.adaptTo(Node.class); if (node == null) { log.error("Tag [ {} ] could not be adapted to a Node", tagDefinition.getId()); return; } if (!StringUtils.equals(tag.getTitle(), tagDefinition.getTitle())) { // Ensure if the tag already exists that the title is set properly node.setProperty("jcr:title", tagDefinition.getTitle()); } if (!tagDefinition.getLocalizedTitles().isEmpty()){ // If Localized titles are provides ensure they are set properly final Map<String,String> translationsMap = tagDefinition.getLocalizedTitles(); for (final Map.Entry<String, String> entry : translationsMap.entrySet()) { node.setProperty("jcr:title." + entry.getKey(), entry.getValue()); } } }
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); } }
@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); }
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); } } } } } } }
@PostConstruct protected void initModel() { title = currentPage.getTitle(); if (StringUtils.isBlank(title)) { title = currentPage.getName(); } Tag[] tags = currentPage.getTags(); keywords = new String[tags.length]; int index = 0; for (Tag tag : tags) { keywords[index++] = tag.getTitle(currentPage.getLanguage(false)); } if (currentDesign != null) { String designPath = currentDesign.getPath(); if (!Designer.DEFAULT_DESIGN_PATH.equals(designPath)) { this.designPath = designPath; if (resolver.getResource(designPath + "/static.css") != null) { staticDesignPath = designPath + "/static.css"; } loadFavicons(designPath); } } populateClientlibCategories(); templateName = extractTemplateName(); }
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; } }
protected SolrInputDocument getSolrDoc() { SolrInputDocument doc = new SolrInputDocument(); doc.addField(ID, getId()); doc.addField(TITLE, getTitle()); doc.addField(DESCRIPTION, getDescription()); doc.addField(BODY, getBody().getBodyAsText()); doc.addField(AUTHOR, getAuthor().displayName()); doc.addField(LAST_MODIFIED, SolrTimestamp.convertToUtcAndUseNowIfNull(getLastUpdate())); doc.addField(PUBLISH_DATE, SolrTimestamp.convertToUtcAndUseNowIfNull(getPublishDate())); doc.addField(SLING_RESOUCE_TYPE, getSlingResourceType()); doc.addField(URL, getUrl()); for (Tag tag : getTags()) { doc.addField(TAGS, tag.getTitle()); } return doc; } }