public List<String> getCategoriesByURI(String URI, IWContext iwc) {
   List<String> categories = new ArrayList<String>();
   BuilderService bservice = null;
   String property = null;
   try {
     bservice = BuilderServiceFactory.getBuilderService(iwc);
   } catch (RemoteException e) {
     e.printStackTrace();
   }
   String pageKey = bservice.getExistingPageKeyByURI(CoreConstants.SLASH + URI);
   List<String> moduleId = bservice.getModuleId(pageKey, ArticleListViewer.class.getName());
   if (moduleId != null) {
     for (int i = 0; i < moduleId.size(); i++) {
       property = bservice.getProperty(pageKey, moduleId.get(i), "categories");
       if (property != null) {
         if (property.indexOf(",") != -1) {
           Collection<String> strings = ListUtil.convertCommaSeparatedStringToList(property);
           for (String string : strings) {
             categories.add(string);
           }
         } else {
           categories.add(property);
         }
       } else {
         // Article list viewer without property - displaying all pages
         categories = null;
       }
     }
   }
   return categories;
 }
  private boolean addAttachment(CommentsViewerProperties properties, Comment comment) {
    if (ListUtil.isEmpty(properties.getUploadedFiles())) {
      return true;
    }

    try {
      ICFileHome fileHome = getFileHome();
      for (String uploadedFile : properties.getUploadedFiles()) {
        if (!uploadedFile.startsWith(CoreConstants.WEBDAV_SERVLET_URI)) {
          uploadedFile =
              new StringBuilder(CoreConstants.WEBDAV_SERVLET_URI).append(uploadedFile).toString();
        }

        ICFile file = fileHome.create();

        file.setName(
            URLEncoder.encode(
                uploadedFile.substring(uploadedFile.lastIndexOf(CoreConstants.SLASH) + 1),
                CoreConstants.ENCODING_UTF8));
        file.setFileUri(URLEncoder.encode(uploadedFile, CoreConstants.ENCODING_UTF8));

        file.store();

        comment.addAttachment(file);
      }
      comment.store();
      return true;
    } catch (Exception e) {
      LOGGER.log(Level.WARNING, "Unable to add attachments: " + properties.getUploadedFiles(), e);
    }
    return false;
  }
  @SuppressWarnings("unchecked")
  public String getFeedContent(Feed feed) {
    if (feed == null) {
      LOGGER.warning("Feed is unknown!");
      return null;
    }

    Date updated = new Date(System.currentTimeMillis());
    feed.setUpdated(updated);
    List<Module> modules = feed.getModules();
    if (!ListUtil.isEmpty(modules)) {
      for (Module module : modules) {
        if (module instanceof DCModule) {
          ((DCModule) module).setDate(updated);
        }
      }
    }

    try {
      return wfo.outputString(feed);
    } catch (Exception e) {
      LOGGER.log(Level.WARNING, "Error while outputing feed to string: " + feed, e);
      return null;
    }
  }
  @SuppressWarnings("deprecation")
  String removeUselessSessions() {
    if (!isManagementOfSessionsTurnedOn()) {
      return CoreConstants.EMPTY;
    }

    if (sessions.isEmpty() || sessions.size() <= 0) {
      return CoreConstants.EMPTY;
    }

    Set<String> keysSet = sessions.keySet();
    if (ListUtil.isEmpty(keysSet)) {
      return CoreConstants.EMPTY;
    }
    List<String> keys = new ArrayList<String>(keysSet);

    List<String> sessionsToRemove = new ArrayList<String>();
    long currentTime = System.currentTimeMillis();
    for (String key : keys) {
      HttpSession session = sessions.get(key);
      if (session == null) {
        continue;
      }

      long idleTime = currentTime - session.getLastAccessedTime();
      if (idleTime >= 600000) {
        //	Session "was" idle for 10 minutes or more

        Object chibaManager = session.getAttribute("chiba.session.manager");
        if (chibaManager != null) {
          continue;
        }

        Object principal = session.getValue("org.apache.slide.webdav.method.principal");
        //	Checking if session was created by Slide's root user
        if (principal instanceof String && "root".equals(principal)) {
          sessionsToRemove.add(session.getId());
        }
      }
    }

    for (String sessionId : sessionsToRemove) {
      removeSession(sessionId);
    }

    return ListUtil.isEmpty(sessionsToRemove) ? CoreConstants.EMPTY : sessionsToRemove.toString();
  }
  @Override
  public void handleRSSRequest(RSSRequest rssRequest) throws IOException {
    String feedParentFolder = null;
    String feedFile = null;
    String category = getCategory(rssRequest.getExtraUri());
    String extraURI = rssRequest.getExtraUri();
    if (extraURI == null) {
      extraURI = CoreConstants.EMPTY;
    }
    if ((!extraURI.endsWith(CoreConstants.SLASH)) && (extraURI.length() != 0)) {
      extraURI = extraURI.concat(CoreConstants.SLASH);
    }

    List<String> categories = new ArrayList<String>();
    List<String> articles = new ArrayList<String>();
    if (category != null) categories.add(category);

    IWContext iwc = getIWContext(rssRequest);
    String language = iwc.getLocale().getLanguage();

    if (StringUtil.isEmpty(extraURI)) {
      feedParentFolder = ARTICLE_RSS;
      feedFile = "all_".concat(language).concat(".xml");
    } else if (category != null) {
      feedParentFolder =
          ARTICLE_RSS.concat("category/").concat(category).concat(CoreConstants.SLASH);
      feedFile = "feed_.".concat(language).concat(".xml");
    } else {
      //	Have page URI
      feedParentFolder = ARTICLE_RSS.concat("page/").concat(extraURI);
      feedFile = "feed_".concat(language).concat(".xml");
      categories = getCategoriesByURI(extraURI, iwc);
      if (ListUtil.isEmpty(categories)) {
        articles = getArticlesByURI(extraURI, iwc);
      }
    }

    String realURI = CoreConstants.WEBDAV_SERVLET_URI + feedParentFolder + feedFile;
    if (rssFileURIsCacheList.contains(feedFile)) {
      try {
        this.dispatch(realURI, rssRequest);
      } catch (ServletException e) {
        LOGGER.log(Level.WARNING, "Error dispatching: " + realURI, e);
      }
    } else {
      //	Generate RSS and store and the dispatch to it and add a listener to that directory
      try {
        // todo code the 3 different cases (see description)
        searchForArticles(rssRequest, feedParentFolder, feedFile, categories, articles, extraURI);
        rssFileURIsCacheList.add(feedFile);

        this.dispatch(realURI, rssRequest);
      } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error while searching or dispatching: " + realURI, e);
        throw new IOException(e.getMessage());
      }
    }
  }
  public void getSelectedAndNotSelectedCategories(IWContext iwc) {
    this.selectedCategories = new ArrayList<ContentCategory>();
    this.notSelectedCategories = new ArrayList<ContentCategory>();

    Locale locale = getLocale(iwc);

    Collection<String> selectedCategories = null;
    try {
      selectedCategories = getSetCategoriesList();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (!ListUtil.isEmpty(selectedCategories)) {
      ContentCategory category = null;
      for (Iterator<String> selectedIter = selectedCategories.iterator();
          selectedIter.hasNext(); ) {
        String categoryKey = selectedIter.next();
        category = CategoryBean.getInstance().getCategory(categoryKey);
        if (category != null) {
          if (category.getName(locale.toString()) != null && !category.isDisabled()) {
            //	Category exists for current locale and it's not disabled
            this.selectedCategories.add(category);
          }
        }
      }
    }

    List<String> providedCategoriesKeys = getProvidedCategoriesKeys();
    Collection<ContentCategory> categories = CategoryBean.getInstance().getCategories(locale);
    if (categories == null) {
      localizedCategories = 0;
    } else {
      localizedCategories = categories.size();

      for (ContentCategory category : categories) {
        if (!category.isDisabled()
            && (selectedCategories == null || !selectedCategories.contains(category.getId()))) {
          if (providedCategoriesKeys != null && providedCategoriesKeys.contains(category.getId())) {
            this.selectedCategories.add(category);
          } else {
            this.notSelectedCategories.add(category);
          }
        }
      }
    }

    if (this.selectedCategories.size() == 0 && this.notSelectedCategories.size() == 0) {
      needDisplayCategoriesSelection = false;
    } else if (setCategories != null && this.selectedCategories.size() == 1) {
      needDisplayCategoriesSelection =
          false; //	If is set only one category, not showing categories editor
    } else {
      needDisplayCategoriesSelection = true; // 	Showing categories to user
    }

    areCategoriesFetched = true;
  }
  protected List<User> getUsersHavingHandlerRole() {
    String roleKey = getHandlerRoleKey();
    if (StringUtil.isEmpty(roleKey)) {
      return null;
    }

    IWApplicationContext iwac = IWMainApplication.getDefaultIWApplicationContext();
    AccessController accessControler =
        IWMainApplication.getDefaultIWMainApplication().getAccessController();
    Collection<Group> groupsWithRole = accessControler.getAllGroupsForRoleKey(roleKey, iwac);
    if (ListUtil.isEmpty(groupsWithRole)) {
      return null;
    }

    UserBusiness userBusiness = getUserBusiness();
    if (userBusiness == null) {
      return null;
    }

    List<User> users = new ArrayList<User>();
    for (Group group : groupsWithRole) {
      if (group instanceof User) {
        User user = (User) group;
        if (!users.contains(user)) {
          users.add(user);
        }
      } else {
        Collection<User> usersInGroup = null;
        try {
          usersInGroup = userBusiness.getUsersInGroup(group);
        } catch (Exception e) {
          LOGGER.log(Level.WARNING, "Error getting users in group: " + group, e);
        }
        if (!ListUtil.isEmpty(usersInGroup)) {
          for (User user : usersInGroup) {
            if (!users.contains(user)) {
              users.add(user);
            }
          }
        }
      }
    }

    return users;
  }
  private List<ContentCategory> getSortedCategories(
      List<ContentCategory> categories, Locale locale) {
    if (ListUtil.isEmpty(categories)) {
      return categories;
    }

    Collections.sort(categories, new ContentCategoryComparator(locale));
    return categories;
  }
  private RemoteScriptingResults handleShirtSizeUpdate(
      IWContext iwc, String sourceName, String distanceIdString) {
    IWResourceBundle iwrb = getResourceBundle(iwc);
    if (distanceIdString != null) {
      Integer distanceID = Integer.valueOf(distanceIdString);
      RunBusiness runBiz = getRunBiz(iwc);

      try {
        Vector ids = new Vector();
        Vector names = new Vector();

        String shirtSizeMetadata = null;
        if (distanceID.intValue() != -1) {
          Group runDistance = runBiz.getRunGroupByGroupId(distanceID);
          shirtSizeMetadata = runDistance.getMetaData(PARAMETER_SHIRT_SIZES_PER_RUN);
        }
        List shirtSizes = null;
        if (shirtSizeMetadata != null) {
          shirtSizes = ListUtil.convertCommaSeparatedStringToList(shirtSizeMetadata);
          Iterator shirtIt = shirtSizes.iterator();
          // ShirtSizeHome shirtSizeHome = (ShirtSizeHome) IDOLookup.getHome(ShirtSize.class);

          if (shirtIt.hasNext()) {
            ids.add("-1");
            names.add(
                iwrb.getLocalizedString(
                    "run_distance_dd.select_shirt_size", "Select shirt size..."));
          }
          while (shirtIt.hasNext()) {
            String shirtSizeKey = (String) shirtIt.next();
            // ShirtSize shirtSize = shirtSizeHome.findByPrimaryKey(shirtSizeKey);
            // String s = iwrb.getLocalizedString(shirtSize.getName(),shirtSize.getName());
            ids.add(shirtSizeKey);
            names.add(iwrb.getLocalizedString("shirt_size." + shirtSizeKey, shirtSizeKey));
          }
          if (shirtSizes.isEmpty()) {
            ids.add("-1");
            names.add(iwrb.getLocalizedString("unavailable", "Unavailable"));
          }
        } else {
          ids.add("-1");
          names.add(iwrb.getLocalizedString("unavailable", "Unavailable"));
        }

        RemoteScriptingResults rsr =
            new RemoteScriptingResults(RemoteScriptHandler.getLayerName(sourceName, "id"), ids);
        rsr.addLayer(RemoteScriptHandler.getLayerName(sourceName, "name"), names);

        return rsr;

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return null;
  }
  public Map<String, String> getUriToDocument(
      FileDownloadNotificationProperties properties, String identifier, List<User> users) {
    if (properties == null || ListUtil.isEmpty(users)) {
      return null;
    }

    Map<String, String> uris = new HashMap<String, String>(users.size());
    for (User user : users) {
      uris.put(user.getId(), properties.getUrl());
    }
    return uris;
  }
 public Collection<Email> getEmails() {
   IWContext iwc = getIwc();
   if (!iwc.isLoggedOn()) {
     return Collections.emptyList();
   }
   User user = iwc.getCurrentUser();
   @SuppressWarnings("unchecked")
   Collection<Email> emails = user.getEmails();
   if (ListUtil.isEmpty(emails)) {
     return Collections.emptyList();
   }
   return emails;
 }
 public Collection<Phone> getPhones() {
   IWContext iwc = getIwc();
   if (!iwc.isLoggedOn()) {
     return Collections.emptyList();
   }
   User user = iwc.getCurrentUser();
   @SuppressWarnings("unchecked")
   Collection<Phone> phones = user.getPhones();
   if (ListUtil.isEmpty(phones)) {
     return Collections.emptyList();
   }
   return phones;
 }
Пример #13
0
  /*
   * (non-Javadoc)
   * @see com.idega.user.data.GroupHome#findGroups(java.util.Collection)
   */
  @Override
  public Collection<Group> findGroups(Collection<String> groupIDs) {
    if (ListUtil.isEmpty(groupIDs)) {
      return Collections.emptyList();
    }

    try {
      return findGroups(ArrayUtil.convertListToArray(groupIDs));
    } catch (FinderException e) {
      java.util.logging.Logger.getLogger(getClass().getName())
          .warning(
              "Failed to get "
                  + getEntityInterfaceClass().getSimpleName()
                  + " by id's: '"
                  + groupIDs
                  + "'");
    }

    return Collections.emptyList();
  }
  protected List<String> getEmails(Collection<User> users) {
    if (ListUtil.isEmpty(users)) {
      return null;
    }

    UserBusiness userBusiness = getUserBusiness();
    if (userBusiness == null) {
      return null;
    }

    List<String> emails = new ArrayList<String>(users.size());
    for (User user : users) {
      Email email = getEmail(user);
      String emailAddress = email == null ? null : email.getEmailAddress();
      if (!StringUtil.isEmpty(emailAddress) && !emails.contains(emailAddress)) {
        emails.add(emailAddress);
      }
    }

    return emails;
  }
  @SuppressWarnings("unchecked")
  public void searchForArticles(
      RSSRequest rssRequest,
      String feedParentPath,
      String feedFileName,
      List<String> categories,
      List<String> articles,
      String extraURI) {

    IWContext iwc = getIWContext(rssRequest);
    boolean getAllArticles = false;

    if (StringUtil.isEmpty(extraURI)) {
      getAllArticles = true;
    }

    String serverName = iwc.getServerURL();
    serverName = serverName.substring(0, serverName.length() - 1);

    Collection<SearchResult> results = getArticleSearchResults(PATH, categories, iwc);
    if (ListUtil.isEmpty(results)) {
      LOGGER.warning("No results found in: " + PATH + " by the categories: " + categories);
      return;
    }

    List<String> urisToArticles = new ArrayList<String>();
    for (SearchResult result : results) {
      urisToArticles.add(result.getSearchResultURI());
    }

    if (!ListUtil.isEmpty(articles)) {
      if (ListUtil.isEmpty(categories)) {
        urisToArticles = articles;
      } else {
        urisToArticles.addAll(articles);
      }
    }

    if (!ListUtil.isEmpty(articles) && ListUtil.isEmpty(categories)) urisToArticles = articles;

    RSSBusiness rss = null;
    SyndFeed articleFeed = null;
    long time = System.currentTimeMillis();
    try {
      rss = IBOLookup.getServiceInstance(iwc, RSSBusiness.class);
    } catch (IBOLookupException e) {
      LOGGER.log(Level.WARNING, "Error getting " + RSSBusiness.class, e);
    }

    String description = CoreConstants.EMPTY;
    String title = CoreConstants.EMPTY;
    if (ListUtil.isEmpty(results) && !getAllArticles) {
      description = "No articles found. Empty feed";
    } else {
      description =
          "Article feed generated by IdegaWeb ePlatform, Idega Software, http://www.idega.com";

      BuilderService bservice = null;
      String pageKey = null;
      try {
        if (!StringUtil.isEmpty(extraURI)) {
          bservice = BuilderServiceFactory.getBuilderService(iwc);
          pageKey = bservice.getExistingPageKeyByURI(CoreConstants.SLASH + extraURI);
          ICPage icpage = bservice.getICPage(pageKey);
          title = icpage.getName();
        }
      } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error getting page name from: " + extraURI, e);
      }

      String lang = iwc.getCurrentLocale().getLanguage();
      SyndFeed allArticles =
          rss.createNewFeed(title, serverName, description, "atom_1.0", lang, new Timestamp(time));

      List<SyndEntry> allEntries = new ArrayList<SyndEntry>();
      for (int i = 0; i < urisToArticles.size(); i++) {
        String articleURL =
            serverName
                .concat(urisToArticles.get(i))
                .concat(CoreConstants.SLASH)
                .concat(lang)
                .concat(".xml");
        articleFeed = rss.getFeed(articleURL);
        if (articleFeed != null) allEntries.addAll(articleFeed.getEntries());
      }

      allArticles.setEntries(allEntries);
      String allArticlesContent = null;
      try {
        allArticlesContent = rss.convertFeedToAtomXMLString(allArticles);
      } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error converting to Atom from: " + allArticles, e);
      }

      try {
        IWSlideService service = this.getIWSlideService(rssRequest);
        service.uploadFileAndCreateFoldersFromStringAsRoot(
            feedParentPath,
            feedFileName,
            allArticlesContent,
            RSSAbstractProducer.RSS_CONTENT_TYPE,
            true);
      } catch (RemoteException e) {
        LOGGER.log(
            Level.WARNING,
            "Error uploading to: " + feedParentPath + feedFileName + " file: " + allArticlesContent,
            e);
      }
    }
  }
Пример #16
0
  /**
   * Creates {@link org.w3.dom.Document} with structure
   * <\tableRow><\ColumName>Value<\/ColumName><\/tableRow>. ColumnName's are parsed from {@link
   * com.idega.util.text.TableRecord#getItems()}.
   *
   * @param list {@link Collection} of {@link com.idega.util.text.TableRecord}.
   * @return {@link org.w3.dom.Document} or null if error happen.
   */
  public static Document createTableDocument(Collection<TableRecord> list) {
    if (ListUtil.isEmpty(list)) {
      return null;
    }

    DocumentBuilder documentBuilder = null;
    try {
      documentBuilder = XmlUtil.getDocumentBuilder();
    } catch (ParserConfigurationException e) {
      LOGGER.log(Level.WARNING, "Unable to create table document.", e);
      return null;
    }

    if (documentBuilder == null) {
      return null;
    }

    Document document = documentBuilder.newDocument();
    if (document == null) {
      return null;
    }

    Element localeElement = document.createElement(items);
    if (localeElement == null) {
      return null;
    }

    for (TableRecord tableRecord : list) {
      Element itemElem = document.createElement(tableRow);
      if (itemElem == null) {
        continue;
      }

      Map<String, String> data = tableRecord.getItems();
      if (MapUtil.isEmpty(data)) {
        continue;
      }

      for (Iterator<Map.Entry<String, String>> iter = data.entrySet().iterator();
          iter.hasNext(); ) {
        Map.Entry<String, String> entry = iter.next();
        if (entry == null) {
          continue;
        }

        String key = entry.getKey();
        String value = entry.getValue();
        if (StringUtil.isEmpty(key) || StringUtil.isEmpty(value)) {
          continue;
        }

        Element itemValueElem = document.createElement(key);
        if (itemValueElem == null) {
          continue;
        }

        itemValueElem.setTextContent(value);
        itemElem.appendChild(itemValueElem);
      }

      Document documentOfItemNode = localeElement.getOwnerDocument();
      if (documentOfItemNode == null) {
        continue;
      }

      Node itemNode = documentOfItemNode.importNode(itemElem, true);
      if (itemNode == null) {
        continue;
      }

      localeElement.appendChild(itemNode);
    }

    document.appendChild(localeElement);
    return document;
  }
  private Table2 getRaceParticipantListForEvent(
      IWContext iwc, List eventParticipants, RaceEvent raceEvent) throws RemoteException {
    Table2 table = new Table2();
    table.setStyleClass("raceParticipantTable");
    table.setStyleClass("ruler");
    table.setWidth("100%");
    table.setCellpadding(0);
    table.setCellspacing(0);

    TableRowGroup group = table.createHeaderRowGroup();
    TableRow row = group.createRow();
    TableCell2 cell = row.createHeaderCell();
    cell.setStyleClass("firstColumn");
    cell.setStyleClass("raceNumber");
    cell.add(
        new Text(getResourceBundle().getLocalizedString("race_participant_list.race_number", "#")));

    cell = row.createHeaderCell();
    cell.setStyleClass("name");
    cell.add(
        new Text(getResourceBundle().getLocalizedString("race_participant_list.name", "Name")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceVehicle");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_vehicle", "Race vehicle")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceVehicleSubtype");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_vehicle_subtype", "Subtype")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceEngineCC");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_engine_CC", "Engine CC")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceEngine");
    cell.add(
        new Text(
            getResourceBundle().getLocalizedString("race_participant_list.race_engine", "Engine")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceTeam");
    cell.add(
        new Text(
            getResourceBundle().getLocalizedString("race_participant_list.race_team", "Team")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceSponsor");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_sponsor", "Sponsor")));

    group = table.createBodyRowGroup();
    int iRow = 1;

    if (!ListUtil.isEmpty(eventParticipants)) {
      Iterator iter = eventParticipants.iterator();
      while (iter.hasNext()) {
        Participant participant = (Participant) iter.next();
        if (participant == null) {
          getLogger().warning("Participant is unknown for race event: " + raceEvent);
          continue;
        }

        row = group.createRow();

        User user = null;
        RaceUserSettings settings = null;
        try {
          user = participant.getUser();
          settings = this.getRaceBusiness(iwc).getRaceUserSettings(user);
        } catch (Exception e) {
          getLogger()
              .log(
                  Level.WARNING,
                  "Error getting settings for participant "
                      + participant
                      + ", user: "******"" : "(ID: " + user.getId() + ")")
                      + ". Race event: "
                      + raceEvent,
                  e);
        }
        if (user == null) {
          getLogger()
              .warning(
                  "User can not be found for participant "
                      + participant
                      + ", race event: "
                      + raceEvent);
        }
        if (settings == null) {
          getLogger()
              .warning(
                  "Settings can not be found for participant "
                      + participant
                      + ", race event: "
                      + raceEvent);
        }

        if (iRow == 1) {
          row.setStyleClass("firstRow");
        } else if (!iter.hasNext()) {
          row.setStyleClass("lastRow");
        }

        cell = row.createCell();
        cell.setStyleClass("firstColumn");
        cell.setStyleClass("raceNumber");
        cell.add(new Text(participant.getRaceNumber() != null ? participant.getRaceNumber() : ""));

        cell = row.createCell();
        cell.setStyleClass("name");
        cell.add(new Text(user != null ? user.getName() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceVehicle");
        String raceVehicleString = "";
        if (settings != null && settings.getVehicleType() != null) {
          raceVehicleString =
              getResourceBundle()
                  .getLocalizedString(
                      settings.getVehicleType().getLocalizationKey(),
                      settings.getVehicleType().getLocalizationKey());
        }
        cell.add(new Text(raceVehicleString));

        cell = row.createCell();
        cell.setStyleClass("raceVehicleSubtype");
        String raceVehicleSubtypeString = "";
        if (settings != null && settings.getVehicleSubType() != null) {
          raceVehicleSubtypeString =
              getResourceBundle()
                  .getLocalizedString(
                      settings.getVehicleSubType().getLocalizationKey(),
                      settings.getVehicleSubType().getLocalizationKey());
        }
        cell.add(new Text(raceVehicleSubtypeString));

        cell = row.createCell();
        cell.setStyleClass("raceEngineCC");
        cell.add(
            new Text(
                settings == null
                    ? ""
                    : settings.getEngineCC() != null ? settings.getEngineCC() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceEngine");
        cell.add(
            new Text(
                settings == null ? "" : settings.getEngine() != null ? settings.getEngine() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceTeam");
        cell.add(
            new Text(settings == null ? "" : settings.getTeam() != null ? settings.getTeam() : ""));

        StringBuffer sponsorString = new StringBuffer("");
        if (settings != null && settings.getSponsor() != null) {
          if (settings.getSponsor().length() > 30) {
            sponsorString.append(settings.getSponsor().substring(0, 30));
          } else {
            sponsorString.append(settings.getSponsor());
          }
        }
        cell = row.createCell();
        cell.setStyleClass("raceSponsor");
        cell.add(new Text(sponsorString.toString()));

        if (iRow % 2 == 0) {
          row.setStyleClass("evenRow");
        } else {
          row.setStyleClass("oddRow");
        }

        iRow++;
      }
    } else {
      getLogger().warning("Participants not provided");
    }

    return table;
  }
  /**
   * Creates a table with checkboxes for all the available categories
   *
   * @param resourcePath
   * @return table
   */
  private Table getCategoriesTable(IWContext iwc, boolean submitted) {
    if (!areCategoriesFetched) {
      getSelectedAndNotSelectedCategories(iwc);
    }

    Table categoriesTable = new Table();
    int categoriesCount = 0;
    Locale locale = getLocale(iwc);

    List<ContentCategory> allCategories = new ArrayList<ContentCategory>(selectedCategories);
    allCategories.addAll(notSelectedCategories);
    allCategories = getSortedCategories(allCategories, locale);
    if (ListUtil.isEmpty(allCategories)) {
      return categoriesTable;
    }

    for (ContentCategory category : allCategories) {
      HtmlSelectBooleanCheckbox categoryCheckBox =
          (HtmlSelectBooleanCheckbox)
              iwc.getApplication().createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE);
      categoryCheckBox.setId(getCategoryKey(category));
      if (selectedCategories.contains(category)) {
        categoryCheckBox.setSelected(Boolean.TRUE);
      } else {
        if (!submitted) {
          if (notSelectedCategories.size() == 1
              && selectedCategories.size() == 0
              && selectAnyCategory) {
            categoryCheckBox.setSelected(Boolean.TRUE);
          }
        }
      }
      categoriesTable.add(
          categoryCheckBox, categoriesCount % COLLUMNS + 1, categoriesCount / COLLUMNS + 1);

      Label categoryName = new Label(category.getName(locale.toString()), categoryCheckBox);
      categoriesTable.add(
          categoryName, categoriesCount % COLLUMNS + 1, categoriesCount / COLLUMNS + 1);
      categoriesCount++;
    }

    categoriesTable.setColumns(Math.min(categoriesCount, COLLUMNS));
    categoriesCount--;
    categoriesTable.setRows(categoriesCount / COLLUMNS + 1);

    if (getDisplaySaveButton()) {
      //	Add the save button
      if (this.resourcePath != null && this.resourcePath.length() > 0) {
        WFResourceUtil localizer = WFResourceUtil.getResourceUtilContent();
        HtmlCommandButton addCategoryButton =
            localizer.getButtonVB(getSaveButtonId(), "save", this);
        categoriesTable.add(addCategoryButton, 1, categoriesCount / COLLUMNS + 2);
        categoriesTable.setRows(categoriesCount / COLLUMNS + 2);
      }
    }

    categoriesTable.setId(categoriesTable.getId() + "_ver");
    categoriesTable.setStyleClass("wf_listtable");

    return categoriesTable;
  }