Пример #1
0
 /** Loads the configuration for log4j from the file log4j.properties */
 public void configureLogging() {
   // BasicConfigurator is used to quickly configure the package log4j
   // Add a ConsoleAppender that uses PatternLayout using the
   // PatternLayout.TTCC_CONVERSION_PATTERN
   // and prints to System.out to the root category.
   BasicConfigurator.configure();
   // Configure log4j by the url : log4j.properties.
   String fileName = "log4j_" + Configuration.instance().getLogLevel() + ".properties";
   System.out.println("Loading logging configuration file: " + fileName);
   URL url = Main.class.getResource(fileName);
   if (url == null) {
     System.out.println(
         "Logging configuration file not found - loading file: log4j_off.properties");
     url = Main.class.getResource("log4j_off.properties"); // $NON-NLS-1$
     if (url == null) {
       System.err.println("No logging configuration found");
       return;
     }
   }
   // PropertyConfigurator allows the configuration of log4j from an
   // external file
   // It will read configuration options from URL url.
   PropertyConfigurator.configure(url);
   LOG = Logger.getLogger(Configuration.class);
 }
Пример #2
0
  /**
   * Creates a new Help window associated with the JMenuItem passed as parameters
   *
   * @param help
   */
  public HelpWindow(JMenuItem help) {
    File path = new File(Configuration.instance().getTangaraPath().getParentFile(), "Help");

    File log = new File(path, LOG_FILE);

    if (!log.exists()) {
      // Log file does not exist : we create the help set
      createJavaHelp(path, Configuration.instance().getLanguage());
    } else {
      // Log file exists : we check that help set correspond to the current language
      try {
        BufferedReader reader = new BufferedReader(new FileReader(log));
        String ligne = reader.readLine();
        if (ligne != null) {
          StringTokenizer st = new StringTokenizer(ligne);
          if (st.nextToken().equals("Language")
              && !st.nextToken().equals(Configuration.instance().getLanguage()))
            // Language has changed: we re-create the help set
            createJavaHelp(path, Configuration.instance().getLanguage());
        }
        reader.close();
      } catch (Exception e) {
        LOG.error("Error while reading log file " + e);
      }
    }

    // Set up the help viewer
    // FIXME help desactivated
    //		try {
    //			URL [] list = new URL[1];
    //			list[0] = path.toURI().toURL();
    //
    //			ClassLoader cl = new URLClassLoader(list);
    //			URL url = HelpSet.findHelpSet(cl, HELPSET_NAME, new
    // Locale(Configuration.instance().getLanguage()));
    //			HelpSet hs = new HelpSet(cl, url);
    //
    //			HelpBroker hb = hs.createHelpBroker();
    //
    //			CSH.setHelpIDString(help, FIRST_PAGE);
    //
    //			help.addActionListener(new CSH.DisplayHelpFromSource(hb));
    //		} catch (Exception e1) {
    //			LOG.error("Error1 " + e1);
    //		}
  }
Пример #3
0
  /**
   * Enables to get the name of an object in the spoken language thanks to the jar file
   *
   * @param jarName the file that contains the object classes
   * @return the object name in the spoken language
   */
  private String getLangName(File jarName) {
    String name = null;

    try {
      URL url = jarName.toURI().toURL();
      JarInputStream jarFile = new JarInputStream(url.openStream());
      JarEntry jarEntry = jarFile.getNextJarEntry();
      while (jarEntry != null) {
        if (!jarEntry.isDirectory()
            && jarEntry.getName().contains(Configuration.instance().getLanguage())) {
          int lang_index = jarEntry.getName().lastIndexOf(Configuration.instance().getLanguage());
          name = jarEntry.getName().substring(lang_index + 3, jarEntry.getName().length() - 6);
        }
        jarEntry = jarFile.getNextJarEntry();
      }
    } catch (Exception e) {
      LOG.error("Error getLangName " + jarName + " " + e);
    }
    return name;
  }
