<commit_before>/**
 * Copyright (C) 2000 - 2012 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:
 * "http://www.silverpeas.org/docs/core/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 com.silverpeas.attachment;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.jsp.JspWriter;

import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringEscapeUtils;
import org.silverpeas.attachment.model.SimpleDocument;

import com.silverpeas.util.StringUtil;
import com.stratelia.silverpeas.util.ResourcesWrapper;
import com.stratelia.webactiv.beans.admin.OrganizationController;

/**
 * @author ehugonnet
 */
public class MenuHelper {

  static final String NEW_LINE = System.getProperty("line.separator");
  private final static String template = "oMenu%s.getItem(%s).cfg.setProperty(\"disabled\", %s);";
  private static OrganizationController organisation = new OrganizationController();

  public static boolean isAdmin(String userId) {
    return organisation.getUserDetail(userId).isAccessAdmin();
  }

  public static boolean isWorker(String userId, SimpleDocument attachment) {
    return userId.equals(attachment.getEditedBy());
  }

  public static boolean isEditable(String userId, SimpleDocument attachment, boolean useWebDAV) {
    return useWebDAV && attachment.isOpenOfficeCompatible() && isWorker(userId, attachment);
  }

  public static void displayActions(SimpleDocument attachment, boolean useXMLForm,
      boolean useFileSharing, boolean useWebDAV, String userId, String language,
      ResourcesWrapper resources, String httpServerBase, boolean showMenuNotif,
      boolean useContextualMenu, JspWriter out)
      throws IOException {

    String attachmentId = String.valueOf(attachment.getOldSilverpeasId());
    boolean webDavOK = useWebDAV && attachment.isOpenOfficeCompatible();
    StringBuilder builder = new StringBuilder(1024);
    builder.append("<div id=\"basicmenu").append(attachmentId).append("\" class=\"yuimenu\">").
        append(NEW_LINE);
    builder.append("<div class=\"bd\">").append(NEW_LINE);
    builder.append("<ul class=\"first-of-type\">").append(NEW_LINE);
    builder.append(
        "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"javascript:checkout('").
        append(attachment.getId()).append("',").append(attachmentId).append(",").append(webDavOK).
        append(")\">").append(resources.getString("checkOut")).append("</a></li>").append(NEW_LINE);
    builder.
        append(
        "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"javascript:checkoutAndDownload('")
        .append(attachment.getId()).append("',").append(attachmentId).append(",").append(webDavOK).
        append(");\">").append(resources.getString("attachment.checkOutAndDownload")).append(
        "</a></li>").append(NEW_LINE);
    builder.
        append(
        "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"javascript:checkoutAndEdit('")
        .append(attachment.getId()).append("',").append(attachmentId).append(");\">").
        append(resources.getString("attachment.checkOutAndEditOnline")).append("</a></li>").append(
        NEW_LINE);
    builder.append(
        "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"javascript:checkin('").
        append(attachment.getId()).append("',").append(attachmentId).append(",").append(attachment.
        isOpenOfficeCompatible()).append(", false)\">").append(resources.getString("checkIn")).
        append("</a></li>").append(<commit_msg>Feature82: fixing missing language in clone menu<commit_after>/**
 * Copyright (C) 2000 - 2012 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:
 * "http://www.silverpeas.org/docs/core/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 com.silverpeas.attachment;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.jsp.JspWriter;

import org.silverpeas.attachment.model.SimpleDocument;

import com.silverpeas.util.i18n.I18NHelper;

import com.stratelia.silverpeas.util.ResourcesWrapper;
import com.stratelia.webactiv.beans.admin.OrganizationController;

import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringEscapeUtils;

/**
 * @author ehugonnet
 */
public class MenuHelper {

  static final String NEW_LINE = System.getProperty("line.separator");
  private final static String template = "oMenu%s.getItem(%s).cfg.setProperty(\"disabled\", %s);";
  private static OrganizationController organisation = new OrganizationController();

  public static boolean isAdmin(String userId) {
    return organisation.getUserDetail(userId).isAccessAdmin();
  }

  public static boolean isWorker(String userId, SimpleDocument attachment) {
    return userId.equals(attachment.getEditedBy());
  }

  public static boolean isEditable(String userId, SimpleDocument attachment, boolean useWebDAV) {
    return useWebDAV && attachment.isOpenOfficeCompatible() && isWorker(userId, attachment);
  }

  public static void displayActions(SimpleDocument attachment, boolean useXMLForm,
      boolean useFileSharing, boolean useWebDAV, String userId, String lang,
      ResourcesWrapper resources, String httpServerBase, boolean showMenuNotif,
      boolean useContextualMenu, JspWriter out) throws IOException {
    String language = I18NHelper.checkLanguage(lang);
    String attachmentId = String.valueOf(attachment.getOldSilverpeasId());
    boolean webDavOK = useWebDAV && attachment.isOpenOfficeCompatible();
    StringBuilder builder = new StringBuilder(1024);
    builder.append("<div id=\"basicmenu").append(attachmentId).append("\" class=\"yuimenu\">").
        append(NEW_LINE);
    builder.append("<div class=\"bd\">").append(NEW_LINE);
    builder.append("<ul class=\"first-of-type\">").append(NEW_LINE);
    builder.append(
        "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"javascript:checkout('").
        append(attachment.getId()).append("',").append(attachmentId).append(",").append(webDavOK).
        append(")\">").append(resources.getString("checkOut")).append("</a></li>").append(NEW_LINE);
    builder.
        append(
        "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"javascript:checkoutAndDownload('")
        .append(attachment.getId()).append("',").append(attachmentId).append(",").append(webDavOK).
        append(");\">").append(resources.getString("attachment.checkOutAndDownload")).append(
        "</a></li>").append(NEW_LINE);
    builder.
        append(
        "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"javascript:checkoutAndEdit('")
        .append(attachment.getId()).append("',").append(attachmentId).append(");\">").
        append(resources.getString("attachment.checkOutAndEditOnline")).append("</a></li>").append(
        NEW_LINE);
    builder.append(
        "<li class=\"yuimenuitem\"><a class=\"yuimenuitemlabel\" href=\"javascript:checkin('").
        append(attachment.getId()).append("',").append(attachmentId).append(",").append(attachment.
        isOpenOfficeCompatible()).append(", false)\">").append(resources.getString("checkIn")).
        append("</a></li>").append(
{'fraction_non_alphanumeric': 0.1358187616848125, 'fraction_numerical': 0.004618937644341801, 'mean_word_length': 4.620519159456118, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2142769', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2480, 'n_words': 640}