public Theme getTheme(long companyId, String themeId, boolean wapTheme) throws SystemException {

    themeId = GetterUtil.getString(themeId);

    Map<String, Theme> themes = _getThemes(companyId);

    Theme theme = themes.get(themeId);

    if (theme == null) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No theme found for specified theme id " + themeId + ". Returning the default theme.");
      }

      if (wapTheme) {
        themeId = ThemeImpl.getDefaultWapThemeId(companyId);
      } else {
        themeId = ThemeImpl.getDefaultRegularThemeId(companyId);
      }

      theme = _themes.get(themeId);
    }

    if (theme == null) {
      if (_themes.isEmpty()) {
        if (_log.isDebugEnabled()) {
          _log.debug("No themes are installed");
        }

        return null;
      }

      if (!themeId.contains(PortletConstants.WAR_SEPARATOR)) {
        _log.error(
            "No theme found for default theme id " + themeId + ". Returning a random theme.");
      }

      for (Map.Entry<String, Theme> entry : _themes.entrySet()) {
        theme = entry.getValue();
      }
    }

    return theme;
  }
  public Theme getTheme(long companyId, String themeId, boolean wapTheme) throws SystemException {

    themeId = GetterUtil.getString(themeId);

    Theme theme = _getThemes(companyId).get(themeId);

    if (theme == null) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No theme found for specified theme id " + themeId + ". Returning the default theme.");
      }

      if (wapTheme) {
        themeId = ThemeImpl.getDefaultWapThemeId(companyId);
      } else {
        themeId = ThemeImpl.getDefaultRegularThemeId(companyId);
      }

      theme = _themes.get(themeId);
    }

    if (theme == null) {
      if (_themes.isEmpty()) {
        if (_log.isDebugEnabled()) {
          _log.debug("No themes are installed");
        }

        return null;
      }

      _log.error("No theme found for default theme id " + themeId + ". Returning a random theme.");

      Iterator<Map.Entry<String, Theme>> itr = _themes.entrySet().iterator();

      while (itr.hasNext()) {
        Map.Entry<String, Theme> entry = itr.next();

        theme = entry.getValue();
      }
    }

    return theme;
  }