protected void exportAssetCategories(PortletDataContext portletDataContext, Element rootElement)
      throws Exception {

    Element assetVocabulariesElement = rootElement.element("vocabularies");

    if (assetVocabulariesElement == null) {
      assetVocabulariesElement = rootElement.addElement("vocabularies");
    }

    Element assetsElement = rootElement.addElement("assets");

    Element assetCategoriesElement = rootElement.addElement("categories");

    Map<String, String[]> assetCategoryUuidsMap = portletDataContext.getAssetCategoryUuidsMap();

    for (Map.Entry<String, String[]> entry : assetCategoryUuidsMap.entrySet()) {

      String[] assetCategoryEntryParts = StringUtil.split(entry.getKey(), CharPool.POUND);

      String className = assetCategoryEntryParts[0];
      long classPK = GetterUtil.getLong(assetCategoryEntryParts[1]);

      Element assetElement = assetsElement.addElement("asset");

      assetElement.addAttribute("class-name", className);
      assetElement.addAttribute("class-pk", String.valueOf(classPK));
      assetElement.addAttribute("category-uuids", StringUtil.merge(entry.getValue()));

      List<AssetCategory> assetCategories =
          AssetCategoryServiceUtil.getCategories(className, classPK);

      for (AssetCategory assestCategory : assetCategories) {
        exportAssetCategory(
            portletDataContext, assetVocabulariesElement,
            assetCategoriesElement, assestCategory);
      }
    }
  }
  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    List<AssetVocabulary> vocabularies = new ArrayList<AssetVocabulary>();
    Map<AssetVocabulary, List<AssetCategory>> vocabulariesMap =
        new HashMap<AssetVocabulary, List<AssetCategory>>();
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long[] categoryIds = ParamUtil.getLongValues(renderRequest, "categoryIds");
    try {

      Group siteGroup = themeDisplay.getSiteGroup();
      long scopeGroupId = themeDisplay.getScopeGroupId();
      vocabularies.addAll(
          AssetVocabularyServiceUtil.getGroupVocabularies(siteGroup.getGroupId(), false));

      if (scopeGroupId != themeDisplay.getCompanyGroupId()) {
        vocabularies.addAll(
            AssetVocabularyServiceUtil.getGroupVocabularies(
                themeDisplay.getCompanyGroupId(), false));
      }

      long classNameId = PortalUtil.getClassNameId(Announcement.class);

      // Select announcement vocabularies for announcement only.
      for (AssetVocabulary vocabulary : vocabularies) {
        vocabulary = vocabulary.toEscapedModel();

        int vocabularyCategoriesCount =
            AssetCategoryServiceUtil.getVocabularyCategoriesCount(
                vocabulary.getGroupId(), vocabulary.getVocabularyId());

        if (vocabularyCategoriesCount == 0) {
          continue;
        }

        UnicodeProperties settingsProperties = vocabulary.getSettingsProperties();

        long[] selectedClassNameIds =
            StringUtil.split(settingsProperties.getProperty("selectedClassNameIds"), 0L);

        if ((selectedClassNameIds.length > 0)
            && (selectedClassNameIds[0] != AssetCategoryConstants.ALL_CLASS_NAME_IDS)
            && !ArrayUtil.contains(selectedClassNameIds, classNameId)) {
          continue;
        }

        List<AssetCategory> assetCategories =
            AssetCategoryServiceUtil.getVocabularyRootCategories(
                themeDisplay.getScopeGroupId(),
                vocabulary.getVocabularyId(),
                QueryUtil.ALL_POS,
                QueryUtil.ALL_POS,
                null);
        vocabulariesMap.put(vocabulary, assetCategories);
      }
    } catch (SystemException e) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(e);
      }
      LOGGER.error("SystemException: unable to get types or currencies or vocabularies");
    } catch (PortalException e) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(e);
      }
      LOGGER.error("SystemException: unable to get types or currencies or vocabularies");
    }

    renderRequest.setAttribute("vocabulariesMap", vocabulariesMap);
    renderRequest.setAttribute("categoryIds", StringUtil.merge(categoryIds));
    renderRequest.setAttribute("htmlUtil", HtmlUtil.getHtml());

    super.doView(renderRequest, renderResponse);
  }