Пример #4
0
  private void mapAndTocForFile(File f, File path, String underscore) {
    // we get the single name of the file and the urlname
    int under_index2 = f.getName().indexOf("_");
    int point_index2 = f.getName().indexOf(".");
    String named = f.getName().substring(under_index2 + 1, point_index2);
    String tmp = path.getAbsolutePath() + "Main_pages/fr/";
    String url_name = f.getPath().replace("\\", "/").substring(tmp.length());
    String targetName = url_name.substring(0, url_name.lastIndexOf(".html"));

    // now we will add into the map and the toc
    print.println("<mapID target=\"" + targetName + "\" url=\"pages/" + url_name + "\"/>");
    File dir_associated = new File(f.getParent(), named);

    if ((dir_associated.exists() && dir_associated.isDirectory()) || named.equals("objects")) {
      print2.println(
          "<tocitem text=\"" + getTitle(f) + "\" target=\"" + targetName + "\" image=\"tamicon\">");
      if (dir_associated.exists()) {
        // Apres on fait pareil pour tous les sous fichiers
        File[] sub_files = dir_associated.listFiles();
        for (int i = 0; i < sub_files.length; i++) {
          if (!sub_files[i].getName().equals("CVS") && sub_files[i].isFile()) {
            if (sub_files[i].getName().endsWith(".html"))
              mapAndTocForFile(sub_files[i], path, underscore);
            else {
              try {
                copyFile(
                    sub_files[i], new File(path, "pages/" + named + "/" + sub_files[i].getName()));
              } catch (IOException e) {
                LOG.error("Error while copying normal files in help " + e);
              }
            }
          }
        }
      }
      if (named.equals("objects")) {
        // Specialement pour les objets on les rajoute tous
        File objects_dir =
            new File(
                Configuration.instance()
                        .getTangaraPath()
                        .getParentFile()
                        .getAbsolutePath()
                        .replace("\\", "/")
                    + "/objects/");
        File[] listfiles = objects_dir.listFiles();
        Vector<String> list_names = new Vector<String>();
        HashMap<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < listfiles.length; i++) {
          try {
            if (listfiles[i].getName().endsWith(".jar")) {
              int point_index = listfiles[i].getName().lastIndexOf(".");
              String name = listfiles[i].getName().substring(0, point_index);

              // Copy the pages in the right directory
              File object_dir = new File(path, "pages/" + name);
              object_dir.mkdir();
              File object_ressource =
                  new File(
                      Configuration.instance()
                              .getTangaraPath()
                              .getParentFile()
                              .getAbsolutePath()
                              .replace("\\", "/")
                          + "/objects/resources/"
                          + name
                          + "/Help");
              if (object_ressource.exists()) {
                File[] list_html_object = object_ressource.listFiles();
                for (int e = 0; e < list_html_object.length; e++) {
                  if (list_html_object[e].getName().endsWith(".html")) {
                    int under_index = list_html_object[e].getName().lastIndexOf("_");
                    if (underscore.equals("") && under_index == -1)
                      copyFile(
                          list_html_object[e],
                          new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                    else if (!underscore.equals("")) {
                      if (list_html_object[e].getName().contains(underscore))
                        copyFile(
                            list_html_object[e],
                            new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                    }
                  } else
                    copyFile(
                        list_html_object[e],
                        new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                }
                // Gets the name of the object in the selected language
                String name_lang = null;
                if (underscore.equals("")) name_lang = name;
                else {
                  name_lang = getLangName(listfiles[i]);
                }
                if (name_lang != null) {
                  list_names.add(name_lang);
                  map.put(name_lang, name);
                  // Add to the map file
                  print.println(
                      "<mapID target=\""
                          + name
                          + "\" url=\"pages/"
                          + name
                          + "/index"
                          + underscore
                          + ".html\" />");
                }
              }
            }
          } catch (Exception e2) {
            LOG.error("Error2 getHelp " + e2);
          }
        }
        // Add to the tam file
        Collections.sort(list_names);
        for (String s : list_names) {
          print2.println(
              "<tocitem text=\"" + s + "\" target=\"" + map.get(s) + "\" image=\"fileicon\" />");
        }
      }
      print2.println("</tocitem>");
    } else {
      // pas de sous fichiers
      print2.println(
          "<tocitem text=\""
              + getTitle(f)
              + "\" target=\""
              + targetName
              + "\" image=\"fileicon\"/>");
    }

    File parent = new File(path, "pages/" + url_name.substring(0, url_name.lastIndexOf(named) - 3));
    if (!parent.exists()) parent.mkdirs();
    File in_pages = new File(path, "pages/" + url_name);
    try {
      in_pages.createNewFile();
      copyFile(f, in_pages);
    } catch (IOException e3) {
      LOG.error("Error 3 getHelp " + e3 + " " + f.getName());
    }
  }