//# 0 errors, 70 messages
//#
/*
    //#excerptdecorator.java:1:1: class: net.sourceforge.pebble.decorator.ExcerptDecorator
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.decorator;

import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
import net.sourceforge.pebble.domain.BlogEntry;
import net.sourceforge.pebble.domain.StaticPage;
import net.sourceforge.pebble.util.StringUtils;
import net.sourceforge.pebble.PluginProperties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Automatically creates an excerpt for blog entries if one doesn't already
 * exist.
 *
 * @author Simon Brown
 */
public class ExcerptDecorator extends ContentDecoratorSupport {
    //#excerptdecorator.java:48: method: void net.sourceforge.pebble.decorator.ExcerptDecorator.net.sourceforge.pebble.decorator.ExcerptDecorator()
    //#input(void net.sourceforge.pebble.decorator.ExcerptDecorator()): this
    //#excerptdecorator.java:48: end of method: void net.sourceforge.pebble.decorator.ExcerptDecorator.net.sourceforge.pebble.decorator.ExcerptDecorator()

  private static final Log log = LogFactory.getLog(ExcerptDecorator.class);
    //#excerptdecorator.java:50: method: net.sourceforge.pebble.decorator.ExcerptDecorator.net.sourceforge.pebble.decorator.ExcerptDecorator__static_init
    //#excerptdecorator.java:50: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.decorator.ExcerptDecorator
    //#    method: net.sourceforge.pebble.decorator.ExcerptDecorator__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Descendant_Table[net/sourceforge/pebble/decorator/ExcerptDecorator]
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.decorate(Lnet/sourceforge/pebble/api/decorator/ContentDecoratorContext;Lnet/sourceforge/pebble/domain/BlogEntry;)V
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.decorate(Lnet/sourceforge/pebble/api/decorator/ContentDecoratorContext;Lnet/sourceforge/pebble/domain/Comment;)V
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.decorate(Lnet/sourceforge/pebble/api/decorator/ContentDecoratorContext;Lnet/sourceforge/pebble/domain/StaticPage;)V
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.decorate(Lnet/sourceforge/pebble/api/decorator/ContentDecoratorContext;Lnet/sourceforge/pebble/domain/TrackBack;)V
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.getBlog()Lnet/sourceforge/pebble/domain/Blog;
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.setBlog(Lnet/sourceforge/pebble/domain/Blog;)V
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): log
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): net/sourceforge/pebble/api/decorator/ContentDecorator.__Descendant_Table[net/sourceforge/pebble/decorator/ExcerptDecorator]
    //#output(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): net/sourceforge/pebble/decorator/ContentDecoratorSupport.__Descendant_Table[net/sourceforge/pebble/decorator/ExcerptDecorator]
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Descendant_Table[net/sourceforge/pebble/decorator/ExcerptDecorator] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): net/sourceforge/pebble/api/decorator/ContentDecorator.__Descendant_Table[net/sourceforge/pebble/decorator/ExcerptDecorator] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): net/sourceforge/pebble/decorator/ContentDecoratorSupport.__Descendant_Table[net/sourceforge/pebble/decorator/ExcerptDecorator] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.decorate(Lnet/sourceforge/pebble/api/decorator/ContentDecoratorContext;Lnet/sourceforge/pebble/domain/BlogEntry;)V == &decorate
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.decorate(Lnet/sourceforge/pebble/api/decorator/ContentDecoratorContext;Lnet/sourceforge/pebble/domain/Comment;)V == &net/sourceforge/pebble/decorator/ContentDecoratorSupport.decorate
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.decorate(Lnet/sourceforge/pebble/api/decorator/ContentDecoratorContext;Lnet/sourceforge/pebble/domain/StaticPage;)V == &decorate
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.decorate(Lnet/sourceforge/pebble/api/decorator/ContentDecoratorContext;Lnet/sourceforge/pebble/domain/TrackBack;)V == &net/sourceforge/pebble/decorator/ContentDecoratorSupport.decorate
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.getBlog()Lnet/sourceforge/pebble/domain/Blog; == &net/sourceforge/pebble/decorator/ContentDecoratorSupport.getBlog
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): __Dispatch_Table.setBlog(Lnet/sourceforge/pebble/domain/Blog;)V == &net/sourceforge/pebble/decorator/ContentDecoratorSupport.setBlog
    //#post(net.sourceforge.pebble.decorator.ExcerptDecorator__static_init): init'ed(log)
    //#excerptdecorator.java:50: end of method: net.sourceforge.pebble.decorator.ExcerptDecorator.net.sourceforge.pebble.decorator.ExcerptDecorator__static_init

  /** the name of the maxLength property */
  public static final String MAX_LENGTH_KEY = "ExcerptDecorator.maxLength";

  /**
   * Decorates the specified blog entry.
   *
   * @param context   the context in which the decoration is running
   * @param blogEntry the blog entry to be decorated
   */
  public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
    PluginProperties props = blogEntry.getBlog().getPluginProperties();
    //#excerptdecorator.java:62: method: void net.sourceforge.pebble.decorator.ExcerptDecorator.decorate(ContentDecoratorContext, BlogEntry)
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.__Tag
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.blog
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.blog.__Tag
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.blog.pluginProperties
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.body
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.excerpt
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.propertyChangeSupport
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): log
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/Blog.__Descendant_Table[net/sourceforge/pebble/domain/Blog]
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/Blog.__Descendant_Table[others]
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/Blog.__Dispatch_Table.getPluginProperties()Lnet/sourceforge/pebble/PluginProperties;
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Descendant_Table[net/sourceforge/pebble/domain/BlogEntry]
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Descendant_Table[others]
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getBlog()Lnet/sourceforge/pebble/domain/Blog;
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getBody()Ljava/lang/String;
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.getExcerpt()Ljava/lang/String;
    //#input(void decorate(ContentDecoratorContext, BlogEntry)): net/sourceforge/pebble/domain/BlogEntry.__Dispatch_Table.setExcerpt(Ljava/lang/String;)V
    //#output(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.excerpt
    //#pre[1] (void decorate(ContentDecoratorContext, BlogEntry)): blogEntry != null
    //#pre[2] (void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.__Tag == net/sourceforge/pebble/domain/BlogEntry
    //#pre[3] (void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.blog != null
    //#pre[4] (void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.blog.__Tag == net/sourceforge/pebble/domain/Blog
    //#pre[5] (void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.blog.pluginProperties != null
    //#pre[8] (void decorate(ContentDecoratorContext, BlogEntry)): init'ed(blogEntry.excerpt)
    //#pre[6] (void decorate(ContentDecoratorContext, BlogEntry)): (soft) init'ed(blogEntry.body)
    //#pre[7] (void decorate(ContentDecoratorContext, BlogEntry)): (soft) blogEntry.propertyChangeSupport != null
    //#presumption(void decorate(ContentDecoratorContext, BlogEntry)): org.apache.commons.logging.LogFactory:getLog(...)@50 != null
    //#post(void decorate(ContentDecoratorContext, BlogEntry)): init'ed(blogEntry.excerpt)
    //#unanalyzed(void decorate(ContentDecoratorContext, BlogEntry)): Effects-of-calling:java.beans.PropertyChangeSupport:firePropertyChange
    //#unanalyzed(void decorate(ContentDecoratorContext, BlogEntry)): Effects-of-calling:java.lang.String:trim
    //#test_vector(void decorate(ContentDecoratorContext, BlogEntry)): blogEntry.excerpt: Addr_Set{null}, Inverse{null}
    //#test_vector(void decorate(ContentDecoratorContext, BlogEntry)): java.lang.String:length(...)@73: {1..4_294_967_295}, {0}
    //#test_vector(void decorate(ContentDecoratorContext, BlogEntry)): net.sourceforge.pebble.PluginProperties:hasProperty(...)@64: {0}, {1}
    int maxLength = StringUtils.MAX_CONTENT_LENGTH;
    if (props.hasProperty(MAX_LENGTH_KEY)) {
    //#excerptdecorator.java:64: Warning: method not available
    //#    -- call on bool net.sourceforge.pebble.PluginProperties:hasProperty(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.decorator.ExcerptDecorator
    //#    method: void decorate(ContentDecoratorContext, BlogEntry)
    //#    unanalyzed callee: bool net.sourceforge.pebble.PluginProperties:hasProperty(String)
      try {
        maxLength = Integer.parseInt(props.getProperty(MAX_LENGTH_KEY));
    //#excerptdecorator.java:66: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.PluginProperties:getProperty(String)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.decorator.ExcerptDecorator
    //#    method: void decorate(ContentDecoratorContext, BlogEntry)
    //#    unanalyzed callee: String net.sourceforge.pebble.PluginProperties:getProperty(String)
      } catch (NumberFormatException nfe) {
        log.error(nfe.getMessage());
    //#excerptdecorator.java:68: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.decorator.ExcerptDecorator
    //#    method: void decorate(ContentDecoratorContext, BlogEntry)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object)
        // do nothing, the value has already been defaulted
      }
    }

    if (blogEntry.getExcerpt() == null || blogEntry.getExcerpt().length() == 0) {
      blogEntry.setExcerpt(StringUtils.truncate(blogEntry.getBody(), maxLength));
    //#excerptdecorator.java:74: Warning: method not available
    //#    -- call on String net.sourceforge.pebble.util.StringUtils:truncate(String, int)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.decorator.ExcerptDecorator
    //#    method: void decorate(ContentDecoratorContext, BlogEntry)
    //#    unanalyzed callee: String net.sourceforge.pebble.util.StringUtils:truncate(String, int)
    }
  }
    //#excerptdecorator.java:76: end of method: void net.sourceforge.pebble.decorator.ExcerptDecorator.decorate(ContentDecoratorContext, BlogEntry)

  /**
   * Decorates the specified static page.
   *
   * @param context    the context in which the decoration is running
   * @param staticPage the static page to be decorated
   */
  public void decorate(ContentDecoratorContext context, StaticPage staticPage) {
  }
    //#excerptdecorator.java:85: method: void net.sourceforge.pebble.decorator.ExcerptDecorator.decorate(ContentDecoratorContext, StaticPage)
    //#excerptdecorator.java:85: end of method: void net.sourceforge.pebble.decorator.ExcerptDecorator.decorate(ContentDecoratorContext, StaticPage)

}    //#excerptdecorator.java:: end of class: net.sourceforge.pebble.decorator.ExcerptDecorator
