public static List<Map<String, String>> getTableElementParameterValue(
     IElementParameter parameter) {
   if (parameter.getFieldType() == EParameterFieldType.TABLE) {
     return createTableValues((List<Map<String, Object>>) parameter.getValue(), parameter);
   }
   return null;
 }
 private static Map<String, String> copyLineXML(
     Map<String, Object> currentLine, IElementParameter param) {
   Map<String, String> newLine = new HashMap<String, String>();
   // PTODO cantoine : check with Nico if cause trouble with others Components.
   String[] items = currentLine.keySet().toArray(new String[] {});
   // //{"QUERY"};
   for (int i = 0; i < items.length; i++) {
     Object o = currentLine.get(items[i]);
     if (o instanceof Integer) {
       IElementParameter tmpParam = (IElementParameter) param.getListItemsValue()[i];
       if ((((Integer) o) == -1) || (tmpParam.getListItemsValue().length == 0)) {
         newLine.put(items[i], ""); // $NON-NLS-1$
       } else {
         newLine.put(items[i], (String) tmpParam.getListItemsValue()[(Integer) o]);
       }
     } else {
       if (o instanceof String) {
         newLine.put(items[i], (String) o);
       } else {
         if (o instanceof Boolean) {
           newLine.put(items[i], ((Boolean) o).toString());
         } else {
           newLine.put(items[i], "*** ERROR in Table ***"); // $NON-NLS-1$
         }
       }
     }
   }
   return newLine;
 }
  public static String getValue(final IElement node, final String text) {
    String newText = new String(""); // $NON-NLS-1$
    if (text == null) {
      return newText;
    }
    IElementParameter param = null;
    boolean end = false;

    List<IElementParameter> params =
        (List<IElementParameter>) node.getElementParametersWithChildrens();
    if (params != null && !params.isEmpty()) {
      for (int i = 0; i < params.size() && !end; i++) {
        param = params.get(i);
        if (text.indexOf(param.getVariableName()) != -1) {
          newText = getDisplayValue(param);
          end = true;
        }
      }
    }
    // see feature 3725 replace tMsgBox MESSAGE parameter
    if (node instanceof INode) {
      INode valueNode = (INode) node;
      /*
       * Apply to all components in Perl mode
       */
      if (isPerlProject()) {
        return PerlVarParserUtils.findAndReplacesAll(newText, valueNode);
      }
    }

    return newText;
  }
 public void setUniqueName(String uniqueName) {
   for (IElementParameter param : elementParameters) {
     if (param.getName().equals("UNIQUE_NAME")) { // $NON-NLS-1$
       param.setValue(uniqueName);
     }
   }
   this.uniqueName = uniqueName;
 }
  public IElementParameter getElementParameter(String name) {
    if (name.contains(":")) { // look for the parent first, then will //$NON-NLS-1$
      // retrieve the children
      StringTokenizer token = new StringTokenizer(name, ":"); // $NON-NLS-1$
      String parentId = token.nextToken();
      String childId = token.nextToken();
      for (int i = 0; i < elementParameters.size(); i++) {
        if (elementParameters.get(i).getName().equals(parentId)) {
          IElementParameter parent = elementParameters.get(i);
          return parent.getChildParameters().get(childId);
        }
      }
    } else {
      for (IElementParameter elementParam : elementParameters) {
        if (elementParam.getName().equals(name)) {
          return elementParam;
        }
      }
    }

    // if not found, look for the name if it's the name of a children
    // this code is added only for compatibility and will be executed only
    // one time
    // to initialize the child.
    // The parameters name are unique, so we just take the first one.
    for (IElementParameter elementParam : elementParameters) {
      for (String key : elementParam.getChildParameters().keySet()) {
        IElementParameter param = elementParam.getChildParameters().get(key);
        if (param.getName().equals(name)) {
          return param;
        }
      }
    }
    return null;
  }
  /*
   * (non-Javadoc)
   *
   * @see org.talend.core.model.process.INode#renameData(java.lang.String, java.lang.String)
   */
  public void renameData(String oldName, String newName) {
    if (oldName.equals(newName)) {
      return;
    }

    for (IElementParameter param : this.getElementParameters()) {
      if (param.getName().equals("UNIQUE_NAME") || isSQLQueryParameter(param)) { // $NON-NLS-1$
        continue;
      }
      ParameterValueUtil.renameValues(param, oldName, newName);
    }
  }
 public boolean isGeneratedAsVirtualComponent() {
   IElementParameter param = getElementParameter("IS_VIRTUAL_COMPONENT"); // $NON-NLS-1$
   if (param != null) { // now only available for tUniqRow.
     return (Boolean) param.getValue();
   }
   List<IMultipleComponentManager> multipleComponentManagers =
       getComponent().getMultipleComponentManagers();
   for (IMultipleComponentManager mcm : multipleComponentManagers) {
     if (!mcm.isLookupMode()) {
       return true;
     }
   }
   return false;
 }
  public List<? extends IElementParameter> getElementParametersWithChildrens() {
    List<IElementParameter> fullListParam =
        new ArrayList<IElementParameter>(this.elementParameters);

    for (IElementParameter curParam : elementParameters) {
      if (curParam.getChildParameters() != null) {
        for (String key : curParam.getChildParameters().keySet()) {
          IElementParameter childParam = curParam.getChildParameters().get(key);
          fullListParam.add(childParam);
        }
      }
    }
    return fullListParam;
  }
  /*
   * (non-Javadoc)
   *
   * @see org.talend.core.model.process.INode#useData(java.lang.String)
   */
  public boolean useData(String name) {

    for (IElementParameter param : this.getElementParameters()) {
      if (param.getFieldType() == EParameterFieldType.IMAGE) {
        continue;
      }
      if (param.getName().equals("UNIQUE_NAME")) { // $NON-NLS-1$
        continue;
      }
      if (ParameterValueUtil.isUseData(param, name)) {
        return true;
      }
    }
    return false;
  }
  /**
   * If a database componenet use an existing connection, its label may replace with variable from
   * the existing connection not the component variable. see bug 0005456: Label Format __DBNAME__
   * not valid when using existing connection
   *
   * @param text String that contains variables which need to replace
   * @param variableMap A map contains variable name and IElementParameter in a pair
   * @return
   */
  public static String replaceWithExistingConnection(
      String text, Map<String, IElementParameter> variableMap) {
    if (text == null) {
      return ""; //$NON-NLS-1$
    }
    String newText = text;

    for (String var : variableMap.keySet()) {
      if (newText.contains(var)) {
        IElementParameter param = variableMap.get(var);
        String value = ElementParameterParser.getDisplayValue(param);
        newText = newText.replace(param.getVariableName(), value);
      }
    }
    return newText;
  }
  public static String parse(final IElement element, final String text) {
    String newText = ""; // $NON-NLS-1$
    if ((element == null) || (text == null)) {
      return newText;
    }
    IElementParameter param;

    newText = text;
    for (int i = 0; i < element.getElementParameters().size(); i++) {
      param = element.getElementParameters().get(i);
      if (newText.contains(param.getVariableName())) {
        String value = getDisplayValue(param);
        newText = newText.replace(param.getVariableName(), value);
      }
    }
    return newText;
  }
  /**
   * Only work with one element.
   *
   * @param element
   * @param text
   * @return
   */
  public static Object getObjectValueXML(final IElement element, final String text) {
    if (text == null) {
      return null;
    }
    IElementParameter param;

    for (int i = 0; i < element.getElementParameters().size(); i++) {
      param = element.getElementParameters().get(i);
      if (text.indexOf(param.getVariableName()) != -1) {
        if (param.getFieldType() == EParameterFieldType.TABLE) {
          return createTableValuesXML((List<Map<String, Object>>) param.getValue(), param);
        }
        return param.getValue();
      }
    }
    return null;
  }
  /**
   * Only work with one element.
   *
   * @param element
   * @param text
   * @return
   */
  public static Object getObjectValue(final IElement element, final String text) {
    if (text == null) {
      return null;
    }
    IElementParameter param;

    List<IElementParameter> params =
        (List<IElementParameter>) element.getElementParametersWithChildrens();
    if (params != null && !params.isEmpty()) {
      for (int i = 0; i < params.size(); i++) {
        param = params.get(i);
        if (text.indexOf(param.getVariableName()) != -1
            || (param.getVariableName() != null && param.getVariableName().contains(text))) {
          if (param.getFieldType() == EParameterFieldType.TABLE) {
            return createTableValues((List<Map<String, Object>>) param.getValue(), param);
          }
          return param.getValue();
        }
      }
    }
    return null;
  }
  @SuppressWarnings("unchecked")
  private static String getDisplayValue(final IElementParameter param) {
    Object value = param.getValue();

    if (value instanceof String) {

      if (param.getName().equals("PROCESS_TYPE_VERSION")
          && value.equals(RelationshipItemBuilder.LATEST_VERSION)) { // $NON-NLS-1$
        String jobId =
            (String)
                param
                    .getParentParameter()
                    .getChildParameters()
                    .get("PROCESS_TYPE_PROCESS")
                    .getValue(); //$NON-NLS-1$
        ProcessItem processItem = ItemCacheManager.getProcessItem(jobId);
        if (processItem == null) {
          return ""; //$NON-NLS-1$
        }
        return processItem.getProperty().getVersion();
      }
      if (param.getName().equals("PROCESS_TYPE_CONTEXT")) { // $NON-NLS-1$
        String jobId =
            (String)
                param
                    .getParentParameter()
                    .getChildParameters()
                    .get("PROCESS_TYPE_PROCESS")
                    .getValue(); //$NON-NLS-1$
        ProcessItem processItem = ItemCacheManager.getProcessItem(jobId);
        if (processItem == null) {
          return ""; //$NON-NLS-1$
        }
        // check if the selected context exists, if not, use the default context of the job.
        boolean contextExists = false;
        for (Object object : processItem.getProcess().getContext()) {
          if (object instanceof ContextType) {
            if (((ContextType) object).getName() != null
                && ((ContextType) object).getName().equals(value)) {
              contextExists = true;
              continue;
            }
          }
        }
        if (!contextExists) {
          return processItem.getProcess().getDefaultContext();
        }
        return (String) value;
      }
      // hywang add for 6484
      if ("SELECTED_FILE".equals(param.getRepositoryValue())) { // $NON-NLS-N$ //$NON-NLS-1$
        IElementParameter propertyParam =
            param
                .getElement()
                .getElementParameter(
                    "PROPERTY:REPOSITORY_PROPERTY_TYPE"); // $NON-NLS-N$ //$NON-NLS-1$
        if (propertyParam != null
            && propertyParam.getValue() != null
            && !propertyParam.getValue().equals("")) { // $NON-NLS-1$
          try {
            IRepositoryViewObject object =
                CoreRuntimePlugin.getInstance()
                    .getProxyRepositoryFactory()
                    .getLastVersion((String) propertyParam.getValue());
            if (object != null) {
              Item item = object.getProperty().getItem();
              String extension = null;

              String rule = ""; // $NON-NLS-1$
              String processLabelAndVersion = null;
              if (item instanceof RulesItem) {
                RulesItem rulesItem = (RulesItem) item;
                extension = rulesItem.getExtension();
                if (param.getElement() instanceof INode) {
                  INode node = (INode) param.getElement();
                  IProcess process = node.getProcess();
                  String jobLabel = process.getName();
                  String jobVersion = process.getVersion();
                  processLabelAndVersion =
                      JavaResourcesHelper.getJobFolderName(jobLabel, jobVersion);
                }

                rule =
                    "rules/final/"
                        + processLabelAndVersion
                        + "/"
                        + rulesItem.getProperty().getLabel() // $NON-NLS-1$ //$NON-NLS-2$
                        + rulesItem.getProperty().getVersion()
                        + extension;
              }
              return TalendQuoteUtils.addQuotes(rule);
            } else {
              return param.getValue().toString();
            }
          } catch (Exception e) {
            ExceptionHandler.process(e);
          }
        }
      }

      return (String) value;
    }
    if (param.getFieldType() == EParameterFieldType.RADIO
        || param.getFieldType() == EParameterFieldType.CHECK
        || param.getFieldType() == EParameterFieldType.AS400_CHECK) {
      if (value instanceof Boolean) {
        return ((Boolean) param.getValue()).toString();
      } else {
        return Boolean.FALSE.toString();
      }
    }

    if (param.getFieldType() == EParameterFieldType.TABLE) {
      List<Map<String, Object>> tableValues = (List<Map<String, Object>>) param.getValue();
      String[] items = param.getListItemsDisplayCodeName();
      String stringValues = "{"; // $NON-NLS-1$
      for (int i = 0; i < tableValues.size(); i++) {
        Map<String, Object> lineValues = tableValues.get(i);
        stringValues += "["; // $NON-NLS-1$
        for (int j = 0; j < items.length; j++) {

          Object currentValue = lineValues.get(items[j]);
          if (currentValue instanceof Integer) {
            IElementParameter tmpParam = (IElementParameter) param.getListItemsValue()[j];
            if (tmpParam.getListItemsDisplayName().length != 0) {
              stringValues += tmpParam.getListItemsDisplayName()[(Integer) currentValue];
            }
          } else {
            stringValues += currentValue;
          }

          if (j != (items.length - 1)) {
            stringValues += ","; // $NON-NLS-1$
          }
        }
        stringValues += "]"; // $NON-NLS-1$
        if (i != (tableValues.size() - 1)) {
          stringValues += ","; // $NON-NLS-1$
        }
      }
      stringValues += "}"; // $NON-NLS-1$
      return stringValues;
    }

    return new String(""); // $NON-NLS-1$
  }
 private static Map<String, String> copyLine(
     Map<String, Object> currentLine, IElementParameter param) {
   Map<String, String> newLine = new HashMap<String, String>();
   String[] items = param.getListItemsDisplayCodeName();
   for (int i = 0; i < items.length; i++) {
     Object o = currentLine.get(items[i]);
     if (o instanceof Integer) {
       IElementParameter tmpParam = (IElementParameter) param.getListItemsValue()[i];
       if ((((Integer) o) == -1) || (tmpParam.getListItemsValue().length == 0)) {
         newLine.put(items[i], ""); // $NON-NLS-1$
       } else {
         newLine.put(items[i], (String) tmpParam.getListItemsValue()[(Integer) o]);
       }
     } else {
       if (o instanceof String) {
         if (param.getName().equals("SQLPATTERN_VALUE")) { // $NON-NLS-1$
           SQLPatternItem item =
               SQLPatternUtils.getItemFromCompoundId(param.getElement(), ((String) o));
           if (item != null) {
             newLine.put(items[i], new String(item.getContent().getInnerContent()));
           } else {
             newLine.put(items[i], ""); // $NON-NLS-1$
           }
         } else if (param.getElement() != null
             && param.getElement() instanceof INode
             && ((INode) param.getElement()).getComponent().getName().equals("tWebService")) {
           String replacedValue = (String) o;
           if (items[i].equals("EXPRESSION")) {
             String inputRow = "row1";
             List connList = ((INode) param.getElement()).getIncomingConnections();
             if (connList.size() > 0) {
               inputRow = ((IConnection) connList.get(0)).getName();
               replacedValue = replacedValue.replace("input.", inputRow + ".");
             }
           }
           newLine.put(items[i], replacedValue);
         } else {
           newLine.put(items[i], (String) o);
         }
       } else {
         if (o instanceof Boolean) {
           newLine.put(items[i], ((Boolean) o).toString());
         } else {
           newLine.put(items[i], ""); // $NON-NLS-1$
         }
       }
     }
   }
   return newLine;
 }
 /**
  * see bug 4733
  *
  * <p>DOC YeXiaowei Comment method "isSQLQueryParameter".
  *
  * @param parameter
  * @return
  */
 private boolean isSQLQueryParameter(final IElementParameter parameter) {
   return parameter.getFieldType().equals(EParameterFieldType.MEMO_SQL)
       && parameter.getName().equals("QUERY"); // $NON-NLS-1$
 }