/**
  * Sets the filter.
  *
  * @param filter the new filter
  */
 public void setFilter(String filter) {
   TracerSingleton.log(
       Constants.NOME_MODULO,
       TracerSingleton.INFORMATION,
       "ListTag::setFilter:: filter " + filter);
   _filter = filter;
 }
 /**
  * Traces the setting of a module name.
  *
  * @param moduleName The module name string at input.
  */
 public void setModuleName(String moduleName) {
   TracerSingleton.log(
       Constants.NOME_MODULO,
       TracerSingleton.INFORMATION,
       "ListTag::setModuleName:: moduleName [" + moduleName + "]");
   _moduleName = moduleName;
 } // public void setModuleName(String moduleName)
 /**
  * Traces the setting of an action name.
  *
  * @param actionName The action name string at input.
  */
 public void setActionName(String actionName) {
   TracerSingleton.log(
       Constants.NOME_MODULO,
       TracerSingleton.DEBUG,
       "DefaultDetailTag::setActionName:: actionName [" + actionName + "]");
   _actionName = actionName;
 } // public void setActionName(String actionName)
 /**
  * Do end tag.
  *
  * @return the int
  * @throws JspException the jsp exception
  * @see javax.servlet.jsp.tagext.Tag#doEndTag()
  */
 public int doEndTag() throws JspException {
   TracerSingleton.log(
       Constants.NOME_MODULO, TracerSingleton.INFORMATION, "ListTag::doEndTag:: invocato");
   _actionName = null;
   _moduleName = null;
   _serviceName = null;
   _content = null;
   _layout = null;
   _providerURL = null;
   _requestContainer = null;
   _serviceRequest = null;
   _responseContainer = null;
   _serviceResponse = null;
   _htmlStream = null;
   _columns = null;
   return super.doEndTag();
 } // public int doEndTag() throws JspException
 /**
  * ending tag.
  *
  * @return the int
  * @throws JspException the jsp exception
  */
 public int doEndTag() throws JspException {
   TracerSingleton.log(
       Constants.NOME_MODULO, TracerSingleton.INFORMATION, "TitleTag::doEndTag:: invocato");
   return super.doEndTag();
 }
  /**
   * Builds list navigation buttons inside the list tag. If the number of elements is higher than
   * 10, they are divided into pages; this methods creates forward and backward arrows and page
   * number information for navigation.
   *
   * @throws JspException If any Exception occurs
   */
  protected void makeNavigationButton() throws JspException {

    String pageNumberString = (String) _content.getAttribute("PAGED_LIST.PAGE_NUMBER");
    if (_session.getAttribute("PAGE_NUMBER") != null) _session.delAttribute("PAGE_NUMBER");
    _session.setAttribute("PAGE_NUMBER", pageNumberString);

    int pageNumber = 1;
    try {
      pageNumber = Integer.parseInt(pageNumberString);
    } catch (NumberFormatException ex) {
      TracerSingleton.log(
          Constants.NOME_MODULO,
          TracerSingleton.WARNING,
          "ListTag::makeNavigationButton:: PAGE_NUMBER nullo");
    }
    String pagesNumberString = (String) _content.getAttribute("PAGED_LIST.PAGES_NUMBER");
    int pagesNumber = 1;
    try {
      pagesNumber = Integer.parseInt(pagesNumberString);
    } catch (NumberFormatException ex) {
      TracerSingleton.log(
          Constants.NOME_MODULO,
          TracerSingleton.WARNING,
          "ListTag::makeNavigationButton:: PAGES_NUMBER nullo");
    }

    int prevPage = pageNumber - 1;
    if (prevPage < 1) prevPage = 1;
    int nextPage = pageNumber + 1;
    if (nextPage > pagesNumber) nextPage = pagesNumber;

    // get the right parameters of the request
    // HashMap paramsMap  = getQueryStringParameter();
    // add the parameter for the provider
    // paramsMap.putAll(_providerUrlMap);

    _htmlStream.append(" <TABLE CELLPADDING=0 CELLSPACING=0  WIDTH='100%' BORDER=0>\n");
    _htmlStream.append("	<TR>\n");
    _htmlStream.append(
        "		<TD class='portlet-section-footer' valign='center' align='left' width='14'>\n");

    // create link for previous page
    HashMap prevParamsMap = new HashMap();
    prevParamsMap.putAll(_providerUrlMap);
    prevParamsMap.put("MESSAGE", "LIST_PAGE");
    prevParamsMap.put("LIST_PAGE", String.valueOf(prevPage));
    PortletURL prevUrl = createUrl(prevParamsMap);

    HashMap nextParamsMap = new HashMap();
    nextParamsMap.putAll(_providerUrlMap);
    nextParamsMap.put("MESSAGE", "LIST_PAGE");
    nextParamsMap.put("LIST_PAGE", String.valueOf(nextPage));
    PortletURL nextUrl = createUrl(nextParamsMap);

    // identity string for object of the page
    UUIDGenerator uuidGen = UUIDGenerator.getInstance();
    UUID uuid = uuidGen.generateTimeBasedUUID();
    String requestIdentity = uuid.toString();
    requestIdentity = requestIdentity.replaceAll("-", "");
    String formId = "formFilter" + requestIdentity;

    String valueFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.VALUE_FILTER);
    String columnFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.COLUMN_FILTER);
    String typeFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.TYPE_FILTER);
    if (valueFilter != null && columnFilter != null && typeFilter != null) {
      prevUrl.setParameter(SpagoBIConstants.VALUE_FILTER, valueFilter);
      prevUrl.setParameter(SpagoBIConstants.COLUMN_FILTER, columnFilter);
      prevUrl.setParameter(SpagoBIConstants.TYPE_FILTER, typeFilter);
      nextUrl.setParameter(SpagoBIConstants.VALUE_FILTER, valueFilter);
      nextUrl.setParameter(SpagoBIConstants.COLUMN_FILTER, columnFilter);
      nextUrl.setParameter(SpagoBIConstants.TYPE_FILTER, typeFilter);
    } else {
      valueFilter = "";
      columnFilter = "";
      typeFilter = "";
    }

    if (pageNumber != 1) {
      // _htmlStream.append("		<A href=\""+prevUrl.toString()+"\"><IMG
      // src='"+renderResponse.encodeURL(renderRequest.getContextPath() + "/img/prevPage.gif")+"'
      // ALIGN=RIGHT border=0></a>\n");
      _htmlStream.append(
          "<input type='image' "
              + "name='"
              + "prevPage"
              + "' "
              + "src ='"
              + renderResponse.encodeURL(renderRequest.getContextPath() + "/img/prevPage.gif")
              + "' "
              + "align='left' border=0"
              + "alt='"
              + "GO To Previous Page"
              + "'>\n");
    } else {
      _htmlStream.append(
          "		<IMG src='"
              + renderResponse.encodeURL(renderRequest.getContextPath() + "/img/prevPage.gif")
              + "' ALIGN=RIGHT border=0>\n");
    }
    _htmlStream.append("		</TD>\n");

    // create center blank cell
    // _htmlStream.append("		<TD class='portlet-section-footer'>&nbsp;</TD>\n");

    // visualize page numbers
    String pageLabel = msgBuilder.getMessage("ListTag.pageLable", _bundle, httpRequest);
    String pageOfLabel = msgBuilder.getMessage("ListTag.pageOfLable", _bundle, httpRequest);
    _htmlStream.append("						<TD class='portlet-section-footer' align='center'>\n");
    _htmlStream.append(
        "							<font class='aindice'>&nbsp;"
            + pageLabel
            + " "
            + pageNumber
            + " "
            + pageOfLabel
            + " "
            + pagesNumber
            + "&nbsp;</font>\n");
    _htmlStream.append("						    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n");

    // Form for list filtering; if not specified, the filter is enabled
    if (_filter == null || _filter.equalsIgnoreCase("enabled")) {

      PortletURL allUrl = createUrl(_providerUrlMap);
      PortletURL filterURL = createUrl(_providerUrlMap);

      String label = msgBuilder.getMessage("SBIListLookPage.labelFilter", _bundle, httpRequest);
      String labelStart = msgBuilder.getMessage("SBIListLookPage.startWith", _bundle, httpRequest);
      ;
      String labelEnd = msgBuilder.getMessage("SBIListLookPage.endWith", _bundle, httpRequest);
      ;
      String labelContain = msgBuilder.getMessage("SBIListLookPage.contains", _bundle, httpRequest);
      ;
      String labelEqual = msgBuilder.getMessage("SBIListLookPage.isEquals", _bundle, httpRequest);
      ;
      String labelFilter = msgBuilder.getMessage("SBIListLookPage.filter", _bundle, httpRequest);
      String labelAll = msgBuilder.getMessage("SBIListLookPage.all", _bundle, httpRequest);

      _htmlStream.append("						    <br/><br/>\n");
      _htmlStream.append(
          "						    <form action='" + filterURL + "' id='" + formId + "' method='post'>\n");
      _htmlStream.append("						    " + label + "\n");
      _htmlStream.append("						    <select name='" + SpagoBIConstants.COLUMN_FILTER + "'>\n");

      for (int i = 0; i < _columns.size(); i++) {
        String nameColumn = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("NAME");
        String labelColumnCode =
            (String) ((SourceBean) _columns.elementAt(i)).getAttribute("LABEL");
        String labelColumn = new String(nameColumn);
        if (labelColumnCode != null)
          labelColumn = msgBuilder.getMessage(labelColumnCode, _bundle, httpRequest);
        String selected = "";
        if (nameColumn.equalsIgnoreCase(columnFilter)) selected = " selected='selected' ";
        _htmlStream.append(
            "						    	<option value='"
                + nameColumn
                + "' "
                + selected
                + " >"
                + labelColumn
                + "</option>\n");
      }
      String selected = "";
      _htmlStream.append("						    </select>\n");
      _htmlStream.append("						    <select name='" + SpagoBIConstants.TYPE_FILTER + "'>\n");
      if (typeFilter.equalsIgnoreCase(SpagoBIConstants.START_FILTER))
        selected = " selected='selected' ";
      else selected = "";
      _htmlStream.append(
          "						    	<option value='"
              + SpagoBIConstants.START_FILTER
              + "' "
              + selected
              + " >"
              + labelStart
              + "</option>\n");
      if (typeFilter.equalsIgnoreCase(SpagoBIConstants.END_FILTER))
        selected = " selected='selected' ";
      else selected = "";
      _htmlStream.append(
          "						    	<option value='"
              + SpagoBIConstants.END_FILTER
              + "' "
              + selected
              + " >"
              + labelEnd
              + "</option>\n");
      if (typeFilter.equalsIgnoreCase(SpagoBIConstants.EQUAL_FILTER))
        selected = " selected='selected' ";
      else selected = "";
      _htmlStream.append(
          "						    	<option value='"
              + SpagoBIConstants.EQUAL_FILTER
              + "' "
              + selected
              + " >"
              + labelEqual
              + "</option>\n");
      if (typeFilter.equalsIgnoreCase(SpagoBIConstants.CONTAIN_FILTER))
        selected = " selected='selected' ";
      else selected = "";
      _htmlStream.append(
          "						    	<option value='"
              + SpagoBIConstants.CONTAIN_FILTER
              + "' "
              + selected
              + " >"
              + labelContain
              + "</option>\n");
      _htmlStream.append("						    </select>\n");
      _htmlStream.append(
          "						    <input type=\"text\" name=\""
              + SpagoBIConstants.VALUE_FILTER
              + "\" size=\"10\" value=\""
              + valueFilter
              + "\" /> \n");
      _htmlStream.append(
          "						    <a href='javascript:document.getElementById(\""
              + formId
              + "\").submit()'>"
              + labelFilter
              + "</a> \n");
      _htmlStream.append(" <a href='" + allUrl.toString() + "'>" + labelAll + "</a> \n");
      _htmlStream.append("						    </form> \n");
    }

    // create link for next page
    _htmlStream.append(
        "		<TD class='portlet-section-footer' valign='center' align='right' width='14'>\n");
    if (pageNumber != pagesNumber) {
      // _htmlStream.append("		<A href=\""+nextUrl.toString()+"\"><IMG
      // src='"+renderResponse.encodeURL(renderRequest.getContextPath() + "/img/nextPage.gif")+"'
      // ALIGN=RIGHT border=0></a>\n");
      _htmlStream.append(
          "<input type='image' "
              + "name='"
              + "nextPage"
              + "' "
              + "src ='"
              + renderResponse.encodeURL(renderRequest.getContextPath() + "/img/nextPage.gif")
              + "' "
              + "align='right' border='0'"
              + "alt='"
              + "GO To Next Page"
              + "'>\n");
    } else {
      _htmlStream.append(
          "		<IMG src='"
              + renderResponse.encodeURL(renderRequest.getContextPath() + "/img/nextPage.gif")
              + "' ALIGN=RIGHT border=0>\n");
    }
    _htmlStream.append("		</TD>\n");
    _htmlStream.append("	</TR>\n");
    _htmlStream.append("</TABLE>\n");
  }
  /**
   * Builds Table list rows, reading all query information.
   *
   * @throws JspException If any Exception occurs.
   */
  protected void makeRows() throws JspException {
    List rows = _content.getAttributeAsList("PAGED_LIST.ROWS.ROW");

    Integer masterId = (Integer) _session.getAttribute("MASTER_ID");
    SourceBean subreports = (SourceBean) _session.getAttribute("SUBREPORTS");

    TracerSingleton.log(
        Constants.NOME_MODULO,
        TracerSingleton.WARNING,
        "ListTag::makeRows:SessionContainer session: MASTER_ID = " + masterId);

    TracerSingleton.log(
        Constants.NOME_MODULO,
        TracerSingleton.WARNING,
        "ListTag::makeRows:request: SUBREPORTS = " + subreports);

    List subreportsList = subreports.getAttributeAsList("ROW");
    Map subreportMap = new HashMap();
    for (int i = 0; i < subreportsList.size(); i++) {
      SourceBean subreport = (SourceBean) subreportsList.get(i);
      Integer id = (Integer) subreport.getAttribute("SUBREPORT_ID");
      if (id != null)
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.WARNING,
            "ListTag::makeRows:request: SUBREPORT_ID = " + id);
      subreportMap.put(id.toString(), id);
    }

    TracerSingleton.log(
        Constants.NOME_MODULO,
        TracerSingleton.WARNING,
        "ListTag::makeRows:request: SUBREPORTS = " + getSubreports(masterId, subreportMap));

    boolean alternate = false;
    String rowClass;
    String rowId = "";
    for (int i = 0; i < rows.size(); i++) {
      SourceBean row = (SourceBean) rows.get(i);
      TracerSingleton.log(
          Constants.NOME_MODULO,
          TracerSingleton.WARNING,
          "ListTag::makeRows:request: RIGA = " + row);
      rowId = ((Integer) row.getAttribute("OBJ_ID")).toString();
      if (rowId.equalsIgnoreCase(masterId.toString())) continue;

      rowClass = (alternate) ? "portlet-section-alternate" : "portlet-section-body";
      alternate = !alternate;

      _htmlStream.append(" <tr class='portlet-font'>\n");
      for (int j = 0; j < _columns.size(); j++) {
        String nameColumn = (String) ((SourceBean) _columns.elementAt(j)).getAttribute("NAME");
        Object fieldObject = row.getAttribute(nameColumn);
        String field = null;
        if (fieldObject != null) field = fieldObject.toString();
        else field = "&nbsp;";

        if (nameColumn.equalsIgnoreCase("OBJ_ID")) rowId = field;

        // if an horizontal-align is specified it is considered, otherwise the defualt is
        // align='left'
        String align =
            (String) ((SourceBean) _columns.elementAt(j)).getAttribute("horizontal-align");
        if (align == null || align.trim().equals("")) align = "left";
        _htmlStream.append(
            " <td class='"
                + rowClass
                + "' align='"
                + align
                + "' valign='top' >"
                + field
                + "</td>\n");
      }

      _htmlStream.append(" <td width='20' class='" + rowClass + "'>\n");
      if (subreportMap.containsKey(rowId)) {
        _htmlStream.append("<input type='checkbox' name='checkbox:" + rowId + "' checked='true'>");
        subreportMap.remove(rowId);
      } else {
        _htmlStream.append("<input type='checkbox' name='checkbox:" + rowId + "'>");
      }

      _htmlStream.append(" </td>\n");
      _htmlStream.append(" </tr>\n");
    }

    _htmlStream.append(" </table>\n");
    _session.delAttribute("SUBREPORTS");
    _session.setAttribute("SUBREPORTS", getSubreports(masterId, subreportMap));
  }