private String getValueOfField(XMLField xmlField, String language) {
   String fieldValue = xmlField.getValue();
   if (fieldValue == null) {
     fieldValue = "";
   } else {
     if (fieldValue.startsWith("image_") || fieldValue.startsWith("file_")) {
       String attachmentId =
           fieldValue.substring(fieldValue.indexOf("_") + 1, fieldValue.length());
       if (StringUtil.isDefined(attachmentId)) {
         if (attachmentId.startsWith("/")) {
           // case of an image provided by a gallery
           fieldValue = attachmentId;
         } else {
           SimpleDocument attachment =
               AttachmentServiceFactory.getAttachmentService()
                   .searchDocumentById(
                       new SimpleDocumentPK(attachmentId, getPK().getInstanceId()), language);
           if (attachment != null) {
             fieldValue = attachment.getAttachmentURL();
           }
         }
       } else {
         fieldValue = "";
       }
     } else if (fieldValue.startsWith(WysiwygFCKFieldDisplayer.dbKey)) {
       fieldValue =
           WysiwygFCKFieldDisplayer.getContentFromFile(
               getPK().getInstanceId(), getPK().getId(), xmlField.getName(), language);
     } else {
       fieldValue = EncodeHelper.javaStringToHtmlParagraphe(fieldValue);
     }
   }
   return fieldValue;
 }
  public static void printSuggestionsScripts(
      PagesContext pageContext, String fieldName, List<String> suggestions, PrintWriter out) {
    out.println("<script type=\"text/javascript\">\n");
    out.println("listArray" + fieldName + " = [\n");

    Iterator<String> itRes = suggestions.iterator();
    String val;
    while (itRes.hasNext()) {
      val = itRes.next();

      out.println("\"" + EncodeHelper.javaStringToJsString(val) + "\"");

      if (itRes.hasNext()) out.println(",");
    }

    out.println("];\n");
    out.println("</script>\n");

    out.println("<script type=\"text/javascript\">\n");
    out.println(
        " this.oACDS"
            + fieldName
            + " = new YAHOO.util.LocalDataSource(listArray"
            + fieldName
            + ");\n");
    out.println(
        "	this.oAutoComp"
            + fieldName
            + " = new YAHOO.widget.AutoComplete('"
            + fieldName
            + "','container"
            + fieldName
            + "', this.oACDS"
            + fieldName
            + ");\n");
    out.println(
        "	this.oAutoComp" + fieldName + ".prehighlightClassName = \"yui-ac-prehighlight\";\n");
    out.println("	this.oAutoComp" + fieldName + ".typeAhead = true;\n");
    out.println("	this.oAutoComp" + fieldName + ".useShadow = true;\n");
    out.println("	this.oAutoComp" + fieldName + ".minQueryLength = 0;\n");

    out.println("	this.oAutoComp" + fieldName + ".textboxFocusEvent.subscribe(function(){\n");
    out.println("		var sInputValue = YAHOO.util.Dom.get('" + fieldName + "').value;\n");
    out.println("		if(sInputValue.length == 0) {\n");
    out.println("			var oSelf = this;\n");
    out.println("			setTimeout(function(){oSelf.sendQuery(sInputValue);},0);\n");
    out.println("		}\n");
    out.println("	});\n");
    out.println("</script>\n");
  }
  @Override
  public void displayScripts(
      final PrintWriter out, final FieldTemplate template, final PagesContext pageContext)
      throws IOException {
    checkFieldType(template.getTypeName(), "VideoFieldDisplayer.displayScripts");
    String language = pageContext.getLanguage();
    String fieldName = template.getFieldName();
    if (template.isMandatory() && pageContext.useMandatory()) {
      out.append("	if (isWhitespace(stripInitialWhitespace(field.value))) {\n")
          .append("		var ")
          .append(fieldName)
          .append("Value = document.getElementById('")
          .append(fieldName)
          .append(Field.FILE_PARAM_NAME_SUFFIX)
          .append("').value;\n")
          .append("   var ")
          .append(fieldName)
          .append("Operation = document.")
          .append(pageContext.getFormName())
          .append(".")
          .append(fieldName)
          .append(OPERATION_KEY)
          .append(".value;\n")
          .append("		if (")
          .append(fieldName)
          .append("Value=='' || ")
          .append(fieldName)
          .append("Operation=='")
          .append(Operation.DELETION.name())
          .append("') {\n")
          .append("			errorMsg+=\"  - '")
          .append(EncodeHelper.javaStringToJsString(template.getLabel(language)))
          .append("' ")
          .append(Util.getString("GML.MustBeFilled", language))
          .append("\\n \";\n")
          .append("			errorNb++;\n")
          .append("		}\n")
          .append("	}\n");
    }

    Util.includeFileNameLengthChecker(template, pageContext, out);
    Util.getJavascriptChecker(template.getFieldName(), pageContext, out);
  }
 public String getContent(String language) {
   SilverTrace.info(
       "notificationManager",
       "NotificationMetaData.getContent()",
       "root.MSG_GEN_ENTER_METHOD",
       "language = " + language);
   String result = "";
   if (templates != null && !templates.isEmpty()) {
     SilverpeasTemplate template = templates.get(language);
     if (template != null) {
       result = template.applyFileTemplate(fileName + '_' + language);
     }
   } else {
     result = contents.get(language);
   }
   SilverTrace.info(
       "notificationManager",
       "NotificationMetaData.getContent()",
       "root.MSG_GEN_EXIT_METHOD",
       "result = " + result);
   return EncodeHelper.convertWhiteSpacesForHTMLDisplay(result);
 }
  /**
   * Prints the HTML value of the field. The displayed value must be updatable by the end user. The
   * value format may be adapted to a local language. The fieldName must be used to name the html
   * form input. Never throws an Exception but log a silvertrace and writes an empty string when :
   *
   * <UL>
   *   <LI>the field type is not a managed type.
   * </UL>
   *
   * @param out
   * @param field
   * @param template
   * @param pageContext
   * @throws FormException
   */
  @Override
  public void display(
      PrintWriter out, TextField field, FieldTemplate template, PagesContext pageContext)
      throws FormException {
    String value = "";
    String html = "";

    String fieldName = template.getFieldName();
    SilverTrace.info(
        "form", "TimeFieldDisplayer.display", "root.MSG_GEN_PARAM_VALUE", "fieldName=" + fieldName);
    Map<String, String> parameters = template.getParameters(pageContext.getLanguage());
    if (field == null) {
      return;
    }
    if (!field.getTypeName().equals(TextField.TYPE)) {
      SilverTrace.info(
          "form", "TimeFieldDisplayer.display", "form.INFO_NOT_CORRECT_TYPE", TextField.TYPE);
    }

    String defaultParam = (parameters.containsKey("default") ? parameters.get("default") : "");
    String defaultValue = "";
    if ("now".equalsIgnoreCase(defaultParam) && !pageContext.isIgnoreDefaultValues()) {
      defaultValue = DateUtil.formatTime(new Date());
    }
    value = (!field.isNull() ? field.getValue(pageContext.getLanguage()) : defaultValue);
    if (pageContext.isBlankFieldsUse()) {
      value = "";
    }

    if (template.isReadOnly() && !template.isHidden()) {
      html = value;
    } else {
      input inputField = new input();
      inputField.setName(template.getFieldName());
      inputField.setID(template.getFieldName());
      inputField.setValue(EncodeHelper.javaStringToHtmlString(value));
      inputField.setType(template.isHidden() ? input.hidden : input.text);
      inputField.setMaxlength("5");
      inputField.setSize("10");
      if (template.isDisabled()) {
        inputField.setDisabled(true);
      } else if (template.isReadOnly()) {
        inputField.setReadOnly(true);
      }

      img image = null;
      if (template.isMandatory()
          && !template.isDisabled()
          && !template.isReadOnly()
          && !template.isHidden()
          && pageContext.useMandatory()) {
        image = new img();
        image.setSrc(Util.getIcon("mandatoryField"));
        image.setWidth(5);
        image.setHeight(5);
        image.setBorder(0);
      }

      // print field
      if (image != null) {
        ElementContainer container = new ElementContainer();
        container.addElement(inputField);
        container.addElement("&nbsp;");
        container.addElement(image);
        out.println(container.toString());
      } else {
        out.println(inputField.toString());
      }
    }
    out.println(html);
  }
  @Override
  public int doStartTag() throws JspException {
    if (pdcBm == null) {
      pdcBm = (PdcBm) new PdcBmImpl();
    }

    List<SearchAxis> primaryAxis = null;
    List daughters = null;

    try {
      if (StringUtil.isDefined(m_spaceOrSubSpace)) {
        List<String> availableComponentIds = new ArrayList<String>();
        SearchContext searchContext = new SearchContext();

        if (StringUtil.isDefined(componentId)) {
          primaryAxis = pdcBm.getPertinentAxisByInstanceId(searchContext, "P", componentId);
        } else {
          String a[] =
              oganisationController.getAvailCompoIds(
                  m_spaceOrSubSpace, mainSessionController.getUserId());
          availableComponentIds = Arrays.asList(a);
          if (!availableComponentIds.isEmpty()) {
            primaryAxis =
                pdcBm.getPertinentAxisByInstanceIds(searchContext, "P", availableComponentIds);
          }
        }

        if (primaryAxis != null && !primaryAxis.isEmpty()) {
          if (!"".equals(selectedAxisId)) {
            if (StringUtil.isDefined(componentId)) {
              daughters =
                  pdcBm.getPertinentDaughterValuesByInstanceId(
                      searchContext, selectedAxisId, selectedAxisPath, componentId);
            } else {
              daughters =
                  pdcBm.getPertinentDaughterValuesByInstanceIds(
                      searchContext, selectedAxisId, selectedAxisPath, availableComponentIds);
            }
          } else {
            SearchAxis searchAxis = primaryAxis.get(0);
            String axisId = new Integer(searchAxis.getAxisId()).toString();
            daughters =
                pdcBm.getPertinentDaughterValuesByInstanceIds(
                    searchContext, axisId, "", availableComponentIds);
          }
        }
      } // end if
    } catch (PdcException e) {
      throw new JspTagException("PdcException occured : " + e.toString());
    }

    try {
      pageContext.getOut().println("<tr class='intfdcolor51'>");
      pageContext.getOut().println("	<td width='100%'>");
      pageContext
          .getOut()
          .println("		<table border='0' cellspacing='0' cellpadding='0' width='100%'>");
      pageContext.getOut().println("			<tr>");
      pageContext.getOut().println("				<td>&nbsp;</td>");
      pageContext.getOut().println("				<td width='100%'><span class='txtnote'>");
      pageContext
          .getOut()
          .println("					<table cellpadding=0 cellspacing=0 border=0 width='100%'>");
      pageContext.getOut().println("						<tr><td>");

      // il peut y avoir aucun axe primaire dans un 1er temps
      if ((primaryAxis != null) && !primaryAxis.isEmpty()) {
        String text_link = "";
        for (SearchAxis searchAxis : primaryAxis) {
          String axisId = new Integer(searchAxis.getAxisId()).toString();
          String axisRootId = new Integer(searchAxis.getAxisRootId()).toString();
          String axisName = EncodeHelper.javaStringToHtmlString(searchAxis.getAxisName());

          int nbPositions = searchAxis.getNbObjects();
          if (nbPositions == 0 && componentId != null) {
            continue;
          }
          String objectLinked = "";
          String link = "javascript:top.scriptFrame.axisClick('" + axisId + "','');";
          text_link =
              webContext
                  + "/RpdcSearch/jsp/showaxishfromhomepage?query=&AxisId="
                  + axisId
                  + "&ValueId=/"
                  + axisRootId
                  + "/&SearchContext=isNotEmpty&component_id="
                  + componentId
                  + "&space_id="
                  + m_spaceOrSubSpace;
          if (axisId.equals(selectedAxisId)) {
            if (daughters != null) {
              if ("".equals(selectedAxisPath)) {
                if ("off".equals(state)) {
                  pageContext
                      .getOut()
                      .println(
                          HomePageFunctions.urlFactory(
                              link,
                              text_link,
                              axisId,
                              "",
                              objectLinked,
                              axisName,
                              "&nbsp;(" + nbPositions + ")",
                              HomePageFunctions.AXIS,
                              HomePageFunctions.AXIS_COLLAPSED,
                              "",
                              webContext));
                  continue;
                }
              }
              pageContext
                  .getOut()
                  .println(
                      HomePageFunctions.urlFactory(
                          link,
                          text_link,
                          axisId,
                          "",
                          objectLinked,
                          axisName,
                          "&nbsp;(" + nbPositions + ")",
                          HomePageFunctions.AXIS,
                          HomePageFunctions.AXIS_EXPANDED,
                          "",
                          webContext));
              // **************Begin daughters

              int d_size = daughters.size();

              int[][] tree_gui_represintation = new int[d_size][d_size];
              int selected_x = -1;
              int selected_y = 0;

              for (int j = 0; j < d_size; j++) {
                Value value = (Value) daughters.get(j);
                int valueLevel = value.getLevelNumber();
                String path = value.getFullPath();
                HomePageFunctions.setTreeNode(tree_gui_represintation, valueLevel, j, d_size);
                if (selectedAxisPath.equals(path)) {
                  selected_x = valueLevel;
                  selected_y = j;
                }
              }

              HomePageFunctions.closeTreeNodes(tree_gui_represintation, 0, d_size, d_size);
              if (selected_x >= 0) {
                if (state.equals("on")) {
                  selected_x++;
                  selected_y++;
                }
                HomePageFunctions.collapseTree(
                    tree_gui_represintation, selected_x, selected_y, d_size);
              }

              for (int j = 1; j < d_size; j++) {
                Value value = (Value) daughters.get(j);
                String valueName = EncodeHelper.javaStringToHtmlString(value.getName());
                int valueLevel = value.getLevelNumber();
                int valueNbObjects = value.getNbObjects();
                if (valueNbObjects == 0 && componentId != null) {
                  continue;
                }
                String valueFullPath = value.getFullPath();
                link =
                    "javascript:top.scriptFrame.axisClick('"
                        + axisId
                        + "','"
                        + valueFullPath
                        + "');";
                text_link =
                    webContext
                        + "/RpdcSearch/jsp/showaxishfromhomepage?query=&AxisId="
                        + axisId
                        + "&ValueId="
                        + valueFullPath
                        + "&SearchContext=isNotEmpty&component_id="
                        + componentId
                        + "&space_id="
                        + m_spaceOrSubSpace;
                if (tree_gui_represintation[0][j] == HomePageFunctions.T_HIDED_NODE) {
                  continue;
                }
                String offset =
                    HomePageFunctions.getTreeNodeOffset(
                        tree_gui_represintation, j, d_size, webContext);
                int node_type;
                if (tree_gui_represintation[valueLevel][j] == HomePageFunctions.T_OPENED_NODE) {
                  node_type = HomePageFunctions.AXIS_EXPANDED;
                } else {
                  node_type = HomePageFunctions.AXIS_COLLAPSED;
                }
                if (selectedAxisPath.equals("")) {
                  if (valueLevel == 1) {
                    pageContext
                        .getOut()
                        .println(
                            HomePageFunctions.urlFactory(
                                link,
                                text_link,
                                valueFullPath,
                                "",
                                objectLinked,
                                valueName,
                                " (" + valueNbObjects + ")",
                                HomePageFunctions.AXIS_LAST,
                                HomePageFunctions.AXIS_COLLAPSED,
                                offset,
                                webContext));
                  }
                  continue;
                } else {
                  pageContext
                      .getOut()
                      .println(
                          HomePageFunctions.urlFactory(
                              link,
                              text_link,
                              valueFullPath,
                              "",
                              objectLinked,
                              valueName,
                              " (" + valueNbObjects + ")",
                              HomePageFunctions.AXIS_LAST,
                              node_type,
                              offset,
                              webContext));
                }
              }
            }
          } else {
            pageContext
                .getOut()
                .println(
                    HomePageFunctions.urlFactory(
                        link,
                        text_link,
                        axisId,
                        "",
                        objectLinked,
                        axisName,
                        "&nbsp;(" + nbPositions + ")",
                        HomePageFunctions.AXIS,
                        HomePageFunctions.AXIS_COLLAPSED,
                        "",
                        webContext));
          }
        } // fin du for
      }

      pageContext.getOut().println("						</td></tr>");
      pageContext.getOut().println("					</table>");
      pageContext.getOut().println("				</span></td>");
      pageContext.getOut().println("			</tr>");
      pageContext.getOut().println("		</table>");
      pageContext.getOut().println("	</td>");
      pageContext.getOut().println("	<td><img src='icons/1px.gif'></td>");
      pageContext.getOut().println("	<td class='intfdcolor'><img src='icons/1px.gif'></td>");
      pageContext.getOut().println("</tr>");
    } catch (IOException ioe) {
      throw new JspTagException("IO_ERROR");
    }

    return SKIP_BODY;
  }