Пример #1
0
  public static void main(String[] args) {
    try {
      String corpusFile = args[0];
      String goldSet = args[1];
      File outputDir = new File(args[2]);

      SystemConfig systemConfig = DriverUtils.configure(args);
      systemConfig.setAnnotationSetName(Constants.GS_NP, goldSet);

      Trainer trainer = new Trainer(systemConfig);
      FeatureGenerator featureGenerator = new FeatureGenerator(systemConfig);

      // get corpus
      Corpus c = DriverUtils.loadFiles(corpusFile);

      Preprocessor preprocessor = new Preprocessor(systemConfig);
      preprocessor.preprocess(c, false);

      // generate features
      String featureSetName = featureGenerator.generateFeatures(c, true);

      // train classifier
      Classifier classifier = trainer.runLearner(c, outputDir, featureSetName);
      System.out.println("classifier trained: " + classifier.getName());

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ConfigurationException e) {
      e.printStackTrace();
    }
  }
Пример #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;
 }
Пример #3
0
  public ScanPolicy getDefaultScanPolicy() {
    try {
      String policyName = extension.getScannerParam().getDefaultPolicy();
      if (this.policyExists(policyName)) {
        logger.debug("getDefaultScanPolicy: " + policyName);
        return this.loadPolicy(policyName);
      }
      // No good, try the default name
      policyName = DEFAULT_POLICY_NAME;
      if (this.policyExists(policyName)) {
        logger.debug("getDefaultScanPolicy (default name): " + policyName);
        return this.loadPolicy(policyName);
      }
      if (this.allPolicyNames.size() > 0) {
        // Still no joy, try the first
        logger.debug("getDefaultScanPolicy (first one): " + policyName);
        return this.loadPolicy(this.allPolicyNames.get(0));
      }

    } catch (ConfigurationException e) {
      logger.error(e.getMessage(), e);
    }
    // Return a new 'blank' one
    logger.debug("getDefaultScanPolicy (new blank)");
    return new ScanPolicy();
  }
Пример #4
0
  public void init() {

    // read network configuration
    Configuration config = null;
    try {
      config = new PropertiesConfiguration("network.cfg");
    } catch (ConfigurationException e) {
      e.printStackTrace();
    }

    urls = config.getStringArray("node.url");
    processes = new ArrayList<DA_Schiper_Eggli_Sandoz_RMI>();

    // locate processes
    for (String url : urls) {
      try {
        DA_Schiper_Eggli_Sandoz_RMI process = (DA_Schiper_Eggli_Sandoz_RMI) Naming.lookup(url);
        process.reset();
        processes.add(process);

      } catch (RemoteException e1) {
        e1.printStackTrace();
      } catch (NotBoundException e2) {
        e2.printStackTrace();
      } catch (MalformedURLException e3) {
        e3.printStackTrace();
      }
    }
  }
  public static ApplicationData CreateApplicationData() {
    try {
      Configuration configFile =
          new PropertiesConfiguration("com/ipcommerce/CWS/Resources/cws.properties");
      ApplicationData appData = new ApplicationData();
      appData.setSoftwareVersion(configFile.getString("SOFTWARE_VERSION"));
      // TODO fix this reading of calendar date - its wrong
      Calendar cal = Calendar.getInstance();
      try {
        cal.setTime(new SimpleDateFormat().parse(configFile.getString("SOFTWARE_VERSION_DATE")));
      } catch (ParseException e) {
        cal.getTime();
      }
      appData.setSoftwareVersionDate(cal);
      appData.setDeviceSerialNumber(configFile.getString("DEVICE_SERIAL_NUMBER"));
      appData.setApplicationAttended(Boolean.valueOf(configFile.getString("APPLICATION_ATTENDED")));
      appData.setApplicationLocation(
          ApplicationLocation.fromValue(configFile.getString("APPLICATION_LOCATION")));
      appData.setPTLSSocketId(configFile.getString("PTLS_SOCKET_ID"));
      appData.setEncryptionType(EncryptionType.fromValue(configFile.getString("ENCRYPTION_TYPE")));
      appData.setApplicationName(configFile.getString("APPLICATION_NAME"));
      appData.setSerialNumber(configFile.getString("SERIAL_NUMBER"));
      appData.setHardwareType(HardwareType.fromValue(configFile.getString("HARDWARE_TYPE")));
      appData.setPINCapability(PINCapability.fromValue(configFile.getString("PIN_CAPABILITY")));
      appData.setReadCapability(ReadCapability.fromValue(configFile.getString("READ_CAPABILITY")));
      return appData;

    } catch (org.apache.commons.configuration.ConfigurationException e) {
      System.out.println("ConfigurationException: " + e.getMessage());
    }
    return null;
  }
  @Test
  public void testDownloadPeopleJdo() {

    ClientFactory cf = null;
    try {
      cf = new ClientFactory(new File(configfilepath));
    } catch (ConfigurationException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (cf == null) {
      fail("no client factory");
    }

    String kind = "PeopleJdo";
    EntityStat es = cf.getAppEngineUtils().getStat(kind);
    long offset = 0;
    int limit = 10;
    Long finish = 100l;
    Long total = es.getCount();

    // download 100 of
    DownloadKind dk = new DownloadKind(cf);
    dk.setLimit(offset, limit, finish, total);
    dk.setKind(kind);
    dk.run();

    System.out.println("finished test");
  }
Пример #7
0
  /** @param args */
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
      config.addConfiguration(new PropertiesConfiguration("storage.properties"));
    } catch (ConfigurationException e) {
      // TODO Auto-generated catch block
      logger.error(e.getMessage());
    }

    String rootFolder = config.getString("bp.root.folder");

    String altpartyid = args[0];

    SqlSession sqlSession = RazorServer.openSession();
    try {
      if (StringUtils.isBlank(altpartyid)) {
        //				altpartyid = "231051"; //NextPax partner GA
        altpartyid = "179795";
      }

      Partner partner = sqlSession.getMapper(PartnerMapper.class).exists(altpartyid);
      if (partner == null) {
        throw new ServiceException(Error.party_id, altpartyid);
      }
      A_Handler handler = new A_Handler(partner);
      handler.downloadImages(rootFolder);
    } catch (Exception e) {
      logger.error(e.getMessage());
    }
  }
