File Source: ContextLoader.java

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   *  contributor license agreements.  The ASF licenses this file to You
     4   * under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.  For additional information regarding
    15   * copyright in this work, please see the NOTICE file in the top level
    16   * directory of this distribution.
    17   */
    18  
    19  package org.apache.roller.weblogger.ui.rendering.velocity.deprecated;
    20  
    21  import java.net.MalformedURLException;
    22  import java.net.URL;
    23  import java.text.SimpleDateFormat;
    24  import java.util.ArrayList;
    25  import java.util.Date;
    26  import java.util.Locale;
    27  import java.util.Map;
    28  import javax.servlet.http.HttpServletRequest;
    29  import javax.servlet.http.HttpServletResponse;
    30  import javax.servlet.http.HttpSession;
    31  import javax.servlet.jsp.PageContext;
    32  import org.apache.commons.logging.Log;
    33  import org.apache.commons.logging.LogFactory;
    34  import org.apache.roller.weblogger.WebloggerException;
    35  import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
    36  import org.apache.roller.weblogger.business.Weblogger;
    37  import org.apache.roller.weblogger.business.WebloggerFactory;
    38  import org.apache.roller.weblogger.pojos.WeblogBookmarkFolder;
    39  import org.apache.roller.weblogger.pojos.RuntimeConfigProperty;
    40  import org.apache.roller.weblogger.pojos.ThemeTemplate;
    41  import org.apache.roller.weblogger.pojos.WeblogCategory;
    42  import org.apache.roller.weblogger.pojos.WeblogEntry;
    43  import org.apache.roller.weblogger.pojos.Weblog;
    44  import org.apache.roller.weblogger.pojos.wrapper.ThemeTemplateWrapper;
    45  import org.apache.roller.weblogger.pojos.wrapper.WeblogEntryWrapper;
    46  import org.apache.roller.weblogger.pojos.wrapper.WeblogWrapper;
    47  import org.apache.roller.weblogger.ui.core.RollerSession;
    48  import org.apache.roller.weblogger.ui.rendering.util.WeblogEntryCommentForm;
    49  import org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest;
    50  import org.apache.roller.util.DateUtil;
    51  import org.apache.roller.util.RegexUtil;
    52  import org.apache.roller.weblogger.business.URLStrategy;
    53  
    54  
    55  /**
    56   * Load Velocity Context with Weblogger objects, values, and custom plugins.
    57   * 
    58   * NOTE: This class has been deprecated and should no longer be used.  It is
    59   *       left here so that old weblogs which rely on it will continue to
    60   *       function properly.  This should only be used by weblog pages.
    61   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.ui.rendering.velocity.deprecated.ContextLoader()
          */
    62  public class ContextLoader {
    63  
    64      public static final String WEBLOG_KEY             = "weblog";
    65      public static final String ANCHOR_KEY             = "entry";
    66      public static final String ANCHOR_KEY_OLD         = "anchor";
    67      public static final String USERNAME_KEY           = "username";
    68  
    69      public static final String PAGELINK_KEY           = "pagelink";
    70      public static final String EXCERPTS_KEY           = "excerpts";
    71      public static final String WEBLOGENTRY_COUNT      = "count";
    72      public static final String WEBLOGCATEGORYNAME_KEY = "cat";
    73      public static final String WEBLOGENTRIES_KEY      = "entries";
    74      public static final String WEBLOGDAY_KEY          = "day";
    75      
    76      public static final String WEBLOGENTRYID_KEY      = "entryid";
    77      
    78      public static final String WEBLOGCATEGORYID_KEY   = "categoryId";
    79      public static final String PINGTARGETID_KEY       = "pingtargetId";
    80      public static final String REFERERID_KEY          = "refId";
    81      public static final String WEBLOGCOMMENTID_KEY    = "commentId";
    82      public static final String WEBSITEID_KEY          = "websiteId";
    83      public static final String BOOKMARKID_KEY         = "bookmarkId";
    84      public static final String FOLDERID_KEY           = "folderId";
    85      public static final String PARENTID_KEY           = "parentId";
    86      public static final String NEWSFEEDID_KEY         = "feedId";
    87      public static final String PAGEID_KEY             = "pageId";
    88      public static final String LOGIN_COOKIE           = "sessionId";    
    89      public static final String OWNING_WEBSITE         = "OWNING_WEBSITE";    
    90  
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.rendering.velocity.deprecated.ContextLoader__static_init
              * 
              *  Postconditions:
              *    init'ed(mLogger)
              */
    91      private static Log mLogger = LogFactory.getLog(ContextLoader.class);
    92      
    93      
    94      /**
    95       * Setup the a Velocity context by loading it with objects, values, and
    96       * RollerPagePlugins needed for Weblogger page execution.
    97       */
    98      public static void setupContext(
    99              Map                 ctx,
   100              HttpServletRequest  request,
   101              HttpServletResponse response,
   102              PageContext pageContext,
   103              WeblogPageRequest pageRequest,
   104              URLStrategy urlStrategy) throws WebloggerException {
   105          
                 /* 
    P/P           *  Method: void setupContext(Map, HttpServletRequest, HttpServletResponse, PageContext, WeblogPageRequest, URLStrategy)
                  * 
                  *  Preconditions:
                  *    ctx != null
                  *    mLogger != null
                  *    init'ed(org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.instance)
                  *    init'ed(pageRequest.localeInstance)
                  *    init'ed(pageRequest.weblog)
                  *    init'ed(pageRequest.weblogCategory)
                  *    init'ed(pageRequest.weblogPage)
                  *    pageRequest != null
                  *    init'ed(pageRequest.locale)
                  *    init'ed(pageRequest.weblogDate)
                  *    ...
                  * 
                  *  Presumptions:
                  *    java.text.SimpleDateFormat:parse(...)@135 != null
                  *    java.text.SimpleDateFormat:parse(...)@145 != null
                  *    org.apache.roller.util.DateUtil:get6charDateFormat(...)@145 != null
                  *    org.apache.roller.util.DateUtil:get8charDateFormat(...)@135 != null
                  *    org.apache.roller.weblogger.pojos.Weblog:getTheme(...)@125 != null
                  * 
                  *  Postconditions:
                  *    org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.instance == One-of{old org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.instance, &new NewsfeedCache(getInstance#1)}
                  *    org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.instance != null
                  *    init'ed(pageRequest.localeInstance)
                  *    init'ed(pageRequest.weblog)
                  *    init'ed(pageRequest.weblogCategory)
                  *    possibly_updated(pageRequest.weblogEntry)
                  *    init'ed(pageRequest.weblogPage)
                  *    new LRUCache2(NewsfeedCache#2) num objects <= 1
                  *    new Locale(getLocaleInstance#1) num objects == 0
                  *    new Locale(getLocaleInstance#2) num objects == 0
                  *    ...
                  * 
                  *  Test Vectors:
                  *    pageRequest.weblogDate: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:length(...)@132: {0..7, 9..232-1}, {8}
                  *    java.lang.String:length(...)@142: {0..5, 7..232-1}, {6}
                  *    java.util.Date:after(...)@136: {0}, {1}
                  *    java.util.Date:after(...)@146: {0}, {1}
                  */
   106          mLogger.debug("setupContext( ctx = "+ctx+")");
   107          
   108          Weblog weblog = null;
   109          WeblogEntry entry = null;
   110          WeblogCategory category = null;
   111          ThemeTemplate page = null;
   112          WeblogBookmarkFolder folder = null;  // don't even know how this is involved :/
   113          Date date = null;
   114          boolean isDay = false;
   115          boolean isMonth = false;
   116          String locale = null;
   117          
   118          // get data from page request
   119          locale = pageRequest.getLocale();
   120          weblog = pageRequest.getWeblog();
   121          entry = pageRequest.getWeblogEntry();
   122          category = pageRequest.getWeblogCategory();
   123          page = pageRequest.getWeblogPage();
   124          if(page == null) {
+  125              page = weblog.getTheme().getDefaultTemplate();
   126          }
   127          
   128          // setup date, isDay, and isMonth
   129          if(pageRequest.getWeblogDate() != null) {
   130              
   131              Date now = new Date();
   132              if(pageRequest.getWeblogDate().length() == 8) {
   133                  isDay = true;
   134                  try {
   135                      date = DateUtil.get8charDateFormat().parse(pageRequest.getWeblogDate());
   136                      if(date.after(now)) {
   137                          date = now;
   138                      }
   139                  } catch(Exception e) {
   140                      // bleh
   141                  }
   142              } else if(pageRequest.getWeblogDate().length() == 6) {
   143                  isMonth = true;
   144                  try {
   145                      date = DateUtil.get6charDateFormat().parse(pageRequest.getWeblogDate());
   146                      if(date.after(now)) {
   147                          date = now;
   148                      }
   149                  } catch(Exception e) {
   150                      // bleh
   151                  }
   152              } else {
   153                  isMonth = true;
   154              }
   155          }
   156          
   157          try {
   158              // Add old page model object to context
   159              OldWeblogPageModel pageModel = new OldWeblogPageModel();
   160              pageModel.init(urlStrategy,
   161                      request,
   162                      weblog,
   163                      entry,
   164                      category,
   165                      date,
   166                      isDay,
   167                      isMonth,
   168                      locale);
   169              ctx.put("pageModel", pageModel);
   170              
   171              // along with old pages list :/
   172              ctx.put("pages", pageModel.getPages());
   173              
   174          } catch (Exception e) {
   175              throw new WebloggerException("ERROR creating Page Model",e);
   176          }
   177          
   178          // Add page helper to context
+  179          OldPageHelper pageHelper = new OldPageHelper(request, 
   180                  response, 
   181                  ctx, 
   182                  weblog, 
   183                  (date == null) ? new Date() : date, 
   184                  folder, 
   185                  page.getName(), 
   186                  pageContext,
   187                  pageRequest);
   188          ctx.put("pageHelper", pageHelper);
   189          
   190          // Load standard Weblogger objects and values into the context
   191          loadWeblogValues(ctx, weblog, pageRequest.getLocaleInstance(), request, urlStrategy);
   192          loadPathValues(ctx, request, weblog, locale, urlStrategy);
+  193          loadRssValues(ctx, request, weblog, category);
   194          loadUtilityObjects(ctx, request, weblog, page);
   195          loadRequestParamKeys(ctx);
   196          loadStatusMessage(ctx, request);
   197          
   198          // If single entry is specified, load comments too
   199          if (entry != null) {
   200              loadCommentValues(ctx, request, entry, urlStrategy);
   201          }
   202      }
   203      
   204      
   205      /**
   206       * Load website object and related objects.
   207       */
   208      private static void loadWeblogValues(
   209              Map ctx,
   210              Weblog weblog,
   211              Locale locale,
   212              HttpServletRequest request,
   213              URLStrategy urlStrategy) throws WebloggerException {
   214          
   215          // weblog cannot be null
                 /* 
    P/P           *  Method: void loadWeblogValues(Map, Weblog, Locale, HttpServletRequest, URLStrategy)
                  * 
                  *  Preconditions:
                  *    (soft) ctx != null
                  *    (soft) mLogger != null
                  * 
                  *  Presumptions:
                  *    java.util.Map:get(...)@236 != null
                  *    java.util.Map:get(...)@240 != null
                  *    org.apache.roller.weblogger.business.PropertiesManager:getProperties(...)@220 != null
                  *    org.apache.roller.weblogger.business.Weblogger:getPropertiesManager(...)@220 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@219 != null
                  *    ...
                  * 
                  *  Test Vectors:
                  *    weblog: Inverse{null}, Addr_Set{null}
                  *    java.lang.String:equals(...)@237: {0}, {1}
                  *    org.apache.roller.weblogger.pojos.WeblogTheme:getTemplateByName(...)@248: Addr_Set{null}, Inverse{null}
                  */
   216          if(weblog == null)
   217              return;
   218          
   219          Weblogger mRoller = WebloggerFactory.getWeblogger();
   220          Map props = mRoller.getPropertiesManager().getProperties();
   221          
   222          ctx.put("userName",         weblog.getHandle());
   223          ctx.put("fullName",         weblog.getName() );
   224          ctx.put("emailAddress",     weblog.getEmailAddress() );
   225          ctx.put("encodedEmail",     RegexUtil.encode(weblog.getEmailAddress()));
   226          ctx.put("obfuscatedEmail",  RegexUtil.obfuscateEmail(weblog.getEmailAddress()));
   227          
   228          // setup Locale for future rendering
   229          ctx.put("locale", weblog.getLocaleInstance());
   230          
   231          // setup Timezone for future rendering
   232          ctx.put("timezone", weblog.getTimeZoneInstance());
   233          ctx.put("timeZone", weblog.getTimeZoneInstance());
   234          ctx.put("website",WeblogWrapper.wrap(weblog, urlStrategy) );
   235          
   236          String siteName = ((RuntimeConfigProperty)props.get("site.name")).getValue();
   237          if ("Roller-based Site".equals(siteName)) siteName = "Main";
   238          ctx.put("siteName", siteName);
   239          
   240          String siteShortName = ((RuntimeConfigProperty)props.get("site.shortName")).getValue();
   241          ctx.put("siteShortName", siteShortName);
   242          
   243          // add language of the session (using locale specified by request)
   244          ctx.put("viewLocale", locale);
   245          mLogger.debug("context viewLocale = "+ctx.get( "viewLocale"));
   246          
   247          // alternative display pages - customization
   248          ThemeTemplate entryPage = weblog.getTheme().getTemplateByName("_entry");
   249          if (entryPage != null) {
   250              ctx.put("entryPage",ThemeTemplateWrapper.wrap(entryPage));
   251          }
   252          // TODO: ATLAS: no templates use this, should be safe to remove
   253          // Template descPage = weblog.getPageByName("_desc");
   254          //if (descPage != null) {
   255          //ctx.put("descPage", TemplateWrapper.wrap(descPage));
   256          //}
   257          
   258          boolean commentsEnabled =
   259                  WebloggerRuntimeConfig.getBooleanProperty("users.comments.enabled");
   260          boolean trackbacksEnabled =
   261                  WebloggerRuntimeConfig.getBooleanProperty("users.trackbacks.enabled");
   262          boolean linkbacksEnabled =
   263                  WebloggerRuntimeConfig.getBooleanProperty("site.linkbacks.enabled");
   264          
   265          ctx.put("commentsEnabled",   new Boolean(commentsEnabled) );
   266          ctx.put("trackbacksEnabled", new Boolean(trackbacksEnabled) );
   267          ctx.put("linkbacksEnabled",  new Boolean(linkbacksEnabled) );
   268      }
   269      
   270      
   271      /**
   272       * Load comments for one weblog entry and related objects.
   273       */
   274      private static void loadCommentValues(
   275              Map ctx,
   276              HttpServletRequest request,
   277              WeblogEntry entry,
   278              URLStrategy urlStrategy) throws WebloggerException {
   279          
                 /* 
    P/P           *  Method: void loadCommentValues(Map, HttpServletRequest, WeblogEntry, URLStrategy)
                  * 
                  *  Preconditions:
                  *    ctx != null
                  *    entry != null
                  *    mLogger != null
                  *    request != null
                  * 
                  *  Presumptions:
                  *    init'ed(java.lang.Boolean.TRUE)
                  *    org.apache.roller.weblogger.pojos.WeblogEntry:getStatus(...)@309 != null
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@309: {0}, {1}
                  *    javax.servlet.http.HttpServletRequest:getAttribute(...)@289: Inverse{null}, Addr_Set{null}
                  */
   280          mLogger.debug("Loading comment values");
   281          
   282          boolean escapeHtml =
   283                  !WebloggerRuntimeConfig.getBooleanProperty("users.comments.htmlenabled");
   284          ctx.put("isCommentPage",     Boolean.TRUE);
   285          ctx.put("escapeHtml",        new Boolean(escapeHtml) );
   286          ctx.put("autoformat",        new Boolean(false) );
   287          
   288          // Make sure comment form object is available in context
   289          WeblogEntryCommentForm commentForm =
   290                  (WeblogEntryCommentForm) request.getAttribute("commentForm");
   291          if ( commentForm == null ) {
   292              commentForm = new WeblogEntryCommentForm();
   293              
   294              // Set fields to spaces to please Velocity
   295              commentForm.setName("");
   296              commentForm.setEmail("");
   297              commentForm.setUrl("");
   298              commentForm.setContent("");
   299          }
   300          ctx.put("commentForm",commentForm);
   301          
   302          // Either put a preview comment in to context
   303          if(commentForm.isPreview()) {
   304              ArrayList list = new ArrayList();
   305              list.add(commentForm.getPreviewComment());
   306              ctx.put("previewComments", list);
   307          }
   308          
   309          if (entry.getStatus().equals(WeblogEntry.PUBLISHED)) {
   310              ctx.put("entry",WeblogEntryWrapper.wrap(entry, urlStrategy));
   311          }
   312      }
   313      
   314      
   315      /**
   316       * Load objects needed for RSS and Atom newsfeed generation.
   317       */
   318      private static void loadRssValues(
   319              Map ctx,
   320              HttpServletRequest request,
   321              Weblog website,
   322              WeblogCategory category)
   323              throws WebloggerException {
   324          
                 /* 
    P/P           *  Method: void loadRssValues(Map, HttpServletRequest, Weblog, WeblogCategory)
                  * 
                  *  Preconditions:
                  *    ctx != null
                  *    mLogger != null
                  *    request != null
                  *    website != null
                  * 
                  *  Test Vectors:
                  *    category: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:equalsIgnoreCase(...)@329: {0}, {1}
                  *    javax.servlet.http.HttpServletRequest:getParameter(...)@328: Addr_Set{null}, Inverse{null}
                  *    org.apache.roller.weblogger.pojos.Weblog:getEntryDisplayCount(...)@335: {1..232-1}, {-231..0}
                  */
   325          mLogger.debug("Loading rss values");
   326          
   327          int entryLength = -1;
   328          String sExcerpts = request.getParameter("excerpts");
   329          if ( sExcerpts!=null && sExcerpts.equalsIgnoreCase("true")) {
   330              entryLength = 150;
   331          }
   332          ctx.put("entryLength",  new Integer(entryLength));
   333          
   334          // Display same number of entries in feed as displayed on page
   335          int entryCount = website.getEntryDisplayCount();
   336          
   337          // But don't exceed installation-wide maxEntries settings
   338          int defaultEntries =
   339                  WebloggerRuntimeConfig.getIntProperty("site.newsfeeds.defaultEntries");
   340          if (entryCount < 1) entryCount = defaultEntries;
   341          if (entryCount > defaultEntries) entryCount = defaultEntries;
   342          ctx.put("entryCount",  new Integer(entryCount));
   343          
   344          String catname = null;
   345          String catPath = null;
   346          if (category != null ) {
   347              catname = category.getName();
   348              catPath = category.getPath();
   349          }
   350          ctx.put("catname", (catname!=null) ? catname : "");
   351          ctx.put("catPath", (catPath != null) ? catPath : "");
   352          ctx.put("updateTime", website.getLastModified());
   353          ctx.put("now", new Date());
   354      }
   355      
   356      
   357      /**
   358       * Load useful utility objects for string and date formatting.
   359       */
   360      private static void loadUtilityObjects(
   361              Map ctx,
   362              HttpServletRequest request,
   363              Weblog website,
   364              ThemeTemplate page) throws WebloggerException {
   365          
                 /* 
    P/P           *  Method: void loadUtilityObjects(Map, HttpServletRequest, Weblog, ThemeTemplate)
                  * 
                  *  Preconditions:
                  *    ctx != null
                  *    mLogger != null
                  *    init'ed(org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.instance)
                  *    request != null
                  *    (soft) org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.log != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@386 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@387 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@388 != null
                  * 
                  *  Postconditions:
                  *    org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.instance == One-of{old org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.instance, &new NewsfeedCache(getInstance#1)}
                  *    org/apache/roller/weblogger/ui/rendering/velocity/deprecated/NewsfeedCache.instance != null
                  *    new LRUCache2(NewsfeedCache#2) num objects <= 1
                  *    new NewsfeedCache(getInstance#1) num objects == new LRUCache2(NewsfeedCache#2) num objects
                  *    new NewsfeedCache(getInstance#1).aggregator_cache_enabled == 1
                  *    new NewsfeedCache(getInstance#1).aggregator_enabled == 1
                  *    init'ed(new NewsfeedCache(getInstance#1).aggregator_cache_timeout)
                  *    new NewsfeedCache(getInstance#1).mCache == &new LRUCache2(NewsfeedCache#2)
                  * 
                  *  Test Vectors:
                  *    website: Addr_Set{null}, Inverse{null}
                  */
   366          mLogger.debug("Loading utility objects");
   367          
   368          // date formatter for macro's set this up with the Locale to make
   369          // sure we can reuse it with other patterns in the macro's
   370          Locale viewLocale = (Locale) ctx.get("viewLocale");
   371          SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", viewLocale);
   372          if (website != null) {
   373              sdf.setTimeZone(website.getTimeZoneInstance());
   374          }
   375          // add formatter to context
   376          ctx.put("dateFormatter", sdf );
   377          
   378          // Note: in the macro's, the formats are taken from the ResourceBundles.
   379          // Only the plainFormat is specified here, because it is used to render
   380          // the Entry Day link.
   381          ctx.put("plainFormat", "yyyyMMdd");
   382          
   383          ctx.put("page",ThemeTemplateWrapper.wrap(page));
   384          ctx.put("utilities",       new OldUtilities() );
   385          ctx.put("stringUtils",     new OldStringUtils() );
   386          ctx.put("rollerVersion",   WebloggerFactory.getWeblogger().getVersion() );
   387          ctx.put("rollerBuildTime", WebloggerFactory.getWeblogger().getBuildTime() );
   388          ctx.put("rollerBuildUser", WebloggerFactory.getWeblogger().getBuildUser() );
   389          ctx.put("newsfeedCache",   NewsfeedCache.getInstance() );
   390          
   391          ctx.put("requestParameters", request.getParameterMap());
   392      }
   393      
   394      
   395      /**
   396       * Load URL paths useful in page templates.
   397       */
   398      private static void loadPathValues(
   399              Map ctx,
   400              HttpServletRequest request,
   401              Weblog   website,
   402              String locale,
   403              URLStrategy urlStrategy) throws WebloggerException {
   404          
                 /* 
    P/P           *  Method: void loadPathValues(Map, HttpServletRequest, Weblog, String, URLStrategy)
                  * 
                  *  Preconditions:
                  *    ctx != null
                  *    mLogger != null
                  *    (soft) urlStrategy != null
                  * 
                  *  Test Vectors:
                  *    website: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:equals(...)@408: {1}, {0}
                  */
   405          mLogger.debug("Loading path values");
   406          
   407          String url = null;
   408          if (website != null  && !"zzz_none_zzz".equals(website.getHandle())) {
   409              url = urlStrategy.getWeblogURL(website, locale, true);
   410          } else {
   411              url= WebloggerRuntimeConfig.getAbsoluteContextURL();
   412          }
   413          ctx.put("websiteURL", url);
   414          ctx.put("baseURL",    WebloggerRuntimeConfig.getRelativeContextURL() );
   415          ctx.put("absBaseURL", WebloggerRuntimeConfig.getAbsoluteContextURL() );
   416          ctx.put("ctxPath",    WebloggerRuntimeConfig.getRelativeContextURL() );
   417          ctx.put("uploadPath", ContextLoader.figureResourcePath());
   418          
   419          try {
   420              URL absUrl = new URL(WebloggerRuntimeConfig.getAbsoluteContextURL());
   421              ctx.put("host", absUrl.getHost());
   422          } catch (MalformedURLException e) {
   423              throw new WebloggerException(e);
   424          }
   425      }
   426      
   427      
   428      /**
   429       * Determine URL path to Weblogger upload directory.
   430       */
   431      private static String figureResourcePath() {
   432          
   433          // legacy junk.  this no longer makes any sense as of 3.0, but oh well
                 /* 
    P/P           *  Method: String figureResourcePath()
                  * 
                  *  Postconditions:
                  *    return_value == &".resources"
                  */
   434          return "/resources";
   435      }
   436      
   437      
   438      /**
   439       * If there is an ERROR or STATUS message in the session,
   440       * place it into the Context for rendering later.
   441       */
   442      private static void loadStatusMessage(Map ctx, HttpServletRequest req) {
   443          
                 /* 
    P/P           *  Method: void loadStatusMessage(Map, HttpServletRequest)
                  * 
                  *  Preconditions:
                  *    mLogger != null
                  *    req != null
                  *    (soft) ctx != null
                  * 
                  *  Test Vectors:
                  *    javax.servlet.http.HttpServletRequest:getSession(...)@446: Addr_Set{null}, Inverse{null}
                  */
   444          mLogger.debug("Loading status message");
   445          
   446          HttpSession session = req.getSession(false);
   447          String msg = null;
   448          if (session != null)
   449              msg = (String)session.getAttribute(RollerSession.ERROR_MESSAGE);
   450          if (msg != null) {
   451              ctx.put("errorMessage", msg);
   452              session.removeAttribute(RollerSession.ERROR_MESSAGE);
   453          }
   454          
   455          if (session != null)
   456              msg = (String)session.getAttribute(RollerSession.STATUS_MESSAGE);
   457          if (msg != null) {
   458              ctx.put("statusMessage", msg);
   459              session.removeAttribute(RollerSession.STATUS_MESSAGE);
   460          }
   461      }
   462      
   463      
   464      private static void loadRequestParamKeys(Map ctx) {
   465          
                 /* 
    P/P           *  Method: void loadRequestParamKeys(Map)
                  * 
                  *  Preconditions:
                  *    ctx != null
                  *    mLogger != null
                  */
   466          mLogger.debug("Loading request param keys");
   467          
   468          // Since Velocity *requires* accessor methods, these values from
   469          // RollerRequest are not available to it, put them into the context
   470          ctx.put("USERNAME_KEY",           USERNAME_KEY);
   471          ctx.put("WEBSITEID_KEY",          WEBSITEID_KEY);
   472          ctx.put("FOLDERID_KEY",           FOLDERID_KEY);
   473          ctx.put("NEWSFEEDID_KEY",         NEWSFEEDID_KEY);
   474          ctx.put("PAGEID_KEY",             PAGEID_KEY);
   475          ctx.put("PAGELINK_KEY",           PAGELINK_KEY);
   476          ctx.put("ANCHOR_KEY",             ANCHOR_KEY);
   477          ctx.put("EXCERPTS_KEY",           EXCERPTS_KEY);
   478          ctx.put("BOOKMARKID_KEY",         BOOKMARKID_KEY);
   479          ctx.put("REFERERID_KEY",          REFERERID_KEY);
   480          ctx.put("WEBLOGENTRYID_KEY",      WEBLOGENTRYID_KEY);
   481          ctx.put("WEBLOGCATEGORYNAME_KEY", WEBLOGCATEGORYNAME_KEY);
   482          ctx.put("WEBLOGCATEGORYID_KEY",   WEBLOGENTRIES_KEY);
   483          ctx.put("WEBLOGENTRIES_KEY",      WEBLOGENTRIES_KEY);
   484          ctx.put("WEBLOGDAY_KEY",          WEBLOGDAY_KEY);
   485          ctx.put("WEBLOGCOMMENTID_KEY",    WEBLOGCOMMENTID_KEY);
   486      }
   487         
   488  }








SofCheck Inspector Build Version : 2.18479
ContextLoader.java 2009-Jan-02 14:25:20
ContextLoader.class 2009-Sep-04 03:12:45