示例#1
0
  /**
   * Format the to site email address.
   *
   * @param event The event that matched criteria to cause the notification.
   * @return the email address attribution for the site.
   */
  protected String getToSite(Event event) {
    Reference ref = EntityManager.newReference(event.getResource());

    // use either the configured site, or if not configured, the site (context) of the resource
    String siteId = (getSite() != null) ? getSite() : ref.getContext();

    // get a site title
    String title = siteId;
    String email = null;
    try {
      Site site = SiteService.getSite(siteId);
      title = site.getTitle();

      // check that the channel exists
      String channel = "/mailarchive/channel/" + siteId + "/main";
      EntityManager.newReference(channel);

      // find the alias for this site's mail channel
      List<Alias> all = AliasService.getAliases(channel);
      if (!all.isEmpty()) email = ((Alias) all.get(0)).getId();
    } catch (Exception ignore) {
    }

    // if for any reason we did not find an email, setup for the no-reply for email
    if (email == null) email = "no-reply";

    String rv =
        "\"" + title + "\" <" + email + "@" + ServerConfigurationService.getServerName() + ">";

    return rv;
  }
 public String lookupPageToAlias(String siteId, SitePage page) {
   // Shortcut if we aren't using page aliases.
   if (!lookForPageAliases) {
     return null;
   }
   String alias = null;
   List<Alias> aliases = AliasService.getAliases(page.getReference());
   if (aliases.size() > 0) {
     if (aliases.size() > 1 && log.isWarnEnabled()) {
       log.warn("More than one alias for: " + siteId + ":" + page.getId());
       // Sort on ID so it is consistent in the alias it uses.
       Collections.sort(aliases, getAliasComparator());
     }
     alias = aliases.get(0).getId();
     alias = parseAlias(alias, siteId);
   }
   return alias;
 }
 public SitePage lookupAliasToPage(String alias, Site site) {
   // Shortcut if we aren't using page aliases.
   if (!lookForPageAliases) {
     return null;
   }
   SitePage page = null;
   if (alias != null && alias.length() > 0) {
     try {
       // Use page#{siteId}:{pageAlias} So we can scan for fist colon and alias can contain any
       // character
       String refString = AliasService.getTarget(buildAlias(alias, site));
       String aliasPageId = EntityManager.newReference(refString).getId();
       page = (SitePage) site.getPage(aliasPageId);
     } catch (IdUnusedException e) {
       if (log.isDebugEnabled()) {
         log.debug("Alias does not resolve " + e.getMessage());
       }
     }
   }
   return page;
 }