/** * Gets a node's default vanity URL for the given locale and workspace. If none is default then * take the first mapping for the locale. * * @param contentNode the content node for which to return a mapping * @param workspace the workspace to look for mappings * @param locale the locale to which the mapping should apply * @param siteKey * @return the VanityUrl bean * @throws RepositoryException if there was an unexpected exception accessing the repository */ public VanityUrl getVanityUrlForWorkspaceAndLocale( final JCRNodeWrapper contentNode, String workspace, Locale locale, final String siteKey) throws RepositoryException { return JCRTemplate.getInstance() .doExecuteWithSystemSession( null, workspace, locale, new JCRCallback<VanityUrl>() { public VanityUrl doInJCR(JCRSessionWrapper session) throws RepositoryException { return vanityUrlManager.getVanityUrlForCurrentLocale(contentNode, siteKey, session); } }); }
/** * Add or update a vanity URL mapping for a specific content node and the language code set in the * VanityUrl bean. * * <p>If the URL mapping has already been saved before we check whether the default and active * flag in the bean is different to the saved one, so we do an update, otherwise no operation is * done. * * <p>If the new or updated mapping is now the default one for the language, then we also check if * there already is another default URL for this language and set its default flag to false. * * <p>We also check whether the same URL is already existing for a different node or language in * the current site and throw a ConstraintViolationException if this is the case. * * @param contentNode the content node for which to add the given mapping * @param vanityUrl the VanityUrl bean representing the URL to be added * @return true if the vanity URL was added or false if it was not added * @throws ConstraintViolationException if the vanity URL mapping already exists for a different * content node or language in the site * @throws RepositoryException if there was an unexpected exception accessing the repository */ public boolean saveVanityUrlMapping(final JCRNodeWrapper contentNode, final VanityUrl vanityUrl) throws RepositoryException { cacheByUrl.flush(); return JCRTemplate.getInstance() .doExecuteWithSystemSession( new JCRCallback<Boolean>() { public Boolean doInJCR(JCRSessionWrapper session) throws RepositoryException { JCRNodeWrapper currentContentNode = session.getNodeByUUID(contentNode.getIdentifier()); return vanityUrlManager.saveVanityUrlMapping( currentContentNode, vanityUrl, session); } }); }
/** * Find any mappings for the given vanity URL. If a site is specified the query will be done only * for the specified site, otherwise all sites in the workspace will be searched through and a * list of VanityURL beans will be returned. The method searches mappings in any language. * * @param url URL path to check whether there is a content mapping for it (URL must start with /) * @param site key of the site to search for the mapping or all sites if the string is null or * empty * @param workspace the workspace to look for mappings * @return the list of VanityUrl beans * @throws RepositoryException if there was an unexpected exception accessing the repository */ public List<VanityUrl> findExistingVanityUrls( final String url, final String site, final String workspace) throws RepositoryException { final String cacheKey = getCacheByUrlKey(url, site, workspace); if (cacheByUrl.containsKey(cacheKey)) { return (List<VanityUrl>) cacheByUrl.get(cacheKey); } return JCRTemplate.getInstance() .doExecuteWithSystemSession( null, workspace, new JCRCallback<List<VanityUrl>>() { public List<VanityUrl> doInJCR(JCRSessionWrapper session) throws RepositoryException { List<VanityUrl> vanityUrls = vanityUrlManager.findExistingVanityUrls(url, site, session); cacheByUrl.put(cacheKey, vanityUrls); return vanityUrls; } }); }
public Collection<Message> produce(final Execution execution) { final Map<String, Object> vars = ((ExecutionImpl) execution).getVariables(); Locale locale = (Locale) vars.get("locale"); if (templateKey != null) { MailTemplate template = null; MailTemplateRegistry templateRegistry = ((ProcessEngine) SpringContextSingleton.getBean("processEngine")) .get(MailTemplateRegistry.class); if (locale != null) { template = (templateRegistry.getTemplate(templateKey + "." + locale.toString())); if (template == null) { template = (templateRegistry.getTemplate(templateKey + "." + locale.getLanguage())); } } if (template == null) { template = templateRegistry.getTemplate(templateKey); } setTemplate(template); } if (ServicesRegistry.getInstance().getMailService().isEnabled() && getTemplate() != null) { try { return JCRTemplate.getInstance() .doExecuteWithSystemSession( null, "default", locale, new JCRCallback<Collection<Message>>() { public Collection<Message> doInJCR(JCRSessionWrapper session) throws RepositoryException { try { scriptEngine = ScriptEngineUtils.getInstance() .getEngineByName(getTemplate().getLanguage()); bindings = null; Message email = instantiateEmail(); fillFrom(email, execution, session); fillRecipients(email, execution, session); fillSubject(email, execution, session); fillContent(email, execution, session); Address[] addresses = email.getRecipients(Message.RecipientType.TO); if (addresses != null && addresses.length > 0) { return Collections.singleton(email); } else { return Collections.emptyList(); } } catch (MessagingException e) { logger.error(e.getMessage(), e); } catch (ScriptException e) { logger.error(e.getMessage(), e); } return Collections.emptyList(); } }); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } return Collections.emptyList(); }