@Override
 public void loadFromXML(Reader in) throws IOException {
   XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
   setStatusCodes(xml.getString("statusCodes", getStatusCodes()));
   setOutputDir(xml.getString("outputDir", getOutputDir()));
   setFileNamePrefix(xml.getString("fileNamePrefix", getFileNamePrefix()));
 }
Beispiel #2
0
 /**
  * Get a connection to MySQL database named in madaap.xml file
  *
  * @return
  */
 static Connection getMySQLconnection() {
   Connection mysqlconn = null;
   try {
     Class.forName("com.mysql.jdbc.Driver").newInstance();
   } catch (Exception e) {
     System.out.println(e.getMessage() + "\nCannot register MySQL to DriverManager");
   }
   try {
     XMLConfiguration config = new XMLConfiguration("config/madaap.xml");
     Properties connectionProp = new Properties();
     System.out.println(config.getString("database.username"));
     connectionProp.put("user", config.getString("database.username"));
     connectionProp.put("password", config.getString("database.password"));
     mysqlconn =
         DriverManager.getConnection(
             "jdbc:mysql"
                 + "://"
                 + config.getString("database.url")
                 + ":"
                 + config.getString("database.port")
                 + "/madaap",
             connectionProp);
   } catch (SQLException e) {
     System.out.println(e.getMessage() + "\nCannot connect to MySQL. Check if MySQL is running.");
     System.exit(0);
   } catch (ConfigurationException e) {
     e.printStackTrace();
   }
   System.out.println("Connection made to MySQL");
   return mysqlconn;
 }
Beispiel #3
0
  public void run() {
    String sourceDir = config.getString("source.path");
    String destDir = config.getString("destination.path");
    String sourceFilePath = file.toString();
    Xls2xmlStats.setThreadFileProcess(Thread.currentThread().getName(), sourceFilePath);
    if (isDebugging) {
      log.debug("Processing " + sourceFilePath);
    }
    // Destination file is same directory in output with xml
    String destFilePath = sourceFilePath.substring(sourceDir.length());
    if (destFilePath.startsWith(File.separator)) {
      destFilePath = destFilePath.substring(1);
    }
    // Add extensions with .xml
    destFilePath = destFilePath + ".xml";
    File destFile = new File(destDir, destFilePath);
    destFilePath = destFile.toString();
    try {
      if (ignoreExisting && destFile.exists() && (FileUtils.sizeOf(destFile) > 0)) {
        log.debug("Ignoring the recreation of file: " + destFilePath);
        log.debug("Filesize is: " + FileUtils.sizeOf(destFile));
      } else {
        FileUtils.touch(destFile);

        if (isDebugging) {
          log.debug("Created destination file: " + destFilePath);
        }
        // Put some XML in the file

        String processedXML = process2xml();

        BufferedWriter output = new BufferedWriter(new FileWriter(destFile));

        // Only write data to the file if there is data from the processing
        if (!processedXML.equals("")) {
          output.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
          output.newLine();
          String roottag = config.getString("conversion.tags.root");
          output.append("<" + roottag + ">");
          output.newLine();
          output.append(processedXML);
          output.append("</" + roottag + ">");
        }

        output.close();
      }
    } catch (IOException ioe) {
      log.error("Could not create destination file: " + destFilePath, ioe);
    }

    Xls2xmlStats.recordFileProcessed();
    Xls2xmlStats.setThreadFileProcess(Thread.currentThread().getName(), "");
    log.info("STATISTICS: " + Xls2xmlStats.status());
  }