Пример #8
0
  static {
    try {
      _configuration = new PropertiesConfiguration("zipper.properties");

    } catch (ConfigurationException e) {
      e.printStackTrace();
    }
  }
Пример #9
0
  public void loadConfig(String file) {
    try {
      xml = new XMLConfiguration();
      xml.load(file);

    } catch (ConfigurationException cex) {
      cex.printStackTrace();
      System.exit(1);
    }
  }
Пример #10
0
 /**
  * Dado el nombre de un fichero <b>Properties</b> genera una instancia del objeto que gestiona el
  * fichero mediante <i>Apache commons-configuration</i>.
  *
  * @param filename del fichero de propiedades <i>(p.e.: config.properties)</i>.
  * @throws ConfigUtilException si el fichero no existe
  */
 public ConfigPropertiesUtil(String filename) throws ConfigUtilException {
   try {
     configuration = new PropertiesConfiguration(filename);
     configuration.load();
   } catch (ConfigurationException ce) {
     throw new ConfigUtilException(ce.getMessage(), ce);
   } catch (Exception e) {
     throw new ConfigUtilException(e.getMessage(), e);
   }
 }
Пример #11
0
  public void write(String filename) {
    if (!filename.endsWith(".xml")) filename += ".xml";
    log.info("write vrp: " + filename);
    XMLConf xmlConfig = new XMLConf();
    xmlConfig.setFileName(filename);
    xmlConfig.setRootElementName("problem");
    xmlConfig.setAttributeSplittingDisabled(true);
    xmlConfig.setDelimiterParsingDisabled(true);

    writeProblemType(xmlConfig);
    writeVehiclesAndTheirTypes(xmlConfig);

    // might be sorted?
    List<Job> jobs = new ArrayList<Job>();
    jobs.addAll(vrp.getJobs().values());
    for (VehicleRoute r : vrp.getInitialVehicleRoutes()) {
      jobs.addAll(r.getTourActivities().getJobs());
    }

    writeServices(xmlConfig, jobs);
    writeShipments(xmlConfig, jobs);

    writeInitialRoutes(xmlConfig);
    writeSolutions(xmlConfig);

    OutputFormat format = new OutputFormat();
    format.setIndenting(true);
    format.setIndent(5);

    try {
      Document document = xmlConfig.createDoc();

      Element element = document.getDocumentElement();
      element.setAttribute("xmlns", "http://www.w3schools.com");
      element.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      element.setAttribute("xsi:schemaLocation", "http://www.w3schools.com vrp_xml_schema.xsd");

    } catch (ConfigurationException e) {
      logger.error("Exception:", e);
      e.printStackTrace();
      System.exit(1);
    }

    try {
      Writer out = new FileWriter(filename);
      XMLSerializer serializer = new XMLSerializer(out, format);
      serializer.serialize(xmlConfig.getDocument());
      out.close();
    } catch (IOException e) {
      logger.error("Exception:", e);
      e.printStackTrace();
      System.exit(1);
    }
  }
 public InformationExtractionConfiguration() {
   String fileName = getExtractionXmlFilename();
   XmlPropertiesConfiguration config;
   try {
     config = new XmlPropertiesConfiguration(fileName);
     LOGGER.debug("Loaded configuration from {}", fileName);
   } catch (ConfigurationException e) {
     throw new IllegalStateException(
         "Error while loading the configuration from " + fileName + ": " + e.getMessage());
   }
   setConfiguration(config);
 }
