Exemplo n.º 1
0
 /**
  * Merges two parameters.
  *
  * @param aParameter TODO End coding this function. TODO Check this function.
  */
 public boolean merge(final Parameter aParameter) {
   Parameter.logger.trace("merge");
   // UI must match
   if (!this.getUiLevel().equals(aParameter.getUiLevel())) {
     Parameter.logger.warn(
         "UI of parameter " + this.sName + " and " + aParameter.sName + " not matching.");
     return false;
   }
   // merge long name
   for (final String sLocale : aParameter.getLongNames().getSetOfLocale()) {
     if (this.getLongNames().hasLocale(sLocale)) {
       this.addLongName(sLocale, aParameter.getLongName(sLocale));
     }
   }
   return true;
 }
Exemplo n.º 2
0
  public static void initTasklists() throws InitializationFailedException {
    logger.debug("-------------------------------------------------------");
    logger.debug(
        "Loading xml task files from tasklist directory: " + Property.get("PATH_TO_TASKLIST"));
    TasksListUnmarshaller aTaskListUnmarshaller = new TaskListUnmarshallerBeans(mapOfObserver);
    File[] tFileXML = ListFiles.listFiles(Property.get("PATH_TO_TASKLIST"), "\\.xml$");
    for (File aFile : tFileXML) {
      try {
        logger.debug("- Loading xml file: " + aFile.getName());
        aTaskListUnmarshaller.addURL(aFile.toURI().toURL());
        aTaskListUnmarshaller.unmarshal();
      } catch (MalformedURLException e) {
        logger.error(e.getMessage(), e);
      } catch (IOException e) {
        logger.error("Error reading file: " + aFile.getName(), e);
        logger.warn("> This task file will be skiped");
      } catch (Exception e) {
        logger.error("Error unmarshalling file: " + aFile.getName(), e);
        logger.warn("> This task file will be skiped");
      }
    }
    mapOfTask = aTaskListUnmarshaller.getMapOfTask();
    if (mapOfTask.size() == 0) {
      throw new InitializationFailedException(
          "No task have been loaded. Check task files in: " + Property.get("PATH_TO_TASKLIST"));
    } else {
      String s = "Map of tasks:";
      logger.debug(s + mapOfTask);
      logger.info("OK - " + mapOfTask.size() + " task(s) successfully loaded.");
    }

    logger.debug("-------------------------------------------------------");
    logger.debug(
        "Loading tasks metadata files from tasks language directory: "
            + Property.get("PATH_TO_TASK_LANGUAGE_FILES"));

    File defaultTaskFile =
        new File(
            Property.get("PATH_TO_TASK_LANGUAGE_FILES", "DEFAULT_LANGUAGE")
                + ".tasklist.properties");
    String defaultLang = Language.getDefaultLocale().getName();

    UCNProperties defaultProps = null;
    try {
      defaultProps = Language.load(defaultTaskFile);
      defaultProps.parse();
      logger.debug("> Found default tasks metadata file: " + defaultTaskFile.getPath());
      LanguageAction.addMetadatasProperties(Language.getDefaultLocale(), defaultProps);
      metadataProperties.put(Language.getDefaultLocale(), defaultProps);
      for (String taskKey : mapOfTask.keySet()) {
        Task task = mapOfTask.get(taskKey);
        if (defaultProps.containsKey(taskKey))
          task.addLongName(defaultLang, defaultProps.getProperty(taskKey));
        else {
          task.addLongName(defaultLang, taskKey);
          logger.warn(
              ">> No default longname found for the task: "
                  + taskKey
                  + ". This task longname will be its key and it won't appear in the translation form.");
        }
        if (defaultProps.containsKey(taskKey + ".description"))
          task.addDescription(defaultLang, defaultProps.getProperty(taskKey + ".description"));
        else
          logger.warn(
              ">> No default description found for the task: "
                  + taskKey
                  + ". This task description will be empty and it won't appear in the translation form.");

        Map<String, Parameter> params = task.getMapOfParameter();
        for (Object paramKey : params.keySet()) {
          Parameter param = (Parameter) params.get(paramKey);
          if (defaultProps.containsKey(taskKey + ".param." + paramKey))
            param.addLongName(
                defaultLang, defaultProps.getProperty(taskKey + ".param." + paramKey));
          else if (defaultProps.containsKey("param." + paramKey))
            param.addLongName(defaultLang, defaultProps.getProperty("param." + paramKey));
          else
            logger.warn(
                ">> No default parameter longname found for the parameter: "
                    + paramKey
                    + ". This parameter longname will be its key and it won't appear in the translation form.");

          Map<String, Value> values = param.getMapOfValue();
          for (Object valueKey : values.keySet()) {
            Value value = (Value) values.get(valueKey);
            if (defaultProps.containsKey(taskKey + ".param." + paramKey + "." + valueKey))
              value.addLongName(
                  defaultLang,
                  defaultProps.getProperty(taskKey + ".param." + paramKey + "." + valueKey));
            else if (defaultProps.containsKey("param." + paramKey + "." + valueKey))
              value.addLongName(
                  defaultLang, defaultProps.getProperty("param." + paramKey + "." + valueKey));
            else if (param.getUiLevel() != TUi.NONE
                && !value.hasLongName(
                    defaultLang)) { // Warn only if the value is displayed and option name is not
                                    // defined directly in contract
              value.addLongName(defaultLang, value.getName());
              logger.warn(
                  ">> No default value longname found for the value \""
                      + valueKey
                      + "\" for the parameter \""
                      + paramKey
                      + "\" from the task "
                      + taskKey
                      + ". This value longname will be its key and it won't appear in the translation form.");
            }
          }
        }
      }
    } catch (IllegalArgumentException e) {
      logger.warn(e.getMessage());
    } catch (FileNotFoundException e) {
      throw new InitializationFailedException(
          "Default tasks metadata file does not exist: " + defaultTaskFile.getPath());
    } catch (IOException e) {
      throw new InitializationFailedException(
          "Unable to read default tasks metadata file " + defaultTaskFile);
    }

    File[] taskFiles =
        ListFiles.listFiles(Property.get("PATH_TO_TASK_LANGUAGE_FILES"), "\\.tasklist.properties$");

    for (File taskFile : taskFiles) {
      if (taskFile.equals(defaultTaskFile)) continue;
      try {
        ULocale fileLocale = Language.getLocaleFromFileName(taskFile.getName());
        String lang = fileLocale.getName();
        UCNProperties props = Language.load(taskFile);
        props.parse();
        logger.debug("> Found tasks metadata file: " + taskFile.getPath());

        ArrayList<Object> keys = new ArrayList<Object>();
        for (Object key : props.keySet()) {
          if (defaultProps != null && !defaultProps.containsKey(key)) {
            keys.add(key);
            logger.warn(
                ">> Unknown key \""
                    + key
                    + "\" found in "
                    + taskFile.getPath()
                    + ". Please remove this key manually from the tasklist properties file.");
          }
        }
        for (Object key : keys) props.remove(key);

        LanguageAction.addMetadatasProperties(fileLocale, props);
        metadataProperties.put(fileLocale, props);

        for (String taskKey : mapOfTask.keySet()) {
          Task task = mapOfTask.get(taskKey);
          if (props.containsKey(taskKey)) task.addLongName(lang, props.getProperty(taskKey));
          if (props.containsKey(taskKey + ".description"))
            task.addDescription(lang, props.getProperty(taskKey + ".description"));

          Map<String, Parameter> params = task.getMapOfParameter();
          for (Object paramKey : params.keySet()) {
            Parameter param = (Parameter) params.get(paramKey);
            if (props.containsKey(taskKey + ".param." + paramKey))
              param.addLongName(lang, props.getProperty(taskKey + ".param." + paramKey));
            else if (props.containsKey("param." + paramKey))
              param.addLongName(lang, props.getProperty("param." + paramKey));

            Map<String, Value> values = param.getMapOfValue();
            for (Object valueKey : values.keySet()) {
              Value value = (Value) values.get(valueKey);
              if (props.containsKey(taskKey + ".param." + paramKey + "." + valueKey))
                value.addLongName(
                    lang, props.getProperty(taskKey + ".param." + paramKey + "." + valueKey));
              else if (props.containsKey("param." + paramKey + "." + valueKey))
                value.addLongName(lang, props.getProperty("param." + paramKey + "." + valueKey));
            }
          }
        }
      } catch (IllegalArgumentException e) {
        logger.warn(e.getMessage());
      } catch (FileNotFoundException e) {
        // Should not happen
        logger.error(e.getMessage(), e);
      } catch (IOException e) {
        logger.error("Unable to read task file " + taskFile + ". This file will be skiped.");
      }
    }
  }