Beispiel #4
0
 public static boolean loadConfig(String configFilePath) {
   String tmp = System.getProperty("os.name").toLowerCase();
   if (tmp.startsWith("windows")) {
     g.os = g.OS_WINDOWS;
   } else if (tmp.startsWith("linux")) {
     g.os = g.OS_LINUX;
   } else {
     g.os = g.OS_OTHER;
   }
   tmp = System.getProperty("sun.arch.data.model");
   if (tmp.equals("64")) {
     g.arch = g.ARCH_64;
   } else {
     g.arch = g.ARCH_32;
   }
   try {
     if (configFilePath == null) {
       config = new XMLConfiguration(configPath + "config.xml");
     } else {
       config = new XMLConfiguration(configFilePath);
     }
     dbConfig = config.getString("db", "").toLowerCase();
     siteUrl = config.getString("serverInfo.siteUrl");
     siteName = config.getString("serverInfo.siteName");
     uploadTemp = rootPath + config.getString("serverInfo.uploadTemp");
     uploadSizeMax = config.getLong("serverInfo.uploadSizeMax", 0);
     sessionExpiredTime = config.getInt("serverInfo.sessionExpiredTime", 0);
     sessionIdName = config.getString("serverInfo.sessionIdName", "ycsid");
     String _s = g.getConfig().getString("startup");
     if ("".equals(_s)) {
       startup = null;
     } else {
       _s = _s.replaceAll("\\s", "");
       startup = _s.split(";");
     }
     _s = null;
     // 加载全局参数
     List<HierarchicalConfiguration> fields = config.configurationsAt("globalVars.var");
     if (fields != null && fields.size() > 0) {
       vars = new String[fields.size()][2];
       HierarchicalConfiguration sub;
       for (int i = 0; i < fields.size(); i++) {
         sub = fields.get(i);
         vars[i][0] = sub.getString("[@name]");
         vars[i][1] = sub.getString("[@value]");
       }
       sub = null;
     }
     return true;
   } catch (ConfigurationException e) {
     return false;
   }
 }
Beispiel #5
0
  /**
   * Load configuration
   *
   * @param config
   * @throws IllegalArgumentException if any required configuration element is invalid or missing
   * @throws IllegalStateException if authentication fails
   * @exception NumberFormatException if any required string property does not contain a parsable
   *     integer.
   */
  public void load(XMLConfiguration config) {
    this.config = config;
    final String url = config.getString("baseURL");
    // see http://commons.apache.org/configuration/userguide/howto_xml.html
    if (StringUtils.isBlank(url)) {
      // TODO: if any tests don't require baseURL then may this optional and have tests check and
      // mark status = SKIPPED
      throw new IllegalArgumentException("baseURL property must be defined");
    } else {
      try {
        baseURL = new URI(url);
        if (baseURL.getQuery() != null) {
          log.error("6.1.1 baseURL MUST NOT contain a query component, baseURL=" + baseURL);
        }
        baseUrlString = baseURL.toASCIIString();
        final String baseRawString = baseURL.toString();
        if (!baseUrlString.equals(baseRawString)) {
          log.warn(
              "baseURL appears to have non-ASCII characters and comparisons using URL may have problems");
          log.debug("baseURL ASCII String=" + baseUrlString);
          log.debug("baseURL raw String=" + baseRawString);
        }
        if (!baseUrlString.endsWith("/")) baseUrlString += '/'; // end the baseURL with slash
      } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
      }
    }

    // setup HTTP proxy if required
    String proxyHost = config.getString("proxy.host");
    String proxyPort = config.getString("proxy.port");
    if (StringUtils.isNotBlank(proxyHost) && StringUtils.isNotBlank(proxyPort)) {
      proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort), "http");
    }

    // load optional HttpRequestChecker for HTTP request handling
    final String httpRequestCheckerClass = config.getString("HttpRequestChecker");
    if (StringUtils.isNotBlank(httpRequestCheckerClass)) {
      try {
        Class httpClass = Class.forName(httpRequestCheckerClass);
        httpRequestChecker = (HttpRequestChecker) httpClass.newInstance();
        httpRequestChecker.setup(this);
        if (httpRequestChecker.getCurrentUser(this) != null) currentUser = DEFAULT_USER;
      } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e);
      } catch (InstantiationException e) {
        throw new IllegalArgumentException(e);
      } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(e);
      }
    }
  }