Пример #13
0
  /** @see Plugin#init() */
  public void init() throws PluginException {
    try {
      if (System.getProperty("roda.home") != null) {
        RODA_HOME = System.getProperty("roda.home");
      } else if (System.getenv("RODA_HOME") != null) {
        RODA_HOME = System.getenv("RODA_HOME");
      } else {
        RODA_HOME = null;
      }
      if (StringUtils.isBlank(RODA_HOME)) {
        throw new PluginException(
            "RODA_HOME enviroment variable and ${roda.home} system property are not set.");
      }
      final File pluginsConfigDirectory = new File(new File(RODA_HOME, "config"), "plugins");

      final File configFile = new File(pluginsConfigDirectory, CONFIGURATION_FILENAME);
      final PropertiesConfiguration configuration = new PropertiesConfiguration();

      if (configFile.isFile()) {
        configuration.load(configFile);
        logger.info("Loading configuration file from " + configFile);
      } else {
        configuration.load(getClass().getResourceAsStream("/" + CONFIGURATION_FILENAME));
        logger.info("Loading default configuration file from resources");
      }

      taverna_bin = configuration.getString("taverna_bin");
      logger.debug("taverna_bin=" + taverna_bin);

      xpathSelectIDs = configuration.getString("xpathSelectIDs");
      logger.debug("xpathSelectIDs=" + xpathSelectIDs);

      xpathSelectWorkflow = configuration.getString("xpathSelectWorkflow");
      logger.debug("xpathSelectWorkflow=" + xpathSelectWorkflow);

      workflowInputPort = configuration.getString("workflowInputPort");
      logger.debug("workflowInputPort=" + workflowInputPort);

      workflowOutputPort = configuration.getString("workflowOutputPort");
      logger.debug("workflowOutputPort=" + workflowOutputPort);

      workflowExtraPorts = configuration.getStringArray("workflowExtraPorts");
      logger.debug("workflowExtraPorts=" + Arrays.asList(workflowExtraPorts));

    } catch (ConfigurationException ex) {
      logger.debug("Error reading plugin configuration - " + ex.getMessage(), ex);
      throw new PluginException("Error reading plugin configuration - " + ex.getMessage(), ex);
    }

    planFile = new File(new File(RODA_HOME, "data"), PLAN_FILENAME);

    logger.debug("init() OK");
  }
Пример #14
0
  public static GitRepositoryState getGitRepositoryState() {

    if (gitRepositoryState == null) {
      PropertiesConfiguration config;
      try {
        config = new PropertiesConfiguration("git.properties");
        gitRepositoryState = new GitRepositoryState(config);
      } catch (ConfigurationException e) {
        e.printStackTrace();
      }
    }
    return gitRepositoryState;
  }
  @Override
  public void contextInitialized(ServletContextEvent ctxEvt) {
    ServletContext ctx = ctxEvt.getServletContext();
    String confFileName = ctx.getInitParameter(SENSEI_CONF_FILE_PARAM);

    File confFile = new File(confFileName);
    try {
      PropertiesConfiguration conf = new PropertiesConfiguration(confFile);
      ctx.setAttribute(SENSEI_CONF_OBJ, conf);
    } catch (ConfigurationException e) {
      logger.error(e.getMessage(), e);
    }
  }
Пример #16
0
  // Saves the settings to config file.
  public static void saveSettings(Settings settings) {
    config.setProperty("vlclocation", settings.getVlcLocation());
    config.setProperty("thumbnailcount", settings.getThumbnailCount());
    config.setProperty("thumbnailwidth", settings.getThumbnailWidth());
    config.setProperty("thumbnailhighlightcolor", settings.getThumbnailHighlightColor());
    config.setProperty("folders", String.join("|", settings.getFolders()));

    try {
      config.save("vidor.config");
    } catch (ConfigurationException ex) {
      ex.printStackTrace();
    }
  }
