/*
 * Copyright (C) 2000 - 2018 Silverpeas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * As a special exception to the terms and conditions of version 3.0 of
 * the GPL, you may redistribute this Program in connection with Free/Libre
 * Open Source Software ("FLOSS") applications as described in Silverpeas's
 * FLOSS exception.  You should have received a copy of the text describing
 * the FLOSS exception, and it is also available here:
 * "https://www.silverpeas.org/legal/floss_exception.html"
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.silverpeas.core.web.util.viewgenerator.html.window;

import org.silverpeas.core.admin.component.model.ComponentInstLight;
import org.silverpeas.core.admin.service.OrganizationController;
import org.silverpeas.core.admin.service.OrganizationControllerProvider;
import org.silverpeas.core.admin.space.SpaceInstLight;
import org.silverpeas.core.util.StringUtil;

import java.util.List;

/**
 * The default implementation of Window interface
 * @author neysseri
 * @version 1.0
 */
public class WindowWithContextualDiv extends AbstractWindow {

  /**
   * Constructor declaration
   *
   */
  public WindowWithContextualDiv() {
    super();
  }

  public String getContextualDiv() {
    StringBuilder spaceIds = new StringBuilder();
    String componentId = getGEF().getComponentIdOfCurrentRequest();
    OrganizationController oc = OrganizationControllerProvider.getOrganisationController();
    if (StringUtil.isDefined(componentId)) {
      List<SpaceInstLight> spaces = oc.getPathToComponent(componentId);

      for (SpaceInstLight spaceInst : spaces) {
        spaceIds.append(spaceInst.getId()).append(" ");
      }
    }

    if (spaceIds.length() > 0) {
      ComponentInstLight component = oc.getComponentInstLight(componentId);
      return "<div class=\"" + spaceIds.toString() + component.getName() + " " + componentId +
          "\">";
    }
    return null;
  }
}
@@ -1446,32 +1446,82 @@
 SpaceInstLight;%0A
+import org.silverpeas.core.admin.user.model.User;%0A
 import org.silve
@@ -2424,16 +2424,386 @@
 entId);%0A
+%0A      // append all profiles of current user%0A      String userId = User.getCurrentRequester().getId();%0A      String%5B%5D profiles = oc.getUserProfiles(userId, componentId);%0A      StringBuilder profilesStr = new StringBuilder();%0A      if (profiles != null) %7B%0A        for (String profile : profiles) %7B%0A          profilesStr.append(%22 profile_%22 + profile);%0A        %7D%0A      %7D%0A%0A
       re
@@ -2898,16 +2898,30 @@
         
+ profilesStr +
  %22%5C%22%3E%22;%0A

append all profiles of current user of each component into existing contextual div