Beispiel #6
0
  public static void main(String[] args) throws Exception {

    /*Set to your Gate installation home*/
    XMLConfiguration config = new XMLConfiguration("config/madaap.xml");
    Gate.setGateHome(new File(config.getString("gate.home")));

    Gate.init();

    Gate.getCreoleRegister()
        .registerDirectories(
            new File(Gate.getPluginsHome(), ANNIEConstants.PLUGIN_DIR).toURI().toURL());

    /*Set the path to \Plugins\Tools directory*/
    Gate.getCreoleRegister()
        .registerDirectories(
            new File(config.getString("gate.home") + "\\plugins\\Tools").toURI().toURL());

    /*Declare queue to receive URL from various collectors*/
    BlockingQueue<URL> queue = new LinkedBlockingQueue<URL>();

    /*Start extractor, initialization will run the thread*/
    Extractor e = new Extractor(queue);

    /*Timer to schedule collector tasks at regular intervals*/
    Timer timer = new Timer();

    /*Collect URL from /input/url.txt*/
    TimerTask manualFeederTask = new ManualFeeder(queue);
    long manualFeederTime =
        Long.parseLong(config.getString("timer.ManualFeederInterval"))
            * ONE_HOUR; // Unit of ManualFeederTime: hour
    timer.scheduleAtFixedRate(manualFeederTask, 0, manualFeederTime);

    /*Collect URL from twitter feed*/

    TimerTask twitterTask = new Twitter(queue);
    long twitterTime =
        Long.parseLong(config.getString("timer.TwitterInterval"))
            * ONE_MIN; // Unit of twitterTime: minutes
    timer.scheduleAtFixedRate(twitterTask, 0, twitterTime);

    /*Check all URL if they are active or not*/
    TimerTask checkerTask = new Checker();
    long checkerTime =
        Long.parseLong(config.getString("timer.CheckerInterval"))
            * ONE_HOUR; // Unit of CheckerTime: hour
    timer.scheduleAtFixedRate(checkerTask, 0, checkerTime);
  }
 @Override
 public void loadFromXML(Reader in) {
   XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
   setRegex(xml.getString(""));
   super.loadFromXML(xml);
   setCaseSensitive(xml.getBoolean("[@caseSensitive]", false));
 }
Beispiel #8
0
 private void readProblemType(XMLConfiguration vrpProblem) {
   String fleetSize = vrpProblem.getString("problemType.fleetSize");
   if (fleetSize == null) vrpBuilder.setFleetSize(FleetSize.INFINITE);
   else if (fleetSize.toUpperCase().equals(FleetSize.INFINITE.toString()))
     vrpBuilder.setFleetSize(FleetSize.INFINITE);
   else vrpBuilder.setFleetSize(FleetSize.FINITE);
 }