Пример #17
0
 protected void saveTabState(AbstractPanel ap) {
   if (ap == null) {
     return;
   }
   Model.getSingleton()
       .getOptionsParam()
       .getConfig()
       .setProperty(OptionsParamView.TAB_PIN_OPTION + "." + safeName(ap.getName()), ap.isPinned());
   try {
     Model.getSingleton().getOptionsParam().getConfig().save();
   } catch (ConfigurationException e) {
     logger.error(e.getMessage(), e);
   }
 }
Пример #18
0
 @Test
 public void testConfigObject() throws JSONException {
   ProjectConfig cp = ProjectConfig.getInstance().init();
   cp.setProperties("aaaa", RoundingMode.HALF_EVEN);
   try {
     cp.save();
   } catch (ConfigurationException e) {
     e.printStackTrace();
   }
   Object property = cp.getReadOnlyConfiguration().getProperty("aaaa");
   System.out.println(
       property + ": instanceof of RoundingMode:" + (property instanceof RoundingMode));
   System.out.println(JSONUtil.serialize(cp.getReadOnlyConfiguration()));
 }
Пример #19
0
  private BaiduDriver() {
    Configuration config = null;
    try {
      config = new XMLConfiguration(BaiduDriver.class.getClassLoader().getResource("Cloud.xml"));
    } catch (ConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    this.ACCESS_KEY_ID = config.getString("Baidu.ACCESS_KEY_ID");
    this.SECRET_ACCESS_KEY = config.getString("Baidu.SECRET_ACCESS_KEY");

    BosClientConfiguration bosconfig = new BosClientConfiguration();
    bosconfig.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
    baiduClient = new BosClient(bosconfig);
  }
Пример #20
0
  public void read(String filename) {
    logger.info("read vrp from file " + filename);
    XMLConfiguration xmlConfig = new XMLConfiguration();
    xmlConfig.setFileName(filename);
    xmlConfig.setAttributeSplittingDisabled(true);
    xmlConfig.setDelimiterParsingDisabled(true);

    if (schemaValidation) {
      final InputStream resource = Resource.getAsInputStream("vrp_xml_schema.xsd");
      if (resource != null) {
        EntityResolver resolver =
            new EntityResolver() {

              @Override
              public InputSource resolveEntity(String publicId, String systemId)
                  throws SAXException, IOException {
                {
                  InputSource is = new InputSource(resource);
                  return is;
                }
              }
            };
        xmlConfig.setEntityResolver(resolver);
        xmlConfig.setSchemaValidation(true);
        logger.info("validating " + filename + " with xsd-schema");
      } else {
        logger.warn(
            "cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation.");
      }
    }
    try {
      xmlConfig.load();
    } catch (ConfigurationException e) {
      logger.error(e);
      e.printStackTrace();
      System.exit(1);
    }
    readProblemType(xmlConfig);
    readVehiclesAndTheirTypes(xmlConfig);

    readShipments(xmlConfig);
    readServices(xmlConfig);

    readInitialRoutes(xmlConfig);
    readSolutions(xmlConfig);

    addJobsAndTheirLocationsToVrp();
  }
Пример #21
0
  /**
   * Loads our SQL statements from the appropriate properties file
   *
   * @param vendor DB vendor string. Must be one of mysql, oracle, hsqldb
   */
  private void initStatements(String vendor) {

    URL url = getClass().getClassLoader().getResource(vendor + ".properties");

    try {
      statements =
          new PropertiesConfiguration(); // must use blank constructor so it doesn't parse just yet
                                         // (as it will split)
      statements.setReloadingStrategy(new InvariantReloadingStrategy()); // don't watch for reloads
      statements.setThrowExceptionOnMissing(true); // throw exception if no prop
      statements.setDelimiterParsingDisabled(true); // don't split properties
      statements.load(url); // now load our file
    } catch (ConfigurationException e) {
      log.error(e.getClass() + ": " + e.getMessage(), e);
      return;
    }
  }
Пример #22
0
  /** @see Plugin#init() */
  public void init() throws PluginException {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    try {

      String RODA_HOME = null;

      if (System.getProperty("roda.home") != null) {
        RODA_HOME = System.getProperty("roda.home"); // $NON-NLS-1$
      } else if (System.getenv("RODA_HOME") != null) {
        RODA_HOME = System.getenv("RODA_HOME"); // $NON-NLS-1$
      } else {
        RODA_HOME = null;
      }

      if (StringUtils.isBlank(RODA_HOME)) {
        throw new PluginException(
            "RODA_HOME enviroment variable and ${roda.home} system property are not set.");
      }

      File RODA_PLUGINS_CONFIG_DIRECTORY = new File(new File(RODA_HOME, "config"), "plugins");

      File configFile = new File(RODA_PLUGINS_CONFIG_DIRECTORY, getConfigurationFile());

      logger.debug("Trying to load configuration file from " + configFile);

      if (configFile.isFile()) {
        configuration.load(configFile);
        logger.info("Loading configuration file from " + configFile);
      } else {
        configuration.load(getClass().getResourceAsStream(getConfigurationFile()));
        logger.info("Loading default configuration file from resources");
      }

      this.converterServiceURL = configuration.getString("converterServiceURL");

      this.representationSubTypes = configuration.getStringArray("representationSubTypes");
      if (this.representationSubTypes == null) {
        this.representationSubTypes = new String[0];
      }

    } catch (ConfigurationException e) {
      logger.debug("Error reading plugin configuration - " + e.getMessage(), e);
      throw new PluginException("Error reading plugin configuration - " + e.getMessage(), e);
    }
  }
Пример #23
0
  /**
   * Tests that the old element security.authentication.name is rejected. This element was never
   * supported properly as authentication is performed before the virtual host is considered.
   */
  public void testSecurityAuthenticationNameRejected() throws Exception {
    getConfigXml()
        .addProperty(
            "virtualhosts.virtualhost.testSecurityAuthenticationNameRejected.security.authentication.name",
            "testdb");

    try {
      super.createBroker();
      fail("Exception not thrown");
    } catch (ConfigurationException ce) {
      assertEquals(
          "Incorrect error message",
          "Validation error : security/authentication/name is no longer a supported element within the configuration xml."
              + " It appears in virtual host definition : "
              + getName(),
          ce.getMessage());
    }
  }
Пример #24
0
 static {
   if (config == null) {
     synchronized (ApiConf.class) {
       if (config == null)
         try {
           entity = new HashMap();
           config = new XMLConfiguration("entity.xml");
           String[] nrs = config.getStringArray("entities.entity.nr");
           String[] ids = config.getStringArray("entities.entity.id");
           for (int i = 0; i < nrs.length; i++) {
             entity.put(nrs[i], ids[i]);
           }
         } catch (ConfigurationException e) {
           e.printStackTrace();
         }
     }
   }
 }
Пример #25
0
  @Override
  public void prepare(
      @SuppressWarnings("rawtypes") Map stormConf,
      TopologyContext context,
      OutputCollector collector) {
    this.collector = collector;

    this.debugMode = stormConf.get("debug").equals("true");
    if (this.debugMode) {
      LOGGER.info("Debug mode is on, will use replication factor of 1 for HDFS");
    }

    // Load target datasource directories from Storm configuration
    try {
      Map<String, Configuration> datasourcesConfigurations =
          IngestionTopology.deserializeConfigurations(
              (Map<String, String>) stormConf.get(IngestionTopology.DATASOURCE_CONF_KEY));
      this.datasourcesDirectories = new HashMap<String, String>();
      for (Map.Entry<String, Configuration> datasourceConfig :
          datasourcesConfigurations.entrySet()) {
        this.datasourcesDirectories.put(
            datasourceConfig.getKey(), datasourceConfig.getValue().getString("hdfs_path"));
      }
    } catch (ConfigurationException ce) {
      LOGGER.error("Error parsing datasource configurations: " + ce.getMessage());
      throw new RuntimeException(ce);
    }

    // Create objects to interact with HDFS
    // This configuration reads from the default files
    this.hadoopConf = new org.apache.hadoop.conf.Configuration(true);
    hadoopConf.addResource(new Path(stormConf.get("hadoop.res.core-site").toString()));
    hadoopConf.addResource(new Path(stormConf.get("hadoop.res.hdfs-site").toString()));

    try {
      this.hdfs = FileSystem.get(this.hadoopConf);
    } catch (IOException ioe) {
      LOGGER.error("Error connecting to HDFS: " + ioe.getMessage());
      throw new RuntimeException(ioe);
    }

    // Initialize cache for DataFileWriter objects
    this.writersCache = createWritersCache();
  }
Пример #26
0
  private TestData() {
    try {
      // Load the configuration file
      config = new PropertiesConfiguration("./config/config.properties");

      // Make sure the test data folder exists
      dataFolder = new File(config.getString("test.folder"));
      //            if (!dataFolder.exists())
      //                dataFolder.createNewFile();

    } catch (ConfigurationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
      //        } catch (IOException e) {
      //            e.printStackTrace();  //To change body of catch statement use File | Settings |
      // File Templates.
    }
  }
  /**
   * This method needs to be called to initialize the Data Controller correctly.<br>
   * Note that this method must only be called once.
   *
   * @param configurationFile
   * @throws DataControllerInitializingException
   */
  public void init(File configurationFile) throws DataControllerInitializingException {
    logger.debug("Initializing Data Controller");

    if (initialized) {
      // Class was already initialized
      logger.error("Controller was already initialized");
      throw new DataControllerInitializingException("Controller was already initialized");
    } else {
      // Initialize
      try {
        propertiesConfiguration = new PropertiesConfiguration(configurationFile);
      } catch (ConfigurationException e) {
        logger.error("Error while loading the properties");
        throw new DataControllerInitializingException(e.getMessage());
      }
      logger.debug("Initializing Data Controller finished");
      this.initialized = true;
    }
  }
Пример #28
0
  @Test
  public void testPropertiesConfiguration() {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    try {
      System.out.println(builder.getConfigurationBasePath());
      System.out.println(
          FileSystem.getDefaultFileSystem().getFileName("pss-settings.properties").toString());
      URL locate =
          ConfigurationUtils.locate(
              "E:/study/jelyworkspace/jelypss/pss-core/target/test-classes/conf",
              "pss-settings.properties");
      builder.load(locate);
      Configuration config = builder.getConfiguration();
      config.setProperty("1123", "asdf");

    } catch (ConfigurationException e) {
      e.printStackTrace();
    }
  }
  public CombinedConfiguration loadConfig() throws ConfigurationException {

    if (combinedConfig == null) {
      combinedConfig = new FileSystemResource(DEFAULT_COMBINED_CONFIG);
    }

    CombinedConfiguration config = null;
    try {
      DefaultConfigurationBuilder builder =
          new DefaultConfigurationBuilder(combinedConfig.getFile());
      boolean load = true;
      config = builder.getConfiguration(load);
      config.setExpressionEngine(new XPathExpressionEngine());
    } catch (org.apache.commons.configuration.ConfigurationException e) {
      throw new ConfigurationException(e.getMessage(), e);
    } catch (IOException e) {
      throw new ConfigurationException(e.getMessage(), e);
    }
    return config;
  }
Пример #30
0
  public LdapTestsSetup() {
    String confFile = System.getenv("LDAP_TESTER_PROPERTIES_FILE");
    if (confFile == null) {
      confFile = "ldap.integ/ldap-test.properties";
    }

    try {
      testProperties = new PropertiesConfiguration(confFile);

      Configuration usersSubset = testProperties.subset("users");
      HierarchicalConfiguration usersConfig = ConfigurationUtils.convertToHierarchical(usersSubset);
      List<ConfigurationNode> childrens = usersConfig.getRootNode().getChildren();
      for (ConfigurationNode node : childrens) {
        String name = node.getName();
        users.put(name, new Person(usersSubset.subset(name)));
      }

      Configuration groupsSubset = testProperties.subset("groups");
      HierarchicalConfiguration groupsConfig =
          ConfigurationUtils.convertToHierarchical(groupsSubset);
      childrens = groupsConfig.getRootNode().getChildren();
      for (ConfigurationNode node : childrens) {
        String name = node.getName();
        groups.put(name, new Group(groupsSubset.subset(name)));
      }

      Configuration ldapConfigurationSubset = testProperties.subset("configuration");
      HierarchicalConfiguration ldapConfig =
          ConfigurationUtils.convertToHierarchical(ldapConfigurationSubset);
      childrens = ldapConfig.getRootNode().getChildren();
      for (ConfigurationNode node : childrens) {
        String key = node.getName();
        String value = (String) node.getValue();
        ldapConfiguration.put(key, value);
      }
    } catch (ConfigurationException ex) {
      String message = "Problem loading configuration: " + ex.getMessage();
      log.error(message);
      throw new IllegalStateException(message);
    }
  }