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()); } } }
@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,";"); }
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; } }
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; }
@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(); }
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()); } }
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; } }