Beispiel #9
0
 private void loadConfiguration(String url) {
   try {
     XMLConfiguration config = new XMLConfiguration(url);
     config.getString("webservice.port");
   } catch (ConfigurationException ex) {
     Logger.getLogger(JEConfig.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
Beispiel #10
0
 /**
  * Dada una clave del fichero <b>XML</b> retorna el valor de dicha propiedad. En caso de no
  * existir la propiedad retorna el valor de <i>defaultValue</i>.
  *
  * @param key de la propiedad que se quiere obtener.
  * @param defaultValue valor a retornar en caso de no existir la propiedad
  * @return valor de la propiedad indicada o <b>defaultValue</b> si la propiedad no existe en el
  *     fichero
  * @throws ConfigUtilException si el fichero no existe
  */
 @Override
 public String getProperty(String key, String defaultValue) throws ConfigUtilException {
   try {
     return (String) configuration.getString(key, defaultValue);
   } catch (Exception e) {
     throw new ConfigUtilException(e.getMessage(), e);
   }
 }
Beispiel #11
0
  public ToolBelt(String configFile) throws FitsConfigurationException {
    XMLConfiguration config = null;
    try {
      config = new XMLConfiguration(configFile);
    } catch (ConfigurationException e) {
      throw new FitsConfigurationException("Error reading " + configFile, e);
    }

    // Collect the tools-used elements
    List<ToolsUsedItem> toolsUsedList = processToolsUsed(config);

    tools = new ArrayList<Tool>();

    // get number of tools
    int size = config.getList("tools.tool[@class]").size();
    // for each tools get the class path and any excluded extensions
    for (int i = 0; i < size; i++) {
      String tClass = config.getString("tools.tool(" + i + ")[@class]");
      @SuppressWarnings("unchecked")
      List<String> excludes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@exclude-exts]");
      @SuppressWarnings("unchecked")
      List<String> includes =
          (List<String>) (List<?>) config.getList("tools.tool(" + i + ")[@include-exts]");
      Tool t = null;
      try {
        @SuppressWarnings("rawtypes")
        Class c = Class.forName(tClass);
        t = (Tool) c.newInstance();
      } catch (Exception e) {
        // Can't use this tool, but continue anyway.
        // throw new FitsConfigurationException("Error initializing "+tClass,e);
        logger.error(
            "Thread "
                + Thread.currentThread().getId()
                + " error initializing "
                + tClass
                + ": "
                + e.getClass().getName()
                + "  Message: "
                + e.getMessage());
        continue;
      }
      if (t != null) {
        t.setName(bareClassName(tClass));
        for (String ext : excludes) {
          t.addExcludedExtension(ext);
        }
        for (String ext : includes) {
          t.addIncludedExtension(ext);
        }
        // Modify included and excluded extensions by tools-used
        t.applyToolsUsed(toolsUsedList);
        tools.add(t);
      }
    }
  }
  @Override
  public void loadFromXML(Reader in) {
    XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
    setSourceReferenceField(xml.getString("sourceReferenceField", sourceReferenceField));
    setKeepSourceReferenceField(
        xml.getBoolean("sourceReferenceField[@keep]", keepSourceReferenceField));
    setTargetReferenceField(xml.getString("targetReferenceField", targetReferenceField));
    setSourceContentField(xml.getString("sourceContentField", sourceContentField));
    setKeepSourceContentField(xml.getBoolean("sourceContentField[@keep]", keepSourceContentField));
    setTargetContentField(xml.getString("targetContentField", targetContentField));
    setQueueDir(xml.getString("queueDir", DEFAULT_QUEUE_DIR));
    setQueueSize(xml.getInt("queueSize", AbstractBatchCommitter.DEFAULT_QUEUE_SIZE));
    setCommitBatchSize(
        xml.getInt("commitBatchSize", AbstractBatchCommitter.DEFAULT_COMMIT_BATCH_SIZE));
    setMaxRetries(xml.getInt("maxRetries", 0));
    setMaxRetryWait(xml.getInt("maxRetryWait", 0));

    loadFromXml(xml);
  }
  /**
   * Answers the configured value for a named parameter.
   *
   * @param paramName the name of the parameter
   * @param paramConfigName the name of the parameter within the config file
   * @param defaultValue the default value to use if no value exists within the config file
   * @param valueRequired <code>true</code> if the parameter is mandatory
   * @return the configured value of the named parameter
   * @throws RavenConfigurationException if the value is required and no value exists within the
   *     config file
   */
  protected final String configureParam(
      String paramName, String paramConfigName, String defaultValue, boolean valueRequired)
      throws RavenConfigurationException {

    String paramValue = Config.getString(paramConfigName);
    if (paramValue == null) {
      if (defaultValue != null) {
        paramValue = defaultValue;
      } else if (valueRequired) {
        throw new RavenConfigurationException(paramConfigName);
      }
    }
    return paramValue;
  }
 @Override
 public void loadFromXML(Reader in) throws IOException {
   try {
     XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
     defaultDelay = xml.getLong("[@default]", defaultDelay);
     ignoreRobotsCrawlDelay = xml.getBoolean("[@ignoreRobotsCrawlDelay]", ignoreRobotsCrawlDelay);
     scope = xml.getString("[@scope]", SCOPE_CRAWLER);
     List<HierarchicalConfiguration> nodes = xml.configurationsAt("schedule");
     for (HierarchicalConfiguration node : nodes) {
       schedules.add(
           new DelaySchedule(
               node.getString("[@dayOfWeek]", null),
               node.getString("[@dayOfMonth]", null),
               node.getString("[@time]", null),
               node.getLong("", DEFAULT_DELAY)));
     }
   } catch (ConfigurationException e) {
     throw new IOException("Cannot load XML.", e);
   }
 }
Beispiel #15
0
  public void runSingleFile() {
    String destFilePath = "";

    try {

      File destFile = specificDestFile;
      destFilePath = destFile.getCanonicalPath();

      if (ignoreExisting && destFile.exists() && (FileUtils.sizeOf(destFile) > 0)) {
        log.debug("Ignoring the recreation of file: " + destFilePath);
        log.debug("Filesize is: " + FileUtils.sizeOf(destFile));
      } else {
        FileUtils.touch(destFile);

        if (isDebugging) {
          log.debug("Created destination file: " + destFilePath);
        }
        // Put some XML in the file

        String processedXML = process2xml();

        BufferedWriter output = new BufferedWriter(new FileWriter(destFile));

        // Only write data to the file if there is data from the processing
        if (!processedXML.equals("")) {
          output.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
          output.newLine();
          String roottag = config.getString("conversion.tags.root");
          output.append("<" + roottag + ">");
          output.newLine();
          output.append(processedXML);
          output.append("</" + roottag + ">");
        }

        output.close();
      }

    } catch (IOException ioe) {
      log.error("Could not create destination file: " + destFilePath, ioe);
    }
  }
Beispiel #16
0
 /**
  * Get a string associated with the given configuration key.
  *
  * @param key The configuration key
  * @return The associated string value if key is found otherwise null
  */
 @CheckForNull
 public String getString(String key) {
   return config != null ? config.getString(key) : null;
 }
  @SuppressWarnings("unchecked")
  public void test() {
    try {
      confRuns.setFileName("confRuns.xml");
      confDbs.setFileName("confDbs.xml");
      confDatasources.setFileName("confDatasources.xml");
      confMethods.setFileName("confMethods.xml");

      confRuns.load();
      confDbs.load();
      confDatasources.load();
      confMethods.load();

      List<String> runs = confRuns.getList("run");
      log.info("Start of testing");
      // runs = new TestRun[confRuns.getInt("threads")];
      int numRuns = confRuns.getInt("threads");
      String resultsFile = "";
      semRuns = new Semaphore(numRuns);
      // Iterate through runs
      for (String run : runs) {
        int dbId = 0;
        run = "runs." + run;
        // Iterate through dbs
        while (confRuns.getProperty(run + ".dbs.db(" + dbId + ").name") != null) {
          String dbName = confRuns.getString(run + ".dbs.db(" + dbId + ").name");
          List<String> datasources = confRuns.getList(run + ".dbs.db(" + dbId + ").datasources");
          int datasourceId = 0;
          // Iterate through datasources
          for (String datasourceName : datasources) {
            int methodId = 0;
            // Iterate through methods
            while (confRuns.getProperty(run + ".methods.method(" + methodId + ").name") != null) {
              String methodName =
                  confRuns.getString(run + ".methods.method(" + methodId + ").name");
              int testId = 0;
              // Iterate through tests
              while (confRuns.getProperty(run + ".tests.test(" + testId + ").class") != null) {
                synchronized (semRuns) {
                  // Waiting for a free slot;
                  semRuns.acquire();

                  String testClass = confRuns.getString(run + ".tests.test(" + testId + ").class");
                  Constructor[] a = Class.forName(testClass).getConstructors();
                  log.info("Datasource " + datasourceName + ", method " + methodName);
                  System.gc();
                  BasicDataSource trainDataSource = getDataSource(datasourceName, dbName);
                  trainDataSource.configDriver(confRuns, run + ".dbs.db(" + dbId + ")");
                  trainDataSource.configDataSource(
                      confRuns, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");
                  BasicDataSource testDataSource = getDataSource(datasourceName, dbName);
                  testDataSource.configDriver(confRuns, run + ".dbs.db(" + dbId + ")");
                  testDataSource.configDataSource(
                      confRuns, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");

                  // ExportAsTHSource.exportAsTHSource(trainDataSource, "C:\\data\\",
                  // trainDataSource.getName());
                  // writeRecords(trainDataSource);
                  // writeRecords(testDataSource);
                  // DataSourceStatistics b = new DataSourceStatistics(trainDataSource.getName());
                  // b.getStatistics(trainDataSource);
                  // semRuns.release();
                  InductiveMethod method = getMethod(methodName);
                  method.configClassifier(confRuns, run + ".methods.method(" + methodId + ")");

                  Test test = (Test) a[0].newInstance();
                  test.configTest(confRuns, run + ".tests.test(" + testId + ")");
                  resultsFile = test.getResultsInterpreter().getFilePrefix() + ".csv";

                  log.info("Testing datasource " + trainDataSource.getName());
                  // Making new thread for a new test.
                  new TestRun(this, trainDataSource, testDataSource, method, test).start();
                  // Wait 1 second for avoid of the colision
                  // in writing of results.
                  Thread.sleep(1000);
                }
                testId++;
              }
              methodId++;
            }
            datasourceId++;
          }
          dbId++;
        }
      }
      // Waiting for all other threads to finish.
      for (int i = 0; i < numRuns; i++) semRuns.acquire();

      log.info("End of testing");

      Process p = Runtime.getRuntime().exec("cmd ", null, null);
      p.getOutputStream().write(("loadResults.bat " + resultsFile + "\n").getBytes());
      p.getOutputStream().flush();
      p.getOutputStream().write("exit\n".getBytes());
      p.getOutputStream().flush();
      BufferedReader stdOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
      while (true) {
        try {
          p.exitValue();
          break;
        } catch (Exception e) {
          while (stdOut.ready() || stdErr.ready()) {
            if (stdOut.ready()) stdOut.readLine();
            else stdErr.readLine();
          }
        }
      }
      p.waitFor();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #18
0
  public String process2xml() {
    String result = "";
    // String sourcefilenametag = config.getString("conversion.tags.sourcefilename");
    String sourcefilename = file.getAbsolutePath();
    try {
      sourcefilename = file.getCanonicalPath();
    } catch (IOException ioe) {
      log.warn("Could not get cannonical path for file!", ioe);
    }
    String templatedir = config.getString("conversion.template.path");

    // result += "<" + sourcefilenametag + "><![CDATA[" + file.toString() + "]]></" +
    // sourcefilenametag + ">";
    try {
      Workbook input = WorkbookFactory.create(file);

      log.debug("Processing " + file.toString() + " as an Excel file.");

      FormulaEvaluator evaluator = input.getCreationHelper().createFormulaEvaluator();

      String templateName = "";

      STGroup g = new STRawGroupDir(templatedir, '$', '$');

      // Go through each sheet
      for (int sheetno = 0; sheetno < input.getNumberOfSheets(); sheetno++) {

        Sheet sheet = input.getSheetAt(sheetno);

        log.debug("Processing sheet #" + sheetno + ": " + sheet.getSheetName());

        LandmarkMatchList lml = new LandmarkMatchList(landmarks.size());

        for (Row row : sheet) {

          // Go through each cell
          for (Cell cell : row) {
            String cellvalue = lml.getCellValue(cell, evaluator);

            if (!cellvalue.equals("")) {
              log.trace(
                  "Cell value is: "
                      + cellvalue
                      + " [Row,Col]=["
                      + cell.getRowIndex()
                      + ","
                      + cell.getColumnIndex()
                      + "]");
              log.trace("Matching landmarks: " + landmarks.getLandmarksFor(cellvalue));

              // Does Cell contents match a landmark?
              lml.addMatches(landmarks.getLandmarksFor(cellvalue), cell);
            } else {
              log.trace(
                  "Cell value is blank. [Row,Col]=["
                      + cell.getRowIndex()
                      + ","
                      + cell.getColumnIndex()
                      + "]");
            }
          }
        }

        templateName = lml.getTemplateName(landmarks);

        if (!templateName.equals("")) {

          ST st = g.getInstanceOf(templateName);

          if (st != null) {

            // Set landmark name to value of cell given direction and distance

            Hashtable templateValues =
                lml.getCellTemplateValues(
                    templateName, sheet, landmarks, evaluator, sourcefilename, sheetno);
            Enumeration templateValuesKeys = templateValues.keys();

            while (templateValuesKeys.hasMoreElements()) {
              String key = (String) templateValuesKeys.nextElement();
              st.add(key, (String) templateValues.get(key));
            }

            ArrayList<String> sectionNames =
                lml.getSectionNamesForTemplate(templateName, landmarks);
            for (String sectionName : sectionNames) {

              ArrayList<Hashtable> sectionrows =
                  lml.getSectionRows(templateName, sheet, landmarks, evaluator, sectionName);

              st.add(sectionName, sectionrows);
            }

            result += st.render();
          } else {
            log.error(
                "Unable to load template "
                    + templateName
                    + ".st! Cannot render data to template while processing "
                    + file.toString()
                    + " sheet number "
                    + sheetno);
          }
        }
      }

    } catch (IOException ioe) {
      log.error("Unable to open " + file.toString() + " as an Excel file.", ioe);
    } catch (InvalidFormatException ife) {
      log.error("Unable to open " + file.toString() + ". Format not recognized as Excel. ", ife);
    } catch (IllegalArgumentException iae) {
      log.error("Unable to open " + file.toString() + " as an Excel file.", iae);
    } catch (Exception e) {
      log.error("Unable to open " + file.toString() + " as an Excel file.", e);
    }
    // If cannot render, make sure don't reprocess unnecessarily
    if (result.equals("")) {
      result = "<Notemplatedata></Notemplatedata>";
    }
    return result;
  }
 /**
  * 封装了PropertiesConfiguration类的getString函数,使p变量对子类透明.
  *
  * @param key property key.
  * @param defaultValue 当使用property key在properties中取不到值时的默认值.
  */
 public static String getString(String key, String defaultValue) {
   return pc.getString(key, defaultValue);
 }
  @SuppressWarnings("unchecked")
  public void test() {
    try {
      confMonoTests.setFileName("confMonoTests.xml");
      confDbs.setFileName("confDbs.xml");
      confDatasources.setFileName("confDatasources.xml");

      confMonoTests.load();
      confDbs.load();
      confDatasources.load();

      List<String> runs = confMonoTests.getList("run");
      log.info("Start of testing");
      // runs = new TestRun[confRuns.getInt("threads")];
      int numRuns = confMonoTests.getInt("threads");
      String resultsFile = "";
      semRuns = new Semaphore(numRuns);
      // Iterate through runs
      for (String run : runs) {
        int dbId = 0;
        run = "runs." + run;
        // Iterate through dbs
        while (confMonoTests.getProperty(run + ".dbs.db(" + dbId + ").name") != null) {
          String dbName = confMonoTests.getString(run + ".dbs.db(" + dbId + ").name");
          List<String> datasources =
              confMonoTests.getList(run + ".dbs.db(" + dbId + ").datasources");
          int datasourceId = 0;
          // Iterate through datasources
          for (String datasourceName : datasources) {
            int methodId = 0;
            // Load possible normalizers
            List<String> numericalNorms =
                confMonoTests.getList(run + ".normalizers.numericalNormalizer");
            List<String> nominalNormalizers =
                confMonoTests.getList(run + ".normalizers.nominalNormalizer");
            List<String> listNormalizer =
                confMonoTests.getList(run + ".normalizers.listNormalizer");
            // Iterate through tests
            if (confMonoTests.getProperty(run + ".test.path") != null) {
              synchronized (semRuns) {
                // Waiting for a free slot;
                semRuns.acquire();

                System.gc();
                BasicDataSource trainDataSource = getDataSource(datasourceName, dbName);
                trainDataSource.configDriver(confMonoTests, run + ".dbs.db(" + dbId + ")");
                trainDataSource.configDataSource(
                    confMonoTests, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");
                BasicDataSource testDataSource = getDataSource(datasourceName, dbName);
                testDataSource.configDriver(confMonoTests, run + ".dbs.db(" + dbId + ")");
                testDataSource.configDataSource(
                    confMonoTests, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");

                MonotonicityTest mt = new MonotonicityTest();
                mt.configTest(confMonoTests, run + ".test");
                log.info("Testing datasource " + trainDataSource.getName());
                // Making new thread for a new test.
                new TestRun(
                        this,
                        mt,
                        trainDataSource,
                        testDataSource,
                        getNorms(nominalNormalizers),
                        getNorms(numericalNorms),
                        getNorms(listNormalizer))
                    .start();
                // Wait 1 second for avoid of the colision
                // in writing of results.
                Thread.sleep(1000);
              }
            }
            datasourceId++;
          }
          dbId++;
        }
      }

      // Waiting for all other threads to finish.
      for (int i = 0; i < numRuns; i++) semRuns.acquire();

      log.info("End of testing");

      Process p = Runtime.getRuntime().exec("cmd ", null, null);
      p.getOutputStream().write(("loadResults.bat " + resultsFile + "\n").getBytes());
      p.getOutputStream().flush();
      p.getOutputStream().write("exit\n".getBytes());
      p.getOutputStream().flush();
      BufferedReader stdOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
      while (true) {
        try {
          p.exitValue();
          break;
        } catch (Exception e) {
          while (stdOut.ready() || stdErr.ready()) {
            if (stdOut.ready()) stdOut.readLine();
            else stdErr.readLine();
          }
        }
      }
      p.waitFor();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #21
0
    /**
     * Connects to MSSP using SSL and waits for response.
     *
     * @param phoneNumber
     * @param selectedFile
     */
    protected void estamblishConnection(String phoneNumber, final File selectedFile) {

      XMLConfiguration config = null;
      try {
        config = new XMLConfiguration("fi/laverca/samples/configuration.xml");
      } catch (ConfigurationException e) {
        log.info("configuration file not found", e);
      }

      log.info("setting up ssl");
      JvmSsl.setSSL(
          config.getString("ssl.trustStore"),
          config.getString("ssl.trustStorePassword"),
          config.getString("ssl.keyStore"),
          config.getString("ssl.keyStorePassword"),
          config.getString("ssl.keyStoreType"));

      String apId = config.getString("ap.apId");
      String apPwd = config.getString("ap.apPwd");

      String msspSignatureUrl = config.getString("mssp.msspSignatureUrl");
      String msspStatusUrl = config.getString("mssp.msspStatusUrl");
      String msspReceiptUrl = config.getString("mssp.msspReceiptUrl");

      SignData.log.info("creating FiComClient");
      FiComClient fiComClient =
          new FiComClient(apId, apPwd, msspSignatureUrl, msspStatusUrl, msspReceiptUrl);

      final byte[] output = SignData.generateSHA1(selectedFile);
      String apTransId = "A" + System.currentTimeMillis();

      Service eventIdService = FiComAdditionalServices.createEventIdService(eventId);
      Service noSpamService = FiComAdditionalServices.createNoSpamService("A12", false);
      LinkedList<Service> additionalServices = new LinkedList<Service>();
      LinkedList<String> attributeNames = new LinkedList<String>();
      attributeNames.add(FiComAdditionalServices.PERSON_ID_VALIDUNTIL);
      Service personIdService = FiComAdditionalServices.createPersonIdService(attributeNames);
      additionalServices.add(personIdService);

      try {
        SignData.log.info("calling signData");
        req =
            fiComClient.signData(
                apTransId,
                output,
                phoneNumber,
                noSpamService,
                eventIdService,
                additionalServices,
                new FiComResponseHandler() {
                  @Override
                  public void onResponse(FiComRequest req, FiComResponse resp) {
                    SignData.log.info("got resp");
                    callStateProgressBar.setIndeterminate(false);
                    SignData.printSHA1(output, responseBox);

                    responseBox.setText(
                        "File path: "
                            + selectedFile.getAbsolutePath()
                            + "\n"
                            + responseBox.getText());

                    try {
                      responseBox.setText(
                          "MSS Signature: "
                              + new String(
                                  Base64.encode(
                                      resp.getMSS_StatusResp()
                                          .getMSS_Signature()
                                          .getBase64Signature()),
                                  "ASCII")
                              + "\nSigner: "
                              + resp.getPkcs7Signature().getSignerCn()
                              + "\n"
                              + responseBox.getText());
                      for (PersonIdAttribute a : resp.getPersonIdAttributes()) {
                        SignData.log.info(a.getName() + " " + a.getStringValue());
                        responseBox.setText(a.getStringValue() + "\n" + responseBox.getText());
                      }
                    } catch (UnsupportedEncodingException e) {
                      SignData.log.info("Unsupported encoding", e);
                    } catch (NullPointerException e) {
                      SignData.log.info("PersonIDAttributes = null", e);
                    }
                  }

                  @Override
                  public void onError(FiComRequest req, Throwable throwable) {
                    callStateProgressBar.setIndeterminate(false);
                    SignData.log.info("got error", throwable);
                  }

                  @Override
                  public void onOutstandingProgress(FiComRequest req, ProgressUpdate prgUpdate) {
                    // TODO Auto-generated method stub

                  }
                });
      } catch (IOException e) {
        SignData.log.info("error establishing connection", e);
      }

      fiComClient.shutdown();
    }