Ejemplo n.º 1
0
  /**
   * There must be a better way of doing this as this hard codes the services in surely there should
   * be some whay of looking up the serivce and making the getSummary part of an interface. TODO:
   * Add an interface beside EntityProducer to generate summaries Make this discoverable
   *
   * @param m
   * @param site
   * @param toolIdentifier
   * @return
   */
  private boolean summarizeTool(Map m, Site site, String toolIdentifier) {
    if (site == null) return false;

    setTemporaryPlacement(site);
    Map newMap = null;

    /*
     * This is a new, cooler way to do this (I hope) chmaurer... (ieb) Yes:)
     * All summaries now through this interface
     */

    // offer to all EntityProducers
    for (Iterator i = EntityManager.getEntityProducers().iterator(); i.hasNext(); ) {
      EntityProducer ep = (EntityProducer) i.next();
      if (ep instanceof EntitySummary) {
        try {
          EntitySummary es = (EntitySummary) ep;

          // if this producer claims this tool id
          if (ArrayUtil.contains(es.summarizableToolIds(), toolIdentifier)) {
            String summarizableReference =
                es.getSummarizableReference(site.getId(), toolIdentifier);
            newMap = es.getSummary(summarizableReference, 5, 30);
          }
        } catch (Throwable t) {
          log.warn(
              "Error encountered while asking EntitySummary to getSummary() for: " + toolIdentifier,
              t);
        }
      }
    }

    if (newMap != null) {
      return (MapUtil.copyHtml(m, "rssDescription", newMap, Summary.PROP_DESCRIPTION)
          && MapUtil.copy(m, "rssPubdate", newMap, Summary.PROP_PUBDATE));
    } else {
      Time modDate = site.getModifiedTime();
      // Yes, some sites have never been modified
      if (modDate != null) {
        m.put("rssPubDate", (modDate.toStringRFC822Local()));
      }
      return false;
    }
  }