code: public static String getContextName(ExternalContext ec)
      {
          try
          {
              if (isPortlet(ec))
              {
                  return (String) _runMethod(ec.getContext(),
                          "getPortletContextName");
              }
              else
              {
                  return ((ServletContext) ec.getContext())
                          .getServletContextName();
              }
          }
          catch (final ClassCastException e)
          {
              _LOG.severe(e.getMessage());
          }
          return null;
      }
docs: Returns the name of the underlying context or <code>null</code> if something
  went wrong in trying to retrieve the context.
  
  @param ec the current external context
  @return a String containing the context name