Exemplo n.º 1
0
  /**
   * writing all model class names into the classnames.properties file. like prefix =
   * 'qualifiedname'
   *
   * @param target
   * @param namespace
   * @throws IOException
   */
  public static void writeModelNames(JarOutputStream target, String namespace, List<Model> models)
      throws IOException {

    String fileName =
        DesktopURLKeys.RESOURCES.concat(File.separator).concat(DesktopURLKeys.MODEL_PROPERTIES);

    JarEntry entry = new JarEntry(fileName);
    entry.setTime(System.currentTimeMillis());
    target.putNextEntry(entry);
    JSONArray array = new JSONArray();
    for (Model model : models) {
      array.put(ModelInfo.toJSON(model));
    }
    target.write(array.toString().getBytes());
    target.closeEntry();
  }
Exemplo n.º 2
0
  private static void writeLabels(List<Translation> dbTranslations, JarOutputStream target)
      throws IOException {
    Map<Language, Map<String, String>> translations = new HashMap<>();
    for (Translation translation : dbTranslations) {
      Language language = translation.getLanguage();
      Map<String, String> map = translations.get(language);
      if (map == null) {
        map = new HashMap<>();
        translations.put(language, map);
      }
      map.put(translation._getLabelName(), translation.getValue());
    }

    if (translations.isEmpty()) {
      return;
    }

    String fileName = DesktopURLKeys.RESOURCES.concat(File.separator).concat(DesktopURLKeys.LABELS);

    JarEntry entry = new JarEntry(fileName);
    entry.setTime(System.currentTimeMillis());
    target.putNextEntry(entry);

    JSONArray results = new JSONArray();

    for (Entry<Language, Map<String, String>> translation : translations.entrySet()) {
      JSONObject result = new JSONObject();
      result.put(DesktopURLKeys.LANGUAGE, translation.getKey().getIdentity());
      JSONArray array = new JSONArray();
      result.put(DesktopURLKeys.TRANSLATIONS, array);
      translation
          .getValue()
          .forEach(
              (key, value) -> {
                JSONObject object = new JSONObject();
                object.put(DesktopURLKeys.LABEL_NAME, key);
                object.put(DesktopURLKeys.LABEL_VALUE, value);
                array.put(object);
              });

      results.put(result);
    }

    target.write(results.toString().getBytes());
    target.closeEntry();
  }