    View Javadoc
    1   /*
    2    * Copyright (c) 2003
    3    * Information Desire GmbH
    4    * All rights reserved.
    5    */
    6   package com.infodesire.infobit.render.velocity;
    7
    8   import com.infodesire.infobit.render.InfobitRenderer;
    9
    10  import java.io.InputStream;
    11  import java.io.Reader;
    12  import java.io.BufferedReader;
    13  import java.io.Writer;
    14  import java.io.PipedOutputStream;
    15  import java.io.PipedInputStream;
    16  import java.io.OutputStreamWriter;
    17  import java.io.InputStreamReader;
    18
    19  import com.infodesire.infobit.InfobitManager;
    20  import com.infodesire.infobit.InfobitException;
    21  import com.infodesire.infobit.InfobitSecurityException;
    22
    23  import com.infodesire.infobit.data.Infobit;
    24  import com.infodesire.infobit.data.Content;
    25  import com.infodesire.infobit.data.Script;
    26  import com.infodesire.infobit.data.Template;
    27  import com.infodesire.infobit.data.BinaryContent;
    28  import com.infodesire.infobit.data.PrimitiveContent;
    29  import com.infodesire.infobit.data.TextContent;
    30
    31  import org.apache.velocity.VelocityContext;
    32  import org.apache.velocity.context.Context;
    33  import org.apache.velocity.app.Velocity;
    34  import org.apache.velocity.app.VelocityEngine;
    35  import org.apache.velocity.runtime.RuntimeConstants;
    36
    37  import java.util.Iterator;
    38  import java.util.Properties;
    39  import java.util.Map;
    40  import java.util.HashMap;
    41
    42  import org.apache.commons.logging.Log;
    43  import org.apache.commons.logging.LogFactory;
    44
    45  /***
    46   * render infobits in a way suitable for xml export
    47   *
    48   * @author    konstantin
    49   * @created   August 21, 2003
    50   * @version   $Revision: 1.3 $
    51   */
    52  public class ExportVelocityRenderer extends VelocityRenderer {
    53
    54      private static Log _log = LogFactory.getLog(ExportVelocityRenderer.class);
    55
    56      private static HashMap _contentClassMap = new HashMap();
    57
    58
    59      /***
    60       * setup context for infobit rendering. this method is called by #inbfobit()
    61       * directive it places following objects on context:
    62       * <ul>
    63       *   <li> $infobit - infobit itself
    64       *   <li> $version - selected infobit version ( currently it's active
    65       *   version )
    66       *   <li> $content - content belonging to this version
    67       *   <li> $linkname where linkname is name of script link - just a
    68       *   convenience ( may dissapear ) script names will be also available in
    69       *   template as $content.links.get("name of the link").name
    70       * </ul>
    71       *
    72       *
    73       * @param context      velocity context to be augmented
    74       * @param infobitName  Description of Parameter
    75       */
    76      public void setupContext(Context context, String infobitName) {
    77          try {
    78              Infobit ibit = _manager.getInfobit(infobitName);
    79              if (ibit == null) {
    80                  // well, this shall not happen, since this method shall be called after
    81                  // resource manager loaded infobit template.
    82                  // log anyway, but do not bomb.
    83                  _log.error("did not found infobit: " + infobitName);
    84                  return;
    85              }
    86              context.put("infobit", ibit);
    87          } catch (Exception ex) {
    88              _log.error("exception occured while acquiring infobit params: " + infobitName, ex);
    89          }
    90
    91      }
    92
    93
    94      /***
    95       * not sure it's good here. just a noop
    96       *
    97       * @param writer   Description of Parameter
    98       * @param content  Description of Parameter
    99       */
    100     public void renderContent(Writer writer, Content content) {
    101     }
    102
    103
    104     /***
    105      * initialize itself and velocity with given properties.
    106      *
    107      * @param properties  Description of Parameter
    108      */
    109     public void init(Properties properties) {
    110         _engine.setApplicationAttribute(VelocityRenderer.class.getName(), this);
    111         super.init(properties);
    112     }
    113
    114
    115     /***
    116      * returns proper version of infobit content. currently we support only
    117      * actual version, but later we may made it more advanced to be able to view
    118      * preview versions / or from certain date.
    119      *
    120      * @param ibit                          Description of Parameter
    121      * @return                              The InfobitContent value
    122      * @exception InfobitException          Description of Exception
    123      * @exception InfobitSecurityException  Description of Exception
    124      */
    125     Content getInfobitContent(Infobit ibit) throws InfobitException, InfobitSecurityException {
    126         return ibit.getActualVersion().getContent();
    127     }
    128
    129
    130     /***
    131      * read content as stream out of infobit. this is callback for your template
    132      * loader. we substitute proxy templates for images. for templates we will
    133      * also tweak out context...
    134      *
    135      * @param name  Description of Parameter
    136      * @return      Description of the Returned Value
    137      */
    138
    139     InputStream getTemplate(String name) {
    140         try {
    141             Infobit ibit = _manager.getInfobit(name);
    142             if (ibit == null) {
    143                 _log.error("did not found infobit: " + name);
    144                 return null;
    145             }
    146             return AdvancedClasspathLoader.getResourceAsStream("com/infodesire/infobit/render/velocity/export.vm");
    147         } catch (Exception ex) {
    148             _log.error("error retrieving template for: " + name, ex);
    149             return null;
    150         }
    151
    152     }
    153
    154 }

This page was automatically generated by Maven