private String prepareMailBodyContentPart(Content content, String defaultLang, boolean isHtml) {
   NewsletterContentType contentType =
       this.getConfig().getContentTypes().get(content.getTypeCode());
   int modelId = isHtml ? contentType.getHtmlModel() : contentType.getSimpleTextModel();
   String mailContentBody = this.getContentRenderer().render(content, modelId, defaultLang, null);
   mailContentBody = this.getLinkResolver().resolveLinks(mailContentBody, null);
   if (!isHtml) {
     return StringEscapeUtils.unescapeHtml(mailContentBody);
   }
   return mailContentBody;
 }
 @Override
 public String buildMailBody(Content content, boolean html) throws ApsSystemException {
   String mailBody = null;
   try {
     NewsletterConfig config = this.getConfig();
     NewsletterContentType contentType = config.getContentType(content.getTypeCode());
     int modelId = html ? contentType.getHtmlModel() : contentType.getSimpleTextModel();
     mailBody = this.buildMailBody(content, modelId, html);
   } catch (Throwable t) {
     ApsSystemUtils.logThrowable(t, this, "buildMailBody");
     throw new ApsSystemException("Errore in generazione body contenuto " + content.getId(), t);
   }
   return mailBody;
 }
  protected void checkOriginaryConfig(NewsletterConfig config) {
    assertEquals(2, config.getSubscriptions().size());
    assertNull(config.getAllContentsAttributeName());
    assertEquals("boolean1", config.getSubscriptions().getProperty("cat1"));
    assertEquals("boolean2", config.getSubscriptions().getProperty("evento"));

    assertEquals(1, config.getContentTypes().size());
    NewsletterContentType contentType = config.getContentType("ART");
    assertEquals("ART", contentType.getContentTypeCode());
    assertEquals(2, contentType.getSimpleTextModel());
    assertEquals(3, contentType.getHtmlModel());

    assertEquals("CODE1", config.getSenderCode());
    assertEquals("email", config.getMailAttrName());
    assertEquals(true, config.isAlsoHtml());
    assertEquals("Oggetto della mail", config.getSubject());

    assertEquals("<strong>Header html della mail</strong>", config.getHtmlHeader());
    assertEquals("<strong>Footer html della mail</strong>", config.getHtmlFooter());
    assertEquals("Separatore html della mail", config.getHtmlSeparator());
    assertEquals("Header text della mail", config.getTextHeader());
    assertEquals("Footer text della mail", config.getTextFooter());
    assertEquals("Separatore text della mail", config.getTextSeparator());
  }
  public void compareConfigs(NewsletterConfig conf1, NewsletterConfig conf2) {
    assertEquals(conf1.getSenderCode(), conf2.getSenderCode());
    assertEquals(conf1.getMailAttrName(), conf2.getMailAttrName());
    assertEquals(conf1.isAlsoHtml(), conf2.isAlsoHtml());
    assertEquals(conf1.getUnsubscriptionPageCode(), conf2.getUnsubscriptionPageCode());
    assertEquals(conf1.getSubject(), conf2.getSubject());
    assertEquals(conf1.getHtmlHeader(), conf2.getHtmlHeader());
    assertEquals(conf1.getHtmlFooter(), conf2.getHtmlFooter());
    assertEquals(conf1.getHtmlSeparator(), conf2.getHtmlSeparator());
    assertEquals(conf1.getTextHeader(), conf2.getTextHeader());
    assertEquals(conf1.getTextFooter(), conf2.getTextFooter());
    assertEquals(conf1.getTextSeparator(), conf2.getTextSeparator());
    assertEquals(conf1.getSubscribersTextFooter(), conf2.getSubscribersTextFooter());
    assertEquals(conf1.getSubscribersHtmlFooter(), conf2.getSubscribersHtmlFooter());

    assertEquals(conf1.getSubscriptionPageCode(), conf2.getSubscriptionPageCode());
    assertEquals(
        conf1.getSubscriptionTokenValidityDays(), conf2.getSubscriptionTokenValidityDays());
    assertEquals(conf1.getSubscriptionSubject(), conf2.getSubscriptionSubject());
    assertEquals(conf1.getSubscriptionHtmlBody(), conf2.getSubscriptionHtmlBody());
    assertEquals(conf1.getSubscriptionTextBody(), conf2.getSubscriptionTextBody());

    assertEquals(conf1.getAllContentsAttributeName(), conf2.getAllContentsAttributeName());
    assertEquals(conf1.getSubscriptions().size(), conf2.getSubscriptions().size());
    Iterator subscriptions = conf1.getSubscriptions().keySet().iterator();
    while (subscriptions.hasNext()) {
      String category = (String) subscriptions.next();
      assertEquals(conf1.getSubscriptions().get(category), conf2.getSubscriptions().get(category));
    }

    assertEquals(conf1.getContentTypes().size(), conf2.getContentTypes().size());
    Iterator contentTypes = conf1.getContentTypes().keySet().iterator();
    while (contentTypes.hasNext()) {
      String contentTypeCode = (String) contentTypes.next();
      NewsletterContentType ct1 = conf1.getContentType(contentTypeCode);
      NewsletterContentType ct2 = conf2.getContentType(contentTypeCode);

      assertEquals(ct1.getContentTypeCode(), ct2.getContentTypeCode());
      assertEquals(ct1.getSimpleTextModel(), ct2.getSimpleTextModel());
      assertEquals(ct1.getHtmlModel(), ct2.getHtmlModel());
    }
  }
  public NewsletterConfig createNewsletterConfig() {
    NewsletterConfig config = new NewsletterConfig();
    config.setSenderCode("senderCode");
    config.setMailAttrName("mailAttrName");
    config.setAlsoHtml(false);
    config.setUnsubscriptionPageCode("newsletter_unsubscribe");
    config.setSubject("subject");
    config.setHtmlHeader("htmlHeader");
    config.setHtmlFooter("htmlFooter");
    config.setHtmlSeparator("htmlSeparator");
    config.setTextHeader("textHeader");
    config.setTextFooter("textFooter");
    config.setTextSeparator("textSeparator");
    config.setSubscribersHtmlFooter(
        "Clicca sul link per cancellare la sottoscrizione <a href=\"{unsubscribeLink}\" >CONFERMA</a></body></html>");
    config.setSubscribersTextFooter(
        "Clicca sul link {unsubscribeLink} per cancellare la sottoscrizione");

    config.setSubscriptionPageCode("newsletter_terminatereg");
    config.setSubscriptionTokenValidityDays(90);
    config.setSubscriptionSubject("Conferma la sottoscrizione al servizio di Newsletter");
    config.setSubscriptionHtmlBody(
        "<p>Clicca sul link per confermare <a href=\"{subscribeLink}\" >***CONFERMA***</a></p>");
    config.setSubscriptionTextBody("Clicca sul link {subscribeLink} per confermare");

    config.setAllContentsAttributeName("allContentsSubscription");
    config.addSubscription("Attach", "attachAttribute");
    config.addSubscription("Image", "imageAttribute");
    NewsletterContentType contentType = new NewsletterContentType();
    contentType.setContentTypeCode("EVN");
    contentType.setHtmlModel(1);
    contentType.setSimpleTextModel(2);
    config.addContentType(contentType);
    contentType = new NewsletterContentType();
    contentType.setContentTypeCode("ART");
    contentType.setHtmlModel(1);
    contentType.setSimpleTextModel(2);
    config.addContentType(contentType);
    return config;
  }